| Index: chrome/browser/chromeos/cros/login_library.cc
|
| diff --git a/chrome/browser/chromeos/cros/login_library.cc b/chrome/browser/chromeos/cros/login_library.cc
|
| index 026757f3b92226b9bdf99ae76e2eb3993e401f2f..7ee6f0ad07d243d783ea2b7e186d54a66d17030d 100644
|
| --- a/chrome/browser/chromeos/cros/login_library.cc
|
| +++ b/chrome/browser/chromeos/cros/login_library.cc
|
| @@ -5,11 +5,14 @@
|
| #include "chrome/browser/chromeos/cros/login_library.h"
|
|
|
| #include "base/message_loop.h"
|
| +#include "base/timer.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/chromeos/cros/cros_library.h"
|
| #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "content/browser/browser_thread.h"
|
| +#include "content/common/notification_observer.h"
|
| +#include "content/common/notification_registrar.h"
|
| #include "content/common/notification_service.h"
|
| #include "content/common/notification_type.h"
|
|
|
| @@ -131,16 +134,57 @@ class LoginLibraryImpl : public LoginLibrary {
|
| }
|
|
|
| bool RestartJob(int pid, const std::string& command_line) {
|
| - if (g_browser_process && g_browser_process->local_state()) {
|
| - // XXX: normally this call must not be needed, however it turned out that
|
| - // without this explicit call to SavePersistentPrefs it is possible for
|
| - // preferences to be lost. See http://crosbug.com/13102
|
| - g_browser_process->local_state()->SavePersistentPrefs();
|
| - }
|
| - return chromeos::RestartJob(pid, command_line.c_str());
|
| + job_restart_request_.reset(new JobRestartRequest(pid, command_line));
|
| + return true;
|
| }
|
|
|
| private:
|
| + class JobRestartRequest : public NotificationObserver {
|
| + public:
|
| + JobRestartRequest(int pid, const std::string& command_line)
|
| + : pid_(pid),
|
| + command_line_(command_line),
|
| + local_state_(g_browser_process->local_state()) {
|
| + if (local_state_) {
|
| + notification_registrar_.Add(this, NotificationType::PREF_COMMITTED,
|
| + Source<PrefService>(local_state_));
|
| + // XXX: normally this call must not be needed, however RestartJob
|
| + // just kills us so settings may be lost. See http://crosbug.com/13102
|
| + local_state_->CommitPendingWrite();
|
| + timer_.Start(
|
| + base::TimeDelta::FromSeconds(3), this,
|
| + &JobRestartRequest::RestartJob);
|
| + } else {
|
| + RestartJob();
|
| + }
|
| + }
|
| +
|
| + private:
|
| + void RestartJob() {
|
| + if (!chromeos::RestartJob(pid_, command_line_.c_str()))
|
| + NOTREACHED();
|
| + }
|
| +
|
| + // NotificationObserver implementation.
|
| + virtual void Observe(NotificationType type,
|
| + const NotificationSource& source,
|
| + const NotificationDetails& details) {
|
| + if (local_state_ &&
|
| + type.value == NotificationType::PREF_COMMITTED &&
|
| + source == Source<PrefService>(local_state_)) {
|
| + RestartJob();
|
| + } else {
|
| + NOTREACHED();
|
| + }
|
| + }
|
| +
|
| + int pid_;
|
| + std::string command_line_;
|
| + NotificationRegistrar notification_registrar_;
|
| + PrefService* local_state_;
|
| + base::OneShotTimer<JobRestartRequest> timer_;
|
| + };
|
| +
|
| static void Handler(void* object, const OwnershipEvent& event) {
|
| LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object);
|
| switch (event) {
|
| @@ -208,6 +252,7 @@ class LoginLibraryImpl : public LoginLibrary {
|
| }
|
|
|
| chromeos::SessionConnection session_connection_;
|
| + scoped_ptr<JobRestartRequest> job_restart_request_;
|
|
|
| Delegate* set_owner_key_callback_;
|
| Delegate* whitelist_op_callback_;
|
|
|