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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bubble_view.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/views/bookmarks/bookmark_bubble_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 bookmark_bubble_->set_parent_window(parent_window); 85 bookmark_bubble_->set_parent_window(parent_window);
86 } 86 }
87 views::Widget* bubble_widget = 87 views::Widget* bubble_widget =
88 views::BubbleDialogDelegateView::CreateBubble(bookmark_bubble_); 88 views::BubbleDialogDelegateView::CreateBubble(bookmark_bubble_);
89 bubble_widget->Show(); 89 bubble_widget->Show();
90 // Select the entire title textfield contents when the bubble is first shown. 90 // Select the entire title textfield contents when the bubble is first shown.
91 bookmark_bubble_->title_tf_->SelectAll(true); 91 bookmark_bubble_->title_tf_->SelectAll(true);
92 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); 92 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
93 93
94 if (bookmark_bubble_->observer_) { 94 if (bookmark_bubble_->observer_) {
95 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); 95 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile);
96 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url); 96 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url);
97 bookmark_bubble_->observer_->OnBookmarkBubbleShown(node); 97 bookmark_bubble_->observer_->OnBookmarkBubbleShown(node);
98 } 98 }
99 return bubble_widget; 99 return bubble_widget;
100 } 100 }
101 101
102 void BookmarkBubbleView::Hide() { 102 void BookmarkBubbleView::Hide() {
103 if (bookmark_bubble_) 103 if (bookmark_bubble_)
104 bookmark_bubble_->GetWidget()->Close(); 104 bookmark_bubble_->GetWidget()->Close();
105 } 105 }
106 106
107 BookmarkBubbleView::~BookmarkBubbleView() { 107 BookmarkBubbleView::~BookmarkBubbleView() {
108 if (apply_edits_) { 108 if (apply_edits_) {
109 ApplyEdits(); 109 ApplyEdits();
110 } else if (remove_bookmark_) { 110 } else if (remove_bookmark_) {
111 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); 111 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_);
112 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); 112 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_);
113 if (node) 113 if (node)
114 model->Remove(node); 114 model->Remove(node);
115 } 115 }
116 // |parent_combobox_| needs to be destroyed before |parent_model_| as it 116 // |parent_combobox_| needs to be destroyed before |parent_model_| as it
117 // uses |parent_model_| in its destructor. 117 // uses |parent_model_| in its destructor.
118 delete parent_combobox_; 118 delete parent_combobox_;
119 } 119 }
120 120
121 void BookmarkBubbleView::WindowClosing() { 121 void BookmarkBubbleView::WindowClosing() {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 std::unique_ptr<BubbleSyncPromoDelegate> delegate, 248 std::unique_ptr<BubbleSyncPromoDelegate> delegate,
249 Profile* profile, 249 Profile* profile,
250 const GURL& url, 250 const GURL& url,
251 bool newly_bookmarked) 251 bool newly_bookmarked)
252 : LocationBarBubbleDelegateView(anchor_view, nullptr), 252 : LocationBarBubbleDelegateView(anchor_view, nullptr),
253 observer_(observer), 253 observer_(observer),
254 delegate_(std::move(delegate)), 254 delegate_(std::move(delegate)),
255 profile_(profile), 255 profile_(profile),
256 url_(url), 256 url_(url),
257 newly_bookmarked_(newly_bookmarked), 257 newly_bookmarked_(newly_bookmarked),
258 parent_model_(BookmarkModelFactory::GetForProfile(profile_), 258 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_),
259 BookmarkModelFactory::GetForProfile(profile_) 259 BookmarkModelFactory::GetForBrowserContext(profile_)
260 ->GetMostRecentlyAddedUserNodeForURL(url)), 260 ->GetMostRecentlyAddedUserNodeForURL(url)),
261 remove_button_(nullptr), 261 remove_button_(nullptr),
262 edit_button_(nullptr), 262 edit_button_(nullptr),
263 close_button_(nullptr), 263 close_button_(nullptr),
264 title_tf_(nullptr), 264 title_tf_(nullptr),
265 parent_combobox_(nullptr), 265 parent_combobox_(nullptr),
266 remove_bookmark_(false), 266 remove_bookmark_(false),
267 apply_edits_(true) {} 267 apply_edits_(true) {}
268 268
269 base::string16 BookmarkBubbleView::GetTitle() { 269 base::string16 BookmarkBubbleView::GetTitle() {
270 BookmarkModel* bookmark_model = 270 BookmarkModel* bookmark_model =
271 BookmarkModelFactory::GetForProfile(profile_); 271 BookmarkModelFactory::GetForBrowserContext(profile_);
272 const BookmarkNode* node = 272 const BookmarkNode* node =
273 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); 273 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_);
274 if (node) 274 if (node)
275 return node->GetTitle(); 275 return node->GetTitle();
276 else 276 else
277 NOTREACHED(); 277 NOTREACHED();
278 return base::string16(); 278 return base::string16();
279 } 279 }
280 280
281 void BookmarkBubbleView::GetAccessibleState(ui::AXViewState* state) { 281 void BookmarkBubbleView::GetAccessibleState(ui::AXViewState* state) {
(...skipping 26 matching lines...) Expand all
308 } else if (sender == edit_button_) { 308 } else if (sender == edit_button_) {
309 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 309 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
310 ShowEditor(); 310 ShowEditor();
311 } else { 311 } else {
312 DCHECK_EQ(close_button_, sender); 312 DCHECK_EQ(close_button_, sender);
313 GetWidget()->Close(); 313 GetWidget()->Close();
314 } 314 }
315 } 315 }
316 316
317 void BookmarkBubbleView::ShowEditor() { 317 void BookmarkBubbleView::ShowEditor() {
318 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( 318 const BookmarkNode* node =
319 profile_)->GetMostRecentlyAddedUserNodeForURL(url_); 319 BookmarkModelFactory::GetForBrowserContext(profile_)
320 ->GetMostRecentlyAddedUserNodeForURL(url_);
320 gfx::NativeWindow native_parent = 321 gfx::NativeWindow native_parent =
321 anchor_widget() ? anchor_widget()->GetNativeWindow() 322 anchor_widget() ? anchor_widget()->GetNativeWindow()
322 : platform_util::GetTopLevel(parent_window()); 323 : platform_util::GetTopLevel(parent_window());
323 DCHECK(native_parent); 324 DCHECK(native_parent);
324 325
325 Profile* profile = profile_; 326 Profile* profile = profile_;
326 ApplyEdits(); 327 ApplyEdits();
327 GetWidget()->Close(); 328 GetWidget()->Close();
328 329
329 if (node && native_parent) 330 if (node && native_parent)
330 BookmarkEditor::Show(native_parent, profile, 331 BookmarkEditor::Show(native_parent, profile,
331 BookmarkEditor::EditDetails::EditNode(node), 332 BookmarkEditor::EditDetails::EditNode(node),
332 BookmarkEditor::SHOW_TREE); 333 BookmarkEditor::SHOW_TREE);
333 } 334 }
334 335
335 void BookmarkBubbleView::ApplyEdits() { 336 void BookmarkBubbleView::ApplyEdits() {
336 // Set this to make sure we don't attempt to apply edits again. 337 // Set this to make sure we don't attempt to apply edits again.
337 apply_edits_ = false; 338 apply_edits_ = false;
338 339
339 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); 340 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_);
340 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); 341 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_);
341 if (node) { 342 if (node) {
342 const base::string16 new_title = title_tf_->text(); 343 const base::string16 new_title = title_tf_->text();
343 if (new_title != node->GetTitle()) { 344 if (new_title != node->GetTitle()) {
344 model->SetTitle(node, new_title); 345 model->SetTitle(node, new_title);
345 content::RecordAction( 346 content::RecordAction(
346 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 347 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
347 } 348 }
348 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 349 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
349 } 350 }
350 } 351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698