| 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_model.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/i18n/string_compare.h" | 12 #include "base/i18n/string_compare.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | |
| 17 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" | 16 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_index.h" | 17 #include "chrome/browser/bookmarks/bookmark_index.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_storage.h" | 19 #include "chrome/browser/bookmarks/bookmark_storage.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_title_match.h" | 20 #include "chrome/browser/bookmarks/bookmark_title_match.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_utils.h" | 21 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 23 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
| 24 #include "chrome/browser/favicon/favicon_changed_details.h" | 23 #include "chrome/browser/favicon/favicon_changed_details.h" |
| 25 #include "chrome/browser/favicon/favicon_service.h" | 24 #include "chrome/browser/favicon/favicon_service.h" |
| 26 #include "chrome/browser/favicon/favicon_service_factory.h" | 25 #include "chrome/browser/favicon/favicon_service_factory.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 | 36 |
| 38 using base::Time; | 37 using base::Time; |
| 39 | 38 |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 // Helper to get a mutable bookmark node. | 41 // Helper to get a mutable bookmark node. |
| 43 BookmarkNode* AsMutable(const BookmarkNode* node) { | 42 BookmarkNode* AsMutable(const BookmarkNode* node) { |
| 44 return const_cast<BookmarkNode*>(node); | 43 return const_cast<BookmarkNode*>(node); |
| 45 } | 44 } |
| 46 | 45 |
| 47 // Helper to recursively determine if a Dictionary has any valid values. | |
| 48 bool HasValues(const base::DictionaryValue& root) { | |
| 49 if (root.empty()) | |
| 50 return false; | |
| 51 for (base::DictionaryValue::Iterator iter(root); !iter.IsAtEnd(); | |
| 52 iter.Advance()) { | |
| 53 const base::Value& value = iter.value(); | |
| 54 if (value.IsType(base::Value::TYPE_DICTIONARY)) { | |
| 55 const base::DictionaryValue* dict_value = NULL; | |
| 56 if (value.GetAsDictionary(&dict_value) && HasValues(*dict_value)) | |
| 57 return true; | |
| 58 } else { | |
| 59 // A non dictionary type was encountered, assume it's a valid value. | |
| 60 return true; | |
| 61 } | |
| 62 } | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 // Whitespace characters to strip from bookmark titles. | 46 // Whitespace characters to strip from bookmark titles. |
| 67 const char16 kInvalidChars[] = { | 47 const char16 kInvalidChars[] = { |
| 68 '\n', '\r', '\t', | 48 '\n', '\r', '\t', |
| 69 0x2028, // Line separator | 49 0x2028, // Line separator |
| 70 0x2029, // Paragraph separator | 50 0x2029, // Paragraph separator |
| 71 0 | 51 0 |
| 72 }; | 52 }; |
| 73 | 53 |
| 74 } // namespace | 54 } // namespace |
| 75 | 55 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 if (meta_info_map.empty()) | 125 if (meta_info_map.empty()) |
| 146 meta_info_map_.reset(); | 126 meta_info_map_.reset(); |
| 147 else | 127 else |
| 148 meta_info_map_.reset(new MetaInfoMap(meta_info_map)); | 128 meta_info_map_.reset(new MetaInfoMap(meta_info_map)); |
| 149 } | 129 } |
| 150 | 130 |
| 151 const BookmarkNode::MetaInfoMap* BookmarkNode::GetMetaInfoMap() const { | 131 const BookmarkNode::MetaInfoMap* BookmarkNode::GetMetaInfoMap() const { |
| 152 return meta_info_map_.get(); | 132 return meta_info_map_.get(); |
| 153 } | 133 } |
| 154 | 134 |
| 155 | |
| 156 void BookmarkNode::Initialize(int64 id) { | 135 void BookmarkNode::Initialize(int64 id) { |
| 157 id_ = id; | 136 id_ = id; |
| 158 type_ = url_.is_empty() ? FOLDER : URL; | 137 type_ = url_.is_empty() ? FOLDER : URL; |
| 159 date_added_ = Time::Now(); | 138 date_added_ = Time::Now(); |
| 160 favicon_state_ = INVALID_FAVICON; | 139 favicon_state_ = INVALID_FAVICON; |
| 161 favicon_load_task_id_ = CancelableTaskTracker::kBadTaskId; | 140 favicon_load_task_id_ = CancelableTaskTracker::kBadTaskId; |
| 162 meta_info_map_.reset(); | 141 meta_info_map_.reset(); |
| 163 sync_transaction_version_ = kInvalidSyncTransactionVersion; | 142 sync_transaction_version_ = kInvalidSyncTransactionVersion; |
| 164 } | 143 } |
| 165 | 144 |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 BookmarkPermanentNode* bb_node = | 1058 BookmarkPermanentNode* bb_node = |
| 1080 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 1059 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
| 1081 BookmarkPermanentNode* other_node = | 1060 BookmarkPermanentNode* other_node = |
| 1082 CreatePermanentNode(BookmarkNode::OTHER_NODE); | 1061 CreatePermanentNode(BookmarkNode::OTHER_NODE); |
| 1083 BookmarkPermanentNode* mobile_node = | 1062 BookmarkPermanentNode* mobile_node = |
| 1084 CreatePermanentNode(BookmarkNode::MOBILE); | 1063 CreatePermanentNode(BookmarkNode::MOBILE); |
| 1085 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, | 1064 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, |
| 1086 new BookmarkIndex(profile_), | 1065 new BookmarkIndex(profile_), |
| 1087 next_node_id_); | 1066 next_node_id_); |
| 1088 } | 1067 } |
| OLD | NEW |