| 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/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
| 36 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" |
| 36 #include "chrome/common/chrome_notification_types.h" | 37 #include "chrome/common/chrome_notification_types.h" |
| 37 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 38 #include "chromeos/chromeos_paths.h" | 39 #include "chromeos/chromeos_paths.h" |
| 39 #include "chromeos/chromeos_switches.h" | 40 #include "chromeos/chromeos_switches.h" |
| 40 #include "chromeos/dbus/dbus_thread_manager.h" | 41 #include "chromeos/dbus/dbus_thread_manager.h" |
| 41 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/notification_details.h" | 43 #include "content/public/browser/notification_details.h" |
| 43 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/notification_source.h" | 45 #include "content/public/browser/notification_source.h" |
| 45 | 46 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( | 188 content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( |
| 188 FROM_HERE, | 189 FROM_HERE, |
| 189 base::Bind(&GetSystemEventTimes, | 190 base::Bind(&GetSystemEventTimes, |
| 190 base::ThreadTaskRunnerHandle::Get(), | 191 base::ThreadTaskRunnerHandle::Get(), |
| 191 base::Bind(&AutomaticRebootManager::Init, | 192 base::Bind(&AutomaticRebootManager::Init, |
| 192 weak_ptr_factory_.GetWeakPtr())), | 193 weak_ptr_factory_.GetWeakPtr())), |
| 193 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 194 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 194 } | 195 } |
| 195 | 196 |
| 196 AutomaticRebootManager::~AutomaticRebootManager() { | 197 AutomaticRebootManager::~AutomaticRebootManager() { |
| 198 FOR_EACH_OBSERVER(AutomaticRebootManagerObserver, |
| 199 observers_, |
| 200 WillDestroyAutomaticRebootManager()); |
| 201 |
| 197 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); | 202 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
| 198 dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this); | 203 dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this); |
| 199 dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this); | 204 dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this); |
| 200 if (ash::Shell::HasInstance()) | 205 if (ash::Shell::HasInstance()) |
| 201 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 206 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| 202 } | 207 } |
| 203 | 208 |
| 209 void AutomaticRebootManager::AddObserver( |
| 210 AutomaticRebootManagerObserver* observer) { |
| 211 observers_.AddObserver(observer); |
| 212 } |
| 213 |
| 214 void AutomaticRebootManager::RemoveObserver( |
| 215 AutomaticRebootManagerObserver* observer) { |
| 216 observers_.RemoveObserver(observer); |
| 217 } |
| 218 |
| 204 void AutomaticRebootManager::SystemResumed( | 219 void AutomaticRebootManager::SystemResumed( |
| 205 const base::TimeDelta& sleep_duration) { | 220 const base::TimeDelta& sleep_duration) { |
| 206 MaybeReboot(true); | 221 MaybeReboot(true); |
| 207 } | 222 } |
| 208 | 223 |
| 209 void AutomaticRebootManager::UpdateStatusChanged( | 224 void AutomaticRebootManager::UpdateStatusChanged( |
| 210 const UpdateEngineClient::Status& status) { | 225 const UpdateEngineClient::Status& status) { |
| 211 // Ignore repeated notifications that a reboot is necessary. This is important | 226 // Ignore repeated notifications that a reboot is necessary. This is important |
| 212 // so that only the time of the first notification is taken into account and | 227 // so that only the time of the first notification is taken into account and |
| 213 // repeated notifications do not postpone the reboot request and grace period. | 228 // repeated notifications do not postpone the reboot request and grace period. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 void AutomaticRebootManager::Reschedule() { | 311 void AutomaticRebootManager::Reschedule() { |
| 297 // Safeguard against reboot loops under error conditions: If the boot time is | 312 // Safeguard against reboot loops under error conditions: If the boot time is |
| 298 // unavailable because /proc/uptime could not be read, do nothing. | 313 // unavailable because /proc/uptime could not be read, do nothing. |
| 299 if (!have_boot_time_) | 314 if (!have_boot_time_) |
| 300 return; | 315 return; |
| 301 | 316 |
| 302 // Assume that no reboot has been requested. | 317 // Assume that no reboot has been requested. |
| 303 reboot_requested_ = false; | 318 reboot_requested_ = false; |
| 304 | 319 |
| 305 const base::TimeDelta kZeroTimeDelta; | 320 const base::TimeDelta kZeroTimeDelta; |
| 321 AutomaticRebootManagerObserver::Reason reboot_reason = |
| 322 AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN; |
| 306 | 323 |
| 307 // If an uptime limit is set, calculate the time at which it should cause a | 324 // If an uptime limit is set, calculate the time at which it should cause a |
| 308 // reboot to be requested. | 325 // reboot to be requested. |
| 309 const base::TimeDelta uptime_limit = base::TimeDelta::FromSeconds( | 326 const base::TimeDelta uptime_limit = base::TimeDelta::FromSeconds( |
| 310 local_state_registrar_.prefs()->GetInteger(prefs::kUptimeLimit)); | 327 local_state_registrar_.prefs()->GetInteger(prefs::kUptimeLimit)); |
| 311 base::TimeTicks reboot_request_time = boot_time_ + uptime_limit; | 328 base::TimeTicks reboot_request_time = boot_time_ + uptime_limit; |
| 312 bool have_reboot_request_time = uptime_limit != kZeroTimeDelta; | 329 bool have_reboot_request_time = uptime_limit != kZeroTimeDelta; |
| 330 if (have_reboot_request_time) |
| 331 reboot_reason = AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC; |
| 313 | 332 |
| 314 // If the policy to automatically reboot after an update is enabled and an | 333 // If the policy to automatically reboot after an update is enabled and an |
| 315 // update has been applied, set the time at which a reboot should be | 334 // update has been applied, set the time at which a reboot should be |
| 316 // requested to the minimum of its current value and the time when the reboot | 335 // requested to the minimum of its current value and the time when the reboot |
| 317 // became necessary. | 336 // became necessary. |
| 318 if (have_update_reboot_needed_time_ && | 337 if (have_update_reboot_needed_time_ && |
| 319 local_state_registrar_.prefs()->GetBoolean(prefs::kRebootAfterUpdate) && | 338 local_state_registrar_.prefs()->GetBoolean(prefs::kRebootAfterUpdate) && |
| 320 (!have_reboot_request_time || | 339 (!have_reboot_request_time || |
| 321 update_reboot_needed_time_ < reboot_request_time)) { | 340 update_reboot_needed_time_ < reboot_request_time)) { |
| 322 reboot_request_time = update_reboot_needed_time_; | 341 reboot_request_time = update_reboot_needed_time_; |
| 323 have_reboot_request_time = true; | 342 have_reboot_request_time = true; |
| 343 reboot_reason = AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE; |
| 324 } | 344 } |
| 325 | 345 |
| 326 // If no reboot should be requested, remove any grace period. | 346 // If no reboot should be requested, remove any grace period. |
| 327 if (!have_reboot_request_time) { | 347 if (!have_reboot_request_time) { |
| 328 grace_start_timer_.reset(); | 348 grace_start_timer_.reset(); |
| 329 grace_end_timer_.reset(); | 349 grace_end_timer_.reset(); |
| 330 return; | 350 return; |
| 331 } | 351 } |
| 332 | 352 |
| 333 // Safeguard against reboot loops: Ensure that the uptime after which a reboot | 353 // Safeguard against reboot loops: Ensure that the uptime after which a reboot |
| (...skipping 14 matching lines...) Expand all Loading... |
| 348 const base::TimeTicks grace_end_time = grace_start_time + | 368 const base::TimeTicks grace_end_time = grace_start_time + |
| 349 base::TimeDelta::FromMilliseconds(kGracePeriodMs); | 369 base::TimeDelta::FromMilliseconds(kGracePeriodMs); |
| 350 // Set up a timer for the end of the grace period. If the grace period ended | 370 // Set up a timer for the end of the grace period. If the grace period ended |
| 351 // in the past, the timer is still used with its delay set to zero. | 371 // in the past, the timer is still used with its delay set to zero. |
| 352 if (!grace_end_timer_) | 372 if (!grace_end_timer_) |
| 353 grace_end_timer_.reset(new base::OneShotTimer<AutomaticRebootManager>); | 373 grace_end_timer_.reset(new base::OneShotTimer<AutomaticRebootManager>); |
| 354 grace_end_timer_->Start(FROM_HERE, | 374 grace_end_timer_->Start(FROM_HERE, |
| 355 std::max(grace_end_time - now, kZeroTimeDelta), | 375 std::max(grace_end_time - now, kZeroTimeDelta), |
| 356 base::Bind(&AutomaticRebootManager::Reboot, | 376 base::Bind(&AutomaticRebootManager::Reboot, |
| 357 base::Unretained(this))); | 377 base::Unretained(this))); |
| 378 |
| 379 DCHECK_NE(AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN, |
| 380 reboot_reason); |
| 381 FOR_EACH_OBSERVER(AutomaticRebootManagerObserver, |
| 382 observers_, |
| 383 OnRebootScheduled(reboot_reason)); |
| 358 } | 384 } |
| 359 | 385 |
| 360 void AutomaticRebootManager::RequestReboot() { | 386 void AutomaticRebootManager::RequestReboot() { |
| 361 reboot_requested_ = true; | 387 reboot_requested_ = true; |
| 362 MaybeReboot(false); | 388 MaybeReboot(false); |
| 363 } | 389 } |
| 364 | 390 |
| 365 void AutomaticRebootManager::MaybeReboot(bool ignore_session) { | 391 void AutomaticRebootManager::MaybeReboot(bool ignore_session) { |
| 366 // Do not reboot if any of the following applies: | 392 // Do not reboot if any of the following applies: |
| 367 // * No reboot has been requested. | 393 // * No reboot has been requested. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 384 } | 410 } |
| 385 | 411 |
| 386 login_screen_idle_timer_.reset(); | 412 login_screen_idle_timer_.reset(); |
| 387 grace_start_timer_.reset(); | 413 grace_start_timer_.reset(); |
| 388 grace_end_timer_.reset(); | 414 grace_end_timer_.reset(); |
| 389 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 415 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
| 390 } | 416 } |
| 391 | 417 |
| 392 } // namespace system | 418 } // namespace system |
| 393 } // namespace chromeos | 419 } // namespace chromeos |
| OLD | NEW |