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

Side by Side Diff: components/sessions/core/serialized_navigation_entry.cc

Issue 2310363002: Persist offline page info in a navigation entry if needed (Closed)
Patch Set: Add extended info support 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/core/serialized_navigation_entry.h" 5 #include "components/sessions/core/serialized_navigation_entry.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 const base::string16& str) { 175 const base::string16& str) {
176 int num_bytes = str.size() * sizeof(base::char16); 176 int num_bytes = str.size() * sizeof(base::char16);
177 if (*bytes_written + num_bytes < max_bytes) { 177 if (*bytes_written + num_bytes < max_bytes) {
178 *bytes_written += num_bytes; 178 *bytes_written += num_bytes;
179 pickle->WriteString16(str); 179 pickle->WriteString16(str);
180 } else { 180 } else {
181 pickle->WriteString16(base::string16()); 181 pickle->WriteString16(base::string16());
182 } 182 }
183 } 183 }
184 184
185 void WriteStringMapToPickle(base::Pickle* pickle,
186 int* bytes_written,
187 int max_bytes,
188 const std::map<std::string, std::string>& map) {
189 pickle->WriteInt(map.size());
190 for (const auto entry : map) {
191 WriteStringToPickle(pickle, bytes_written, max_bytes, entry.first);
192 WriteStringToPickle(pickle, bytes_written, max_bytes, entry.second);
193 }
194 }
195
185 // A mask used for arbitrary boolean values needed to represent a 196 // A mask used for arbitrary boolean values needed to represent a
186 // NavigationEntry. Currently only contains HAS_POST_DATA. 197 // NavigationEntry. Currently only contains HAS_POST_DATA.
187 // 198 //
188 // NOTE(akalin): We may want to just serialize |has_post_data_| 199 // NOTE(akalin): We may want to just serialize |has_post_data_|
189 // directly. Other bools (|is_overriding_user_agent_|) haven't been 200 // directly. Other bools (|is_overriding_user_agent_|) haven't been
190 // added to this mask. 201 // added to this mask.
191 enum TypeMask { 202 enum TypeMask {
192 HAS_POST_DATA = 1 203 HAS_POST_DATA = 1
193 }; 204 };
194 205
(...skipping 11 matching lines...) Expand all
206 // 217 //
207 // type_mask (has_post_data_) 218 // type_mask (has_post_data_)
208 // referrer_url_ 219 // referrer_url_
209 // referrer_policy_ (broken, crbug.com/450589) 220 // referrer_policy_ (broken, crbug.com/450589)
210 // original_request_url_ 221 // original_request_url_
211 // is_overriding_user_agent_ 222 // is_overriding_user_agent_
212 // timestamp_ 223 // timestamp_
213 // search_terms_ 224 // search_terms_
214 // http_status_code_ 225 // http_status_code_
215 // referrer_policy_ 226 // referrer_policy_
227 // extended_info_map_
216 228
217 void SerializedNavigationEntry::WriteToPickle(int max_size, 229 void SerializedNavigationEntry::WriteToPickle(int max_size,
218 base::Pickle* pickle) const { 230 base::Pickle* pickle) const {
219 pickle->WriteInt(index_); 231 pickle->WriteInt(index_);
220 232
221 int bytes_written = 0; 233 int bytes_written = 0;
222 234
223 WriteStringToPickle(pickle, &bytes_written, max_size, 235 WriteStringToPickle(pickle, &bytes_written, max_size,
224 virtual_url_.spec()); 236 virtual_url_.spec());
225 237
(...skipping 24 matching lines...) Expand all
250 original_request_url_.is_valid() ? 262 original_request_url_.is_valid() ?
251 original_request_url_.spec() : std::string()); 263 original_request_url_.spec() : std::string());
252 pickle->WriteBool(is_overriding_user_agent_); 264 pickle->WriteBool(is_overriding_user_agent_);
253 pickle->WriteInt64(timestamp_.ToInternalValue()); 265 pickle->WriteInt64(timestamp_.ToInternalValue());
254 266
255 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); 267 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_);
256 268
257 pickle->WriteInt(http_status_code_); 269 pickle->WriteInt(http_status_code_);
258 270
259 pickle->WriteInt(referrer_policy_); 271 pickle->WriteInt(referrer_policy_);
272
273 WriteStringMapToPickle(pickle, &bytes_written, max_size, extended_info_map_);
260 } 274 }
261 275
262 bool SerializedNavigationEntry::ReadFromPickle(base::PickleIterator* iterator) { 276 bool SerializedNavigationEntry::ReadFromPickle(base::PickleIterator* iterator) {
263 *this = SerializedNavigationEntry(); 277 *this = SerializedNavigationEntry();
264 std::string virtual_url_spec; 278 std::string virtual_url_spec;
265 int transition_type_int = 0; 279 int transition_type_int = 0;
266 if (!iterator->ReadInt(&index_) || 280 if (!iterator->ReadInt(&index_) ||
267 !iterator->ReadString(&virtual_url_spec) || 281 !iterator->ReadString(&virtual_url_spec) ||
268 !iterator->ReadString16(&title_) || 282 !iterator->ReadString16(&title_) ||
269 !iterator->ReadString(&encoded_page_state_) || 283 !iterator->ReadString(&encoded_page_state_) ||
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 int mapped_referrer_policy; 342 int mapped_referrer_policy;
329 if (!SerializedNavigationDriver::Get()->MapReferrerPolicyToNewValues( 343 if (!SerializedNavigationDriver::Get()->MapReferrerPolicyToNewValues(
330 referrer_policy_, &mapped_referrer_policy)) { 344 referrer_policy_, &mapped_referrer_policy)) {
331 referrer_url_ = GURL(); 345 referrer_url_ = GURL();
332 } 346 }
333 referrer_policy_ = mapped_referrer_policy; 347 referrer_policy_ = mapped_referrer_policy;
334 encoded_page_state_ = 348 encoded_page_state_ =
335 SerializedNavigationDriver::Get()->StripReferrerFromPageState( 349 SerializedNavigationDriver::Get()->StripReferrerFromPageState(
336 encoded_page_state_); 350 encoded_page_state_);
337 } 351 }
352
353 int extended_info_map_size = 0;
354 if (iterator->ReadInt(&extended_info_map_size) &&
355 extended_info_map_size >= 0) {
356 for (int i = 0; i < extended_info_map_size; ++i) {
357 std::string key;
358 std::string value;
359 if (iterator->ReadString(&key) && iterator->ReadString(&value))
360 extended_info_map_[key] = value;
361 }
362 } else {
363 extended_info_map_.clear();
364 }
338 } 365 }
339 366
340 SerializedNavigationDriver::Get()->Sanitize(this); 367 SerializedNavigationDriver::Get()->Sanitize(this);
341 368
342 is_restored_ = true; 369 is_restored_ = true;
343 370
344 return true; 371 return true;
345 } 372 }
346 373
347 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? 374 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well?
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 redirect_chain_[last_entry].spec()); 503 redirect_chain_[last_entry].spec());
477 } 504 }
478 } 505 }
479 506
480 sync_data.set_is_restored(is_restored_); 507 sync_data.set_is_restored(is_restored_);
481 508
482 return sync_data; 509 return sync_data;
483 } 510 }
484 511
485 } // namespace sessions 512 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698