OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout.h" | 5 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout.h" |
6 | 6 |
7 #include "ash/shell.h" | |
8 #include "base/bind.h" | 7 #include "base/bind.h" |
9 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | 12 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
14 #include "chrome/browser/chromeos/ui/idle_logout_dialog_view.h" | 13 #include "chrome/browser/chromeos/ui/idle_logout_dialog_view.h" |
15 #include "components/user_manager/user_manager.h" | 14 #include "components/user_manager/user_manager.h" |
16 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
19 #include "ui/wm/core/user_activity_detector.h" | 18 #include "ui/wm/core/user_activity_detector.h" |
20 | 19 |
20 #if defined(USE_ASH) | |
Jun Mukai
2014/10/29 01:03:27
IIRC Athena still links to ash right now, so this
| |
21 #include "ash/shell.h" | |
22 #endif | |
23 | |
21 namespace chromeos { | 24 namespace chromeos { |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
25 static base::LazyInstance<KioskModeIdleLogout> | 28 static base::LazyInstance<KioskModeIdleLogout> |
26 g_kiosk_mode_idle_logout = LAZY_INSTANCE_INITIALIZER; | 29 g_kiosk_mode_idle_logout = LAZY_INSTANCE_INITIALIZER; |
27 | 30 |
28 } // namespace | 31 } // namespace |
29 | 32 |
30 // static | 33 // static |
31 void KioskModeIdleLogout::Initialize() { | 34 void KioskModeIdleLogout::Initialize() { |
32 g_kiosk_mode_idle_logout.Get(); | 35 g_kiosk_mode_idle_logout.Get(); |
33 } | 36 } |
34 | 37 |
35 KioskModeIdleLogout::KioskModeIdleLogout() { | 38 KioskModeIdleLogout::KioskModeIdleLogout() { |
36 if (KioskModeSettings::Get()->is_initialized()) { | 39 if (KioskModeSettings::Get()->is_initialized()) { |
37 Setup(); | 40 Setup(); |
38 } else { | 41 } else { |
39 KioskModeSettings::Get()->Initialize(base::Bind(&KioskModeIdleLogout::Setup, | 42 KioskModeSettings::Get()->Initialize(base::Bind(&KioskModeIdleLogout::Setup, |
40 base::Unretained(this))); | 43 base::Unretained(this))); |
41 } | 44 } |
42 } | 45 } |
43 | 46 |
44 KioskModeIdleLogout::~KioskModeIdleLogout() { | 47 KioskModeIdleLogout::~KioskModeIdleLogout() { |
48 #if defined(USE_ASH) | |
45 if (ash::Shell::HasInstance() && | 49 if (ash::Shell::HasInstance() && |
46 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) | 50 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) |
47 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 51 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
52 #endif | |
48 } | 53 } |
49 | 54 |
50 void KioskModeIdleLogout::Setup() { | 55 void KioskModeIdleLogout::Setup() { |
51 if (user_manager::UserManager::Get()->IsLoggedInAsDemoUser()) { | 56 if (user_manager::UserManager::Get()->IsLoggedInAsDemoUser()) { |
52 // This means that we're recovering from a crash. The user is already | 57 // This means that we're recovering from a crash. The user is already |
53 // logged in, so go ahead and start the timer. | 58 // logged in, so go ahead and start the timer. |
54 Start(); | 59 Start(); |
55 } else { | 60 } else { |
56 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 61 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
57 content::NotificationService::AllSources()); | 62 content::NotificationService::AllSources()); |
58 } | 63 } |
59 } | 64 } |
60 | 65 |
61 void KioskModeIdleLogout::Observe( | 66 void KioskModeIdleLogout::Observe( |
62 int type, | 67 int type, |
63 const content::NotificationSource& source, | 68 const content::NotificationSource& source, |
64 const content::NotificationDetails& details) { | 69 const content::NotificationDetails& details) { |
65 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 70 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
66 Start(); | 71 Start(); |
67 registrar_.RemoveAll(); | 72 registrar_.RemoveAll(); |
68 } | 73 } |
69 } | 74 } |
70 | 75 |
71 void KioskModeIdleLogout::OnUserActivity(const ui::Event* event) { | 76 void KioskModeIdleLogout::OnUserActivity(const ui::Event* event) { |
72 IdleLogoutDialogView::CloseDialog(); | 77 IdleLogoutDialogView::CloseDialog(); |
73 ResetTimer(); | 78 ResetTimer(); |
74 } | 79 } |
75 | 80 |
76 void KioskModeIdleLogout::Start() { | 81 void KioskModeIdleLogout::Start() { |
82 #if defined(USE_ASH) | |
77 if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) | 83 if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) |
78 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | 84 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); |
85 #endif | |
79 ResetTimer(); | 86 ResetTimer(); |
80 } | 87 } |
81 | 88 |
82 void KioskModeIdleLogout::ResetTimer() { | 89 void KioskModeIdleLogout::ResetTimer() { |
83 if (timer_.IsRunning()) { | 90 if (timer_.IsRunning()) { |
84 timer_.Reset(); | 91 timer_.Reset(); |
85 } else { | 92 } else { |
86 // OneShotTimer destroys the posted task after running it, so Reset() | 93 // OneShotTimer destroys the posted task after running it, so Reset() |
87 // isn't safe to call on a timer that's already fired. | 94 // isn't safe to call on a timer that's already fired. |
88 timer_.Start(FROM_HERE, KioskModeSettings::Get()->GetIdleLogoutTimeout(), | 95 timer_.Start(FROM_HERE, KioskModeSettings::Get()->GetIdleLogoutTimeout(), |
89 base::Bind(&KioskModeIdleLogout::OnTimeout, | 96 base::Bind(&KioskModeIdleLogout::OnTimeout, |
90 base::Unretained(this))); | 97 base::Unretained(this))); |
91 } | 98 } |
92 } | 99 } |
93 | 100 |
94 void KioskModeIdleLogout::OnTimeout() { | 101 void KioskModeIdleLogout::OnTimeout() { |
95 IdleLogoutDialogView::ShowDialog(); | 102 IdleLogoutDialogView::ShowDialog(); |
96 } | 103 } |
97 | 104 |
98 } // namespace chromeos | 105 } // namespace chromeos |
OLD | NEW |