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

Unified Diff: components/offline_pages/core/prefetch/prefetch_proto_utils.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/prefetch_proto_utils.cc
diff --git a/components/offline_pages/core/prefetch/prefetch_utils.cc b/components/offline_pages/core/prefetch/prefetch_proto_utils.cc
similarity index 60%
rename from components/offline_pages/core/prefetch/prefetch_utils.cc
rename to components/offline_pages/core/prefetch/prefetch_proto_utils.cc
index 9a25f78975951aca2215fde5b220895fa3102ccd..0fe504049bc45368c1e3c5e567e40727b7f53fbb 100644
--- a/components/offline_pages/core/prefetch/prefetch_utils.cc
+++ b/components/offline_pages/core/prefetch/prefetch_proto_utils.cc
@@ -2,18 +2,23 @@
// 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/prefetch_utils.h"
+#include "components/offline_pages/core/prefetch/prefetch_proto_utils.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "components/offline_pages/core/prefetch/proto/any.pb.h"
#include "components/offline_pages/core/prefetch/proto/offline_pages.pb.h"
+#include "components/offline_pages/core/prefetch/proto/operation.pb.h"
namespace offline_pages {
const char kPageBundleTypeURL[] =
- "type.googleapis.com/chrome.offlinepages.v1.PageBundle";
+ "type.googleapis.com/google.internal.chrome.offlinepages.v1.PageBundle";
+namespace {
+
+// Parse PageBundle data stored as Any proto data. True is returned when the
+// parsing succeeds and the result pages are stored in |pages|.
bool ParsePageBundleInAnyData(const proto::Any& any_data,
std::vector<RenderPageInfo>* pages) {
if (any_data.type_url() != kPageBundleTypeURL) {
@@ -91,4 +96,45 @@ bool ParsePageBundleInAnyData(const proto::Any& any_data,
return true;
}
+bool ParseDoneOperationResponse(const proto::Operation& operation,
+ std::vector<RenderPageInfo>* pages) {
+ switch (operation.result_case()) {
+ case proto::Operation::kError:
+ DCHECK_NE(proto::OK, operation.error().code());
+ DVLOG(1) << "Error found in operation: " << operation.error().code()
+ << operation.error().message();
+ return false;
+ case proto::Operation::kResponse:
+ return ParsePageBundleInAnyData(operation.response(), pages);
+ default:
+ DVLOG(1) << "Result not set in operation";
+ return false;
+ }
+}
+
+bool ParsePendingOperationResponse(const proto::Operation& operation,
+ std::vector<RenderPageInfo>* pages) {
+ if (!operation.has_metadata()) {
+ DVLOG(1) << "metadata not found in GeneratePageBundle response";
+ return false;
+ }
+ return ParsePageBundleInAnyData(operation.metadata(), pages);
+}
+
+} // namespace
+
+bool ParseOperationResponse(const std::string& data,
+ std::vector<RenderPageInfo>* pages) {
+ proto::Operation operation;
+ if (!operation.ParseFromString(data)) {
+ DVLOG(1) << "Failed to parse operation";
+ return false;
+ }
+
+ if (operation.done())
+ return ParseDoneOperationResponse(operation, pages);
+ else
+ return ParsePendingOperationResponse(operation, pages);
+}
+
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698