| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/app_mode/kiosk_mode_idle_app_name_notification
.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_mode_idle_app_name_notification
.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | |
| 8 #include "base/bind.h" | 7 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "chrome/browser/chromeos/ui/idle_app_name_notification_view.h" | 10 #include "chrome/browser/chromeos/ui/idle_app_name_notification_view.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 #include "components/user_manager/user_manager.h" | 15 #include "components/user_manager/user_manager.h" |
| 17 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 49 } |
| 51 | 50 |
| 52 KioskModeIdleAppNameNotification::KioskModeIdleAppNameNotification() | 51 KioskModeIdleAppNameNotification::KioskModeIdleAppNameNotification() |
| 53 : show_notification_upon_next_user_activity_(false) { | 52 : show_notification_upon_next_user_activity_(false) { |
| 54 // Note: The timeout is currently fixed. If that changes we need to check if | 53 // Note: The timeout is currently fixed. If that changes we need to check if |
| 55 // the KioskModeSettings were already initialized. | 54 // the KioskModeSettings were already initialized. |
| 56 Setup(); | 55 Setup(); |
| 57 } | 56 } |
| 58 | 57 |
| 59 KioskModeIdleAppNameNotification::~KioskModeIdleAppNameNotification() { | 58 KioskModeIdleAppNameNotification::~KioskModeIdleAppNameNotification() { |
| 60 if (ash::Shell::HasInstance() && | 59 wm::UserActivityDetector* user_activity_detector = |
| 61 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) { | 60 wm::UserActivityDetector::Get(); |
| 62 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 61 if (user_activity_detector && user_activity_detector->HasObserver(this)) { |
| 62 user_activity_detector->RemoveObserver(this); |
| 63 // At this time the DBusThreadManager might already be gone. | 63 // At this time the DBusThreadManager might already be gone. |
| 64 if (chromeos::DBusThreadManager::IsInitialized()) | 64 if (chromeos::DBusThreadManager::IsInitialized()) |
| 65 chromeos::DBusThreadManager::Get()->GetPowerManagerClient( | 65 chromeos::DBusThreadManager::Get()->GetPowerManagerClient( |
| 66 )->RemoveObserver(this); | 66 )->RemoveObserver(this); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void KioskModeIdleAppNameNotification::Setup() { | 70 void KioskModeIdleAppNameNotification::Setup() { |
| 71 DCHECK(user_manager::UserManager::Get()->IsUserLoggedIn()); | 71 DCHECK(user_manager::UserManager::Get()->IsUserLoggedIn()); |
| 72 Start(); | 72 Start(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 | 91 |
| 92 void KioskModeIdleAppNameNotification::SuspendDone( | 92 void KioskModeIdleAppNameNotification::SuspendDone( |
| 93 const base::TimeDelta& sleep_duration) { | 93 const base::TimeDelta& sleep_duration) { |
| 94 // When we come back from a system resume we stop the timer and show the | 94 // When we come back from a system resume we stop the timer and show the |
| 95 // message. | 95 // message. |
| 96 timer_.Stop(); | 96 timer_.Stop(); |
| 97 OnTimeout(); | 97 OnTimeout(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void KioskModeIdleAppNameNotification::Start() { | 100 void KioskModeIdleAppNameNotification::Start() { |
| 101 if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) { | 101 if (!wm::UserActivityDetector::Get()->HasObserver(this)) { |
| 102 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | 102 wm::UserActivityDetector::Get()->AddObserver(this); |
| 103 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 103 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 104 this); | 104 this); |
| 105 } | 105 } |
| 106 ResetTimer(); | 106 ResetTimer(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void KioskModeIdleAppNameNotification::ResetTimer() { | 109 void KioskModeIdleAppNameNotification::ResetTimer() { |
| 110 if (timer_.IsRunning()) { | 110 if (timer_.IsRunning()) { |
| 111 timer_.Reset(); | 111 timer_.Reset(); |
| 112 } else { | 112 } else { |
| 113 // OneShotTimer destroys the posted task after running it, so Reset() | 113 // OneShotTimer destroys the posted task after running it, so Reset() |
| 114 // isn't safe to call on a timer that's already fired. | 114 // isn't safe to call on a timer that's already fired. |
| 115 timer_.Start( | 115 timer_.Start( |
| 116 FROM_HERE, | 116 FROM_HERE, |
| 117 base::TimeDelta::FromMilliseconds(kIdleAppNameNotificationTimeoutMs), | 117 base::TimeDelta::FromMilliseconds(kIdleAppNameNotificationTimeoutMs), |
| 118 base::Bind(&KioskModeIdleAppNameNotification::OnTimeout, | 118 base::Bind(&KioskModeIdleAppNameNotification::OnTimeout, |
| 119 base::Unretained(this))); | 119 base::Unretained(this))); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void KioskModeIdleAppNameNotification::OnTimeout() { | 123 void KioskModeIdleAppNameNotification::OnTimeout() { |
| 124 show_notification_upon_next_user_activity_ = true; | 124 show_notification_upon_next_user_activity_ = true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace chromeos | 127 } // namespace chromeos |
| OLD | NEW |