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

Side by Side Diff: components/sessions/content/content_serialized_navigation_builder.cc

Issue 2310363002: Persist offline page info in a navigation entry if needed (Closed)
Patch Set: Update 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sessions/content/content_serialized_navigation_builder.h" 5 #include "components/sessions/content/content_serialized_navigation_builder.h"
6 6
7 #include "base/logging.h"
7 #include "components/sessions/content/content_record_password_state.h" 8 #include "components/sessions/content/content_record_password_state.h"
9 #include "components/sessions/content/content_serialized_navigation_driver.h"
10 #include "components/sessions/content/extended_info_handler.h"
8 #include "components/sessions/core/serialized_navigation_entry.h" 11 #include "components/sessions/core/serialized_navigation_entry.h"
9 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/favicon_status.h" 13 #include "content/public/browser/favicon_status.h"
11 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/common/page_state.h" 16 #include "content/public/common/page_state.h"
14 #include "content/public/common/referrer.h" 17 #include "content/public/common/referrer.h"
15 18
16 namespace sessions { 19 namespace sessions {
17 20
(...skipping 17 matching lines...) Expand all
35 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); 38 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent();
36 navigation.timestamp_ = entry.GetTimestamp(); 39 navigation.timestamp_ = entry.GetTimestamp();
37 navigation.is_restored_ = entry.IsRestored(); 40 navigation.is_restored_ = entry.IsRestored();
38 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); 41 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_);
39 if (entry.GetFavicon().valid) 42 if (entry.GetFavicon().valid)
40 navigation.favicon_url_ = entry.GetFavicon().url; 43 navigation.favicon_url_ = entry.GetFavicon().url;
41 navigation.http_status_code_ = entry.GetHttpStatusCode(); 44 navigation.http_status_code_ = entry.GetHttpStatusCode();
42 navigation.redirect_chain_ = entry.GetRedirectChain(); 45 navigation.redirect_chain_ = entry.GetRedirectChain();
43 navigation.password_state_ = GetPasswordStateFromNavigation(entry); 46 navigation.password_state_ = GetPasswordStateFromNavigation(entry);
44 47
48 for (const auto& handler_entry :
49 ContentSerializedNavigationDriver::GetInstance()->
50 GetAllExtendedInfoHandlers()) {
51 ExtendedInfoHandler* handler = handler_entry.second.get();
52 DCHECK(handler);
53 navigation.extended_info_map_[handler_entry.first] =
sky 2016/09/29 03:08:19 I think you should only add the entry if GetExtend
jianli 2016/09/29 22:02:28 Done.
54 handler->GetExtendedInfo(entry);
55 }
56
45 return navigation; 57 return navigation;
46 } 58 }
47 59
48 // static 60 // static
49 std::unique_ptr<content::NavigationEntry> 61 std::unique_ptr<content::NavigationEntry>
50 ContentSerializedNavigationBuilder::ToNavigationEntry( 62 ContentSerializedNavigationBuilder::ToNavigationEntry(
51 const SerializedNavigationEntry* navigation, 63 const SerializedNavigationEntry* navigation,
52 int page_id, 64 int page_id,
53 content::BrowserContext* browser_context) { 65 content::BrowserContext* browser_context) {
54 blink::WebReferrerPolicy policy = 66 blink::WebReferrerPolicy policy =
(...skipping 16 matching lines...) Expand all
71 entry->SetPageID(page_id); 83 entry->SetPageID(page_id);
72 entry->SetHasPostData(navigation->has_post_data_); 84 entry->SetHasPostData(navigation->has_post_data_);
73 entry->SetPostID(navigation->post_id_); 85 entry->SetPostID(navigation->post_id_);
74 entry->SetOriginalRequestURL(navigation->original_request_url_); 86 entry->SetOriginalRequestURL(navigation->original_request_url_);
75 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_); 87 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_);
76 entry->SetTimestamp(navigation->timestamp_); 88 entry->SetTimestamp(navigation->timestamp_);
77 entry->SetExtraData(kSearchTermsKey, navigation->search_terms_); 89 entry->SetExtraData(kSearchTermsKey, navigation->search_terms_);
78 entry->SetHttpStatusCode(navigation->http_status_code_); 90 entry->SetHttpStatusCode(navigation->http_status_code_);
79 entry->SetRedirectChain(navigation->redirect_chain_); 91 entry->SetRedirectChain(navigation->redirect_chain_);
80 92
93 for (const auto& handler_entry :
sky 2016/09/29 03:08:19 Rather than iterating over the handlers I think it
jianli 2016/09/29 22:02:28 Done.
94 ContentSerializedNavigationDriver::GetInstance()->
95 GetAllExtendedInfoHandlers()) {
96 const std::string& key = handler_entry.first;
97 if (!navigation->extended_info_map_.count(key))
98 continue;
99 ExtendedInfoHandler* handler = handler_entry.second.get();
100 DCHECK(handler);
101 const std::string& value = navigation->extended_info_map_.at(key);
sky 2016/09/29 03:08:19 at -> [key] ?
jianli 2016/09/29 22:02:29 I can't use operator[] since navigation is const t
102 handler->RestoreExtendedInfo(value, entry.get());
103 }
104
81 // These fields should have default values. 105 // These fields should have default values.
82 DCHECK_EQ(SerializedNavigationEntry::STATE_INVALID, 106 DCHECK_EQ(SerializedNavigationEntry::STATE_INVALID,
83 navigation->blocked_state_); 107 navigation->blocked_state_);
84 DCHECK_EQ(0u, navigation->content_pack_categories_.size()); 108 DCHECK_EQ(0u, navigation->content_pack_categories_.size());
85 109
86 return entry; 110 return entry;
87 } 111 }
88 112
89 // static 113 // static
90 std::vector<std::unique_ptr<content::NavigationEntry>> 114 std::vector<std::unique_ptr<content::NavigationEntry>>
91 ContentSerializedNavigationBuilder::ToNavigationEntries( 115 ContentSerializedNavigationBuilder::ToNavigationEntries(
92 const std::vector<SerializedNavigationEntry>& navigations, 116 const std::vector<SerializedNavigationEntry>& navigations,
93 content::BrowserContext* browser_context) { 117 content::BrowserContext* browser_context) {
94 int page_id = 0; 118 int page_id = 0;
95 std::vector<std::unique_ptr<content::NavigationEntry>> entries; 119 std::vector<std::unique_ptr<content::NavigationEntry>> entries;
96 entries.reserve(navigations.size()); 120 entries.reserve(navigations.size());
97 for (const auto& navigation : navigations) { 121 for (const auto& navigation : navigations) {
98 entries.push_back(ToNavigationEntry(&navigation, page_id, browser_context)); 122 entries.push_back(ToNavigationEntry(&navigation, page_id, browser_context));
99 ++page_id; 123 ++page_id;
100 } 124 }
101 return entries; 125 return entries;
102 } 126 }
103 127
104 } // namespace sessions 128 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698