Adds shutdown when FrameTreeServer goes away
[chromium-blink-merge.git] / components / bubble / bubble_manager.h
blob5f0d9cf0406d8e11c70d5e313409308906c39571
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.
5 #ifndef COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_
6 #define COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/observer_list.h"
11 #include "base/threading/thread_checker.h"
12 #include "components/bubble/bubble_close_reason.h"
13 #include "components/bubble/bubble_reference.h"
15 class BubbleDelegate;
17 // Inherit from BubbleManager to show, update, and close bubbles.
18 // Any class that inherits from BubbleManager should capture any events that
19 // should dismiss a bubble or update its anchor point.
20 // This class assumes that we won't be showing a lot of bubbles simultaneously.
21 // TODO(hcarmona): Handle simultaneous bubbles. http://crbug.com/366937
22 class BubbleManager {
23 public:
24 // This interface should be used to observe the manager. This is useful when
25 // collecting metrics.
26 class BubbleManagerObserver {
27 public:
28 BubbleManagerObserver() {}
29 virtual ~BubbleManagerObserver() {}
31 // Called when a bubble is asked to be displayed but never shown.
32 // ex: a bubble chained on destruction will not be shown.
33 virtual void OnBubbleNeverShown(BubbleReference bubble) = 0;
35 // Called when a bubble is closed. The reason for closing is provided.
36 virtual void OnBubbleClosed(BubbleReference bubble,
37 BubbleCloseReason reason) = 0;
39 private:
40 DISALLOW_COPY_AND_ASSIGN(BubbleManagerObserver);
43 // Should be instantiated on the UI thread.
44 BubbleManager();
45 virtual ~BubbleManager();
47 // Shows a specific bubble and returns a reference to it.
48 // This reference should be used through the BubbleManager.
49 BubbleReference ShowBubble(scoped_ptr<BubbleDelegate> bubble);
51 // Notify a bubble of an event that might trigger close.
52 // Returns true if the bubble was actually closed.
53 bool CloseBubble(BubbleReference bubble, BubbleCloseReason reason);
55 // Notify all bubbles of an event that might trigger close.
56 void CloseAllBubbles(BubbleCloseReason reason);
58 // Notify all bubbles that their anchor or parent may have changed.
59 void UpdateAllBubbleAnchors();
61 // Add an observer for this BubbleManager.
62 void AddBubbleManagerObserver(BubbleManagerObserver* observer);
64 // Remove an observer from this BubbleManager.
65 void RemoveBubbleManagerObserver(BubbleManagerObserver* observer);
67 protected:
68 // Will close any open bubbles and prevent new ones from being shown.
69 void FinalizePendingRequests();
71 private:
72 enum ManagerStates {
73 SHOW_BUBBLES,
74 QUEUE_BUBBLES,
75 NO_MORE_BUBBLES,
78 // Show any bubbles that were added to |show_queue_|.
79 void ShowPendingBubbles();
81 base::ObserverList<BubbleManagerObserver> observers_;
83 // Verify that functions that affect the UI are done on the same thread.
84 base::ThreadChecker thread_checker_;
86 // Determines what happens to a bubble when |ShowBubble| is called.
87 ManagerStates manager_state_;
89 // The bubbles that are being managed.
90 ScopedVector<BubbleController> controllers_;
92 // The bubbles queued to be shown when possible.
93 ScopedVector<BubbleController> show_queue_;
95 DISALLOW_COPY_AND_ASSIGN(BubbleManager);
98 #endif // COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_