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/core/browser/bookmark_utils.h" | 5 #include "components/bookmarks/core/browser/bookmark_utils.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
12 #include "base/i18n/string_search.h" | 12 #include "base/i18n/string_search.h" |
13 #include "base/metrics/user_metrics_action.h" | 13 #include "base/metrics/user_metrics_action.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string16.h" | |
16 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
18 #include "components/bookmarks/core/browser/bookmark_model.h" | 17 #include "components/bookmarks/core/browser/bookmark_model.h" |
19 #include "components/bookmarks/core/browser/scoped_group_bookmark_actions.h" | 18 #include "components/bookmarks/core/browser/scoped_group_bookmark_actions.h" |
20 #include "components/bookmarks/core/common/bookmark_pref_names.h" | 19 #include "components/bookmarks/core/common/bookmark_pref_names.h" |
21 #include "components/query_parser/query_parser.h" | 20 #include "components/query_parser/query_parser.h" |
22 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
23 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
24 #include "ui/base/models/tree_node_iterator.h" | 23 #include "ui/base/models/tree_node_iterator.h" |
25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
26 | 25 |
27 using base::Time; | 26 using base::Time; |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 // The maximum length of URL or title returned by the Cleanup functions. | 30 // The maximum length of URL or title returned by the Cleanup functions. |
32 const size_t kCleanedUpUrlMaxLength = 1024u; | 31 const size_t kCleanedUpUrlMaxLength = 1024u; |
33 const size_t kCleanedUpTitleMaxLength = 1024u; | 32 const size_t kCleanedUpTitleMaxLength = 1024u; |
34 | 33 |
35 void CloneBookmarkNodeImpl(BookmarkModel* model, | 34 void CloneBookmarkNodeImpl(BookmarkModel* model, |
36 const BookmarkNodeData::Element& element, | 35 const BookmarkNodeData::Element& element, |
37 const BookmarkNode* parent, | 36 const BookmarkNode* parent, |
38 int index_to_add_at, | 37 int index_to_add_at, |
39 bool reset_node_times) { | 38 bool reset_node_times) { |
40 if (element.is_url) { | 39 if (element.is_url) { |
41 base::Time date_added = reset_node_times ? Time::Now() : element.date_added; | 40 Time date_added = reset_node_times ? Time::Now() : element.date_added; |
42 DCHECK(!date_added.is_null()); | 41 DCHECK(!date_added.is_null()); |
43 | 42 |
44 model->AddURLWithCreationTimeAndMetaInfo(parent, | 43 model->AddURLWithCreationTimeAndMetaInfo(parent, |
45 index_to_add_at, | 44 index_to_add_at, |
46 element.title, | 45 element.title, |
47 element.url, | 46 element.url, |
48 date_added, | 47 date_added, |
49 &element.meta_info_map); | 48 &element.meta_info_map); |
50 } else { | 49 } else { |
51 const BookmarkNode* cloned_node = model->AddFolderWithMetaInfo( | 50 const BookmarkNode* cloned_node = model->AddFolderWithMetaInfo( |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 211 |
213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( | 212 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
214 BookmarkModel* model, | 213 BookmarkModel* model, |
215 size_t max_count) { | 214 size_t max_count) { |
216 std::vector<const BookmarkNode*> nodes; | 215 std::vector<const BookmarkNode*> nodes; |
217 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), | 216 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), |
218 PruneInvisibleFolders); | 217 PruneInvisibleFolders); |
219 | 218 |
220 while (iterator.has_next()) { | 219 while (iterator.has_next()) { |
221 const BookmarkNode* parent = iterator.Next(); | 220 const BookmarkNode* parent = iterator.Next(); |
222 if (parent->is_folder() && parent->date_folder_modified() > base::Time()) { | 221 if (parent->is_folder() && parent->date_folder_modified() > Time()) { |
223 if (max_count == 0) { | 222 if (max_count == 0) { |
224 nodes.push_back(parent); | 223 nodes.push_back(parent); |
225 } else { | 224 } else { |
226 std::vector<const BookmarkNode*>::iterator i = | 225 std::vector<const BookmarkNode*>::iterator i = |
227 std::upper_bound(nodes.begin(), nodes.end(), parent, | 226 std::upper_bound(nodes.begin(), nodes.end(), parent, |
228 &MoreRecentlyModified); | 227 &MoreRecentlyModified); |
229 if (nodes.size() < max_count || i != nodes.end()) { | 228 if (nodes.size() < max_count || i != nodes.end()) { |
230 nodes.insert(i, parent); | 229 nodes.insert(i, parent); |
231 while (nodes.size() > max_count) | 230 while (nodes.size() > max_count) |
232 nodes.pop_back(); | 231 nodes.pop_back(); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 base::string16 CleanUpTitleForMatching(const base::string16& title) { | 414 base::string16 CleanUpTitleForMatching(const base::string16& title) { |
416 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); | 415 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); |
417 } | 416 } |
418 | 417 |
419 } // namespace bookmark_utils | 418 } // namespace bookmark_utils |
420 | 419 |
421 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 420 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
422 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 421 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
423 return GetNodeByID(model->root_node(), id); | 422 return GetNodeByID(model->root_node(), id); |
424 } | 423 } |
OLD | NEW |