| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/bookmarks/core/browser/bookmark_node.h" | |
| 6 | |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // Whitespace characters to strip from bookmark titles. | |
| 13 const base::char16 kInvalidChars[] = { | |
| 14 '\n', '\r', '\t', | |
| 15 0x2028, // Line separator | |
| 16 0x2029, // Paragraph separator | |
| 17 0 | |
| 18 }; | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 // BookmarkNode --------------------------------------------------------------- | |
| 23 | |
| 24 const int64 BookmarkNode::kInvalidSyncTransactionVersion = -1; | |
| 25 | |
| 26 BookmarkNode::BookmarkNode(const GURL& url) | |
| 27 : url_(url) { | |
| 28 Initialize(0); | |
| 29 } | |
| 30 | |
| 31 BookmarkNode::BookmarkNode(int64 id, const GURL& url) | |
| 32 : url_(url) { | |
| 33 Initialize(id); | |
| 34 } | |
| 35 | |
| 36 BookmarkNode::~BookmarkNode() { | |
| 37 } | |
| 38 | |
| 39 void BookmarkNode::SetTitle(const base::string16& title) { | |
| 40 // Replace newlines and other problematic whitespace characters in | |
| 41 // folder/bookmark names with spaces. | |
| 42 base::string16 trimmed_title; | |
| 43 base::ReplaceChars(title, kInvalidChars, base::ASCIIToUTF16(" "), | |
| 44 &trimmed_title); | |
| 45 ui::TreeNode<BookmarkNode>::SetTitle(trimmed_title); | |
| 46 } | |
| 47 | |
| 48 bool BookmarkNode::IsVisible() const { | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 bool BookmarkNode::GetMetaInfo(const std::string& key, | |
| 53 std::string* value) const { | |
| 54 if (!meta_info_map_) | |
| 55 return false; | |
| 56 | |
| 57 MetaInfoMap::const_iterator it = meta_info_map_->find(key); | |
| 58 if (it == meta_info_map_->end()) | |
| 59 return false; | |
| 60 | |
| 61 *value = it->second; | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 bool BookmarkNode::SetMetaInfo(const std::string& key, | |
| 66 const std::string& value) { | |
| 67 if (!meta_info_map_) | |
| 68 meta_info_map_.reset(new MetaInfoMap); | |
| 69 | |
| 70 MetaInfoMap::iterator it = meta_info_map_->find(key); | |
| 71 if (it == meta_info_map_->end()) { | |
| 72 (*meta_info_map_)[key] = value; | |
| 73 return true; | |
| 74 } | |
| 75 // Key already in map, check if the value has changed. | |
| 76 if (it->second == value) | |
| 77 return false; | |
| 78 it->second = value; | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 bool BookmarkNode::DeleteMetaInfo(const std::string& key) { | |
| 83 if (!meta_info_map_) | |
| 84 return false; | |
| 85 bool erased = meta_info_map_->erase(key) != 0; | |
| 86 if (meta_info_map_->empty()) | |
| 87 meta_info_map_.reset(); | |
| 88 return erased; | |
| 89 } | |
| 90 | |
| 91 void BookmarkNode::SetMetaInfoMap(const MetaInfoMap& meta_info_map) { | |
| 92 if (meta_info_map.empty()) | |
| 93 meta_info_map_.reset(); | |
| 94 else | |
| 95 meta_info_map_.reset(new MetaInfoMap(meta_info_map)); | |
| 96 } | |
| 97 | |
| 98 const BookmarkNode::MetaInfoMap* BookmarkNode::GetMetaInfoMap() const { | |
| 99 return meta_info_map_.get(); | |
| 100 } | |
| 101 | |
| 102 void BookmarkNode::Initialize(int64 id) { | |
| 103 id_ = id; | |
| 104 type_ = url_.is_empty() ? FOLDER : URL; | |
| 105 date_added_ = base::Time::Now(); | |
| 106 favicon_type_ = favicon_base::INVALID_ICON; | |
| 107 favicon_state_ = INVALID_FAVICON; | |
| 108 favicon_load_task_id_ = base::CancelableTaskTracker::kBadTaskId; | |
| 109 meta_info_map_.reset(); | |
| 110 sync_transaction_version_ = kInvalidSyncTransactionVersion; | |
| 111 } | |
| 112 | |
| 113 void BookmarkNode::InvalidateFavicon() { | |
| 114 icon_url_ = GURL(); | |
| 115 favicon_ = gfx::Image(); | |
| 116 favicon_type_ = favicon_base::INVALID_ICON; | |
| 117 favicon_state_ = INVALID_FAVICON; | |
| 118 } | |
| 119 | |
| 120 // BookmarkPermanentNode ------------------------------------------------------- | |
| 121 | |
| 122 BookmarkPermanentNode::BookmarkPermanentNode(int64 id) | |
| 123 : BookmarkNode(id, GURL()), | |
| 124 visible_(true) { | |
| 125 } | |
| 126 | |
| 127 BookmarkPermanentNode::~BookmarkPermanentNode() { | |
| 128 } | |
| 129 | |
| 130 bool BookmarkPermanentNode::IsVisible() const { | |
| 131 return visible_ || !empty(); | |
| 132 } | |
| OLD | NEW |