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"
7 #include "base/command_line.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync_file_system/local/local_file_sync_service.h"
10 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
12 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
14 namespace sync_file_system
{
17 const char kDisableLastWriteWin
[] = "disable-syncfs-last-write-win";
21 SyncFileSystemService
* SyncFileSystemServiceFactory::GetForProfile(
23 return static_cast<SyncFileSystemService
*>(
24 GetInstance()->GetServiceForBrowserContext(profile
, true));
28 SyncFileSystemServiceFactory
* SyncFileSystemServiceFactory::GetInstance() {
29 return Singleton
<SyncFileSystemServiceFactory
>::get();
32 void SyncFileSystemServiceFactory::set_mock_remote_file_service(
33 scoped_ptr
<RemoteFileSyncService
> mock_remote_service
) {
34 mock_remote_file_service_
= mock_remote_service
.Pass();
37 SyncFileSystemServiceFactory::SyncFileSystemServiceFactory()
38 : BrowserContextKeyedServiceFactory(
39 "SyncFileSystemService",
40 BrowserContextDependencyManager::GetInstance()) {
41 typedef std::set
<BrowserContextKeyedServiceFactory
*> FactorySet
;
43 RemoteFileSyncService::AppendDependsOnFactories(
44 RemoteFileSyncService::V1
, &factories
);
45 RemoteFileSyncService::AppendDependsOnFactories(
46 RemoteFileSyncService::V2
, &factories
);
47 for (FactorySet::iterator iter
= factories
.begin();
48 iter
!= factories
.end();
54 SyncFileSystemServiceFactory::~SyncFileSystemServiceFactory() {}
56 BrowserContextKeyedService
*
57 SyncFileSystemServiceFactory::BuildServiceInstanceFor(
58 content::BrowserContext
* context
) const {
59 Profile
* profile
= Profile::FromBrowserContext(context
);
61 SyncFileSystemService
* service
= new SyncFileSystemService(profile
);
63 scoped_ptr
<LocalFileSyncService
> local_file_service(
64 new LocalFileSyncService(profile
));
66 scoped_ptr
<RemoteFileSyncService
> remote_file_service
;
67 if (mock_remote_file_service_
) {
68 remote_file_service
= mock_remote_file_service_
.Pass();
69 } else if (IsV2Enabled()) {
70 remote_file_service
= RemoteFileSyncService::CreateForBrowserContext(
71 RemoteFileSyncService::V2
, context
);
73 remote_file_service
= RemoteFileSyncService::CreateForBrowserContext(
74 RemoteFileSyncService::V1
, context
);
77 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableLastWriteWin
)) {
78 remote_file_service
->SetConflictResolutionPolicy(
79 CONFLICT_RESOLUTION_POLICY_MANUAL
);
82 service
->Initialize(local_file_service
.Pass(),
83 remote_file_service
.Pass());
87 } // namespace sync_file_system