| 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_utils.h" | 5 #include "components/bookmarks/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/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "components/bookmarks/browser/bookmark_client.h" | 17 #include "components/bookmarks/browser/bookmark_client.h" |
| 18 #include "components/bookmarks/browser/bookmark_model.h" | 18 #include "components/bookmarks/browser/bookmark_model.h" |
| 19 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" | 19 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
| 20 #include "components/bookmarks/common/bookmark_pref_names.h" | 20 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 #include "components/query_parser/query_parser.h" | 22 #include "components/query_parser/query_parser.h" |
| 23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 24 #include "ui/base/models/tree_node_iterator.h" | 24 #include "ui/base/models/tree_node_iterator.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 | 26 |
| 27 using base::Time; | 27 using base::Time; |
| 28 using bookmarks::BookmarkClient; | 28 |
| 29 namespace bookmarks { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // The maximum length of URL or title returned by the Cleanup functions. | 33 // The maximum length of URL or title returned by the Cleanup functions. |
| 33 const size_t kCleanedUpUrlMaxLength = 1024u; | 34 const size_t kCleanedUpUrlMaxLength = 1024u; |
| 34 const size_t kCleanedUpTitleMaxLength = 1024u; | 35 const size_t kCleanedUpTitleMaxLength = 1024u; |
| 35 | 36 |
| 36 void CloneBookmarkNodeImpl(BookmarkModel* model, | 37 void CloneBookmarkNodeImpl(BookmarkModel* model, |
| 37 const BookmarkNodeData::Element& element, | 38 const BookmarkNodeData::Element& element, |
| 38 const BookmarkNode* parent, | 39 const BookmarkNode* parent, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (url[kCleanedUpUrlMaxLength - 1] == '%') | 137 if (url[kCleanedUpUrlMaxLength - 1] == '%') |
| 137 return url.substr(0, kCleanedUpUrlMaxLength - 1); | 138 return url.substr(0, kCleanedUpUrlMaxLength - 1); |
| 138 if (url[kCleanedUpUrlMaxLength - 2] == '%') | 139 if (url[kCleanedUpUrlMaxLength - 2] == '%') |
| 139 return url.substr(0, kCleanedUpUrlMaxLength - 2); | 140 return url.substr(0, kCleanedUpUrlMaxLength - 2); |
| 140 | 141 |
| 141 return url.substr(0, kCleanedUpUrlMaxLength); | 142 return url.substr(0, kCleanedUpUrlMaxLength); |
| 142 } | 143 } |
| 143 | 144 |
| 144 } // namespace | 145 } // namespace |
| 145 | 146 |
| 146 namespace bookmark_utils { | |
| 147 | |
| 148 QueryFields::QueryFields() {} | 147 QueryFields::QueryFields() {} |
| 149 QueryFields::~QueryFields() {} | 148 QueryFields::~QueryFields() {} |
| 150 | 149 |
| 151 void CloneBookmarkNode(BookmarkModel* model, | 150 void CloneBookmarkNode(BookmarkModel* model, |
| 152 const std::vector<BookmarkNodeData::Element>& elements, | 151 const std::vector<BookmarkNodeData::Element>& elements, |
| 153 const BookmarkNode* parent, | 152 const BookmarkNode* parent, |
| 154 int index_to_add_at, | 153 int index_to_add_at, |
| 155 bool reset_node_times) { | 154 bool reset_node_times) { |
| 156 if (!parent->is_folder() || !model) { | 155 if (!parent->is_folder() || !model) { |
| 157 NOTREACHED(); | 156 NOTREACHED(); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 bool IsBookmarkedByUser(BookmarkModel* model, const GURL& url) { | 431 bool IsBookmarkedByUser(BookmarkModel* model, const GURL& url) { |
| 433 std::vector<const BookmarkNode*> nodes; | 432 std::vector<const BookmarkNode*> nodes; |
| 434 model->GetNodesByURL(url, &nodes); | 433 model->GetNodesByURL(url, &nodes); |
| 435 for (size_t i = 0; i < nodes.size(); ++i) { | 434 for (size_t i = 0; i < nodes.size(); ++i) { |
| 436 if (model->client()->CanBeEditedByUser(nodes[i])) | 435 if (model->client()->CanBeEditedByUser(nodes[i])) |
| 437 return true; | 436 return true; |
| 438 } | 437 } |
| 439 return false; | 438 return false; |
| 440 } | 439 } |
| 441 | 440 |
| 442 } // namespace bookmark_utils | |
| 443 | |
| 444 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 445 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 446 return GetNodeByID(model->root_node(), id); | 443 return GetNodeByID(model->root_node(), id); |
| 447 } | 444 } |
| 445 |
| 446 } // namespace bookmarks |
| OLD | NEW |