Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / sync_engine_context.cc
blob16f2c01942d076ccb18419d0577fa274dd5f802c
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/sync_file_system/drive_backend/metadata_database.h"
13 #include "chrome/browser/sync_file_system/remote_change_processor.h"
14 #include "chrome/browser/sync_file_system/task_logger.h"
15 #include "components/drive/drive_uploader.h"
16 #include "components/drive/service/drive_service_interface.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 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
26 const scoped_refptr<base::SequencedTaskRunner>& worker_task_runner,
27 const scoped_refptr<base::SequencedWorkerPool>& worker_pool)
28 : drive_service_(drive_service.Pass()),
29 drive_uploader_(drive_uploader.Pass()),
30 task_logger_(task_logger ? task_logger->AsWeakPtr()
31 : base::WeakPtr<TaskLogger>()),
32 remote_change_processor_(nullptr),
33 ui_task_runner_(ui_task_runner),
34 worker_task_runner_(worker_task_runner),
35 worker_pool_(worker_pool) {
36 sequence_checker_.DetachFromSequence();
39 SyncEngineContext::~SyncEngineContext() {
40 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
43 drive::DriveServiceInterface* SyncEngineContext::GetDriveService() {
44 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
45 return drive_service_.get();
48 drive::DriveUploaderInterface* SyncEngineContext::GetDriveUploader() {
49 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
50 return drive_uploader_.get();
53 base::WeakPtr<TaskLogger> SyncEngineContext::GetTaskLogger() {
54 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
55 return task_logger_;
58 MetadataDatabase* SyncEngineContext::GetMetadataDatabase() {
59 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
60 return metadata_database_.get();
63 scoped_ptr<MetadataDatabase> SyncEngineContext::PassMetadataDatabase() {
64 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
65 return metadata_database_.Pass();
68 RemoteChangeProcessor* SyncEngineContext::GetRemoteChangeProcessor() {
69 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
70 return remote_change_processor_;
73 base::SingleThreadTaskRunner* SyncEngineContext::GetUITaskRunner() {
74 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
75 return ui_task_runner_.get();
78 base::SequencedTaskRunner* SyncEngineContext::GetWorkerTaskRunner() {
79 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
80 return worker_task_runner_.get();
83 base::SequencedWorkerPool* SyncEngineContext::GetWorkerPool() {
84 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
85 return worker_pool_.get();
88 void SyncEngineContext::SetMetadataDatabase(
89 scoped_ptr<MetadataDatabase> metadata_database) {
90 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
91 if (metadata_database)
92 metadata_database_ = metadata_database.Pass();
95 void SyncEngineContext::SetRemoteChangeProcessor(
96 RemoteChangeProcessor* remote_change_processor) {
97 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
98 DCHECK(remote_change_processor);
99 remote_change_processor_ = remote_change_processor;
102 void SyncEngineContext::DetachFromSequence() {
103 sequence_checker_.DetachFromSequence();
106 } // namespace drive_backend
107 } // namespace sync_file_system