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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/offline_pages/offline_page_info_handler.h"
6
7 #include "base/strings/string_util.h"
8 #include "components/offline_pages/request_header/offline_page_header.h"
9 #include "components/sessions/content/content_serialized_navigation_driver.h"
10 #include "content/public/browser/navigation_entry.h"
11
12 namespace offline_pages {
13
14 namespace {
15 const char kOfflinePageInfoKey[] = "offline";
16 }
17
18 // static
19 void OfflinePageInfoHandler::Register() {
20 std::unique_ptr<OfflinePageInfoHandler> instance(new OfflinePageInfoHandler);
21 sessions::ContentSerializedNavigationDriver::GetInstance()
22 ->RegisterExtendedInfoHandler(kOfflinePageInfoKey, std::move(instance));
23 }
24
25 OfflinePageInfoHandler::OfflinePageInfoHandler() {}
26
27 OfflinePageInfoHandler::~OfflinePageInfoHandler() {}
28
29 std::string OfflinePageInfoHandler::GetExtendedInfo(
30 const content::NavigationEntry& entry) const {
31 std::string extra_headers = entry.GetExtraHeaders();
32 if (extra_headers.empty())
33 return std::string();
34
35 // The offline header will be the only extra header if it is present.
36 std::string offline_header_key(offline_pages::kOfflinePageHeader);
37 offline_header_key += ": ";
38 if (!base::StartsWith(extra_headers, offline_header_key,
39 base::CompareCase::INSENSITIVE_ASCII)) {
40 return std::string();
41 }
42 std::string header_value = extra_headers.substr(offline_header_key.length());
43 if (header_value.find("\n") != std::string::npos)
44 return std::string();
45
46 OfflinePageHeader header(header_value);
47 if (!header.need_to_persist)
48 return std::string();
49
50 return header_value;
51 }
52
53 void OfflinePageInfoHandler::RestoreExtendedInfo(
54 const std::string& info,
55 content::NavigationEntry* entry) {
56 OfflinePageHeader header(info);
57 // Some sanity check.
58 if (header.reason == OfflinePageHeader::Reason::NONE ||
59 !header.need_to_persist)
60 return;
61 entry->AddExtraHeaders(header.GetCompleteHeaderString());
62 }
63
64 } // namespace offline_pages
OLDNEW
« 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