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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/background/request_coordinator.cc
diff --git a/components/offline_pages/background/request_coordinator.cc b/components/offline_pages/background/request_coordinator.cc
index 5876d8386d79b7c3834f6cf9b7d72bd22f8c38cd..7e7862f2e6d3155c151ceed7fd503902f3a38c4d 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -69,6 +69,37 @@ bool RequestCoordinator::SavePageLater(
weak_ptr_factory_.GetWeakPtr()));
return true;
}
+void RequestCoordinator::GetRequestStatuses(
+ std::string client_namespace, RequestStatusCallback callback) {
+ // Get all requests from the request queue, send them to our callback. We
+ // bind the namespace and callback to the front of the callback param set.
+ queue_->GetRequests(base::Bind(
+ &RequestCoordinator::GetRequestStatusesCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ client_namespace, callback));
+}
+
+// For each request matching the client_namespace, put the ClientID and
+// status into a RequestStatus object.
+void RequestCoordinator::GetRequestStatusesCallback(
+ std::string client_namespace,
+ RequestStatusCallback callback,
+ RequestQueue::GetRequestsResult result,
+ const std::vector<SavePageRequest>& requests) {
+ std::vector<RequestStatus> found_requests;
+
+ // TODO(petewil): Is find_if better?
+ 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
+ if (client_namespace == iter->client_id().name_space) {
+ RequestStatus status(iter->client_id().id,
+ 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
+ found_requests.push_back(status);
+ }
+ }
+
+ callback.Run(found_requests);
+
fgorski 2016/08/02 04:18:11 nit: remove extra line
Pete Williamson 2016/08/03 00:24:31 Done.
+}
void RequestCoordinator::AddRequestResultCallback(
RequestQueue::AddRequestResult result,

Powered by Google App Engine
This is Rietveld 408576698