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

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

Issue 22363005: Switch BaseSessionService to use SequencedWorkerPool instead of FILE thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
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/pickle.h" 9 #include "base/pickle.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 // static 71 // static
72 const int BaseSessionService::max_persist_navigation_count = 6; 72 const int BaseSessionService::max_persist_navigation_count = 6;
73 73
74 BaseSessionService::BaseSessionService(SessionType type, 74 BaseSessionService::BaseSessionService(SessionType type,
75 Profile* profile, 75 Profile* profile,
76 const base::FilePath& path) 76 const base::FilePath& path)
77 : profile_(profile), 77 : profile_(profile),
78 weak_factory_(this), 78 weak_factory_(this),
79 pending_reset_(false), 79 pending_reset_(false),
80 commands_since_reset_(0) { 80 commands_since_reset_(0),
81 sequence_token_(
82 content::BrowserThread::GetBlockingPool()->GetSequenceToken()) {
81 if (profile) { 83 if (profile) {
82 // We should never be created when incognito. 84 // We should never be created when incognito.
83 DCHECK(!profile->IsOffTheRecord()); 85 DCHECK(!profile->IsOffTheRecord());
84 } 86 }
85 backend_ = new SessionBackend(type, profile_ ? profile_->GetPath() : path); 87 backend_ = new SessionBackend(type, profile_ ? profile_->GetPath() : path);
86 DCHECK(backend_.get()); 88 DCHECK(backend_.get());
87
88 // SessionBackend::Init() cannot be scheduled to be called here. There are
89 // service processes which create the BaseSessionService, but they should not
90 // initialize the backend. If they do, the backend will cycle the session
91 // restore files. That in turn prevents the session restore from working when
92 // the normal chromium process is launched. Normally, the backend will be
93 // initialized before it's actually used. However, if we're running as a part
94 // of a test, it must be initialized now.
95 if (!RunningInProduction())
96 backend_->Init();
97 } 89 }
98 90
99 BaseSessionService::~BaseSessionService() { 91 BaseSessionService::~BaseSessionService() {
100 } 92 }
101 93
102 void BaseSessionService::DeleteLastSession() { 94 void BaseSessionService::DeleteLastSession() {
103 RunTaskOnBackendThread( 95 RunTaskOnBackendThread(
104 FROM_HERE, 96 FROM_HERE,
105 base::Bind(&SessionBackend::DeleteLastSession, backend())); 97 base::Bind(&SessionBackend::DeleteLastSession, backend()));
106 } 98 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 RunTaskOnBackendThread( 284 RunTaskOnBackendThread(
293 FROM_HERE, 285 FROM_HERE,
294 base::Bind(&SessionBackend::ReadLastSessionCommands, backend(), 286 base::Bind(&SessionBackend::ReadLastSessionCommands, backend(),
295 is_canceled, callback_runner)); 287 is_canceled, callback_runner));
296 return id; 288 return id;
297 } 289 }
298 290
299 bool BaseSessionService::RunTaskOnBackendThread( 291 bool BaseSessionService::RunTaskOnBackendThread(
300 const tracked_objects::Location& from_here, 292 const tracked_objects::Location& from_here,
301 const base::Closure& task) { 293 const base::Closure& task) {
302 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { 294 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
303 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); 295 if (!pool->IsShutdownInProgress()) {
296 return pool->PostSequencedWorkerTask(sequence_token_,
297 from_here,
298 task);
304 } else { 299 } else {
305 // Fall back to executing on the main thread if the file thread 300 // Fall back to executing on the main thread if the sequence
306 // has gone away (around shutdown time) or if we're running as 301 // worker pool has been requested to shutdown (around shutdown
307 // part of a unit test that does not set profile_. 302 // time).
308 task.Run(); 303 task.Run();
jochen (gone - plz use gerrit) 2013/08/09 11:49:56 that means that the tasks will ran in an random or
309 return true; 304 return true;
310 } 305 }
311 } 306 }
312
313 bool BaseSessionService::RunningInProduction() const {
314 return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE);
315 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/base_session_service.h ('k') | chrome/browser/sessions/persistent_tab_restore_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698