1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/session/last_window_closed_logout_reminder.h"
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/shell.h"
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/session/logout_confirmation_controller.h"
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/user/login_status.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/time/time.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace ash {
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace {
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)const int kLogoutConfirmationDelayInSeconds = 20;
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)LastWindowClosedLogoutReminder::LastWindowClosedLogoutReminder() {
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Shell::GetInstance()->system_tray_notifier()->AddLastWindowClosedObserver(
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      this);
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)LastWindowClosedLogoutReminder::~LastWindowClosedLogoutReminder() {
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Shell::GetInstance()->system_tray_notifier()->RemoveLastWindowClosedObserver(
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      this);
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void LastWindowClosedLogoutReminder::OnLastWindowClosed() {
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() !=
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      user::LOGGED_IN_PUBLIC) {
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Ask the user to confirm logout if a public session is in progress and the
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // screen is not locked.
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Shell::GetInstance()->logout_confirmation_controller()->ConfirmLogout(
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::TimeTicks::Now() +
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::TimeDelta::FromSeconds(kLogoutConfirmationDelayInSeconds));
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace ash
43