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

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: CR feedback per Dimich 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 <algorithm>
7 #include <set> 8 #include <set>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/offline_pages/background/save_page_request.h" 13 #include "components/offline_pages/background/save_page_request.h"
13 14
14 namespace offline_pages { 15 namespace offline_pages {
15 16
16 RequestQueueInMemoryStore::RequestQueueInMemoryStore() {} 17 RequestQueueInMemoryStore::RequestQueueInMemoryStore() {}
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 ++count; 67 ++count;
67 } else { 68 } else {
68 ++iter; 69 ++iter;
69 } 70 }
70 } 71 }
71 72
72 base::ThreadTaskRunnerHandle::Get()->PostTask( 73 base::ThreadTaskRunnerHandle::Get()->PostTask(
73 FROM_HERE, base::Bind(callback, true, count)); 74 FROM_HERE, base::Bind(callback, true, count));
74 } 75 }
75 76
77 void RequestQueueInMemoryStore::ChangeRequestsState(
78 const std::vector<int64_t>& request_ids,
79 const SavePageRequest::RequestState new_state,
80 const UpdateCallback& callback) {
81 int count = 0;
82
83 for (int64_t request_id : request_ids) {
84 auto pair = std::find_if(
85 requests_.begin(), requests_.end(),
fgorski 2016/08/10 16:00:09 I don't think lambda is necessary here, as you we
Pete Williamson 2016/08/10 21:38:00 Ah, good catch, I totally forgot what the map was
86 [request_id](
87 std::pair<const long, offline_pages::SavePageRequest> pair) {
88 return (request_id == pair.second.request_id());
89 });
90 if (pair != requests_.end()) {
91 ++count;
92 pair->second.set_request_state(new_state);
93 }
94 }
95
96 RequestQueueStore::UpdateStatus status =
97 count > 0 ? UpdateStatus::UPDATED : UpdateStatus::FAILED;
fgorski 2016/08/10 16:00:09 what if there were no items? Makes me think that o
Pete Williamson 2016/08/10 21:38:00 Done.
98
99 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
100 base::Bind(callback, status));
101 }
102
76 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) { 103 void RequestQueueInMemoryStore::Reset(const ResetCallback& callback) {
77 requests_.clear(); 104 requests_.clear();
78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 105 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
79 base::Bind(callback, true)); 106 base::Bind(callback, true));
80 } 107 }
81 108
82 } // namespace offline_pages 109 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698