hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 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 | #ifndef COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_ |
| 6 | #define COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_ |
| 7 | |
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 8 | #include "base/macros.h" |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
| 10 | #include "base/memory/weak_ptr.h" |
hcarmona | 3e2a58c2 | 2015-09-08 23:46:15 | [diff] [blame] | 11 | #include "base/threading/thread_checker.h" |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 12 | #include "components/bubble/bubble_close_reason.h" |
| 13 | |
| 14 | class BubbleDelegate; |
| 15 | class BubbleManager; |
hcarmona | 3e2a58c2 | 2015-09-08 23:46:15 | [diff] [blame] | 16 | class BubbleUi; |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 17 | |
jyasskin | 4a12e67 | 2016-02-09 22:39:07 | [diff] [blame] | 18 | namespace content { |
| 19 | class RenderFrameHost; |
| 20 | } |
| 21 | |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 22 | // BubbleController is responsible for the lifetime of the delegate and its UI. |
| 23 | class BubbleController : public base::SupportsWeakPtr<BubbleController> { |
| 24 | public: |
| 25 | explicit BubbleController(BubbleManager* manager, |
| 26 | scoped_ptr<BubbleDelegate> delegate); |
| 27 | virtual ~BubbleController(); |
| 28 | |
| 29 | // Calls CloseBubble on the associated BubbleManager. |
| 30 | bool CloseBubble(BubbleCloseReason reason); |
| 31 | |
hcarmona | 3e2a58c2 | 2015-09-08 23:46:15 | [diff] [blame] | 32 | // Calls UpdateBubbleUi on the associated BubbleManager. |
| 33 | // Returns true if the UI was updated. |
| 34 | bool UpdateBubbleUi(); |
| 35 | |
hcarmona | 631f598 | 2015-09-11 02:01:24 | [diff] [blame] | 36 | // Used to identify a bubble for collecting metrics. |
| 37 | std::string GetName() const; |
| 38 | |
| 39 | // Used for collecting metrics. |
| 40 | base::TimeDelta GetVisibleTime() const; |
| 41 | |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 42 | private: |
| 43 | friend class BubbleManager; |
| 44 | |
| 45 | // Creates and shows the UI for the delegate. |
| 46 | void Show(); |
| 47 | |
| 48 | // Notifies the bubble UI that it should update its anchor location. |
| 49 | // Important when there's a UI change (ex: fullscreen transition). |
| 50 | void UpdateAnchorPosition(); |
| 51 | |
hcarmona | de57000 | 2015-09-30 01:33:36 | [diff] [blame] | 52 | // Returns true if the bubble should be closed. |
| 53 | bool ShouldClose(BubbleCloseReason reason) const; |
| 54 | |
jyasskin | 4a12e67 | 2016-02-09 22:39:07 | [diff] [blame] | 55 | // Returns true if |frame| owns this bubble. |
| 56 | bool OwningFrameIs(const content::RenderFrameHost* frame) const; |
| 57 | |
hcarmona | de57000 | 2015-09-30 01:33:36 | [diff] [blame] | 58 | // Cleans up the delegate and its UI. |
hcarmona | 5d51107 | 2016-02-23 23:23:53 | [diff] [blame^] | 59 | void DoClose(BubbleCloseReason reason); |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 60 | |
| 61 | BubbleManager* manager_; |
| 62 | scoped_ptr<BubbleDelegate> delegate_; |
hcarmona | 3e2a58c2 | 2015-09-08 23:46:15 | [diff] [blame] | 63 | scoped_ptr<BubbleUi> bubble_ui_; |
| 64 | |
| 65 | // Verify that functions that affect the UI are done on the same thread. |
| 66 | base::ThreadChecker thread_checker_; |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 67 | |
hcarmona | 631f598 | 2015-09-11 02:01:24 | [diff] [blame] | 68 | // To keep track of the amount of time a bubble was visible. |
| 69 | base::TimeTicks show_time_; |
| 70 | |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(BubbleController); |
| 72 | }; |
| 73 | |
| 74 | #endif // COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_ |