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

Unified Diff: components/offline_pages/core/prefetch/get_operation_request.cc

Issue 2889453003: [Offline Prefetech] Send GetOperationReqest to the server (Closed)
Patch Set: Rebase Created 3 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/core/prefetch/get_operation_request.cc
diff --git a/components/offline_pages/core/prefetch/get_operation_request.cc b/components/offline_pages/core/prefetch/get_operation_request.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1f3a78ac5b59cc3b4359ebd5d77b69024752759c
--- /dev/null
+++ b/components/offline_pages/core/prefetch/get_operation_request.cc
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/offline_pages/core/prefetch/get_operation_request.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "components/offline_pages/core/prefetch/prefetch_proto_utils.h"
+#include "components/offline_pages/core/prefetch/prefetch_request_fetcher.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "url/gurl.h"
+
+namespace offline_pages {
+
+namespace {
+const char kGetOperationURLPath[] = "v1/operations/";
+} // namespace
+
+GetOperationRequest::GetOperationRequest(
+ const std::string& name,
+ net::URLRequestContextGetter* request_context_getter,
+ const PrefetchRequestFinishedCallback& callback)
+ : callback_(callback) {
+ std::string path(kGetOperationURLPath);
+ path += name;
+ fetcher_ = PrefetchRequestFetcher::CreateForGet(
+ path, request_context_getter,
+ base::Bind(&GetOperationRequest::OnCompleted,
+ // Fetcher is owned by this instance.
+ base::Unretained(this)));
+}
+
+GetOperationRequest::~GetOperationRequest() {}
+
+void GetOperationRequest::OnCompleted(PrefetchRequestStatus status,
+ const std::string& data) {
+ if (status != PrefetchRequestStatus::SUCCESS) {
+ callback_.Run(status, std::vector<RenderPageInfo>());
+ return;
+ }
+
+ std::vector<RenderPageInfo> pages;
+ if (!ParseOperationResponse(data, &pages)) {
+ callback_.Run(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
+ std::vector<RenderPageInfo>());
+ return;
+ }
+
+ callback_.Run(PrefetchRequestStatus::SUCCESS, pages);
+}
+
+} // offline_pages

Powered by Google App Engine
This is Rietveld 408576698