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

Unified Diff: components/offline_pages/background/request_coordinator.cc

Issue 1969463002: Add a save page request to the request queue (and test it). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More CR feedback from FGorski Created 4 years, 7 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 e2270fbfd99f8df5e2b9e6a5eb2a7fd7a232fce3..bf447575773bc00e0defe3b16d72bbbdf0695afa 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "base/bind.h"
#include "components/offline_pages/background/offliner_factory.h"
#include "components/offline_pages/background/offliner_policy.h"
#include "components/offline_pages/background/save_page_request.h"
@@ -13,27 +14,48 @@
namespace offline_pages {
-RequestCoordinator::RequestCoordinator(
- std::unique_ptr<OfflinerPolicy> policy,
- std::unique_ptr<OfflinerFactory> factory) {
+RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
+ std::unique_ptr<OfflinerFactory> factory,
+ std::unique_ptr<RequestQueue> queue) {
// Do setup as needed.
// TODO(petewil): Assert policy not null.
policy_ = std::move(policy);
factory_ = std::move(factory);
+ queue_ = std::move(queue);
}
RequestCoordinator::~RequestCoordinator() {}
bool RequestCoordinator::SavePageLater(
const GURL& url, const ClientId& client_id) {
+ DVLOG(2) << "URL is " << url << " " << __FUNCTION__;
// TODO(petewil): We need a robust scheme for allocating new IDs.
- // TODO(petewil): Build a SavePageRequest.
- // TODO(petewil): Put the request on the request queue, nudge the scheduler.
+ static int64_t id = 0;
+
+ // Build a SavePageRequest.
+ // TODO(petewil): Use something like base::Clock to help in testing.
+ offline_pages::SavePageRequest request(
+ id++, url, client_id, base::Time::Now());
+
+ // Put the request on the request queue.
+ queue_->AddRequest(request,
+ base::Bind(&RequestCoordinator::AddRequestResultCallback,
+ AsWeakPtr()));
+ // TODO: Do I need to persist the request in case the add fails?
return true;
}
+void RequestCoordinator::AddRequestResultCallback(
+ RequestQueue::AddRequestResult result,
+ const SavePageRequest& request) {
+ DVLOG(2) << __FUNCTION__;
+
+ // Inform the scheduler that we have an outstanding task.
+ // TODO(petewil): implement.
+}
+
bool RequestCoordinator::StartProcessing(
const ProcessingDoneCallback& callback) {
return false;

Powered by Google App Engine
This is Rietveld 408576698