blob: f24230928eb25a474bd10a13b0849c403395cbbd [file] [log] [blame]
hcarmonaaa431c02015-08-28 18:45:571// 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
avibc5337b2015-12-25 23:16:338#include "base/macros.h"
hcarmonaaa431c02015-08-28 18:45:579#include "base/memory/scoped_ptr.h"
10#include "base/memory/weak_ptr.h"
hcarmona3e2a58c22015-09-08 23:46:1511#include "base/threading/thread_checker.h"
hcarmonaaa431c02015-08-28 18:45:5712#include "components/bubble/bubble_close_reason.h"
13
14class BubbleDelegate;
15class BubbleManager;
hcarmona3e2a58c22015-09-08 23:46:1516class BubbleUi;
hcarmonaaa431c02015-08-28 18:45:5717
jyasskin4a12e672016-02-09 22:39:0718namespace content {
19class RenderFrameHost;
20}
21
hcarmonaaa431c02015-08-28 18:45:5722// BubbleController is responsible for the lifetime of the delegate and its UI.
23class 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
hcarmona3e2a58c22015-09-08 23:46:1532 // Calls UpdateBubbleUi on the associated BubbleManager.
33 // Returns true if the UI was updated.
34 bool UpdateBubbleUi();
35
hcarmona631f5982015-09-11 02:01:2436 // 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
hcarmonaaa431c02015-08-28 18:45:5742 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
hcarmonade570002015-09-30 01:33:3652 // Returns true if the bubble should be closed.
53 bool ShouldClose(BubbleCloseReason reason) const;
54
jyasskin4a12e672016-02-09 22:39:0755 // Returns true if |frame| owns this bubble.
56 bool OwningFrameIs(const content::RenderFrameHost* frame) const;
57
hcarmonade570002015-09-30 01:33:3658 // Cleans up the delegate and its UI.
hcarmona5d511072016-02-23 23:23:5359 void DoClose(BubbleCloseReason reason);
hcarmonaaa431c02015-08-28 18:45:5760
61 BubbleManager* manager_;
62 scoped_ptr<BubbleDelegate> delegate_;
hcarmona3e2a58c22015-09-08 23:46:1563 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_;
hcarmonaaa431c02015-08-28 18:45:5767
hcarmona631f5982015-09-11 02:01:2468 // To keep track of the amount of time a bubble was visible.
69 base::TimeTicks show_time_;
70
hcarmonaaa431c02015-08-28 18:45:5771 DISALLOW_COPY_AND_ASSIGN(BubbleController);
72};
73
74#endif // COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_