1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h"
7 #include "base/basictypes.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/sequenced_task_runner.h"
11 #include "base/single_thread_task_runner.h"
12 #include "chrome/browser/drive/drive_service_interface.h"
13 #include "chrome/browser/drive/drive_uploader.h"
14 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
15 #include "chrome/browser/sync_file_system/remote_change_processor.h"
16 #include "chrome/browser/sync_file_system/task_logger.h"
18 namespace sync_file_system
{
19 namespace drive_backend
{
21 SyncEngineContext::SyncEngineContext(
22 scoped_ptr
<drive::DriveServiceInterface
> drive_service
,
23 scoped_ptr
<drive::DriveUploaderInterface
> drive_uploader
,
24 TaskLogger
* task_logger
,
25 base::SingleThreadTaskRunner
* ui_task_runner
,
26 base::SequencedTaskRunner
* worker_task_runner
)
27 : drive_service_(drive_service
.Pass()),
28 drive_uploader_(drive_uploader
.Pass()),
29 task_logger_(task_logger
30 ? task_logger
->AsWeakPtr()
31 : base::WeakPtr
<TaskLogger
>()),
32 remote_change_processor_(NULL
),
33 ui_task_runner_(ui_task_runner
),
34 worker_task_runner_(worker_task_runner
) {
35 sequence_checker_
.DetachFromSequence();
38 SyncEngineContext::~SyncEngineContext() {
39 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
42 drive::DriveServiceInterface
* SyncEngineContext::GetDriveService() {
43 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
44 return drive_service_
.get();
47 drive::DriveUploaderInterface
* SyncEngineContext::GetDriveUploader() {
48 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
49 return drive_uploader_
.get();
52 base::WeakPtr
<TaskLogger
> SyncEngineContext::GetTaskLogger() {
53 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
57 MetadataDatabase
* SyncEngineContext::GetMetadataDatabase() {
58 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
59 return metadata_database_
.get();
62 scoped_ptr
<MetadataDatabase
> SyncEngineContext::PassMetadataDatabase() {
63 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
64 return metadata_database_
.Pass();
67 RemoteChangeProcessor
* SyncEngineContext::GetRemoteChangeProcessor() {
68 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
69 return remote_change_processor_
;
72 base::SingleThreadTaskRunner
* SyncEngineContext::GetUITaskRunner() {
73 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
74 return ui_task_runner_
.get();
77 base::SequencedTaskRunner
* SyncEngineContext::GetWorkerTaskRunner() {
78 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
79 return worker_task_runner_
.get();
82 void SyncEngineContext::SetMetadataDatabase(
83 scoped_ptr
<MetadataDatabase
> metadata_database
) {
84 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
85 if (metadata_database
)
86 metadata_database_
= metadata_database
.Pass();
89 void SyncEngineContext::SetRemoteChangeProcessor(
90 RemoteChangeProcessor
* remote_change_processor
) {
91 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
92 DCHECK(remote_change_processor
);
93 remote_change_processor_
= remote_change_processor
;
96 void SyncEngineContext::DetachFromSequence() {
97 sequence_checker_
.DetachFromSequence();
100 } // namespace drive_backend
101 } // namespace sync_file_system