OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmarks/browser/bookmark_node_data.h" | 5 #include "components/bookmarks/browser/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 if (!is_url) { | 51 if (!is_url) { |
52 pickle->WriteSizeT(children.size()); | 52 pickle->WriteSizeT(children.size()); |
53 for (std::vector<Element>::const_iterator i = children.begin(); | 53 for (std::vector<Element>::const_iterator i = children.begin(); |
54 i != children.end(); ++i) { | 54 i != children.end(); ++i) { |
55 i->WriteToPickle(pickle); | 55 i->WriteToPickle(pickle); |
56 } | 56 } |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 bool BookmarkNodeData::Element::ReadFromPickle(PickleIterator* iterator) { | 60 bool BookmarkNodeData::Element::ReadFromPickle(Pickle* pickle, |
| 61 PickleIterator* iterator) { |
61 std::string url_spec; | 62 std::string url_spec; |
62 if (!iterator->ReadBool(&is_url) || | 63 if (!pickle->ReadBool(iterator, &is_url) || |
63 !iterator->ReadString(&url_spec) || | 64 !pickle->ReadString(iterator, &url_spec) || |
64 !iterator->ReadString16(&title) || | 65 !pickle->ReadString16(iterator, &title) || |
65 !iterator->ReadInt64(&id_)) { | 66 !pickle->ReadInt64(iterator, &id_)) { |
66 return false; | 67 return false; |
67 } | 68 } |
68 url = GURL(url_spec); | 69 url = GURL(url_spec); |
69 date_added = base::Time(); | 70 date_added = base::Time(); |
70 date_folder_modified = base::Time(); | 71 date_folder_modified = base::Time(); |
71 meta_info_map.clear(); | 72 meta_info_map.clear(); |
72 size_t meta_field_count; | 73 size_t meta_field_count; |
73 if (!iterator->ReadSizeT(&meta_field_count)) | 74 if (!pickle->ReadSizeT(iterator, &meta_field_count)) |
74 return false; | 75 return false; |
75 for (size_t i = 0; i < meta_field_count; ++i) { | 76 for (size_t i = 0; i < meta_field_count; ++i) { |
76 std::string key; | 77 std::string key; |
77 std::string value; | 78 std::string value; |
78 if (!iterator->ReadString(&key) || | 79 if (!pickle->ReadString(iterator, &key) || |
79 !iterator->ReadString(&value)) { | 80 !pickle->ReadString(iterator, &value)) { |
80 return false; | 81 return false; |
81 } | 82 } |
82 meta_info_map[key] = value; | 83 meta_info_map[key] = value; |
83 } | 84 } |
84 children.clear(); | 85 children.clear(); |
85 if (!is_url) { | 86 if (!is_url) { |
86 size_t children_count; | 87 size_t children_count; |
87 if (!iterator->ReadSizeT(&children_count)) | 88 if (!pickle->ReadSizeT(iterator, &children_count)) |
88 return false; | 89 return false; |
89 children.reserve(children_count); | 90 children.reserve(children_count); |
90 for (size_t i = 0; i < children_count; ++i) { | 91 for (size_t i = 0; i < children_count; ++i) { |
91 children.push_back(Element()); | 92 children.push_back(Element()); |
92 if (!children.back().ReadFromPickle(iterator)) | 93 if (!children.back().ReadFromPickle(pickle, iterator)) |
93 return false; | 94 return false; |
94 } | 95 } |
95 } | 96 } |
96 return true; | 97 return true; |
97 } | 98 } |
98 | 99 |
99 // BookmarkNodeData ----------------------------------------------------------- | 100 // BookmarkNodeData ----------------------------------------------------------- |
100 | 101 |
101 BookmarkNodeData::BookmarkNodeData() { | 102 BookmarkNodeData::BookmarkNodeData() { |
102 } | 103 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 pickle->WriteSizeT(elements.size()); | 238 pickle->WriteSizeT(elements.size()); |
238 | 239 |
239 for (size_t i = 0; i < elements.size(); ++i) | 240 for (size_t i = 0; i < elements.size(); ++i) |
240 elements[i].WriteToPickle(pickle); | 241 elements[i].WriteToPickle(pickle); |
241 } | 242 } |
242 | 243 |
243 bool BookmarkNodeData::ReadFromPickle(Pickle* pickle) { | 244 bool BookmarkNodeData::ReadFromPickle(Pickle* pickle) { |
244 PickleIterator data_iterator(*pickle); | 245 PickleIterator data_iterator(*pickle); |
245 size_t element_count; | 246 size_t element_count; |
246 if (profile_path_.ReadFromPickle(&data_iterator) && | 247 if (profile_path_.ReadFromPickle(&data_iterator) && |
247 data_iterator.ReadSizeT(&element_count)) { | 248 pickle->ReadSizeT(&data_iterator, &element_count)) { |
248 std::vector<Element> tmp_elements; | 249 std::vector<Element> tmp_elements; |
249 tmp_elements.resize(element_count); | 250 tmp_elements.resize(element_count); |
250 for (size_t i = 0; i < element_count; ++i) { | 251 for (size_t i = 0; i < element_count; ++i) { |
251 if (!tmp_elements[i].ReadFromPickle(&data_iterator)) { | 252 if (!tmp_elements[i].ReadFromPickle(pickle, &data_iterator)) { |
252 return false; | 253 return false; |
253 } | 254 } |
254 } | 255 } |
255 elements.swap(tmp_elements); | 256 elements.swap(tmp_elements); |
256 } | 257 } |
257 | 258 |
258 return true; | 259 return true; |
259 } | 260 } |
260 | 261 |
261 std::vector<const BookmarkNode*> BookmarkNodeData::GetNodes( | 262 std::vector<const BookmarkNode*> BookmarkNodeData::GetNodes( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 profile_path_ = profile_path; | 296 profile_path_ = profile_path; |
296 } | 297 } |
297 | 298 |
298 bool BookmarkNodeData::IsFromProfilePath( | 299 bool BookmarkNodeData::IsFromProfilePath( |
299 const base::FilePath& profile_path) const { | 300 const base::FilePath& profile_path) const { |
300 // An empty path means the data is not associated with any profile. | 301 // An empty path means the data is not associated with any profile. |
301 return !profile_path_.empty() && profile_path_ == profile_path; | 302 return !profile_path_.empty() && profile_path_ == profile_path; |
302 } | 303 } |
303 | 304 |
304 } // namespace bookmarks | 305 } // namespace bookmarks |
OLD | NEW |