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

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: Clean up naming 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 const QueuedRequestCallback& callback,
87 RequestQueue::GetRequestsResult result,
88 const std::vector<SavePageRequest>& requests) {
89 std::vector<ClientId> client_ids;
90
91 for (const auto& request : requests) {
92 if (client_namespace == request.client_id().name_space)
93 client_ids.push_back(request.client_id());
94 }
95
96 callback.Run(client_ids);
97 }
72 98
73 void RequestCoordinator::RemoveRequests( 99 void RequestCoordinator::RemoveRequests(
74 const std::vector<ClientId>& client_ids) { 100 const std::vector<ClientId>& client_ids) {
75 queue_->RemoveRequestsByClientId( 101 queue_->RemoveRequestsByClientId(
76 client_ids, base::Bind(&RequestCoordinator::UpdateRequestCallback, 102 client_ids, base::Bind(&RequestCoordinator::UpdateRequestCallback,
77 weak_ptr_factory_.GetWeakPtr())); 103 weak_ptr_factory_.GetWeakPtr()));
78 } 104 }
79 105
80 void RequestCoordinator::AddRequestResultCallback( 106 void RequestCoordinator::AddRequestResultCallback(
81 RequestQueue::AddRequestResult result, 107 RequestQueue::AddRequestResult result,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return trigger_conditions; 294 return trigger_conditions;
269 } 295 }
270 296
271 void RequestCoordinator::GetOffliner() { 297 void RequestCoordinator::GetOffliner() {
272 if (!offliner_) { 298 if (!offliner_) {
273 offliner_ = factory_->GetOffliner(policy_.get()); 299 offliner_ = factory_->GetOffliner(policy_.get());
274 } 300 }
275 } 301 }
276 302
277 } // namespace offline_pages 303 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698