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/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 Loading... |
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::kDisableRestoreSessionState); | 88 !command_line->HasSwitch(switches::kDisableRestoreSessionState); |
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 if (!RunningInProduction()) { | 94 RunTaskOnBackendThread(FROM_HERE, |
95 // We seem to be running as part of a test, in which case we need | 95 base::Bind(&SessionBackend::Init, backend_)); |
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 } | |
103 } | 96 } |
104 | 97 |
105 BaseSessionService::~BaseSessionService() { | 98 BaseSessionService::~BaseSessionService() { |
106 } | 99 } |
107 | 100 |
108 void BaseSessionService::DeleteLastSession() { | 101 void BaseSessionService::DeleteLastSession() { |
109 RunTaskOnBackendThread( | 102 RunTaskOnBackendThread( |
110 FROM_HERE, | 103 FROM_HERE, |
111 base::Bind(&SessionBackend::DeleteLastSession, backend())); | 104 base::Bind(&SessionBackend::DeleteLastSession, backend())); |
112 } | 105 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 CancelableRequestConsumerBase* consumer) { | 350 CancelableRequestConsumerBase* consumer) { |
358 scoped_refptr<InternalGetCommandsRequest> request_wrapper(request); | 351 scoped_refptr<InternalGetCommandsRequest> request_wrapper(request); |
359 AddRequest(request, consumer); | 352 AddRequest(request, consumer); |
360 RunTaskOnBackendThread( | 353 RunTaskOnBackendThread( |
361 FROM_HERE, | 354 FROM_HERE, |
362 base::Bind(&SessionBackend::ReadLastSessionCommands, backend(), | 355 base::Bind(&SessionBackend::ReadLastSessionCommands, backend(), |
363 request_wrapper)); | 356 request_wrapper)); |
364 return request->handle(); | 357 return request->handle(); |
365 } | 358 } |
366 | 359 |
367 bool BaseSessionService::RunningInProduction() const { | |
368 return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE); | |
369 } | |
370 | |
371 bool BaseSessionService::RunTaskOnBackendThread( | 360 bool BaseSessionService::RunTaskOnBackendThread( |
372 const tracked_objects::Location& from_here, | 361 const tracked_objects::Location& from_here, |
373 const base::Closure& task) { | 362 const base::Closure& task) { |
374 if (RunningInProduction()) { | 363 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
375 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); | 364 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); |
376 } else { | 365 } else { |
377 // Fall back to executing on the main thread if the file thread | 366 // Fall back to executing on the main thread if the file thread |
378 // has gone away (around shutdown time) or if we're running as | 367 // has gone away (around shutdown time) or if we're running as |
379 // part of a unit test that does not set profile_. | 368 // part of a unit test that does not set profile_. |
380 task.Run(); | 369 task.Run(); |
381 return true; | 370 return true; |
382 } | 371 } |
383 } | 372 } |
384 | 373 |
385 void BaseSessionService::ResetContentStateReadingMetrics() { | 374 void BaseSessionService::ResetContentStateReadingMetrics() { |
386 time_spent_reading_compressed_content_states = base::TimeDelta(); | 375 time_spent_reading_compressed_content_states = base::TimeDelta(); |
387 } | 376 } |
388 | 377 |
389 void BaseSessionService::WriteContentStateReadingMetrics() { | 378 void BaseSessionService::WriteContentStateReadingMetrics() { |
390 UMA_HISTOGRAM_TIMES("SessionService.ReadingCompressedContentStates", | 379 UMA_HISTOGRAM_TIMES("SessionService.ReadingCompressedContentStates", |
391 time_spent_reading_compressed_content_states); | 380 time_spent_reading_compressed_content_states); |
392 ResetContentStateReadingMetrics(); | 381 ResetContentStateReadingMetrics(); |
393 } | 382 } |
OLD | NEW |