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

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

Issue 2216713002: Use BookmarkModelFactory::GetForBrowserContext everywhere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bookmarks
Patch Set: Replace in .mm files Created 4 years, 4 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
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/ui/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return true; 177 return true;
178 } 178 }
179 #endif 179 #endif
180 180
181 return false; 181 return false;
182 } 182 }
183 183
184 int GetBookmarkDragOperation(content::BrowserContext* browser_context, 184 int GetBookmarkDragOperation(content::BrowserContext* browser_context,
185 const BookmarkNode* node) { 185 const BookmarkNode* node) {
186 PrefService* prefs = user_prefs::UserPrefs::Get(browser_context); 186 PrefService* prefs = user_prefs::UserPrefs::Get(browser_context);
187 Profile* profile = Profile::FromBrowserContext(browser_context); 187 BookmarkModel* model =
188 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); 188 BookmarkModelFactory::GetForBrowserContext(browser_context);
189 189
190 int move = ui::DragDropTypes::DRAG_MOVE; 190 int move = ui::DragDropTypes::DRAG_MOVE;
191 if (!prefs->GetBoolean(bookmarks::prefs::kEditBookmarksEnabled) || 191 if (!prefs->GetBoolean(bookmarks::prefs::kEditBookmarksEnabled) ||
192 !model->client()->CanBeEditedByUser(node)) { 192 !model->client()->CanBeEditedByUser(node)) {
193 move = ui::DragDropTypes::DRAG_NONE; 193 move = ui::DragDropTypes::DRAG_NONE;
194 } 194 }
195 if (node->is_url()) 195 if (node->is_url())
196 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK | move; 196 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK | move;
197 return ui::DragDropTypes::DRAG_COPY | move; 197 return ui::DragDropTypes::DRAG_COPY | move;
198 } 198 }
(...skipping 18 matching lines...) Expand all
217 int index) { 217 int index) {
218 const base::FilePath& profile_path = profile->GetPath(); 218 const base::FilePath& profile_path = profile->GetPath();
219 219
220 if (data.IsFromProfilePath(profile_path) && data.size() > 1) 220 if (data.IsFromProfilePath(profile_path) && data.size() > 1)
221 // Currently only accept one dragged node at a time. 221 // Currently only accept one dragged node at a time.
222 return ui::DragDropTypes::DRAG_NONE; 222 return ui::DragDropTypes::DRAG_NONE;
223 223
224 if (!IsValidBookmarkDropLocation(profile, data, parent, index)) 224 if (!IsValidBookmarkDropLocation(profile, data, parent, index))
225 return ui::DragDropTypes::DRAG_NONE; 225 return ui::DragDropTypes::DRAG_NONE;
226 226
227 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); 227 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile);
228 if (!model->client()->CanBeEditedByUser(parent)) 228 if (!model->client()->CanBeEditedByUser(parent))
229 return ui::DragDropTypes::DRAG_NONE; 229 return ui::DragDropTypes::DRAG_NONE;
230 230
231 const BookmarkNode* dragged_node = 231 const BookmarkNode* dragged_node =
232 data.GetFirstNode(model, profile->GetPath()); 232 data.GetFirstNode(model, profile->GetPath());
233 if (dragged_node) { 233 if (dragged_node) {
234 // User is dragging from this profile. 234 // User is dragging from this profile.
235 if (!model->client()->CanBeEditedByUser(dragged_node)) { 235 if (!model->client()->CanBeEditedByUser(dragged_node)) {
236 // Do a copy instead of a move when dragging bookmarks that the user can't 236 // Do a copy instead of a move when dragging bookmarks that the user can't
237 // modify. 237 // modify.
(...skipping 12 matching lines...) Expand all
250 const BookmarkNode* drop_parent, 250 const BookmarkNode* drop_parent,
251 int index) { 251 int index) {
252 if (!drop_parent->is_folder()) { 252 if (!drop_parent->is_folder()) {
253 NOTREACHED(); 253 NOTREACHED();
254 return false; 254 return false;
255 } 255 }
256 256
257 if (!data.is_valid()) 257 if (!data.is_valid())
258 return false; 258 return false;
259 259
260 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); 260 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile);
261 if (!model->client()->CanBeEditedByUser(drop_parent)) 261 if (!model->client()->CanBeEditedByUser(drop_parent))
262 return false; 262 return false;
263 263
264 const base::FilePath& profile_path = profile->GetPath(); 264 const base::FilePath& profile_path = profile->GetPath();
265 if (data.IsFromProfilePath(profile_path)) { 265 if (data.IsFromProfilePath(profile_path)) {
266 std::vector<const BookmarkNode*> nodes = data.GetNodes(model, profile_path); 266 std::vector<const BookmarkNode*> nodes = data.GetNodes(model, profile_path);
267 for (size_t i = 0; i < nodes.size(); ++i) { 267 for (size_t i = 0; i < nodes.size(); ++i) {
268 // Don't allow the drop if the user is attempting to drop on one of the 268 // Don't allow the drop if the user is attempting to drop on one of the
269 // nodes being dragged. 269 // nodes being dragged.
270 const BookmarkNode* node = nodes[i]; 270 const BookmarkNode* node = nodes[i];
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 312 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
313 IDR_BOOKMARK_BAR_FOLDER_MANAGED); 313 IDR_BOOKMARK_BAR_FOLDER_MANAGED);
314 } 314 }
315 #endif 315 #endif
316 316
317 return GetFolderIcon(gfx::VectorIconId::FOLDER_MANAGED, text_color); 317 return GetFolderIcon(gfx::VectorIconId::FOLDER_MANAGED, text_color);
318 } 318 }
319 #endif 319 #endif
320 320
321 } // namespace chrome 321 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/bookmarks/bookmark_tab_helper.cc ('k') | chrome/browser/ui/bookmarks/bookmark_utils_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698