OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ | 5 #ifndef COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ |
6 #define COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ | 6 #define COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
13 #include "components/bubble/bubble_close_reason.h" | 13 #include "components/bubble/bubble_close_reason.h" |
14 #include "components/bubble/bubble_reference.h" | 14 #include "components/bubble/bubble_reference.h" |
15 | 15 |
16 class BubbleDelegate; | 16 class BubbleDelegate; |
17 | 17 |
| 18 namespace content { |
| 19 class RenderFrameHost; |
| 20 } |
| 21 |
18 // Inherit from BubbleManager to show, update, and close bubbles. | 22 // Inherit from BubbleManager to show, update, and close bubbles. |
19 // Any class that inherits from BubbleManager should capture any events that | 23 // Any class that inherits from BubbleManager should capture any events that |
20 // should dismiss a bubble or update its anchor point. | 24 // should dismiss a bubble or update its anchor point. |
21 // This class assumes that we won't be showing a lot of bubbles simultaneously. | 25 // This class assumes that we won't be showing a lot of bubbles simultaneously. |
22 // TODO(hcarmona): Handle simultaneous bubbles. http://crbug.com/366937 | 26 // TODO(hcarmona): Handle simultaneous bubbles. http://crbug.com/366937 |
23 class BubbleManager { | 27 class BubbleManager { |
24 public: | 28 public: |
25 // This interface should be used to observe the manager. This is useful when | 29 // This interface should be used to observe the manager. This is useful when |
26 // collecting metrics. | 30 // collecting metrics. |
27 class BubbleManagerObserver { | 31 class BubbleManagerObserver { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Add an observer for this BubbleManager. | 66 // Add an observer for this BubbleManager. |
63 void AddBubbleManagerObserver(BubbleManagerObserver* observer); | 67 void AddBubbleManagerObserver(BubbleManagerObserver* observer); |
64 | 68 |
65 // Remove an observer from this BubbleManager. | 69 // Remove an observer from this BubbleManager. |
66 void RemoveBubbleManagerObserver(BubbleManagerObserver* observer); | 70 void RemoveBubbleManagerObserver(BubbleManagerObserver* observer); |
67 | 71 |
68 protected: | 72 protected: |
69 // Will close any open bubbles and prevent new ones from being shown. | 73 // Will close any open bubbles and prevent new ones from being shown. |
70 void FinalizePendingRequests(); | 74 void FinalizePendingRequests(); |
71 | 75 |
| 76 // Closes bubbles that declare |frame| as their owner, with |
| 77 // a reason of BUBBLE_CLOSE_FRAME_DESTROYED. |
| 78 void CloseBubblesOwnedBy(const content::RenderFrameHost* frame); |
| 79 |
72 private: | 80 private: |
73 enum ManagerState { | 81 enum ManagerState { |
74 SHOW_BUBBLES, | 82 SHOW_BUBBLES, |
75 NO_MORE_BUBBLES, | 83 NO_MORE_BUBBLES, |
76 ITERATING_BUBBLES, | 84 ITERATING_BUBBLES, |
77 }; | 85 }; |
78 | 86 |
79 // All bubbles will get a close event for the specified |reason| if |match| is | 87 // All matching bubbles will get a close event for the specified |reason|. Any |
80 // nullptr, otherwise only the bubble held by |match| will get a close event. | 88 // bubble that is closed will also be deleted. Bubbles match if 1) |bubble| is |
81 // Any bubble that is closed will also be deleted. | 89 // null or it refers to the bubble, and 2) |owner| is null or owns the bubble. |
82 bool CloseAllMatchingBubbles(BubbleController* match, | 90 // At most one can be non-null. |
| 91 bool CloseAllMatchingBubbles(BubbleController* bubble, |
| 92 const content::RenderFrameHost* owner, |
83 BubbleCloseReason reason); | 93 BubbleCloseReason reason); |
84 | 94 |
85 base::ObserverList<BubbleManagerObserver> observers_; | 95 base::ObserverList<BubbleManagerObserver> observers_; |
86 | 96 |
87 // Verify that functions that affect the UI are done on the same thread. | 97 // Verify that functions that affect the UI are done on the same thread. |
88 base::ThreadChecker thread_checker_; | 98 base::ThreadChecker thread_checker_; |
89 | 99 |
90 // Determines what happens to a bubble when |ShowBubble| is called. | 100 // Determines what happens to a bubble when |ShowBubble| is called. |
91 ManagerState manager_state_; | 101 ManagerState manager_state_; |
92 | 102 |
93 // The bubbles that are being managed. | 103 // The bubbles that are being managed. |
94 ScopedVector<BubbleController> controllers_; | 104 ScopedVector<BubbleController> controllers_; |
95 | 105 |
96 DISALLOW_COPY_AND_ASSIGN(BubbleManager); | 106 DISALLOW_COPY_AND_ASSIGN(BubbleManager); |
97 }; | 107 }; |
98 | 108 |
99 #endif // COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ | 109 #endif // COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ |
OLD | NEW |