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