Index: chrome/browser/sessions/base_session_service.cc |
diff --git a/chrome/browser/sessions/base_session_service.cc b/chrome/browser/sessions/base_session_service.cc |
index 6991e24c4294cd7693bd9d50b3eaa5941650cd1a..a529d31c4026a4d8c830d3e699cbcd2ae52f8064 100644 |
--- a/chrome/browser/sessions/base_session_service.cc |
+++ b/chrome/browser/sessions/base_session_service.cc |
@@ -91,8 +91,15 @@ BaseSessionService::BaseSessionService(SessionType type, |
profile_ ? profile_->GetPath() : path_); |
DCHECK(backend_.get()); |
- RunTaskOnBackendThread(FROM_HERE, |
- base::Bind(&SessionBackend::Init, backend_)); |
+ if (!RunningInProduction()) { |
+ // We seem to be running as part of a test, in which case we need |
+ // to explicitly initialize the backend. In production, the |
+ // backend will automatically initialize itself just in time. |
+ // |
+ // Note that it's important not to initialize too early in |
+ // production; this can cause e.g. http://crbug.com/110785. |
+ backend_->Init(); |
+ } |
} |
BaseSessionService::~BaseSessionService() { |
@@ -322,10 +329,14 @@ BaseSessionService::Handle BaseSessionService::ScheduleGetLastSessionCommands( |
return request->handle(); |
} |
+bool BaseSessionService::RunningInProduction() const { |
+ return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE); |
+} |
+ |
bool BaseSessionService::RunTaskOnBackendThread( |
const tracked_objects::Location& from_here, |
const base::Closure& task) { |
- if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
+ if (RunningInProduction()) { |
return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); |
} else { |
// Fall back to executing on the main thread if the file thread |