ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / ash / system / chromeos / session / logout_confirmation_controller.cc
blobfdf1cc627c751d59bb5b55777ddcc57463fb2b8a
1 // Copyright 2014 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 "ash/system/chromeos/session/logout_confirmation_controller.h"
7 #include "ash/session/session_state_delegate.h"
8 #include "ash/shell.h"
9 #include "ash/system/chromeos/session/logout_confirmation_dialog.h"
10 #include "base/location.h"
11 #include "base/time/default_tick_clock.h"
12 #include "base/time/tick_clock.h"
13 #include "ui/views/widget/widget.h"
15 namespace ash {
17 LogoutConfirmationController::LogoutConfirmationController(
18 const base::Closure& logout_closure)
19 : clock_(new base::DefaultTickClock),
20 logout_closure_(logout_closure),
21 dialog_(NULL),
22 logout_timer_(false, false) {
23 if (Shell::HasInstance())
24 Shell::GetInstance()->AddShellObserver(this);
27 LogoutConfirmationController::~LogoutConfirmationController() {
28 if (Shell::HasInstance())
29 Shell::GetInstance()->RemoveShellObserver(this);
30 if (dialog_)
31 dialog_->GetWidget()->Close();
34 void LogoutConfirmationController::ConfirmLogout(
35 base::TimeTicks logout_time) {
36 if (!logout_time_.is_null() && logout_time >= logout_time_) {
37 // If a confirmation dialog is already being shown and its countdown expires
38 // no later than the |logout_time| requested now, keep the current dialog
39 // open.
40 return;
42 logout_time_ = logout_time;
44 if (!dialog_) {
45 // Show confirmation dialog unless this is a unit test without a Shell.
46 if (Shell::HasInstance())
47 dialog_ = new LogoutConfirmationDialog(this, logout_time_);
48 } else {
49 dialog_->Update(logout_time_);
52 logout_timer_.Start(FROM_HERE,
53 logout_time_ - clock_->NowTicks(),
54 logout_closure_);
57 void LogoutConfirmationController::SetClockForTesting(
58 scoped_ptr<base::TickClock> clock) {
59 clock_ = clock.Pass();
62 void LogoutConfirmationController::OnLockStateChanged(bool locked) {
63 if (!locked || logout_time_.is_null())
64 return;
66 // If the screen is locked while a confirmation dialog is being shown, close
67 // the dialog.
68 logout_time_ = base::TimeTicks();
69 if (dialog_)
70 dialog_->GetWidget()->Close();
71 logout_timer_.Stop();
74 void LogoutConfirmationController::OnLogoutConfirmed() {
75 logout_timer_.Stop();
76 logout_closure_.Run();
79 void LogoutConfirmationController::OnDialogClosed() {
80 logout_time_ = base::TimeTicks();
81 dialog_ = NULL;
82 logout_timer_.Stop();
85 } // namespace ash