1 // Copyright (c) 2013 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/sync_file_system_service_factory.h"
9 #include "base/command_line.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync_file_system/local/local_file_sync_service.h"
12 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
13 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "extensions/browser/extension_registry_factory.h"
17 namespace sync_file_system
{
20 SyncFileSystemService
* SyncFileSystemServiceFactory::GetForProfile(
22 return static_cast<SyncFileSystemService
*>(
23 GetInstance()->GetServiceForBrowserContext(profile
, true));
27 SyncFileSystemServiceFactory
* SyncFileSystemServiceFactory::GetInstance() {
28 return Singleton
<SyncFileSystemServiceFactory
>::get();
31 void SyncFileSystemServiceFactory::set_mock_local_file_service(
32 scoped_ptr
<LocalFileSyncService
> mock_local_service
) {
33 mock_local_file_service_
= mock_local_service
.Pass();
36 void SyncFileSystemServiceFactory::set_mock_remote_file_service(
37 scoped_ptr
<RemoteFileSyncService
> mock_remote_service
) {
38 mock_remote_file_service_
= mock_remote_service
.Pass();
41 SyncFileSystemServiceFactory::SyncFileSystemServiceFactory()
42 : BrowserContextKeyedServiceFactory(
43 "SyncFileSystemService",
44 BrowserContextDependencyManager::GetInstance()) {
45 typedef std::set
<BrowserContextKeyedServiceFactory
*> FactorySet
;
47 factories
.insert(extensions::ExtensionRegistryFactory::GetInstance());
48 RemoteFileSyncService::AppendDependsOnFactories(&factories
);
49 for (FactorySet::iterator iter
= factories
.begin();
50 iter
!= factories
.end();
56 SyncFileSystemServiceFactory::~SyncFileSystemServiceFactory() {}
58 KeyedService
* SyncFileSystemServiceFactory::BuildServiceInstanceFor(
59 content::BrowserContext
* context
) const {
60 Profile
* profile
= Profile::FromBrowserContext(context
);
62 SyncFileSystemService
* service
= new SyncFileSystemService(profile
);
64 scoped_ptr
<LocalFileSyncService
> local_file_service
;
65 if (mock_local_file_service_
)
66 local_file_service
= mock_local_file_service_
.Pass();
68 local_file_service
= LocalFileSyncService::Create(profile
);
70 scoped_ptr
<RemoteFileSyncService
> remote_file_service
;
71 if (mock_remote_file_service_
) {
72 remote_file_service
= mock_remote_file_service_
.Pass();
74 remote_file_service
= RemoteFileSyncService::CreateForBrowserContext(
75 context
, service
->task_logger());
78 service
->Initialize(local_file_service
.Pass(),
79 remote_file_service
.Pass());
83 } // namespace sync_file_system