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

Side by Side Diff: components/bubble/bubble_manager.cc

Issue 1251633002: Add BubbleManager to manage bubbles and ChromeBubbleManager for events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: TESTS! Created 5 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/bubble/bubble_manager.h"
6
7 #include <vector>
8
9 #include "components/bubble/bubble_controller.h"
10 #include "content/public/browser/browser_thread.h"
11
12 BubbleManager::~BubbleManager() {
13 can_show_bubbles_ = false;
14 CloseAllBubbles(BUBBLE_CLOSE_FORCED);
15 }
16
17 BubbleReference BubbleManager::ShowBubble(scoped_ptr<BubbleDelegate> bubble) {
18 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
19 DCHECK(bubble);
20 scoped_ptr<BubbleController> controller(new BubbleController(bubble.Pass()));
21
22 BubbleReference bubble_ref = controller->AsWeakPtr();
23
24 if (!can_show_bubbles_) {
msw 2015/08/21 01:48:30 As I eluded to with my suggestion in the header, c
hcarmona 2015/08/25 02:13:37 Acknowledged.
25 // The controller will be cleaned up and this reference will be invalidated.
26 // It's important that the controller is created even though it's destroyed
27 // immediately because it will collect metrics about the bubble.
28 return bubble_ref;
29 }
30
31 if (show_queue_) {
32 show_queue_->push_back(controller.Pass());
33 } else {
34 controller->Show();
35 controllers_.push_back(controller.Pass());
36 }
37
38 return bubble_ref;
39 }
40
41 bool BubbleManager::CloseBubble(BubbleReference bubble,
42 BubbleCloseReason reason) {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 show_queue_.reset(new ScopedVector<BubbleController>);
45
46 for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
47 if (*iter == bubble.get()) {
48 if ((*iter)->ShouldClose(reason)) {
49 iter = controllers_.erase(iter);
50 ShowPendingBubbles();
51 return true;
52 }
53 ShowPendingBubbles();
msw 2015/08/21 01:48:31 I don't think this call would be necessary... If t
hcarmona 2015/08/25 02:13:37 A bubble could theoretically trigger another bubbl
msw 2015/08/26 01:42:35 I guess so.
54 return false;
55 }
56 }
57
58 // Attempting to close a bubble that is already closed or that this manager
59 // doesn't own is a bug.
60 NOTREACHED();
61 return false;
62 }
63
64 void BubbleManager::UpdateAllBubbleAnchors() {
65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
66 for (auto controller : controllers_)
67 controller->UpdateAnchorPosition();
68 }
69
70 BubbleManager::BubbleManager() : can_show_bubbles_(true) {}
71
72 void BubbleManager::CloseAllBubbles(BubbleCloseReason reason) {
73 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
74 show_queue_.reset(new ScopedVector<BubbleController>);
75
76 for (auto iter = controllers_.begin(); iter != controllers_.end();) {
77 if ((*iter)->ShouldClose(reason)) {
msw 2015/08/21 01:48:30 optionally consider: iter = (*iter)->ShouldClose(r
hcarmona 2015/08/25 02:13:37 Done.
78 iter = controllers_.erase(iter);
79 continue;
80 }
81 ++iter;
82 }
83
84 ShowPendingBubbles();
85 }
86
87 void BubbleManager::ShowPendingBubbles() {
88 DCHECK(show_queue_);
89 if (can_show_bubbles_) {
90 for (auto controller : *show_queue_)
91 controller->Show();
92
93 controllers_.insert(controllers_.end(), show_queue_->begin(),
94 show_queue_->end());
95
96 show_queue_->weak_clear();
97 }
98 show_queue_.reset();
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698