summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 09:05:33 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 09:05:33 +0000
commit6ffcb08137cb8512ecc5f0c8eaf6e871b502263c (patch)
tree1dc6fff9501e1044b20b02b4692b9ce88b8db7ef /chrome
parent148830a6dc30305128796a7d28cac4ceedbe377c (diff)
downloadchromium_src-6ffcb08137cb8512ecc5f0c8eaf6e871b502263c.zip
chromium_src-6ffcb08137cb8512ecc5f0c8eaf6e871b502263c.tar.gz
chromium_src-6ffcb08137cb8512ecc5f0c8eaf6e871b502263c.tar.bz2
Move JobRestartRequest from LoginLibrary to LoginUtils.
This is a preparation work for moving login manager D-Bus code from libcros to Chrome. We want to make the D-Bus layer to be as simple as possible. This change simply moves code, but NewRunnableMethod() is replaced with base::Bind() along the way. BUG=chromium-os:16555 TEST=guest mode works as before Review URL: http://codereview.chromium.org/8226032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105280 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/cros/login_library.cc54
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc59
2 files changed, 60 insertions, 53 deletions
diff --git a/chrome/browser/chromeos/cros/login_library.cc b/chrome/browser/chromeos/cros/login_library.cc
index 6781378..efc30b7 100644
--- a/chrome/browser/chromeos/cros/login_library.cc
+++ b/chrome/browser/chromeos/cros/login_library.cc
@@ -24,7 +24,7 @@ LoginLibrary::~LoginLibrary() {}
class LoginLibraryImpl : public LoginLibrary {
public:
- LoginLibraryImpl() : job_restart_request_(NULL) {
+ LoginLibraryImpl() {
}
virtual ~LoginLibraryImpl() {
@@ -85,57 +85,10 @@ class LoginLibraryImpl : public LoginLibrary {
}
virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {
- if (job_restart_request_) {
- NOTREACHED();
- }
- job_restart_request_ = new JobRestartRequest(pid, command_line);
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ chromeos::RestartJob(pid, command_line.c_str());
}
- private:
- class JobRestartRequest
- : public base::RefCountedThreadSafe<JobRestartRequest> {
- public:
- JobRestartRequest(int pid, const std::string& command_line)
- : pid_(pid),
- command_line_(command_line),
- local_state_(g_browser_process->local_state()) {
- AddRef();
- if (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(
- FROM_HERE, base::TimeDelta::FromSeconds(3), this,
- &JobRestartRequest::RestartJob);
- // Post task on file thread thus it occurs last on task queue, so it
- // would be executed after committing pending write on file thread.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(this, &JobRestartRequest::RestartJob));
- } else {
- RestartJob();
- }
- }
-
- private:
- void RestartJob() {
- if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- if (!chromeos::RestartJob(pid_, command_line_.c_str()))
- NOTREACHED();
- } else {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, &JobRestartRequest::RestartJob));
- MessageLoop::current()->AssertIdle();
- }
- }
-
- int pid_;
- std::string command_line_;
- PrefService* local_state_;
- base::OneShotTimer<JobRestartRequest> timer_;
- };
-
class StubDelegate
: public SignedSettings::Delegate<const em::PolicyFetchResponse&> {
public:
@@ -215,7 +168,6 @@ class LoginLibraryImpl : public LoginLibrary {
}
chromeos::SessionConnection session_connection_;
- JobRestartRequest* job_restart_request_;
DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl);
};
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index 500f5af..7f02836 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -355,6 +355,52 @@ class PolicyOAuthFetcher : public GaiaOAuthConsumer {
DISALLOW_COPY_AND_ASSIGN(PolicyOAuthFetcher);
};
+// Used to request a restart to switch to the guest mode.
+class JobRestartRequest
+ : public base::RefCountedThreadSafe<JobRestartRequest> {
+ public:
+ JobRestartRequest(int pid, const std::string& command_line)
+ : pid_(pid),
+ command_line_(command_line),
+ local_state_(g_browser_process->local_state()) {
+ AddRef();
+ if (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(
+ FROM_HERE, base::TimeDelta::FromSeconds(3), this,
+ &JobRestartRequest::RestartJob);
+ // Post task on FILE thread thus it occurs last on task queue, so it
+ // would be executed after committing pending write on file thread.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&JobRestartRequest::RestartJob, this));
+ } else {
+ RestartJob();
+ }
+ }
+
+ private:
+ void RestartJob() {
+ if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ CrosLibrary::Get()->GetLoginLibrary()->RestartJob(
+ pid_, command_line_);
+ } else {
+ // This function can be called on FILE thread. See PostTask in the
+ // constructor.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &JobRestartRequest::RestartJob));
+ MessageLoop::current()->AssertIdle();
+ }
+ }
+
+ int pid_;
+ std::string command_line_;
+ PrefService* local_state_;
+ base::OneShotTimer<JobRestartRequest> timer_;
+};
class LoginUtilsImpl : public LoginUtils,
public ProfileManagerObserver,
@@ -366,7 +412,8 @@ class LoginUtilsImpl : public LoginUtils,
pending_requests_(false),
using_oauth_(false),
has_cookies_(false),
- delegate_(NULL) {
+ delegate_(NULL),
+ job_restart_request_(NULL) {
net::NetworkChangeNotifier::AddOnlineStateObserver(this);
}
@@ -482,6 +529,9 @@ class LoginUtilsImpl : public LoginUtils,
// Delegate to be fired when the profile will be prepared.
LoginUtils::Delegate* delegate_;
+ // Used to restart Chrome to switch to the guest mode.
+ JobRestartRequest* job_restart_request_;
+
DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl);
};
@@ -791,7 +841,12 @@ void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) {
browser_command_line,
&command_line);
- CrosLibrary::Get()->GetLoginLibrary()->RestartJob(getpid(), cmd_line_str);
+ if (job_restart_request_) {
+ NOTREACHED();
+ }
+ VLOG(1) << "Requesting a restart with PID " << getpid()
+ << " and command line: " << cmd_line_str;
+ job_restart_request_ = new JobRestartRequest(getpid(), cmd_line_str);
}
}