Adds shutdown when FrameTreeServer goes away
[chromium-blink-merge.git] / components / bubble / bubble_controller.cc
blob7dc65b03b35a1e12cde89d8d2d6ffaa95d6bc612
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()) {
14 DCHECK(manager_);
15 DCHECK(delegate_);
18 BubbleController::~BubbleController() {
19 if (bubble_ui_)
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());
30 if (!bubble_ui_)
31 return false;
32 return delegate_->UpdateBubbleUi(bubble_ui_.get());
35 std::string BubbleController::GetName() const {
36 return delegate_->GetName();
39 base::TimeDelta BubbleController::GetVisibleTime() const {
40 return base::TimeTicks::Now() - show_time_;
43 void BubbleController::Show() {
44 DCHECK(!bubble_ui_);
45 bubble_ui_ = delegate_->BuildBubbleUi();
46 DCHECK(bubble_ui_);
47 bubble_ui_->Show(AsWeakPtr());
48 show_time_ = base::TimeTicks::Now();
51 void BubbleController::UpdateAnchorPosition() {
52 DCHECK(bubble_ui_);
53 bubble_ui_->UpdateAnchorPosition();
56 bool BubbleController::ShouldClose(BubbleCloseReason reason) {
57 DCHECK(bubble_ui_);
58 if (delegate_->ShouldClose(reason) || reason == BUBBLE_CLOSE_FORCED) {
59 bubble_ui_->Close();
60 bubble_ui_.reset();
61 return true;
63 return false;