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

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

Issue 2202113002: API to provide status of save page reqeusts to API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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_coordinator.h" 5 #include "components/offline_pages/background/request_coordinator.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // Build a SavePageRequest. 62 // Build a SavePageRequest.
63 offline_pages::SavePageRequest request( 63 offline_pages::SavePageRequest request(
64 id++, url, client_id, base::Time::Now(), was_user_requested); 64 id++, url, client_id, base::Time::Now(), was_user_requested);
65 65
66 // Put the request on the request queue. 66 // Put the request on the request queue.
67 queue_->AddRequest(request, 67 queue_->AddRequest(request,
68 base::Bind(&RequestCoordinator::AddRequestResultCallback, 68 base::Bind(&RequestCoordinator::AddRequestResultCallback,
69 weak_ptr_factory_.GetWeakPtr())); 69 weak_ptr_factory_.GetWeakPtr()));
70 return true; 70 return true;
71 } 71 }
72 void RequestCoordinator::GetRequestStatuses(
73 std::string client_namespace, RequestStatusCallback callback) {
74 // Get all requests from the request queue, send them to our callback. We
75 // bind the namespace and callback to the front of the callback param set.
76 queue_->GetRequests(base::Bind(
77 &RequestCoordinator::GetRequestStatusesCallback,
78 weak_ptr_factory_.GetWeakPtr(),
79 client_namespace, callback));
80 }
81
82 // For each request matching the client_namespace, put the ClientID and
83 // status into a RequestStatus object.
84 void RequestCoordinator::GetRequestStatusesCallback(
85 std::string client_namespace,
86 RequestStatusCallback callback,
87 RequestQueue::GetRequestsResult result,
88 const std::vector<SavePageRequest>& requests) {
89 std::vector<RequestStatus> found_requests;
90
91 // TODO(petewil): Is find_if better?
92 for(auto iter = requests.begin(); iter != requests.end(); ++iter) {
fgorski 2016/08/02 04:18:11 for (const auto& request : requests) is the simple
Pete Williamson 2016/08/03 00:24:31 Right, find_if would take a lambda and the collect
fgorski 2016/08/03 03:13:15 What I suggested is not a lambda, but a C++11 idio
Pete Williamson 2016/08/03 20:13:44 I changed this to use a ranged for loop as you sug
93 if (client_namespace == iter->client_id().name_space) {
94 RequestStatus status(iter->client_id().id,
95 iter->GetStatus(base::Time::Now()));
fgorski 2016/08/02 04:18:12 consider extracting the time to a variable. Also,
Pete Williamson 2016/08/03 00:24:31 Removed this code instead, we don't need a time an
96 found_requests.push_back(status);
97 }
98 }
99
100 callback.Run(found_requests);
101
fgorski 2016/08/02 04:18:11 nit: remove extra line
Pete Williamson 2016/08/03 00:24:31 Done.
102 }
72 103
73 void RequestCoordinator::AddRequestResultCallback( 104 void RequestCoordinator::AddRequestResultCallback(
74 RequestQueue::AddRequestResult result, 105 RequestQueue::AddRequestResult result,
75 const SavePageRequest& request) { 106 const SavePageRequest& request) {
76 107
77 // Inform the scheduler that we have an outstanding task.. 108 // Inform the scheduler that we have an outstanding task..
78 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); 109 scheduler_->Schedule(GetTriggerConditionsForUserRequest());
79 } 110 }
80 111
81 // Called in response to updating a request in the request queue. 112 // Called in response to updating a request in the request queue.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return trigger_conditions; 271 return trigger_conditions;
241 } 272 }
242 273
243 void RequestCoordinator::GetOffliner() { 274 void RequestCoordinator::GetOffliner() {
244 if (!offliner_) { 275 if (!offliner_) {
245 offliner_ = factory_->GetOffliner(policy_.get()); 276 offliner_ = factory_->GetOffliner(policy_.get());
246 } 277 }
247 } 278 }
248 279
249 } // namespace offline_pages 280 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698