Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: chrome/browser/chromeos/system/automatic_reboot_manager.cc

Issue 727363002: Fire notifications when reboot is requested, not scheduled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@managed_cros
Patch Set: Add missing run_loop.Run(); Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/system/automatic_reboot_manager.cc
diff --git a/chrome/browser/chromeos/system/automatic_reboot_manager.cc b/chrome/browser/chromeos/system/automatic_reboot_manager.cc
index 81d6dcdfc3ff888994f99c15c930ea47013388f9..2e36a7b99211ed0f88e5a1e1a65e26a829050383 100644
--- a/chrome/browser/chromeos/system/automatic_reboot_manager.cc
+++ b/chrome/browser/chromeos/system/automatic_reboot_manager.cc
@@ -20,6 +20,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
+#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/posix/eintr_wrapper.h"
#include "base/prefs/pref_registry_simple.h"
@@ -32,7 +33,6 @@
#include "base/time/tick_clock.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h"
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/chromeos_switches.h"
@@ -54,6 +54,8 @@ const int kLoginManagerIdleTimeoutMs = 60 * 1000; // 60 seconds.
const int kGracePeriodMs = 24 * 60 * 60 * 1000; // 24 hours.
const int kOneKilobyte = 1 << 10; // 1 kB in bytes.
+const char kSequenceToken[] = "automatic-reboot-manager";
+
base::TimeDelta ReadTimeDeltaFromFile(const base::FilePath& path) {
base::ThreadRestrictions::AssertIOAllowed();
base::ScopedFD fd(
@@ -151,6 +153,7 @@ AutomaticRebootManager::AutomaticRebootManager(
: clock_(clock.Pass()),
have_boot_time_(false),
have_update_reboot_needed_time_(false),
+ reboot_reason_(AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN),
reboot_requested_(false),
weak_ptr_factory_(this) {
local_state_registrar_.Init(g_browser_process->local_state());
@@ -184,7 +187,10 @@ AutomaticRebootManager::AutomaticRebootManager(
// base::MessageLoopProxy::current() return pointers to the same object.
// In unit tests, using base::ThreadTaskRunnerHandle::Get() has the advantage
// that it allows a custom base::SingleThreadTaskRunner to be injected.
- content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior(
+ base::SequencedWorkerPool* worker_pool =
+ content::BrowserThread::GetBlockingPool();
+ worker_pool->PostSequencedWorkerTaskWithShutdownBehavior(
+ worker_pool->GetNamedSequenceToken(kSequenceToken),
FROM_HERE,
base::Bind(&GetSystemEventTimes,
base::ThreadTaskRunnerHandle::Get(),
@@ -317,8 +323,6 @@ void AutomaticRebootManager::Reschedule() {
reboot_requested_ = false;
const base::TimeDelta kZeroTimeDelta;
- AutomaticRebootManagerObserver::Reason reboot_reason =
- AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN;
// If an uptime limit is set, calculate the time at which it should cause a
// reboot to be requested.
@@ -327,7 +331,7 @@ void AutomaticRebootManager::Reschedule() {
base::TimeTicks reboot_request_time = boot_time_ + uptime_limit;
bool have_reboot_request_time = uptime_limit != kZeroTimeDelta;
if (have_reboot_request_time)
- reboot_reason = AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC;
+ reboot_reason_ = AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC;
// If the policy to automatically reboot after an update is enabled and an
// update has been applied, set the time at which a reboot should be
@@ -339,7 +343,7 @@ void AutomaticRebootManager::Reschedule() {
update_reboot_needed_time_ < reboot_request_time)) {
reboot_request_time = update_reboot_needed_time_;
have_reboot_request_time = true;
- reboot_reason = AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE;
+ reboot_reason_ = AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE;
}
// If no reboot should be requested, remove any grace period.
@@ -355,6 +359,7 @@ void AutomaticRebootManager::Reschedule() {
const base::TimeTicks now = clock_->NowTicks();
const base::TimeTicks grace_start_time = std::max(reboot_request_time,
boot_time_ + base::TimeDelta::FromMilliseconds(kMinRebootUptimeMs));
+
// Set up a timer for the start of the grace period. If the grace period
// started in the past, the timer is still used with its delay set to zero.
if (!grace_start_timer_)
@@ -374,16 +379,15 @@ void AutomaticRebootManager::Reschedule() {
std::max(grace_end_time - now, kZeroTimeDelta),
base::Bind(&AutomaticRebootManager::Reboot,
base::Unretained(this)));
-
- DCHECK_NE(AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN,
- reboot_reason);
- FOR_EACH_OBSERVER(AutomaticRebootManagerObserver,
- observers_,
- OnRebootScheduled(reboot_reason));
}
void AutomaticRebootManager::RequestReboot() {
reboot_requested_ = true;
+ DCHECK_NE(AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN,
+ reboot_reason_);
+ FOR_EACH_OBSERVER(AutomaticRebootManagerObserver,
+ observers_,
+ OnRebootRequested(reboot_reason_));
MaybeReboot(false);
}

Powered by Google App Engine
This is Rietveld 408576698