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