Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(909)

Side by Side Diff: chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout.cc

Issue 693643004: Make UserActivityDetector a singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@athena_do_not_use_ash45
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 7 #include "ash/shell.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 24 matching lines...) Expand all
35 KioskModeIdleLogout::KioskModeIdleLogout() { 35 KioskModeIdleLogout::KioskModeIdleLogout() {
36 if (KioskModeSettings::Get()->is_initialized()) { 36 if (KioskModeSettings::Get()->is_initialized()) {
37 Setup(); 37 Setup();
38 } else { 38 } else {
39 KioskModeSettings::Get()->Initialize(base::Bind(&KioskModeIdleLogout::Setup, 39 KioskModeSettings::Get()->Initialize(base::Bind(&KioskModeIdleLogout::Setup,
40 base::Unretained(this))); 40 base::Unretained(this)));
41 } 41 }
42 } 42 }
43 43
44 KioskModeIdleLogout::~KioskModeIdleLogout() { 44 KioskModeIdleLogout::~KioskModeIdleLogout() {
45 if (ash::Shell::HasInstance() && 45 wm::UserActivityDetector* user_activity_detector =
46 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) 46 wm::UserActivityDetector::Get();
47 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); 47 if (user_activity_detector && user_activity_detector->HasObserver(this))
48 user_activity_detector->RemoveObserver(this);
48 } 49 }
49 50
50 void KioskModeIdleLogout::Setup() { 51 void KioskModeIdleLogout::Setup() {
51 if (user_manager::UserManager::Get()->IsLoggedInAsDemoUser()) { 52 if (user_manager::UserManager::Get()->IsLoggedInAsDemoUser()) {
52 // This means that we're recovering from a crash. The user is already 53 // This means that we're recovering from a crash. The user is already
53 // logged in, so go ahead and start the timer. 54 // logged in, so go ahead and start the timer.
54 Start(); 55 Start();
55 } else { 56 } else {
56 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, 57 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED,
57 content::NotificationService::AllSources()); 58 content::NotificationService::AllSources());
58 } 59 }
59 } 60 }
60 61
61 void KioskModeIdleLogout::Observe( 62 void KioskModeIdleLogout::Observe(
62 int type, 63 int type,
63 const content::NotificationSource& source, 64 const content::NotificationSource& source,
64 const content::NotificationDetails& details) { 65 const content::NotificationDetails& details) {
65 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { 66 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) {
66 Start(); 67 Start();
67 registrar_.RemoveAll(); 68 registrar_.RemoveAll();
68 } 69 }
69 } 70 }
70 71
71 void KioskModeIdleLogout::OnUserActivity(const ui::Event* event) { 72 void KioskModeIdleLogout::OnUserActivity(const ui::Event* event) {
72 IdleLogoutDialogView::CloseDialog(); 73 IdleLogoutDialogView::CloseDialog();
73 ResetTimer(); 74 ResetTimer();
74 } 75 }
75 76
76 void KioskModeIdleLogout::Start() { 77 void KioskModeIdleLogout::Start() {
77 if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) 78 if (!wm::UserActivityDetector::Get()->HasObserver(this))
78 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); 79 wm::UserActivityDetector::Get()->AddObserver(this);
79 ResetTimer(); 80 ResetTimer();
80 } 81 }
81 82
82 void KioskModeIdleLogout::ResetTimer() { 83 void KioskModeIdleLogout::ResetTimer() {
83 if (timer_.IsRunning()) { 84 if (timer_.IsRunning()) {
84 timer_.Reset(); 85 timer_.Reset();
85 } else { 86 } else {
86 // OneShotTimer destroys the posted task after running it, so Reset() 87 // OneShotTimer destroys the posted task after running it, so Reset()
87 // isn't safe to call on a timer that's already fired. 88 // isn't safe to call on a timer that's already fired.
88 timer_.Start(FROM_HERE, KioskModeSettings::Get()->GetIdleLogoutTimeout(), 89 timer_.Start(FROM_HERE, KioskModeSettings::Get()->GetIdleLogoutTimeout(),
89 base::Bind(&KioskModeIdleLogout::OnTimeout, 90 base::Bind(&KioskModeIdleLogout::OnTimeout,
90 base::Unretained(this))); 91 base::Unretained(this)));
91 } 92 }
92 } 93 }
93 94
94 void KioskModeIdleLogout::OnTimeout() { 95 void KioskModeIdleLogout::OnTimeout() {
95 IdleLogoutDialogView::ShowDialog(); 96 IdleLogoutDialogView::ShowDialog();
96 } 97 }
97 98
98 } // namespace chromeos 99 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/idle_detector.cc ('k') | chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698