OLD | NEW |
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 Loading... |
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 Loading... |
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 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
303 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); | 295 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 296 if (!pool->IsShutdownInProgress()) { |
| 297 return pool->PostSequencedWorkerTask(sequence_token_, |
| 298 from_here, |
| 299 task); |
304 } else { | 300 } else { |
305 // Fall back to executing on the main thread if the file thread | 301 // Fall back to executing on the main thread if the sequence |
306 // has gone away (around shutdown time) or if we're running as | 302 // worker pool has been requested to shutdown (around shutdown |
307 // part of a unit test that does not set profile_. | 303 // time). |
308 task.Run(); | 304 task.Run(); |
309 return true; | 305 return true; |
310 } | 306 } |
311 } | 307 } |
312 | |
313 bool BaseSessionService::RunningInProduction() const { | |
314 return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE); | |
315 } | |
OLD | NEW |