| OLD | NEW |
| 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/serialized_navigation_entry.h" | 5 #include "components/sessions/serialized_navigation_entry.h" |
| 6 | 6 |
| 7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/sessions/core/serialized_navigation_driver.h" | 9 #include "components/sessions/core/serialized_navigation_driver.h" |
| 10 #include "sync/protocol/session_specifics.pb.h" | 10 #include "sync/protocol/session_specifics.pb.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 namespace { | 138 namespace { |
| 139 | 139 |
| 140 // Helper used by SerializedNavigationEntry::WriteToPickle(). It writes |str| to | 140 // Helper used by SerializedNavigationEntry::WriteToPickle(). It writes |str| to |
| 141 // |pickle|, if and only if |str| fits within (|max_bytes| - | 141 // |pickle|, if and only if |str| fits within (|max_bytes| - |
| 142 // |*bytes_written|). |bytes_written| is incremented to reflect the | 142 // |*bytes_written|). |bytes_written| is incremented to reflect the |
| 143 // data written. | 143 // data written. |
| 144 // | 144 // |
| 145 // TODO(akalin): Unify this with the same function in | 145 // TODO(akalin): Unify this with the same function in |
| 146 // base_session_service.cc. | 146 // base_session_service.cc. |
| 147 void WriteStringToPickle(Pickle* pickle, | 147 void WriteStringToPickle(base::Pickle* pickle, |
| 148 int* bytes_written, | 148 int* bytes_written, |
| 149 int max_bytes, | 149 int max_bytes, |
| 150 const std::string& str) { | 150 const std::string& str) { |
| 151 int num_bytes = str.size() * sizeof(char); | 151 int num_bytes = str.size() * sizeof(char); |
| 152 if (*bytes_written + num_bytes < max_bytes) { | 152 if (*bytes_written + num_bytes < max_bytes) { |
| 153 *bytes_written += num_bytes; | 153 *bytes_written += num_bytes; |
| 154 pickle->WriteString(str); | 154 pickle->WriteString(str); |
| 155 } else { | 155 } else { |
| 156 pickle->WriteString(std::string()); | 156 pickle->WriteString(std::string()); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 // base::string16 version of WriteStringToPickle. | 160 // base::string16 version of WriteStringToPickle. |
| 161 // | 161 // |
| 162 // TODO(akalin): Unify this, too. | 162 // TODO(akalin): Unify this, too. |
| 163 void WriteString16ToPickle(Pickle* pickle, | 163 void WriteString16ToPickle(base::Pickle* pickle, |
| 164 int* bytes_written, | 164 int* bytes_written, |
| 165 int max_bytes, | 165 int max_bytes, |
| 166 const base::string16& str) { | 166 const base::string16& str) { |
| 167 int num_bytes = str.size() * sizeof(base::char16); | 167 int num_bytes = str.size() * sizeof(base::char16); |
| 168 if (*bytes_written + num_bytes < max_bytes) { | 168 if (*bytes_written + num_bytes < max_bytes) { |
| 169 *bytes_written += num_bytes; | 169 *bytes_written += num_bytes; |
| 170 pickle->WriteString16(str); | 170 pickle->WriteString16(str); |
| 171 } else { | 171 } else { |
| 172 pickle->WriteString16(base::string16()); | 172 pickle->WriteString16(base::string16()); |
| 173 } | 173 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 199 // referrer_url_ | 199 // referrer_url_ |
| 200 // referrer_policy_ (broken, crbug.com/450589) | 200 // referrer_policy_ (broken, crbug.com/450589) |
| 201 // original_request_url_ | 201 // original_request_url_ |
| 202 // is_overriding_user_agent_ | 202 // is_overriding_user_agent_ |
| 203 // timestamp_ | 203 // timestamp_ |
| 204 // search_terms_ | 204 // search_terms_ |
| 205 // http_status_code_ | 205 // http_status_code_ |
| 206 // referrer_policy_ | 206 // referrer_policy_ |
| 207 | 207 |
| 208 void SerializedNavigationEntry::WriteToPickle(int max_size, | 208 void SerializedNavigationEntry::WriteToPickle(int max_size, |
| 209 Pickle* pickle) const { | 209 base::Pickle* pickle) const { |
| 210 pickle->WriteInt(index_); | 210 pickle->WriteInt(index_); |
| 211 | 211 |
| 212 int bytes_written = 0; | 212 int bytes_written = 0; |
| 213 | 213 |
| 214 WriteStringToPickle(pickle, &bytes_written, max_size, | 214 WriteStringToPickle(pickle, &bytes_written, max_size, |
| 215 virtual_url_.spec()); | 215 virtual_url_.spec()); |
| 216 | 216 |
| 217 WriteString16ToPickle(pickle, &bytes_written, max_size, title_); | 217 WriteString16ToPickle(pickle, &bytes_written, max_size, title_); |
| 218 | 218 |
| 219 const std::string encoded_page_state = | 219 const std::string encoded_page_state = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 243 pickle->WriteBool(is_overriding_user_agent_); | 243 pickle->WriteBool(is_overriding_user_agent_); |
| 244 pickle->WriteInt64(timestamp_.ToInternalValue()); | 244 pickle->WriteInt64(timestamp_.ToInternalValue()); |
| 245 | 245 |
| 246 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); | 246 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); |
| 247 | 247 |
| 248 pickle->WriteInt(http_status_code_); | 248 pickle->WriteInt(http_status_code_); |
| 249 | 249 |
| 250 pickle->WriteInt(referrer_policy_); | 250 pickle->WriteInt(referrer_policy_); |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { | 253 bool SerializedNavigationEntry::ReadFromPickle(base::PickleIterator* iterator) { |
| 254 *this = SerializedNavigationEntry(); | 254 *this = SerializedNavigationEntry(); |
| 255 std::string virtual_url_spec; | 255 std::string virtual_url_spec; |
| 256 int transition_type_int = 0; | 256 int transition_type_int = 0; |
| 257 if (!iterator->ReadInt(&index_) || | 257 if (!iterator->ReadInt(&index_) || |
| 258 !iterator->ReadString(&virtual_url_spec) || | 258 !iterator->ReadString(&virtual_url_spec) || |
| 259 !iterator->ReadString16(&title_) || | 259 !iterator->ReadString16(&title_) || |
| 260 !iterator->ReadString(&encoded_page_state_) || | 260 !iterator->ReadString(&encoded_page_state_) || |
| 261 !iterator->ReadInt(&transition_type_int)) | 261 !iterator->ReadInt(&transition_type_int)) |
| 262 return false; | 262 return false; |
| 263 virtual_url_ = GURL(virtual_url_spec); | 263 virtual_url_ = GURL(virtual_url_spec); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 redirect_chain_[last_entry].spec()); | 464 redirect_chain_[last_entry].spec()); |
| 465 } | 465 } |
| 466 } | 466 } |
| 467 | 467 |
| 468 sync_data.set_is_restored(is_restored_); | 468 sync_data.set_is_restored(is_restored_); |
| 469 | 469 |
| 470 return sync_data; | 470 return sync_data; |
| 471 } | 471 } |
| 472 | 472 |
| 473 } // namespace sessions | 473 } // namespace sessions |
| OLD | NEW |