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_CONTROLLER_H_
6 #define COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/thread_checker.h"
11 #include "components/bubble/bubble_close_reason.h"
17 // BubbleController is responsible for the lifetime of the delegate and its UI.
18 class BubbleController
: public base::SupportsWeakPtr
<BubbleController
> {
20 explicit BubbleController(BubbleManager
* manager
,
21 scoped_ptr
<BubbleDelegate
> delegate
);
22 virtual ~BubbleController();
24 // Calls CloseBubble on the associated BubbleManager.
25 bool CloseBubble(BubbleCloseReason reason
);
27 // Calls UpdateBubbleUi on the associated BubbleManager.
28 // Returns true if the UI was updated.
29 bool UpdateBubbleUi();
32 friend class BubbleManager
;
34 // Creates and shows the UI for the delegate.
37 // Notifies the bubble UI that it should update its anchor location.
38 // Important when there's a UI change (ex: fullscreen transition).
39 void UpdateAnchorPosition();
41 // Cleans up the delegate and its UI if it closed.
42 // Returns true if the bubble was closed.
43 bool ShouldClose(BubbleCloseReason reason
);
45 BubbleManager
* manager_
;
46 scoped_ptr
<BubbleDelegate
> delegate_
;
47 scoped_ptr
<BubbleUi
> bubble_ui_
;
49 // Verify that functions that affect the UI are done on the same thread.
50 base::ThreadChecker thread_checker_
;
52 DISALLOW_COPY_AND_ASSIGN(BubbleController
);
55 #endif // COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_