OLD | NEW |
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 "chrome/browser/bookmarks/bookmark_node_data.h" | 5 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (!is_url) { | 48 if (!is_url) { |
49 pickle->WriteSize(children.size()); | 49 pickle->WriteSize(children.size()); |
50 for (std::vector<Element>::const_iterator i = children.begin(); | 50 for (std::vector<Element>::const_iterator i = children.begin(); |
51 i != children.end(); ++i) { | 51 i != children.end(); ++i) { |
52 i->WriteToPickle(pickle); | 52 i->WriteToPickle(pickle); |
53 } | 53 } |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 bool BookmarkNodeData::Element::ReadFromPickle(Pickle* pickle, | 57 bool BookmarkNodeData::Element::ReadFromPickle(Pickle* pickle, |
58 void** iterator) { | 58 PickleIterator* iterator) { |
59 std::string url_spec; | 59 std::string url_spec; |
60 if (!pickle->ReadBool(iterator, &is_url) || | 60 if (!pickle->ReadBool(iterator, &is_url) || |
61 !pickle->ReadString(iterator, &url_spec) || | 61 !pickle->ReadString(iterator, &url_spec) || |
62 !pickle->ReadString16(iterator, &title) || | 62 !pickle->ReadString16(iterator, &title) || |
63 !pickle->ReadInt64(iterator, &id_)) { | 63 !pickle->ReadInt64(iterator, &id_)) { |
64 return false; | 64 return false; |
65 } | 65 } |
66 url = GURL(url_spec); | 66 url = GURL(url_spec); |
67 children.clear(); | 67 children.clear(); |
68 if (!is_url) { | 68 if (!is_url) { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 void BookmarkNodeData::WriteToPickle(Profile* profile, Pickle* pickle) const { | 287 void BookmarkNodeData::WriteToPickle(Profile* profile, Pickle* pickle) const { |
288 FilePath path = profile ? profile->GetPath() : FilePath(); | 288 FilePath path = profile ? profile->GetPath() : FilePath(); |
289 path.WriteToPickle(pickle); | 289 path.WriteToPickle(pickle); |
290 pickle->WriteSize(elements.size()); | 290 pickle->WriteSize(elements.size()); |
291 | 291 |
292 for (size_t i = 0; i < elements.size(); ++i) | 292 for (size_t i = 0; i < elements.size(); ++i) |
293 elements[i].WriteToPickle(pickle); | 293 elements[i].WriteToPickle(pickle); |
294 } | 294 } |
295 | 295 |
296 bool BookmarkNodeData::ReadFromPickle(Pickle* pickle) { | 296 bool BookmarkNodeData::ReadFromPickle(Pickle* pickle) { |
297 void* data_iterator = NULL; | 297 PickleIterator data_iterator(*pickle); |
298 size_t element_count; | 298 size_t element_count; |
299 if (profile_path_.ReadFromPickle(pickle, &data_iterator) && | 299 if (profile_path_.ReadFromPickle(&data_iterator) && |
300 pickle->ReadSize(&data_iterator, &element_count)) { | 300 pickle->ReadSize(&data_iterator, &element_count)) { |
301 std::vector<Element> tmp_elements; | 301 std::vector<Element> tmp_elements; |
302 tmp_elements.resize(element_count); | 302 tmp_elements.resize(element_count); |
303 for (size_t i = 0; i < element_count; ++i) { | 303 for (size_t i = 0; i < element_count; ++i) { |
304 if (!tmp_elements[i].ReadFromPickle(pickle, &data_iterator)) { | 304 if (!tmp_elements[i].ReadFromPickle(pickle, &data_iterator)) { |
305 return false; | 305 return false; |
306 } | 306 } |
307 } | 307 } |
308 elements.swap(tmp_elements); | 308 elements.swap(tmp_elements); |
309 } | 309 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 DCHECK(profile_path_.empty()); | 344 DCHECK(profile_path_.empty()); |
345 | 345 |
346 if (profile) | 346 if (profile) |
347 profile_path_ = profile->GetPath(); | 347 profile_path_ = profile->GetPath(); |
348 } | 348 } |
349 | 349 |
350 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { | 350 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { |
351 // An empty path means the data is not associated with any profile. | 351 // An empty path means the data is not associated with any profile. |
352 return !profile_path_.empty() && profile_path_ == profile->GetPath(); | 352 return !profile_path_.empty() && profile_path_ == profile->GetPath(); |
353 } | 353 } |
OLD | NEW |