Chromium Code Reviews| 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/string_number_conversions.h" | |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "components/bookmarks/browser/bookmark_client.h" | 18 #include "components/bookmarks/browser/bookmark_client.h" |
| 18 #include "components/bookmarks/browser/bookmark_model.h" | 19 #include "components/bookmarks/browser/bookmark_model.h" |
| 19 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" | 20 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
| 20 #include "components/bookmarks/common/bookmark_pref_names.h" | 21 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 #include "components/query_parser/query_parser.h" | 23 #include "components/query_parser/query_parser.h" |
| 23 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 24 #include "ui/base/models/tree_node_iterator.h" | 25 #include "ui/base/models/tree_node_iterator.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 if (!parent) | 195 if (!parent) |
| 195 return; | 196 return; |
| 196 | 197 |
| 197 BookmarkNodeData bookmark_data; | 198 BookmarkNodeData bookmark_data; |
| 198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 199 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) |
| 199 return; | 200 return; |
| 200 | 201 |
| 201 if (index == -1) | 202 if (index == -1) |
| 202 index = parent->child_count(); | 203 index = parent->child_count(); |
| 203 ScopedGroupBookmarkActions group_paste(model); | 204 ScopedGroupBookmarkActions group_paste(model); |
| 205 | |
| 206 if (bookmark_data.elements.size() == 1 && | |
| 207 model->IsBookmarked(bookmark_data.elements[0].url)) { | |
| 208 std::vector<const BookmarkNode*> nodes; | |
| 209 std::vector<base::string16> titles; | |
| 210 std::vector<base::string16>::iterator it; | |
| 211 base::string16 newTitle = bookmark_data.elements[0].title; | |
|
tfarina
2014/08/13 13:40:52
new_title
but, pointing this style issues is gett
Deepak
2014/08/14 02:54:50
Done.
| |
| 212 model->GetNodesByURLAndTitle(bookmark_data.elements[0].url, | |
| 213 bookmark_data.elements[0].title, | |
| 214 parent, | |
| 215 &nodes, | |
| 216 &titles); | |
| 217 size_t i = 0; | |
| 218 it = std::find(titles.begin(), titles.end(), newTitle); | |
| 219 if (it == titles.end()) { | |
| 220 newTitle = bookmark_data.elements[0].title; | |
| 221 } else { | |
| 222 for (i = 0; i < nodes.size(); i++) { | |
| 223 newTitle = bookmark_data.elements[0].title + | |
|
tfarina
2014/08/13 13:40:52
was this clang-formatted?
Deepak
2014/08/14 02:54:50
yes , I have used git cl format for making it form
| |
| 224 base::UTF8ToUTF16("-Copy(") + base::IntToString16(i + 1) + | |
| 225 base::UTF8ToUTF16(")"); | |
| 226 it = std::find(titles.begin(), titles.end(), newTitle); | |
| 227 if (it == titles.end()) | |
| 228 break; | |
| 229 } | |
| 230 } | |
| 231 bookmark_data.elements[0].title = newTitle; | |
| 232 } | |
| 204 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 233 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
| 205 } | 234 } |
| 206 | 235 |
| 207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { | 236 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
| 208 if (!node || !model->client()->CanBeEditedByUser(node)) | 237 if (!node || !model->client()->CanBeEditedByUser(node)) |
| 209 return false; | 238 return false; |
| 210 return BookmarkNodeData::ClipboardContainsBookmarks(); | 239 return BookmarkNodeData::ClipboardContainsBookmarks(); |
| 211 } | 240 } |
| 212 | 241 |
| 213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( | 242 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 } | 466 } |
| 438 return false; | 467 return false; |
| 439 } | 468 } |
| 440 | 469 |
| 441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 470 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 471 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 443 return GetNodeByID(model->root_node(), id); | 472 return GetNodeByID(model->root_node(), id); |
| 444 } | 473 } |
| 445 | 474 |
| 446 } // namespace bookmarks | 475 } // namespace bookmarks |
| OLD | NEW |