| 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/bookmarks/bookmark_model_factory.h" |
| 18 #include "chrome/browser/history/query_parser.h" | 19 #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" | 20 #include "chrome/common/pref_names.h" |
| 23 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
| 24 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
| 25 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 26 #include "ui/base/models/tree_node_iterator.h" | 24 #include "ui/base/models/tree_node_iterator.h" |
| 27 | 25 |
| 28 using base::Time; | 26 using base::Time; |
| 29 | 27 |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // Create array of selected nodes with descendants filtered out. | 139 // Create array of selected nodes with descendants filtered out. |
| 142 std::vector<const BookmarkNode*> filteredNodes; | 140 std::vector<const BookmarkNode*> filteredNodes; |
| 143 for (size_t i = 0; i < nodes.size(); ++i) | 141 for (size_t i = 0; i < nodes.size(); ++i) |
| 144 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) | 142 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) |
| 145 filteredNodes.push_back(nodes[i]); | 143 filteredNodes.push_back(nodes[i]); |
| 146 | 144 |
| 147 BookmarkNodeData(filteredNodes). | 145 BookmarkNodeData(filteredNodes). |
| 148 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); | 146 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 149 | 147 |
| 150 if (remove_nodes) { | 148 if (remove_nodes) { |
| 151 #if !defined(OS_ANDROID) | 149 ScopedGroupBookmarkActions grouped_cut(model); |
| 152 ScopedGroupBookmarkActions group_cut(model->profile()); | |
| 153 #endif | |
| 154 for (size_t i = 0; i < filteredNodes.size(); ++i) { | 150 for (size_t i = 0; i < filteredNodes.size(); ++i) { |
| 155 int index = filteredNodes[i]->parent()->GetIndexOf(filteredNodes[i]); | 151 int index = filteredNodes[i]->parent()->GetIndexOf(filteredNodes[i]); |
| 156 if (index > -1) | 152 if (index > -1) |
| 157 model->Remove(filteredNodes[i]->parent(), index); | 153 model->Remove(filteredNodes[i]->parent(), index); |
| 158 } | 154 } |
| 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 ScopedGroupBookmarkActions grouped_paste(model); |
| 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); |
| 178 } | 172 } |
| 179 | 173 |
| 180 bool CanPasteFromClipboard(const BookmarkNode* node) { | 174 bool CanPasteFromClipboard(const BookmarkNode* node) { |
| 181 if (!node) | 175 if (!node) |
| 182 return false; | 176 return false; |
| 183 return BookmarkNodeData::ClipboardContainsBookmarks(); | 177 return BookmarkNodeData::ClipboardContainsBookmarks(); |
| 184 } | 178 } |
| 185 | 179 |
| 186 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( | 180 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 360 |
| 367 // Remove all the bookmarks. | 361 // Remove all the bookmarks. |
| 368 for (size_t i = 0; i < bookmarks.size(); ++i) { | 362 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| 369 const BookmarkNode* node = bookmarks[i]; | 363 const BookmarkNode* node = bookmarks[i]; |
| 370 int index = node->parent()->GetIndexOf(node); | 364 int index = node->parent()->GetIndexOf(node); |
| 371 if (index > -1) | 365 if (index > -1) |
| 372 model->Remove(node->parent(), index); | 366 model->Remove(node->parent(), index); |
| 373 } | 367 } |
| 374 } | 368 } |
| 375 | 369 |
| 370 // ScopedGroupBookmarkActions ------------------------------------------------- |
| 371 |
| 372 ScopedGroupBookmarkActions::ScopedGroupBookmarkActions(Profile* profile) |
| 373 : model_(NULL) { |
| 374 if (profile) |
| 375 model_ = BookmarkModelFactory::GetForProfile(profile); |
| 376 if (model_) |
| 377 model_->BeginGroupedChanges(); |
| 378 } |
| 379 |
| 380 ScopedGroupBookmarkActions::ScopedGroupBookmarkActions(BookmarkModel* model) |
| 381 : model_(model) { |
| 382 if (model_) |
| 383 model_->BeginGroupedChanges(); |
| 384 } |
| 385 |
| 386 ScopedGroupBookmarkActions::~ScopedGroupBookmarkActions() { |
| 387 if (model_) |
| 388 model_->EndGroupedChanges(); |
| 389 } |
| 390 |
| 376 } // namespace bookmark_utils | 391 } // namespace bookmark_utils |
| OLD | NEW |