Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: components/offline_pages/background/request_queue_in_memory_store.cc

Issue 2221323003: Add an API to Pause and Resume background offlining requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test break introduced by merge Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/offline_pages/background/request_queue_in_memory_store.h" 5 #include "components/offline_pages/background/request_queue_in_memory_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/offline_pages/background/save_page_request.h" 10 #include "components/offline_pages/background/save_page_request.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } else { 49 } else {
50 result = RequestQueue::UpdateRequestResult::REQUEST_DOES_NOT_EXIST; 50 result = RequestQueue::UpdateRequestResult::REQUEST_DOES_NOT_EXIST;
51 } 51 }
52 results.push_back(std::make_pair(request_id, result)); 52 results.push_back(std::make_pair(request_id, result));
53 } 53 }
54 54
55 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 55 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
56 base::Bind(callback, results)); 56 base::Bind(callback, results));
57 } 57 }
58 58
59 void RequestQueueInMemoryStore::ChangeRequestsState(
60 const std::vector<int64_t>& request_ids,
61 const SavePageRequest::RequestState new_state,
62 const UpdateCallback& callback) {
63 int count = 0;
64
65 for (int64_t request_id : request_ids) {
66 auto pair = requests_.find(request_id);
67 if (pair != requests_.end()) {
68 ++count;
69 pair->second.set_request_state(new_state);
70 }
71 }
72
73 RequestQueueStore::UpdateStatus status =
74 count > 0 ? UpdateStatus::UPDATED : UpdateStatus::FAILED;
75
76 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
77 base::Bind(callback, status));
78 }
79
59 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { 80 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) {
60 requests_.clear(); 81 requests_.clear();
61 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 82 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
62 base::Bind(callback, true)); 83 base::Bind(callback, true));
63 } 84 }
64 85
65 } // namespace offline_pages 86 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698