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"
16 namespace sync_file_system
{
19 const char kDisableLastWriteWin
[] = "disable-syncfs-last-write-win";
23 SyncFileSystemService
* SyncFileSystemServiceFactory::GetForProfile(
25 return static_cast<SyncFileSystemService
*>(
26 GetInstance()->GetServiceForBrowserContext(profile
, true));
30 SyncFileSystemServiceFactory
* SyncFileSystemServiceFactory::GetInstance() {
31 return Singleton
<SyncFileSystemServiceFactory
>::get();
34 void SyncFileSystemServiceFactory::set_mock_remote_file_service(
35 scoped_ptr
<RemoteFileSyncService
> mock_remote_service
) {
36 mock_remote_file_service_
= mock_remote_service
.Pass();
39 SyncFileSystemServiceFactory::SyncFileSystemServiceFactory()
40 : BrowserContextKeyedServiceFactory(
41 "SyncFileSystemService",
42 BrowserContextDependencyManager::GetInstance()) {
43 typedef std::set
<BrowserContextKeyedServiceFactory
*> FactorySet
;
45 RemoteFileSyncService::AppendDependsOnFactories(
46 RemoteFileSyncService::V1
, &factories
);
47 RemoteFileSyncService::AppendDependsOnFactories(
48 RemoteFileSyncService::V2
, &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 LocalFileSyncService::Create(profile
);
67 scoped_ptr
<RemoteFileSyncService
> remote_file_service
;
68 if (mock_remote_file_service_
) {
69 remote_file_service
= mock_remote_file_service_
.Pass();
70 } else if (IsV2Enabled()) {
71 remote_file_service
= RemoteFileSyncService::CreateForBrowserContext(
72 RemoteFileSyncService::V2
, context
);
74 remote_file_service
= RemoteFileSyncService::CreateForBrowserContext(
75 RemoteFileSyncService::V1
, context
);
78 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableLastWriteWin
)) {
79 remote_file_service
->SetDefaultConflictResolutionPolicy(
80 CONFLICT_RESOLUTION_POLICY_MANUAL
);
83 service
->Initialize(local_file_service
.Pass(),
84 remote_file_service
.Pass());
88 } // namespace sync_file_system