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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc

Issue 10827047: Removing instances of profile_->GetBookmarkModel() as part of converting BookmarkModel to a PKS. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | 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/ui/views/bookmarks/bookmark_bubble_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
6 6
7 #include "base/string16.h" 7 #include "base/string16.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/bookmarks/bookmark_editor.h" 11 #include "chrome/browser/bookmarks/bookmark_editor.h"
12 #include "chrome/browser/bookmarks/bookmark_model.h" 12 #include "chrome/browser/bookmarks/bookmark_model.h"
13 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/bookmarks/bookmark_utils.h" 14 #include "chrome/browser/bookmarks/bookmark_utils.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/user_metrics.h" 20 #include "content/public/browser/user_metrics.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
22 #include "ui/base/keycodes/keyboard_codes.h" 23 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 104
104 void BookmarkBubbleView::Hide() { 105 void BookmarkBubbleView::Hide() {
105 if (IsShowing()) 106 if (IsShowing())
106 bookmark_bubble_->GetWidget()->Close(); 107 bookmark_bubble_->GetWidget()->Close();
107 } 108 }
108 109
109 BookmarkBubbleView::~BookmarkBubbleView() { 110 BookmarkBubbleView::~BookmarkBubbleView() {
110 if (apply_edits_) { 111 if (apply_edits_) {
111 ApplyEdits(); 112 ApplyEdits();
112 } else if (remove_bookmark_) { 113 } else if (remove_bookmark_) {
113 BookmarkModel* model = profile_->GetBookmarkModel(); 114 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_);
114 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); 115 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
115 if (node) 116 if (node)
116 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); 117 model->Remove(node->parent(), node->parent()->GetIndexOf(node));
117 } 118 }
118 } 119 }
119 120
120 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { 121 views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
121 return title_tf_; 122 return title_tf_;
122 } 123 }
123 124
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 246
246 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, 247 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view,
247 Profile* profile, 248 Profile* profile,
248 const GURL& url, 249 const GURL& url,
249 bool newly_bookmarked) 250 bool newly_bookmarked)
250 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 251 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
251 profile_(profile), 252 profile_(profile),
252 url_(url), 253 url_(url),
253 newly_bookmarked_(newly_bookmarked), 254 newly_bookmarked_(newly_bookmarked),
254 parent_model_( 255 parent_model_(
255 profile_->GetBookmarkModel(), 256 BookmarkModelFactory::GetForProfile(profile_),
256 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), 257 BookmarkModelFactory::GetForProfile(profile_)->
258 GetMostRecentlyAddedNodeForURL(url)),
257 remove_link_(NULL), 259 remove_link_(NULL),
258 edit_button_(NULL), 260 edit_button_(NULL),
259 close_button_(NULL), 261 close_button_(NULL),
260 title_tf_(NULL), 262 title_tf_(NULL),
261 parent_combobox_(NULL), 263 parent_combobox_(NULL),
262 remove_bookmark_(false), 264 remove_bookmark_(false),
263 apply_edits_(true) { 265 apply_edits_(true) {
264 } 266 }
265 267
266 string16 BookmarkBubbleView::GetTitle() { 268 string16 BookmarkBubbleView::GetTitle() {
267 BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); 269 BookmarkModel* bookmark_model =
270 BookmarkModelFactory::GetForProfile(profile_);
268 const BookmarkNode* node = 271 const BookmarkNode* node =
269 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); 272 bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
270 if (node) 273 if (node)
271 return node->GetTitle(); 274 return node->GetTitle();
272 else 275 else
273 NOTREACHED(); 276 NOTREACHED();
274 return string16(); 277 return string16();
275 } 278 }
276 279
277 void BookmarkBubbleView::ButtonPressed( 280 void BookmarkBubbleView::ButtonPressed(
(...skipping 22 matching lines...) Expand all
300 if (sender == edit_button_) { 303 if (sender == edit_button_) {
301 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 304 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
302 ShowEditor(); 305 ShowEditor();
303 } else { 306 } else {
304 DCHECK_EQ(close_button_, sender); 307 DCHECK_EQ(close_button_, sender);
305 StartFade(false); 308 StartFade(false);
306 } 309 }
307 } 310 }
308 311
309 void BookmarkBubbleView::ShowEditor() { 312 void BookmarkBubbleView::ShowEditor() {
310 const BookmarkNode* node = 313 const BookmarkNode* node = BookmarkModelFactory::GetForProfile(
311 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); 314 profile_)->GetMostRecentlyAddedNodeForURL(url_);
312 views::Widget* parent = anchor_widget(); 315 views::Widget* parent = anchor_widget();
313 DCHECK(parent); 316 DCHECK(parent);
314 317
315 Profile* profile = profile_; 318 Profile* profile = profile_;
316 ApplyEdits(); 319 ApplyEdits();
317 GetWidget()->Close(); 320 GetWidget()->Close();
318 321
319 if (node && parent) 322 if (node && parent)
320 BookmarkEditor::Show(parent->GetNativeWindow(), profile, 323 BookmarkEditor::Show(parent->GetNativeWindow(), profile,
321 BookmarkEditor::EditDetails::EditNode(node), 324 BookmarkEditor::EditDetails::EditNode(node),
322 BookmarkEditor::SHOW_TREE); 325 BookmarkEditor::SHOW_TREE);
323 } 326 }
324 327
325 void BookmarkBubbleView::ApplyEdits() { 328 void BookmarkBubbleView::ApplyEdits() {
326 // Set this to make sure we don't attempt to apply edits again. 329 // Set this to make sure we don't attempt to apply edits again.
327 apply_edits_ = false; 330 apply_edits_ = false;
328 331
329 BookmarkModel* model = profile_->GetBookmarkModel(); 332 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_);
330 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); 333 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
331 if (node) { 334 if (node) {
332 const string16 new_title = title_tf_->text(); 335 const string16 new_title = title_tf_->text();
333 if (new_title != node->GetTitle()) { 336 if (new_title != node->GetTitle()) {
334 model->SetTitle(node, new_title); 337 model->SetTitle(node, new_title);
335 content::RecordAction( 338 content::RecordAction(
336 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 339 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
337 } 340 }
338 // Last index means 'Choose another folder...' 341 // Last index means 'Choose another folder...'
339 if (parent_combobox_->selected_index() < parent_model_.GetItemCount() - 1) { 342 if (parent_combobox_->selected_index() < parent_model_.GetItemCount() - 1) {
340 const BookmarkNode* new_parent = 343 const BookmarkNode* new_parent =
341 parent_model_.GetNodeAt(parent_combobox_->selected_index()); 344 parent_model_.GetNodeAt(parent_combobox_->selected_index());
342 if (new_parent != node->parent()) { 345 if (new_parent != node->parent()) {
343 content::RecordAction( 346 content::RecordAction(
344 UserMetricsAction("BookmarkBubble_ChangeParent")); 347 UserMetricsAction("BookmarkBubble_ChangeParent"));
345 model->Move(node, new_parent, new_parent->child_count()); 348 model->Move(node, new_parent, new_parent->child_count());
346 } 349 }
347 } 350 }
348 } 351 }
349 } 352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698