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

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: CR fixes per DougArnett and FGorski. Also gets rid of status. 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::GetQueuedRequests(
73 const std::string& client_namespace,
74 const QueuedRequestCallback& callback) {
75 // Get all matching requests from the request queue, send them to our
76 // callback. We bind the namespace and callback to the front of the callback
77 // param set.
78 queue_->GetRequests(base::Bind(&RequestCoordinator::GetQueuedRequestsCallback,
79 weak_ptr_factory_.GetWeakPtr(),
80 client_namespace, callback));
81 }
82
83 // For each request matching the client_namespace, return the ClientId.
84 void RequestCoordinator::GetQueuedRequestsCallback(
85 const std::string& client_namespace,
86 QueuedRequestCallback callback,
87 RequestQueue::GetRequestsResult result,
88 const std::vector<SavePageRequest>& requests) {
89 std::vector<ClientId> found_requests;
fgorski 2016/08/03 03:13:15 Consider renaming to client_ids.
Pete Williamson 2016/08/03 20:13:44 Done.
90
91 // TODO(petewil): Is find_if better that a for loop here?
fgorski 2016/08/03 03:13:15 no, it would be incorrect, because: find_if return
Pete Williamson 2016/08/03 20:13:44 Acknowledged.
92 for (auto iter = requests.begin(); iter != requests.end(); ++iter) {
93 if (client_namespace == iter->client_id().name_space) {
fgorski 2016/08/03 03:13:15 nit: remove {}
Pete Williamson 2016/08/03 20:13:44 Done.
94 found_requests.push_back(iter->client_id());
95 }
96 }
97
98 callback.Run(found_requests);
99 }
72 100
73 void RequestCoordinator::AddRequestResultCallback( 101 void RequestCoordinator::AddRequestResultCallback(
74 RequestQueue::AddRequestResult result, 102 RequestQueue::AddRequestResult result,
75 const SavePageRequest& request) { 103 const SavePageRequest& request) {
76 104
77 // Inform the scheduler that we have an outstanding task.. 105 // Inform the scheduler that we have an outstanding task..
78 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); 106 scheduler_->Schedule(GetTriggerConditionsForUserRequest());
79 } 107 }
80 108
81 // Called in response to updating a request in the request queue. 109 // 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; 268 return trigger_conditions;
241 } 269 }
242 270
243 void RequestCoordinator::GetOffliner() { 271 void RequestCoordinator::GetOffliner() {
244 if (!offliner_) { 272 if (!offliner_) {
245 offliner_ = factory_->GetOffliner(policy_.get()); 273 offliner_ = factory_->GetOffliner(policy_.get());
246 } 274 }
247 } 275 }
248 276
249 } // namespace offline_pages 277 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698