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 #include "components/bubble/bubble_controller.h"
7 #include "components/bubble/bubble_delegate.h"
8 #include "components/bubble/bubble_manager.h"
9 #include "components/bubble/bubble_ui.h"
11 BubbleController::BubbleController(BubbleManager
* manager
,
12 scoped_ptr
<BubbleDelegate
> delegate
)
13 : manager_(manager
), delegate_(delegate
.Pass()) {
18 BubbleController::~BubbleController() {
20 ShouldClose(BUBBLE_CLOSE_FORCED
);
23 bool BubbleController::CloseBubble(BubbleCloseReason reason
) {
24 DCHECK(thread_checker_
.CalledOnValidThread());
25 return manager_
->CloseBubble(this->AsWeakPtr(), reason
);
28 bool BubbleController::UpdateBubbleUi() {
29 DCHECK(thread_checker_
.CalledOnValidThread());
32 return delegate_
->UpdateBubbleUi(bubble_ui_
.get());
35 void BubbleController::Show() {
37 bubble_ui_
= delegate_
->BuildBubbleUi();
39 bubble_ui_
->Show(AsWeakPtr());
40 // TODO(hcarmona): log that bubble was shown.
43 void BubbleController::UpdateAnchorPosition() {
45 bubble_ui_
->UpdateAnchorPosition();
48 bool BubbleController::ShouldClose(BubbleCloseReason reason
) {
50 if (delegate_
->ShouldClose(reason
) || reason
== BUBBLE_CLOSE_FORCED
) {
53 // TODO(hcarmona): log that bubble was hidden.