sync_file_system_service_factory.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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.
4
5#include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
6
7#include <set>
8
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
16namespace sync_file_system {
17
18// static
19SyncFileSystemService* SyncFileSystemServiceFactory::GetForProfile(
20    Profile* profile) {
21  return static_cast<SyncFileSystemService*>(
22      GetInstance()->GetServiceForBrowserContext(profile, true));
23}
24
25// static
26SyncFileSystemServiceFactory* SyncFileSystemServiceFactory::GetInstance() {
27  return Singleton<SyncFileSystemServiceFactory>::get();
28}
29
30void SyncFileSystemServiceFactory::set_mock_remote_file_service(
31    scoped_ptr<RemoteFileSyncService> mock_remote_service) {
32  mock_remote_file_service_ = mock_remote_service.Pass();
33}
34
35SyncFileSystemServiceFactory::SyncFileSystemServiceFactory()
36    : BrowserContextKeyedServiceFactory(
37        "SyncFileSystemService",
38        BrowserContextDependencyManager::GetInstance()) {
39  typedef std::set<BrowserContextKeyedServiceFactory*> FactorySet;
40  FactorySet factories;
41  RemoteFileSyncService::AppendDependsOnFactories(
42      RemoteFileSyncService::V1, &factories);
43  RemoteFileSyncService::AppendDependsOnFactories(
44      RemoteFileSyncService::V2, &factories);
45  for (FactorySet::iterator iter = factories.begin();
46       iter != factories.end();
47       ++iter) {
48    DependsOn(*iter);
49  }
50}
51
52SyncFileSystemServiceFactory::~SyncFileSystemServiceFactory() {}
53
54KeyedService* SyncFileSystemServiceFactory::BuildServiceInstanceFor(
55    content::BrowserContext* context) const {
56  Profile* profile = Profile::FromBrowserContext(context);
57
58  SyncFileSystemService* service = new SyncFileSystemService(profile);
59
60  scoped_ptr<LocalFileSyncService> local_file_service =
61      LocalFileSyncService::Create(profile);
62
63  scoped_ptr<RemoteFileSyncService> remote_file_service;
64  if (mock_remote_file_service_) {
65    remote_file_service = mock_remote_file_service_.Pass();
66  } else if (IsV2Enabled()) {
67    remote_file_service = RemoteFileSyncService::CreateForBrowserContext(
68        RemoteFileSyncService::V2, context, service->task_logger());
69  } else {
70    remote_file_service = RemoteFileSyncService::CreateForBrowserContext(
71        RemoteFileSyncService::V1, context, service->task_logger());
72  }
73
74  service->Initialize(local_file_service.Pass(),
75                      remote_file_service.Pass());
76  return service;
77}
78
79}  // namespace sync_file_system
80