Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_file_system/drive_backend/sync_engine.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_engine.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/drive/drive_api_service.h" | 13 #include "chrome/browser/drive/drive_api_service.h" |
| 13 #include "chrome/browser/drive/drive_notification_manager.h" | 14 #include "chrome/browser/drive/drive_notification_manager.h" |
| 14 #include "chrome/browser/drive/drive_notification_manager_factory.h" | 15 #include "chrome/browser/drive/drive_notification_manager_factory.h" |
| 15 #include "chrome/browser/drive/drive_service_interface.h" | 16 #include "chrome/browser/drive/drive_service_interface.h" |
| 16 #include "chrome/browser/drive/drive_uploader.h" | 17 #include "chrome/browser/drive/drive_uploader.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h" | 22 #include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h" |
| 22 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h" | 23 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h" |
| 24 #include "chrome/browser/sync_file_system/drive_backend/drive_service_messenger. h" | |
| 25 #include "chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.h" | |
| 23 #include "chrome/browser/sync_file_system/drive_backend/list_changes_task.h" | 26 #include "chrome/browser/sync_file_system/drive_backend/list_changes_task.h" |
| 24 #include "chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer.h " | 27 #include "chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer.h " |
| 25 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 28 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
| 26 #include "chrome/browser/sync_file_system/drive_backend/register_app_task.h" | 29 #include "chrome/browser/sync_file_system/drive_backend/register_app_task.h" |
| 27 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h " | 30 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h " |
| 28 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" | 31 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" |
| 29 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_initializer. h" | 32 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_initializer. h" |
| 30 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h" | 33 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h" |
| 31 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" | 34 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" |
| 32 #include "chrome/browser/sync_file_system/drive_backend/uninstall_app_task.h" | 35 #include "chrome/browser/sync_file_system/drive_backend/uninstall_app_task.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 drive_service->Initialize(signin_manager->GetAuthenticatedAccountId()); | 86 drive_service->Initialize(signin_manager->GetAuthenticatedAccountId()); |
| 84 | 87 |
| 85 scoped_ptr<drive::DriveUploaderInterface> drive_uploader( | 88 scoped_ptr<drive::DriveUploaderInterface> drive_uploader( |
| 86 new drive::DriveUploader(drive_service.get(), drive_task_runner.get())); | 89 new drive::DriveUploader(drive_service.get(), drive_task_runner.get())); |
| 87 | 90 |
| 88 drive::DriveNotificationManager* notification_manager = | 91 drive::DriveNotificationManager* notification_manager = |
| 89 drive::DriveNotificationManagerFactory::GetForBrowserContext(context); | 92 drive::DriveNotificationManagerFactory::GetForBrowserContext(context); |
| 90 ExtensionService* extension_service = | 93 ExtensionService* extension_service = |
| 91 extensions::ExtensionSystem::Get(context)->extension_service(); | 94 extensions::ExtensionSystem::Get(context)->extension_service(); |
| 92 | 95 |
| 93 scoped_refptr<base::SequencedTaskRunner> file_task_runner( | |
| 94 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 95 worker_pool->GetSequenceToken(), | |
| 96 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
| 97 | |
| 98 // TODO(peria): Create another task runner to manage SyncWorker. | 96 // TODO(peria): Create another task runner to manage SyncWorker. |
| 99 scoped_refptr<base::SingleThreadTaskRunner> | 97 scoped_refptr<base::SingleThreadTaskRunner> |
| 100 worker_task_runner = base::MessageLoopProxy::current(); | 98 worker_task_runner = base::MessageLoopProxy::current(); |
| 101 | 99 |
| 102 scoped_ptr<drive_backend::SyncEngine> sync_engine( | 100 scoped_ptr<drive_backend::SyncEngine> sync_engine( |
| 103 new SyncEngine(drive_service.Pass(), | 101 new SyncEngine(drive_service.Pass(), |
| 104 drive_uploader.Pass(), | 102 drive_uploader.Pass(), |
| 105 worker_task_runner, | 103 worker_task_runner, |
| 106 notification_manager, | 104 notification_manager, |
| 107 extension_service, | 105 extension_service, |
| 108 signin_manager)); | 106 signin_manager)); |
| 107 | |
| 108 scoped_refptr<base::SequencedTaskRunner> file_task_runner( | |
| 109 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 110 worker_pool->GetSequenceToken(), | |
| 111 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
| 112 | |
| 109 sync_engine->Initialize( | 113 sync_engine->Initialize( |
| 110 GetSyncFileSystemDir(context->GetPath()), | 114 GetSyncFileSystemDir(context->GetPath()), |
| 111 file_task_runner.get(), | 115 file_task_runner.get(), |
| 112 NULL); | 116 false, |
| 117 NULL /* env_override */); | |
| 113 | 118 |
| 114 return sync_engine.Pass(); | 119 return sync_engine.Pass(); |
| 115 } | 120 } |
| 116 | 121 |
| 117 void SyncEngine::AppendDependsOnFactories( | 122 void SyncEngine::AppendDependsOnFactories( |
| 118 std::set<BrowserContextKeyedServiceFactory*>* factories) { | 123 std::set<BrowserContextKeyedServiceFactory*>* factories) { |
| 119 DCHECK(factories); | 124 DCHECK(factories); |
| 120 factories->insert(drive::DriveNotificationManagerFactory::GetInstance()); | 125 factories->insert(drive::DriveNotificationManagerFactory::GetInstance()); |
| 121 factories->insert(SigninManagerFactory::GetInstance()); | 126 factories->insert(SigninManagerFactory::GetInstance()); |
| 122 factories->insert( | 127 factories->insert( |
| 123 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 128 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 124 } | 129 } |
| 125 | 130 |
| 126 SyncEngine::~SyncEngine() { | 131 SyncEngine::~SyncEngine() { |
| 127 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 132 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 128 GetDriveService()->RemoveObserver(this); | 133 GetDriveService()->RemoveObserver(this); |
| 129 if (notification_manager_) | 134 if (notification_manager_) |
| 130 notification_manager_->RemoveObserver(this); | 135 notification_manager_->RemoveObserver(this); |
| 131 } | 136 } |
| 132 | 137 |
| 133 void SyncEngine::Initialize(const base::FilePath& base_dir, | 138 void SyncEngine::Initialize(const base::FilePath& base_dir, |
|
peria
2014/04/24 04:08:38
It may be good to make InitializeForTesting().
In
| |
| 134 base::SequencedTaskRunner* file_task_runner, | 139 base::SequencedTaskRunner* file_task_runner, |
| 140 bool pass_service_to_worker, | |
| 135 leveldb::Env* env_override) { | 141 leveldb::Env* env_override) { |
| 136 scoped_ptr<SyncEngineContext> sync_engine_context( | 142 scoped_ptr<SyncEngineContext> sync_engine_context; |
| 137 new SyncEngineContext(drive_service_.get(), | 143 if (pass_service_to_worker) { |
| 138 drive_uploader_.get(), | 144 sync_engine_context.reset( |
| 139 base::MessageLoopProxy::current(), | 145 new SyncEngineContext(drive_service_.Pass(), |
| 140 file_task_runner)); | 146 drive_uploader_.get(), |
| 147 base::MessageLoopProxy::current(), | |
| 148 file_task_runner)); | |
| 149 } else { | |
| 150 scoped_ptr<drive::DriveServiceInterface> drive_service_messenger( | |
| 151 new DriveServiceMessenger(drive_service_wrapper_->AsWeakPtr())); | |
| 152 sync_engine_context.reset( | |
| 153 new SyncEngineContext(drive_service_messenger.Pass(), | |
| 154 drive_uploader_.get(), | |
| 155 base::MessageLoopProxy::current(), | |
| 156 file_task_runner)); | |
| 157 } | |
| 141 // TODO(peria): Use PostTask on |worker_task_runner_| to call this function. | 158 // TODO(peria): Use PostTask on |worker_task_runner_| to call this function. |
| 142 sync_worker_ = SyncWorker::CreateOnWorker(weak_ptr_factory_.GetWeakPtr(), | 159 sync_worker_ = SyncWorker::CreateOnWorker(weak_ptr_factory_.GetWeakPtr(), |
| 143 base_dir, | 160 base_dir, |
| 144 sync_engine_context.Pass(), | 161 sync_engine_context.Pass(), |
| 145 env_override); | 162 env_override); |
| 146 | 163 |
| 147 if (notification_manager_) | 164 if (notification_manager_) |
| 148 notification_manager_->AddObserver(this); | 165 notification_manager_->AddObserver(this); |
| 149 GetDriveService()->AddObserver(this); | 166 GetDriveService()->AddObserver(this); |
| 150 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 167 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 void SyncEngine::OnNetworkChanged( | 376 void SyncEngine::OnNetworkChanged( |
| 360 net::NetworkChangeNotifier::ConnectionType type) { | 377 net::NetworkChangeNotifier::ConnectionType type) { |
| 361 worker_task_runner_->PostTask( | 378 worker_task_runner_->PostTask( |
| 362 FROM_HERE, | 379 FROM_HERE, |
| 363 base::Bind(&SyncWorker::OnNetworkChanged, | 380 base::Bind(&SyncWorker::OnNetworkChanged, |
| 364 base::Unretained(sync_worker_.get()), | 381 base::Unretained(sync_worker_.get()), |
| 365 type)); | 382 type)); |
| 366 } | 383 } |
| 367 | 384 |
| 368 drive::DriveServiceInterface* SyncEngine::GetDriveService() { | 385 drive::DriveServiceInterface* SyncEngine::GetDriveService() { |
| 369 return drive_service_.get(); | 386 return sync_worker_->GetDriveService(); |
| 370 } | 387 } |
| 371 | 388 |
| 372 drive::DriveUploaderInterface* SyncEngine::GetDriveUploader() { | 389 drive::DriveUploaderInterface* SyncEngine::GetDriveUploader() { |
| 373 return drive_uploader_.get(); | 390 return sync_worker_->GetDriveUploader(); |
| 374 } | 391 } |
| 375 | 392 |
| 376 MetadataDatabase* SyncEngine::GetMetadataDatabase() { | 393 MetadataDatabase* SyncEngine::GetMetadataDatabase() { |
| 377 // TODO(peria): Post task | 394 // TODO(peria): Post task |
| 378 return sync_worker_->GetMetadataDatabase(); | 395 return sync_worker_->GetMetadataDatabase(); |
| 379 } | 396 } |
| 380 | 397 |
| 381 SyncEngine::SyncEngine( | 398 SyncEngine::SyncEngine( |
| 382 scoped_ptr<drive::DriveServiceInterface> drive_service, | 399 scoped_ptr<drive::DriveServiceInterface> drive_service, |
| 383 scoped_ptr<drive::DriveUploaderInterface> drive_uploader, | 400 scoped_ptr<drive::DriveUploaderInterface> drive_uploader, |
| 384 base::SequencedTaskRunner* worker_task_runner, | 401 base::SequencedTaskRunner* worker_task_runner, |
| 385 drive::DriveNotificationManager* notification_manager, | 402 drive::DriveNotificationManager* notification_manager, |
| 386 ExtensionServiceInterface* extension_service, | 403 ExtensionServiceInterface* extension_service, |
| 387 SigninManagerBase* signin_manager) | 404 SigninManagerBase* signin_manager) |
| 388 : drive_service_(drive_service.Pass()), | 405 : drive_service_(drive_service.Pass()), |
| 406 drive_service_wrapper_(new DriveServiceWrapper(drive_service_.get())), | |
| 389 drive_uploader_(drive_uploader.Pass()), | 407 drive_uploader_(drive_uploader.Pass()), |
| 390 notification_manager_(notification_manager), | 408 notification_manager_(notification_manager), |
| 391 extension_service_(extension_service), | 409 extension_service_(extension_service), |
| 392 signin_manager_(signin_manager), | 410 signin_manager_(signin_manager), |
| 393 worker_task_runner_(worker_task_runner), | 411 worker_task_runner_(worker_task_runner), |
| 394 weak_ptr_factory_(this) {} | 412 weak_ptr_factory_(this) {} |
| 395 | 413 |
| 396 void SyncEngine::DidProcessRemoteChange( | 414 void SyncEngine::DidProcessRemoteChange( |
| 397 sync_file_system::SyncAction sync_action, | 415 sync_file_system::SyncAction sync_action, |
| 398 const fileapi::FileSystemURL& url) { | 416 const fileapi::FileSystemURL& url) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 void SyncEngine::NotifyLastOperationStatus() { | 492 void SyncEngine::NotifyLastOperationStatus() { |
| 475 FOR_EACH_OBSERVER( | 493 FOR_EACH_OBSERVER( |
| 476 Observer, | 494 Observer, |
| 477 service_observers_, | 495 service_observers_, |
| 478 OnRemoteChangeQueueUpdated( | 496 OnRemoteChangeQueueUpdated( |
| 479 GetMetadataDatabase()->CountDirtyTracker())); | 497 GetMetadataDatabase()->CountDirtyTracker())); |
| 480 } | 498 } |
| 481 | 499 |
| 482 } // namespace drive_backend | 500 } // namespace drive_backend |
| 483 } // namespace sync_file_system | 501 } // namespace sync_file_system |
| OLD | NEW |