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

Side by Side Diff: chrome/browser/sessions/base_session_service.cc

Issue 9361056: Allow SessionBackend::Init() to occur just-in-time in production builds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sessions/base_session_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sessions/base_session_service.h" 5 #include "chrome/browser/sessions/base_session_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // We should never be created when incognito. 84 // We should never be created when incognito.
85 DCHECK(!profile->IsOffTheRecord()); 85 DCHECK(!profile->IsOffTheRecord());
86 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 86 const CommandLine* command_line = CommandLine::ForCurrentProcess();
87 save_post_data_ = 87 save_post_data_ =
88 command_line->HasSwitch(switches::kEnableRestoreSessionState); 88 command_line->HasSwitch(switches::kEnableRestoreSessionState);
89 } 89 }
90 backend_ = new SessionBackend(type, 90 backend_ = new SessionBackend(type,
91 profile_ ? profile_->GetPath() : path_); 91 profile_ ? profile_->GetPath() : path_);
92 DCHECK(backend_.get()); 92 DCHECK(backend_.get());
93 93
94 RunTaskOnBackendThread(FROM_HERE, 94 if (!RunningInProduction()) {
95 base::Bind(&SessionBackend::Init, backend_)); 95 // We seem to be running as part of a test, in which case we need
96 // to explicitly initialize the backend. In production, the
97 // backend will automatically initialize itself just in time.
98 //
99 // Note that it's important not to initialize too early in
100 // production; this can cause e.g. http://crbug.com/110785.
101 backend_->Init();
102 }
96 } 103 }
97 104
98 BaseSessionService::~BaseSessionService() { 105 BaseSessionService::~BaseSessionService() {
99 } 106 }
100 107
101 void BaseSessionService::DeleteLastSession() { 108 void BaseSessionService::DeleteLastSession() {
102 RunTaskOnBackendThread( 109 RunTaskOnBackendThread(
103 FROM_HERE, 110 FROM_HERE,
104 base::Bind(&SessionBackend::DeleteLastSession, backend())); 111 base::Bind(&SessionBackend::DeleteLastSession, backend()));
105 } 112 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 CancelableRequestConsumerBase* consumer) { 322 CancelableRequestConsumerBase* consumer) {
316 scoped_refptr<InternalGetCommandsRequest> request_wrapper(request); 323 scoped_refptr<InternalGetCommandsRequest> request_wrapper(request);
317 AddRequest(request, consumer); 324 AddRequest(request, consumer);
318 RunTaskOnBackendThread( 325 RunTaskOnBackendThread(
319 FROM_HERE, 326 FROM_HERE,
320 base::Bind(&SessionBackend::ReadLastSessionCommands, backend(), 327 base::Bind(&SessionBackend::ReadLastSessionCommands, backend(),
321 request_wrapper)); 328 request_wrapper));
322 return request->handle(); 329 return request->handle();
323 } 330 }
324 331
332 bool BaseSessionService::RunningInProduction() const {
333 return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE);
334 }
335
325 bool BaseSessionService::RunTaskOnBackendThread( 336 bool BaseSessionService::RunTaskOnBackendThread(
326 const tracked_objects::Location& from_here, 337 const tracked_objects::Location& from_here,
327 const base::Closure& task) { 338 const base::Closure& task) {
328 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { 339 if (RunningInProduction()) {
329 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); 340 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task);
330 } else { 341 } else {
331 // Fall back to executing on the main thread if the file thread 342 // Fall back to executing on the main thread if the file thread
332 // has gone away (around shutdown time) or if we're running as 343 // has gone away (around shutdown time) or if we're running as
333 // part of a unit test that does not set profile_. 344 // part of a unit test that does not set profile_.
334 task.Run(); 345 task.Run();
335 return true; 346 return true;
336 } 347 }
337 } 348 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/base_session_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698