Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils.cc

Issue 12475013: bookmarks: Extract PerformBookmarkDrop() function out of bookmark_utils.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: chromeos fixes Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/bookmarks/bookmark_model.h" 18 #include "chrome/browser/bookmarks/bookmark_model.h"
19 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
20 #include "chrome/browser/bookmarks/bookmark_node_data.h" 19 #include "chrome/browser/bookmarks/bookmark_node_data.h"
21 #include "chrome/browser/history/query_parser.h" 20 #include "chrome/browser/history/query_parser.h"
22 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
23 #include "components/user_prefs/pref_registry_syncable.h" 22 #include "components/user_prefs/pref_registry_syncable.h"
24 #include "content/public/browser/user_metrics.h" 23 #include "content/public/browser/user_metrics.h"
25 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
26 #include "ui/base/dragdrop/drag_drop_types.h"
27 #include "ui/base/events/event.h" 25 #include "ui/base/events/event.h"
28 #include "ui/base/models/tree_node_iterator.h" 26 #include "ui/base/models/tree_node_iterator.h"
29 27
30 using base::Time; 28 using base::Time;
31 using content::UserMetricsAction; 29 using content::UserMetricsAction;
32 30
33 namespace { 31 namespace {
34 32
35 void CloneBookmarkNodeImpl(BookmarkModel* model, 33 void CloneBookmarkNodeImpl(BookmarkModel* model,
36 const BookmarkNodeData::Element& element, 34 const BookmarkNodeData::Element& element,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return NULL; 105 return NULL;
108 } 106 }
109 107
110 return node; 108 return node;
111 } 109 }
112 110
113 } // namespace 111 } // namespace
114 112
115 namespace bookmark_utils { 113 namespace bookmark_utils {
116 114
117 int PerformBookmarkDrop(Profile* profile,
118 const BookmarkNodeData& data,
119 const BookmarkNode* parent_node,
120 int index) {
121 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
122 if (data.IsFromProfile(profile)) {
123 const std::vector<const BookmarkNode*> dragged_nodes =
124 data.GetNodes(profile);
125 if (!dragged_nodes.empty()) {
126 // Drag from same profile. Move nodes.
127 for (size_t i = 0; i < dragged_nodes.size(); ++i) {
128 model->Move(dragged_nodes[i], parent_node, index);
129 index = parent_node->GetIndexOf(dragged_nodes[i]) + 1;
130 }
131 return ui::DragDropTypes::DRAG_MOVE;
132 }
133 return ui::DragDropTypes::DRAG_NONE;
134 }
135 // Dropping a folder from different profile. Always accept.
136 CloneBookmarkNode(model, data.elements, parent_node, index);
137 return ui::DragDropTypes::DRAG_COPY;
138 }
139
140 void CloneBookmarkNode(BookmarkModel* model, 115 void CloneBookmarkNode(BookmarkModel* model,
141 const std::vector<BookmarkNodeData::Element>& elements, 116 const std::vector<BookmarkNodeData::Element>& elements,
142 const BookmarkNode* parent, 117 const BookmarkNode* parent,
143 int index_to_add_at) { 118 int index_to_add_at) {
144 if (!parent->is_folder() || !model) { 119 if (!parent->is_folder() || !model) {
145 NOTREACHED(); 120 NOTREACHED();
146 return; 121 return;
147 } 122 }
148 for (size_t i = 0; i < elements.size(); ++i) 123 for (size_t i = 0; i < elements.size(); ++i)
149 CloneBookmarkNodeImpl(model, elements[i], parent, index_to_add_at + i); 124 CloneBookmarkNodeImpl(model, elements[i], parent, index_to_add_at + i);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 411 }
437 412
438 void RecordAppsPageOpen(BookmarkLaunchLocation location) { 413 void RecordAppsPageOpen(BookmarkLaunchLocation location) {
439 if (location == LAUNCH_DETACHED_BAR || location == LAUNCH_ATTACHED_BAR) { 414 if (location == LAUNCH_DETACHED_BAR || location == LAUNCH_ATTACHED_BAR) {
440 content::RecordAction( 415 content::RecordAction(
441 UserMetricsAction("ClickedBookmarkBarAppsShortcutButton")); 416 UserMetricsAction("ClickedBookmarkBarAppsShortcutButton"));
442 } 417 }
443 } 418 }
444 419
445 } // namespace bookmark_utils 420 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698