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