| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 17 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 17 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 18 | 18 |
| 19 const char* BookmarkNodeData::kClipboardFormatString = | 19 const char* BookmarkNodeData::kClipboardFormatString = |
| 20 "chromium/x-bookmark-entries"; | 20 "chromium/x-bookmark-entries"; |
| 21 | 21 |
| 22 BookmarkNodeData::Element::Element() : is_url(false), id_(0) { | 22 BookmarkNodeData::Element::Element() : is_url(false), id_(0) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 BookmarkNodeData::Element::Element(const BookmarkNode* node) | 25 BookmarkNodeData::Element::Element(const BookmarkNode* node) |
| 26 : is_url(node->is_url()), | 26 : is_url(node->is_url()), |
| 27 url(node->url()), | 27 url(node->url()), |
| 28 title(node->GetTitle()), | 28 title(node->GetTitle()), |
| 29 date_added(node->date_added()), |
| 30 date_folder_modified(node->date_folder_modified()), |
| 29 id_(node->id()) { | 31 id_(node->id()) { |
| 30 for (int i = 0; i < node->child_count(); ++i) | 32 for (int i = 0; i < node->child_count(); ++i) |
| 31 children.push_back(Element(node->GetChild(i))); | 33 children.push_back(Element(node->GetChild(i))); |
| 32 } | 34 } |
| 33 | 35 |
| 34 BookmarkNodeData::Element::~Element() { | 36 BookmarkNodeData::Element::~Element() { |
| 35 } | 37 } |
| 36 | 38 |
| 37 void BookmarkNodeData::Element::WriteToPickle(Pickle* pickle) const { | 39 void BookmarkNodeData::Element::WriteToPickle(Pickle* pickle) const { |
| 38 pickle->WriteBool(is_url); | 40 pickle->WriteBool(is_url); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 bool BookmarkNodeData::Element::ReadFromPickle(Pickle* pickle, | 53 bool BookmarkNodeData::Element::ReadFromPickle(Pickle* pickle, |
| 52 PickleIterator* iterator) { | 54 PickleIterator* iterator) { |
| 53 std::string url_spec; | 55 std::string url_spec; |
| 54 if (!pickle->ReadBool(iterator, &is_url) || | 56 if (!pickle->ReadBool(iterator, &is_url) || |
| 55 !pickle->ReadString(iterator, &url_spec) || | 57 !pickle->ReadString(iterator, &url_spec) || |
| 56 !pickle->ReadString16(iterator, &title) || | 58 !pickle->ReadString16(iterator, &title) || |
| 57 !pickle->ReadInt64(iterator, &id_)) { | 59 !pickle->ReadInt64(iterator, &id_)) { |
| 58 return false; | 60 return false; |
| 59 } | 61 } |
| 60 url = GURL(url_spec); | 62 url = GURL(url_spec); |
| 63 date_added = base::Time(); |
| 64 date_folder_modified = base::Time(); |
| 61 children.clear(); | 65 children.clear(); |
| 62 if (!is_url) { | 66 if (!is_url) { |
| 63 uint64 children_count; | 67 uint64 children_count; |
| 64 if (!pickle->ReadUInt64(iterator, &children_count)) | 68 if (!pickle->ReadUInt64(iterator, &children_count)) |
| 65 return false; | 69 return false; |
| 66 children.reserve(children_count); | 70 children.reserve(children_count); |
| 67 for (uint64 i = 0; i < children_count; ++i) { | 71 for (uint64 i = 0; i < children_count; ++i) { |
| 68 children.push_back(Element()); | 72 children.push_back(Element()); |
| 69 if (!children.back().ReadFromPickle(pickle, iterator)) | 73 if (!children.back().ReadFromPickle(pickle, iterator)) |
| 70 return false; | 74 return false; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 DCHECK(profile_path_.empty()); | 250 DCHECK(profile_path_.empty()); |
| 247 | 251 |
| 248 if (profile) | 252 if (profile) |
| 249 profile_path_ = profile->GetPath(); | 253 profile_path_ = profile->GetPath(); |
| 250 } | 254 } |
| 251 | 255 |
| 252 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { | 256 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { |
| 253 // An empty path means the data is not associated with any profile. | 257 // An empty path means the data is not associated with any profile. |
| 254 return !profile_path_.empty() && profile_path_ == profile->GetPath(); | 258 return !profile_path_.empty() && profile_path_ == profile->GetPath(); |
| 255 } | 259 } |
| OLD | NEW |