| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/system/automatic_reboot_manager.h" | 5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "chrome/browser/chrome_notification_types.h" | 35 #include "chrome/browser/chrome_notification_types.h" |
| 36 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 37 #include "chromeos/chromeos_paths.h" | 37 #include "chromeos/chromeos_paths.h" |
| 38 #include "chromeos/chromeos_switches.h" | 38 #include "chromeos/chromeos_switches.h" |
| 39 #include "chromeos/dbus/dbus_thread_manager.h" | 39 #include "chromeos/dbus/dbus_thread_manager.h" |
| 40 #include "components/user_manager/user_manager.h" | 40 #include "components/user_manager/user_manager.h" |
| 41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/notification_details.h" | 42 #include "content/public/browser/notification_details.h" |
| 43 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/notification_source.h" | 44 #include "content/public/browser/notification_source.h" |
| 45 #include "ui/wm/core/user_activity_detector.h" | 45 #include "ui/base/user_activity/user_activity_detector.h" |
| 46 | 46 |
| 47 namespace chromeos { | 47 namespace chromeos { |
| 48 namespace system { | 48 namespace system { |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 const int kMinRebootUptimeMs = 60 * 60 * 1000; // 1 hour. | 52 const int kMinRebootUptimeMs = 60 * 60 * 1000; // 1 hour. |
| 53 const int kLoginManagerIdleTimeoutMs = 60 * 1000; // 60 seconds. | 53 const int kLoginManagerIdleTimeoutMs = 60 * 1000; // 60 seconds. |
| 54 const int kGracePeriodMs = 24 * 60 * 60 * 1000; // 24 hours. | 54 const int kGracePeriodMs = 24 * 60 * 60 * 1000; // 24 hours. |
| 55 const int kOneKilobyte = 1 << 10; // 1 kB in bytes. | 55 const int kOneKilobyte = 1 << 10; // 1 kB in bytes. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 content::NotificationService::AllSources()); | 167 content::NotificationService::AllSources()); |
| 168 | 168 |
| 169 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); | 169 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
| 170 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this); | 170 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this); |
| 171 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); | 171 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); |
| 172 | 172 |
| 173 // If no user is logged in, a reboot may be performed whenever the user is | 173 // If no user is logged in, a reboot may be performed whenever the user is |
| 174 // idle. Start listening for user activity to determine whether the user is | 174 // idle. Start listening for user activity to determine whether the user is |
| 175 // idle or not. | 175 // idle or not. |
| 176 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { | 176 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { |
| 177 if (wm::UserActivityDetector::Get()) | 177 if (ui::UserActivityDetector::Get()) |
| 178 wm::UserActivityDetector::Get()->AddObserver(this); | 178 ui::UserActivityDetector::Get()->AddObserver(this); |
| 179 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 179 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 180 content::NotificationService::AllSources()); | 180 content::NotificationService::AllSources()); |
| 181 login_screen_idle_timer_.reset( | 181 login_screen_idle_timer_.reset( |
| 182 new base::OneShotTimer<AutomaticRebootManager>); | 182 new base::OneShotTimer<AutomaticRebootManager>); |
| 183 OnUserActivity(NULL); | 183 OnUserActivity(NULL); |
| 184 } | 184 } |
| 185 | 185 |
| 186 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and | 186 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and |
| 187 // base::MessageLoopProxy::current() return pointers to the same object. | 187 // base::MessageLoopProxy::current() return pointers to the same object. |
| 188 // In unit tests, using base::ThreadTaskRunnerHandle::Get() has the advantage | 188 // In unit tests, using base::ThreadTaskRunnerHandle::Get() has the advantage |
| (...skipping 11 matching lines...) Expand all Loading... |
| 200 } | 200 } |
| 201 | 201 |
| 202 AutomaticRebootManager::~AutomaticRebootManager() { | 202 AutomaticRebootManager::~AutomaticRebootManager() { |
| 203 FOR_EACH_OBSERVER(AutomaticRebootManagerObserver, | 203 FOR_EACH_OBSERVER(AutomaticRebootManagerObserver, |
| 204 observers_, | 204 observers_, |
| 205 WillDestroyAutomaticRebootManager()); | 205 WillDestroyAutomaticRebootManager()); |
| 206 | 206 |
| 207 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); | 207 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
| 208 dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this); | 208 dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this); |
| 209 dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this); | 209 dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this); |
| 210 if (wm::UserActivityDetector::Get()) | 210 if (ui::UserActivityDetector::Get()) |
| 211 wm::UserActivityDetector::Get()->RemoveObserver(this); | 211 ui::UserActivityDetector::Get()->RemoveObserver(this); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void AutomaticRebootManager::AddObserver( | 214 void AutomaticRebootManager::AddObserver( |
| 215 AutomaticRebootManagerObserver* observer) { | 215 AutomaticRebootManagerObserver* observer) { |
| 216 observers_.AddObserver(observer); | 216 observers_.AddObserver(observer); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void AutomaticRebootManager::RemoveObserver( | 219 void AutomaticRebootManager::RemoveObserver( |
| 220 AutomaticRebootManagerObserver* observer) { | 220 AutomaticRebootManagerObserver* observer) { |
| 221 observers_.RemoveObserver(observer); | 221 observers_.RemoveObserver(observer); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 const content::NotificationDetails& details) { | 268 const content::NotificationDetails& details) { |
| 269 if (type == chrome::NOTIFICATION_APP_TERMINATING) { | 269 if (type == chrome::NOTIFICATION_APP_TERMINATING) { |
| 270 if (user_manager::UserManager::Get()->IsUserLoggedIn()) { | 270 if (user_manager::UserManager::Get()->IsUserLoggedIn()) { |
| 271 // The browser is terminating during a session, either because the session | 271 // The browser is terminating during a session, either because the session |
| 272 // is ending or because the browser is being restarted. | 272 // is ending or because the browser is being restarted. |
| 273 MaybeReboot(true); | 273 MaybeReboot(true); |
| 274 } | 274 } |
| 275 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 275 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
| 276 // A session is starting. Stop listening for user activity as it no longer | 276 // A session is starting. Stop listening for user activity as it no longer |
| 277 // is a relevant criterion. | 277 // is a relevant criterion. |
| 278 if (wm::UserActivityDetector::Get()) | 278 if (ui::UserActivityDetector::Get()) |
| 279 wm::UserActivityDetector::Get()->RemoveObserver(this); | 279 ui::UserActivityDetector::Get()->RemoveObserver(this); |
| 280 notification_registrar_.Remove( | 280 notification_registrar_.Remove( |
| 281 this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 281 this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 282 content::NotificationService::AllSources()); | 282 content::NotificationService::AllSources()); |
| 283 login_screen_idle_timer_.reset(); | 283 login_screen_idle_timer_.reset(); |
| 284 } else { | 284 } else { |
| 285 NOTREACHED(); | 285 NOTREACHED(); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 | 288 |
| 289 // static | 289 // static |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 413 } |
| 414 | 414 |
| 415 login_screen_idle_timer_.reset(); | 415 login_screen_idle_timer_.reset(); |
| 416 grace_start_timer_.reset(); | 416 grace_start_timer_.reset(); |
| 417 grace_end_timer_.reset(); | 417 grace_end_timer_.reset(); |
| 418 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 418 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 } // namespace system | 421 } // namespace system |
| 422 } // namespace chromeos | 422 } // namespace chromeos |
| OLD | NEW |