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

Side by Side Diff: android_webview/native/state_serializer.cc

Issue 101573003: Add the navigation redirect-chain to Sync sessions proto for offline analysis. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android unit test (state_serializer_unittests.cc). Created 6 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "android_webview/native/state_serializer.h" 5 #include "android_webview/native/state_serializer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 17 matching lines...) Expand all
28 28
29 using std::string; 29 using std::string;
30 30
31 namespace android_webview { 31 namespace android_webview {
32 32
33 namespace { 33 namespace {
34 34
35 // Sanity check value that we are restoring from a valid pickle. 35 // Sanity check value that we are restoring from a valid pickle.
36 // This can potentially used as an actual serialization version number in the 36 // This can potentially used as an actual serialization version number in the
37 // future if we ever decide to support restoring from older versions. 37 // future if we ever decide to support restoring from older versions.
38 const uint32 AW_STATE_VERSION = 20130814; 38 const uint32 AW_STATE_VERSION = 20140115;
39 39
40 } // namespace 40 } // namespace
41 41
42 bool WriteToPickle(const content::WebContents& web_contents, 42 bool WriteToPickle(const content::WebContents& web_contents,
43 Pickle* pickle) { 43 Pickle* pickle) {
44 DCHECK(pickle); 44 DCHECK(pickle);
45 45
46 if (!internal::WriteHeaderToPickle(pickle)) 46 if (!internal::WriteHeaderToPickle(pickle))
47 return false; 47 return false;
48 48
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent()))) 183 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent())))
184 return false; 184 return false;
185 185
186 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue())) 186 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue()))
187 return false; 187 return false;
188 188
189 if (!pickle->WriteInt(entry.GetHttpStatusCode())) 189 if (!pickle->WriteInt(entry.GetHttpStatusCode()))
190 return false; 190 return false;
191 191
192 // The redirect chain has a variable number of entries.
193 bool did_write_all_redirects = true;
194 if (!pickle->WriteUInt16(entry.GetRedirectChain().size()))
195 return false;
196 for (size_t i = 0; i < entry.GetRedirectChain().size(); i++) {
197 if (!pickle->WriteString(entry.GetRedirectChain().at(i).spec())) {
198 did_write_all_redirects = false;
199 }
200 }
201 if (!did_write_all_redirects)
202 return false;
203
192 // Please update AW_STATE_VERSION if serialization format is changed. 204 // Please update AW_STATE_VERSION if serialization format is changed.
193 205
194 return true; 206 return true;
195 } 207 }
196 208
197 bool RestoreNavigationEntryFromPickle(PickleIterator* iterator, 209 bool RestoreNavigationEntryFromPickle(PickleIterator* iterator,
198 content::NavigationEntry* entry) { 210 content::NavigationEntry* entry) {
199 { 211 {
200 string url; 212 string url;
201 if (!iterator->ReadString(&url)) 213 if (!iterator->ReadString(&url))
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 entry->SetTimestamp(base::Time::FromInternalValue(timestamp)); 287 entry->SetTimestamp(base::Time::FromInternalValue(timestamp));
276 } 288 }
277 289
278 { 290 {
279 int http_status_code; 291 int http_status_code;
280 if (!iterator->ReadInt(&http_status_code)) 292 if (!iterator->ReadInt(&http_status_code))
281 return false; 293 return false;
282 entry->SetHttpStatusCode(http_status_code); 294 entry->SetHttpStatusCode(http_status_code);
283 } 295 }
284 296
297 {
298 unsigned short redirect_chain_length = 0;
299 if (!iterator->ReadUInt16(&redirect_chain_length))
300 return false;
301 std::vector<GURL> full_redirect_chain;
302 bool was_full_chain_read_successfully = true;
303 for (size_t i = 0; i < redirect_chain_length; i++) {
304 std::string a_redirect;
305 if (!iterator->ReadString(&a_redirect)) {
306 was_full_chain_read_successfully = false;
307 } else {
308 full_redirect_chain.push_back(GURL(a_redirect));
309 }
310 }
311 if (was_full_chain_read_successfully) {
312 entry->SetRedirectChain(full_redirect_chain);
313 } else {
314 return false;
315 }
316 }
317
285 return true; 318 return true;
286 } 319 }
287 320
288 } // namespace internal 321 } // namespace internal
289 322
290 } // namespace android_webview 323 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698