| 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_utils.h" | 5 #include "chrome/browser/bookmarks/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/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.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 "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 18 #include "chrome/browser/history/query_parser.h" | 18 #include "chrome/browser/history/query_parser.h" |
| 19 #include "chrome/browser/undo/bookmark_undo_service.h" | |
| 20 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | |
| 21 #include "chrome/browser/undo/bookmark_undo_utils.h" | |
| 22 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 23 #include "components/user_prefs/pref_registry_syncable.h" | 20 #include "components/user_prefs/pref_registry_syncable.h" |
| 24 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 25 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 26 #include "ui/base/models/tree_node_iterator.h" | 23 #include "ui/base/models/tree_node_iterator.h" |
| 27 | 24 |
| 28 using base::Time; | 25 using base::Time; |
| 29 | 26 |
| 30 namespace { | 27 namespace { |
| 31 | 28 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // Create array of selected nodes with descendants filtered out. | 138 // Create array of selected nodes with descendants filtered out. |
| 142 std::vector<const BookmarkNode*> filteredNodes; | 139 std::vector<const BookmarkNode*> filteredNodes; |
| 143 for (size_t i = 0; i < nodes.size(); ++i) | 140 for (size_t i = 0; i < nodes.size(); ++i) |
| 144 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) | 141 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) |
| 145 filteredNodes.push_back(nodes[i]); | 142 filteredNodes.push_back(nodes[i]); |
| 146 | 143 |
| 147 BookmarkNodeData(filteredNodes). | 144 BookmarkNodeData(filteredNodes). |
| 148 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); | 145 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 149 | 146 |
| 150 if (remove_nodes) { | 147 if (remove_nodes) { |
| 151 #if !defined(OS_ANDROID) | 148 model->BeginGroupedChanges(); |
| 152 ScopedGroupBookmarkActions group_cut(model->profile()); | |
| 153 #endif | |
| 154 for (size_t i = 0; i < filteredNodes.size(); ++i) { | 149 for (size_t i = 0; i < filteredNodes.size(); ++i) { |
| 155 int index = filteredNodes[i]->parent()->GetIndexOf(filteredNodes[i]); | 150 int index = filteredNodes[i]->parent()->GetIndexOf(filteredNodes[i]); |
| 156 if (index > -1) | 151 if (index > -1) |
| 157 model->Remove(filteredNodes[i]->parent(), index); | 152 model->Remove(filteredNodes[i]->parent(), index); |
| 158 } | 153 } |
| 154 model->EndGroupedChanges(); |
| 159 } | 155 } |
| 160 } | 156 } |
| 161 | 157 |
| 162 void PasteFromClipboard(BookmarkModel* model, | 158 void PasteFromClipboard(BookmarkModel* model, |
| 163 const BookmarkNode* parent, | 159 const BookmarkNode* parent, |
| 164 int index) { | 160 int index) { |
| 165 if (!parent) | 161 if (!parent) |
| 166 return; | 162 return; |
| 167 | 163 |
| 168 BookmarkNodeData bookmark_data; | 164 BookmarkNodeData bookmark_data; |
| 169 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 165 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) |
| 170 return; | 166 return; |
| 171 | 167 |
| 172 if (index == -1) | 168 if (index == -1) |
| 173 index = parent->child_count(); | 169 index = parent->child_count(); |
| 174 #if !defined(OS_ANDROID) | 170 model->BeginGroupedChanges(); |
| 175 ScopedGroupBookmarkActions group_paste(model->profile()); | |
| 176 #endif | |
| 177 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 171 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
| 172 model->EndGroupedChanges(); |
| 178 } | 173 } |
| 179 | 174 |
| 180 bool CanPasteFromClipboard(const BookmarkNode* node) { | 175 bool CanPasteFromClipboard(const BookmarkNode* node) { |
| 181 if (!node) | 176 if (!node) |
| 182 return false; | 177 return false; |
| 183 return BookmarkNodeData::ClipboardContainsBookmarks(); | 178 return BookmarkNodeData::ClipboardContainsBookmarks(); |
| 184 } | 179 } |
| 185 | 180 |
| 186 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( | 181 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
| 187 BookmarkModel* model, | 182 BookmarkModel* model, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // Remove all the bookmarks. | 362 // Remove all the bookmarks. |
| 368 for (size_t i = 0; i < bookmarks.size(); ++i) { | 363 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| 369 const BookmarkNode* node = bookmarks[i]; | 364 const BookmarkNode* node = bookmarks[i]; |
| 370 int index = node->parent()->GetIndexOf(node); | 365 int index = node->parent()->GetIndexOf(node); |
| 371 if (index > -1) | 366 if (index > -1) |
| 372 model->Remove(node->parent(), index); | 367 model->Remove(node->parent(), index); |
| 373 } | 368 } |
| 374 } | 369 } |
| 375 | 370 |
| 376 } // namespace bookmark_utils | 371 } // namespace bookmark_utils |
| OLD | NEW |