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

Unified Diff: chrome/browser/android/offline_pages/offline_page_info_handler.cc

Issue 2310363002: Persist offline page info in a navigation entry if needed (Closed)
Patch Set: Fix win compiling error due to using unique_ptr map in SESSIONS_EXPORT class Created 4 years, 3 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: chrome/browser/android/offline_pages/offline_page_info_handler.cc
diff --git a/chrome/browser/android/offline_pages/offline_page_info_handler.cc b/chrome/browser/android/offline_pages/offline_page_info_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..204a524e93dff520cd71e9a5f7242a13e177a091
--- /dev/null
+++ b/chrome/browser/android/offline_pages/offline_page_info_handler.cc
@@ -0,0 +1,64 @@
+// Copyright 2016 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 "chrome/browser/android/offline_pages/offline_page_info_handler.h"
+
+#include "base/strings/string_util.h"
+#include "components/offline_pages/request_header/offline_page_header.h"
+#include "components/sessions/content/content_serialized_navigation_driver.h"
+#include "content/public/browser/navigation_entry.h"
+
+namespace offline_pages {
+
+namespace {
+const char kOfflinePageInfoKey[] = "offline";
+}
+
+// static
+void OfflinePageInfoHandler::Register() {
+ std::unique_ptr<OfflinePageInfoHandler> instance(new OfflinePageInfoHandler);
+ sessions::ContentSerializedNavigationDriver::GetInstance()
+ ->RegisterExtendedInfoHandler(kOfflinePageInfoKey, std::move(instance));
+}
+
+OfflinePageInfoHandler::OfflinePageInfoHandler() {}
+
+OfflinePageInfoHandler::~OfflinePageInfoHandler() {}
+
+std::string OfflinePageInfoHandler::GetExtendedInfo(
+ const content::NavigationEntry& entry) const {
+ std::string extra_headers = entry.GetExtraHeaders();
+ if (extra_headers.empty())
+ return std::string();
+
+ // The offline header will be the only extra header if it is present.
+ std::string offline_header_key(offline_pages::kOfflinePageHeader);
+ offline_header_key += ": ";
+ if (!base::StartsWith(extra_headers, offline_header_key,
+ base::CompareCase::INSENSITIVE_ASCII)) {
+ return std::string();
+ }
+ std::string header_value = extra_headers.substr(offline_header_key.length());
+ if (header_value.find("\n") != std::string::npos)
+ return std::string();
+
+ OfflinePageHeader header(header_value);
+ if (!header.need_to_persist)
+ return std::string();
+
+ return header_value;
+}
+
+void OfflinePageInfoHandler::RestoreExtendedInfo(
+ const std::string& info,
+ content::NavigationEntry* entry) {
+ OfflinePageHeader header(info);
+ // Some sanity check.
+ if (header.reason == OfflinePageHeader::Reason::NONE ||
+ !header.need_to_persist)
+ return;
+ entry->AddExtraHeaders(header.GetCompleteHeaderString());
+}
+
+} // namespace offline_pages
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_info_handler.h ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698