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 15 matching lines...) Expand all Loading... |
26 #include "base/prefs/pref_registry_simple.h" | 26 #include "base/prefs/pref_registry_simple.h" |
27 #include "base/prefs/pref_service.h" | 27 #include "base/prefs/pref_service.h" |
28 #include "base/single_thread_task_runner.h" | 28 #include "base/single_thread_task_runner.h" |
29 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
30 #include "base/thread_task_runner_handle.h" | 30 #include "base/thread_task_runner_handle.h" |
31 #include "base/threading/sequenced_worker_pool.h" | 31 #include "base/threading/sequenced_worker_pool.h" |
32 #include "base/threading/thread_restrictions.h" | 32 #include "base/threading/thread_restrictions.h" |
33 #include "base/time/tick_clock.h" | 33 #include "base/time/tick_clock.h" |
34 #include "chrome/browser/browser_process.h" | 34 #include "chrome/browser/browser_process.h" |
35 #include "chrome/browser/chrome_notification_types.h" | 35 #include "chrome/browser/chrome_notification_types.h" |
36 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
37 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" | 36 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" |
38 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
39 #include "chromeos/chromeos_paths.h" | 38 #include "chromeos/chromeos_paths.h" |
40 #include "chromeos/chromeos_switches.h" | 39 #include "chromeos/chromeos_switches.h" |
41 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
| 41 #include "components/user_manager/user_manager.h" |
42 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/notification_details.h" | 43 #include "content/public/browser/notification_details.h" |
44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/notification_source.h" | 45 #include "content/public/browser/notification_source.h" |
46 #include "ui/wm/core/user_activity_detector.h" | 46 #include "ui/wm/core/user_activity_detector.h" |
47 | 47 |
48 namespace chromeos { | 48 namespace chromeos { |
49 namespace system { | 49 namespace system { |
50 | 50 |
51 namespace { | 51 namespace { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 164 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
165 content::NotificationService::AllSources()); | 165 content::NotificationService::AllSources()); |
166 | 166 |
167 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); | 167 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
168 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this); | 168 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this); |
169 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); | 169 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); |
170 | 170 |
171 // If no user is logged in, a reboot may be performed whenever the user is | 171 // If no user is logged in, a reboot may be performed whenever the user is |
172 // idle. Start listening for user activity to determine whether the user is | 172 // idle. Start listening for user activity to determine whether the user is |
173 // idle or not. | 173 // idle or not. |
174 if (!UserManager::Get()->IsUserLoggedIn()) { | 174 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { |
175 if (ash::Shell::HasInstance()) | 175 if (ash::Shell::HasInstance()) |
176 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | 176 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); |
177 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 177 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
178 content::NotificationService::AllSources()); | 178 content::NotificationService::AllSources()); |
179 login_screen_idle_timer_.reset( | 179 login_screen_idle_timer_.reset( |
180 new base::OneShotTimer<AutomaticRebootManager>); | 180 new base::OneShotTimer<AutomaticRebootManager>); |
181 OnUserActivity(NULL); | 181 OnUserActivity(NULL); |
182 } | 182 } |
183 | 183 |
184 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and | 184 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 base::Bind(&AutomaticRebootManager::MaybeReboot, | 255 base::Bind(&AutomaticRebootManager::MaybeReboot, |
256 base::Unretained(this), | 256 base::Unretained(this), |
257 false)); | 257 false)); |
258 } | 258 } |
259 | 259 |
260 void AutomaticRebootManager::Observe( | 260 void AutomaticRebootManager::Observe( |
261 int type, | 261 int type, |
262 const content::NotificationSource& source, | 262 const content::NotificationSource& source, |
263 const content::NotificationDetails& details) { | 263 const content::NotificationDetails& details) { |
264 if (type == chrome::NOTIFICATION_APP_TERMINATING) { | 264 if (type == chrome::NOTIFICATION_APP_TERMINATING) { |
265 if (UserManager::Get()->IsUserLoggedIn()) { | 265 if (user_manager::UserManager::Get()->IsUserLoggedIn()) { |
266 // The browser is terminating during a session, either because the session | 266 // The browser is terminating during a session, either because the session |
267 // is ending or because the browser is being restarted. | 267 // is ending or because the browser is being restarted. |
268 MaybeReboot(true); | 268 MaybeReboot(true); |
269 } | 269 } |
270 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 270 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
271 // A session is starting. Stop listening for user activity as it no longer | 271 // A session is starting. Stop listening for user activity as it no longer |
272 // is a relevant criterion. | 272 // is a relevant criterion. |
273 if (ash::Shell::HasInstance()) | 273 if (ash::Shell::HasInstance()) |
274 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 274 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
275 notification_registrar_.Remove( | 275 notification_registrar_.Remove( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 MaybeReboot(false); | 388 MaybeReboot(false); |
389 } | 389 } |
390 | 390 |
391 void AutomaticRebootManager::MaybeReboot(bool ignore_session) { | 391 void AutomaticRebootManager::MaybeReboot(bool ignore_session) { |
392 // Do not reboot if any of the following applies: | 392 // Do not reboot if any of the following applies: |
393 // * No reboot has been requested. | 393 // * No reboot has been requested. |
394 // * A user is interacting with the login screen. | 394 // * A user is interacting with the login screen. |
395 // * A session is in progress and |ignore_session| is not set. | 395 // * A session is in progress and |ignore_session| is not set. |
396 if (!reboot_requested_ || | 396 if (!reboot_requested_ || |
397 (login_screen_idle_timer_ && login_screen_idle_timer_->IsRunning()) || | 397 (login_screen_idle_timer_ && login_screen_idle_timer_->IsRunning()) || |
398 (!ignore_session && UserManager::Get()->IsUserLoggedIn())) { | 398 (!ignore_session && user_manager::UserManager::Get()->IsUserLoggedIn())) { |
399 return; | 399 return; |
400 } | 400 } |
401 | 401 |
402 Reboot(); | 402 Reboot(); |
403 } | 403 } |
404 | 404 |
405 void AutomaticRebootManager::Reboot() { | 405 void AutomaticRebootManager::Reboot() { |
406 // If a non-kiosk-app session is in progress, do not reboot. | 406 // If a non-kiosk-app session is in progress, do not reboot. |
407 if (UserManager::Get()->IsUserLoggedIn() && | 407 if (user_manager::UserManager::Get()->IsUserLoggedIn() && |
408 !UserManager::Get()->IsLoggedInAsKioskApp()) { | 408 !user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) { |
409 return; | 409 return; |
410 } | 410 } |
411 | 411 |
412 login_screen_idle_timer_.reset(); | 412 login_screen_idle_timer_.reset(); |
413 grace_start_timer_.reset(); | 413 grace_start_timer_.reset(); |
414 grace_end_timer_.reset(); | 414 grace_end_timer_.reset(); |
415 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 415 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
416 } | 416 } |
417 | 417 |
418 } // namespace system | 418 } // namespace system |
419 } // namespace chromeos | 419 } // namespace chromeos |
OLD | NEW |