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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 if (profile) { | 80 if (profile) { |
81 // We should never be created when incognito. | 81 // We should never be created when incognito. |
82 DCHECK(!profile->IsOffTheRecord()); | 82 DCHECK(!profile->IsOffTheRecord()); |
83 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 83 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
84 save_post_data_ = | 84 save_post_data_ = |
85 !command_line->HasSwitch(switches::kDisableRestoreSessionState); | 85 !command_line->HasSwitch(switches::kDisableRestoreSessionState); |
86 } | 86 } |
87 backend_ = new SessionBackend(type, profile_ ? profile_->GetPath() : path); | 87 backend_ = new SessionBackend(type, profile_ ? profile_->GetPath() : path); |
88 DCHECK(backend_.get()); | 88 DCHECK(backend_.get()); |
89 | 89 |
90 RunTaskOnBackendThread(FROM_HERE, | 90 // SessionBackend::Init() cannot be scheduled to be called here. There are |
91 base::Bind(&SessionBackend::Init, backend_)); | 91 // service processes which create the BaseSessionService, but they should not |
| 92 // initialize the backend. If they do, the backend will cycle the session |
| 93 // restore files. That in turn prevents the session restore from working when |
| 94 // the normal chromium process is launched. Normally, the backend will be |
| 95 // initialized before it's actually used. However, if we're running as a part |
| 96 // of a test, it must be initialized now. |
| 97 if (!RunningInProduction()) |
| 98 backend_->Init(); |
92 } | 99 } |
93 | 100 |
94 BaseSessionService::~BaseSessionService() { | 101 BaseSessionService::~BaseSessionService() { |
95 } | 102 } |
96 | 103 |
97 void BaseSessionService::DeleteLastSession() { | 104 void BaseSessionService::DeleteLastSession() { |
98 RunTaskOnBackendThread( | 105 RunTaskOnBackendThread( |
99 FROM_HERE, | 106 FROM_HERE, |
100 base::Bind(&SessionBackend::DeleteLastSession, backend())); | 107 base::Bind(&SessionBackend::DeleteLastSession, backend())); |
101 } | 108 } |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { | 380 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
374 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); | 381 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); |
375 } else { | 382 } else { |
376 // Fall back to executing on the main thread if the file thread | 383 // Fall back to executing on the main thread if the file thread |
377 // has gone away (around shutdown time) or if we're running as | 384 // has gone away (around shutdown time) or if we're running as |
378 // part of a unit test that does not set profile_. | 385 // part of a unit test that does not set profile_. |
379 task.Run(); | 386 task.Run(); |
380 return true; | 387 return true; |
381 } | 388 } |
382 } | 389 } |
| 390 |
| 391 bool BaseSessionService::RunningInProduction() const { |
| 392 return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE); |
| 393 } |
OLD | NEW |