Index: components/sessions/serialized_navigation_entry.cc |
diff --git a/components/sessions/serialized_navigation_entry.cc b/components/sessions/serialized_navigation_entry.cc |
index 969a1270e470f18fe2ef598804e855cf2f50a1f9..862a6efb9be214620fe02c2a67253d5ed9e71353 100644 |
--- a/components/sessions/serialized_navigation_entry.cc |
+++ b/components/sessions/serialized_navigation_entry.cc |
@@ -55,6 +55,7 @@ SerializedNavigationEntry SerializedNavigationEntry::FromNavigationEntry( |
if (entry.GetFavicon().valid) |
navigation.favicon_url_ = entry.GetFavicon().url; |
navigation.http_status_code_ = entry.GetHttpStatusCode(); |
+ navigation.redirect_chain_ = entry.GetRedirectChain(); |
return navigation; |
} |
@@ -147,6 +148,8 @@ SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( |
navigation.http_status_code_ = sync_data.http_status_code(); |
+ // The redirect chain does not need to be synced down. |
haitaol1
2014/01/17 23:52:23
I think the comment should be on redirect_chain_ s
Donn Denman
2014/01/18 01:30:19
Done.
|
+ |
// We shouldn't sync session data for managed users down at the moment. |
DCHECK(!sync_data.has_blocked_state()); |
DCHECK_EQ(0, sync_data.content_pack_categories_size()); |
@@ -221,6 +224,7 @@ enum TypeMask { |
// timestamp_ |
// search_terms_ |
// http_status_code_ |
+// redirect_chain_ |
void SerializedNavigationEntry::WriteToPickle(int max_size, |
Pickle* pickle) const { |
@@ -262,6 +266,14 @@ void SerializedNavigationEntry::WriteToPickle(int max_size, |
WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); |
pickle->WriteInt(http_status_code_); |
+ |
+ // Redirect chain has variable number of entries. |
+ pickle->WriteUInt16(redirect_chain_.size()); |
+ for (size_t i = 0; i < redirect_chain_.size(); i++) { |
+ GURL redirect_url = redirect_chain_.at(i); |
+ WriteStringToPickle(pickle, &bytes_written, max_size, |
+ redirect_url.is_valid() ? redirect_url.spec() : std::string()); |
+ } |
} |
bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { |
@@ -323,6 +335,24 @@ bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { |
if (!iterator->ReadInt(&http_status_code_)) |
http_status_code_ = 0; |
+ |
+ // The redirect chain is only in newer pickle streams. |
+ unsigned short redirect_chain_length = 0; |
+ if (iterator->ReadUInt16(&redirect_chain_length)) { |
+ std::vector<GURL> full_redirect_chain; |
+ bool was_full_chain_read_successfully = true; |
+ for (size_t i = 0; i < redirect_chain_length; i++) { |
+ std::string a_redirect; |
+ if (iterator->ReadString(&a_redirect)) { |
+ full_redirect_chain.push_back(GURL(a_redirect)); |
+ } else { |
+ was_full_chain_read_successfully = false; |
+ } |
+ } |
+ if (was_full_chain_read_successfully) { |
+ redirect_chain_ = full_redirect_chain; |
+ } |
+ } |
} |
return true; |
@@ -353,6 +383,7 @@ scoped_ptr<NavigationEntry> SerializedNavigationEntry::ToNavigationEntry( |
entry->SetTimestamp(timestamp_); |
entry->SetExtraData(kSearchTermsKey, search_terms_); |
entry->SetHttpStatusCode(http_status_code_); |
+ entry->SetRedirectChain(redirect_chain_); |
// These fields should have default values. |
DCHECK_EQ(STATE_INVALID, blocked_state_); |
@@ -467,6 +498,22 @@ sync_pb::TabNavigation SerializedNavigationEntry::ToSyncData() const { |
sync_data.add_content_pack_categories(*it); |
} |
+ // Copy all redirect chain entries except the last URL. |
+ for (size_t i = 0; i < redirect_chain_.size(); i++) { |
+ bool is_last_url = (i == redirect_chain_.size() - 1); |
+ if (is_last_url) { |
+ bool did_redirect = redirect_chain_.size() > 1; |
+ if (did_redirect && |
+ sync_data.virtual_url() != redirect_chain_.at(i).spec()) { |
+ sync_data.set_last_navigation_redirect_url( |
+ redirect_chain_.at(i).spec()); |
+ } |
+ } else { |
+ sync_pb::NavigationRedirect *navigation_redirect = |
+ sync_data.add_navigation_redirect(); |
+ navigation_redirect->set_url(redirect_chain_.at(i).spec()); |
+ } |
+ } |
return sync_data; |
} |