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();
31 // Used to identify a bubble for collecting metrics.
32 std::string
GetName() const;
34 // Used for collecting metrics.
35 base::TimeDelta
GetVisibleTime() const;
38 friend class BubbleManager
;
40 // Creates and shows the UI for the delegate.
43 // Notifies the bubble UI that it should update its anchor location.
44 // Important when there's a UI change (ex: fullscreen transition).
45 void UpdateAnchorPosition();
47 // Cleans up the delegate and its UI if it closed.
48 // Returns true if the bubble was closed.
49 bool ShouldClose(BubbleCloseReason reason
);
51 BubbleManager
* manager_
;
52 scoped_ptr
<BubbleDelegate
> delegate_
;
53 scoped_ptr
<BubbleUi
> bubble_ui_
;
55 // Verify that functions that affect the UI are done on the same thread.
56 base::ThreadChecker thread_checker_
;
58 // To keep track of the amount of time a bubble was visible.
59 base::TimeTicks show_time_
;
61 DISALLOW_COPY_AND_ASSIGN(BubbleController
);
64 #endif // COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_