blob: 46bd66adcc75a1c6ffd5ede877ff7911cb27cec5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_SYSTEM_SERVICE_H_
#define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_SYSTEM_SERVICE_H_
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/google_apis/gdata_errorcode.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
class FilePath;
namespace gdata {
class DriveCache;
class DriveDownloadObserver;
class DriveFileSystemInterface;
class DriveServiceInterface;
class DriveUploader;
class DriveWebAppsRegistry;
class FileWriteHelper;
class DriveSyncClient;
class StaleCacheFilesRemover;
// DriveSystemService runs the Drive system, including the Drive file system
// implementation for the file manager, and some other sub systems.
//
// The class is essentially a container that manages lifetime of the objects
// that are used to run the Drive system. The DriveSystemService object is
// created per-profile.
class DriveSystemService : public ProfileKeyedService {
public:
DriveServiceInterface* drive_service() { return drive_service_.get(); }
DriveCache* cache() { return cache_; }
DriveFileSystemInterface* file_system() { return file_system_.get(); }
FileWriteHelper* file_write_helper() { return file_write_helper_.get(); }
DriveUploader* uploader() { return uploader_.get(); }
DriveWebAppsRegistry* webapps_registry() { return webapps_registry_.get(); }
// Clears all the local cache files and in-memory data, and remounts the file
// system.
void ClearCacheAndRemountFileSystem(
const base::Callback<void(bool)>& callback);
// ProfileKeyedService override:
virtual void Shutdown() OVERRIDE;
private:
explicit DriveSystemService(Profile* profile);
virtual ~DriveSystemService();
// Initializes the object. This function should be called before any
// other functions.
void Initialize(DriveServiceInterface* drive_service,
const FilePath& cache_root);
// Registers remote file system proxy for drive mount point.
void AddDriveMountPoint();
// Unregisters drive mount point from File API.
void RemoveDriveMountPoint();
// Adds back the drive mount point. Used to implement ClearCache().
void AddBackDriveMountPoint(const base::Callback<void(bool)>& callback,
DriveFileError error,
const FilePath& file_path);
friend class DriveSystemServiceFactory;
Profile* profile_;
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
DriveCache* cache_;
scoped_ptr<DriveServiceInterface> drive_service_;
scoped_ptr<DriveUploader> uploader_;
scoped_ptr<DriveWebAppsRegistry> webapps_registry_;
scoped_ptr<DriveFileSystemInterface> file_system_;
scoped_ptr<FileWriteHelper> file_write_helper_;
scoped_ptr<DriveDownloadObserver> download_observer_;
scoped_ptr<DriveSyncClient> sync_client_;
scoped_ptr<StaleCacheFilesRemover> stale_cache_files_remover_;
base::WeakPtrFactory<DriveSystemService> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DriveSystemService);
};
// Singleton that owns all DriveSystemServices and associates them with
// Profiles.
class DriveSystemServiceFactory : public ProfileKeyedServiceFactory {
public:
// Returns the DriveSystemService for |profile|, creating it if it is not
// yet created.
static DriveSystemService* GetForProfile(Profile* profile);
// Returns the DriveSystemService that is already associated with |profile|,
// if it is not yet created it will return NULL.
static DriveSystemService* FindForProfile(Profile* profile);
// Returns the DriveSystemServiceFactory instance.
static DriveSystemServiceFactory* GetInstance();
// Sets drive service that should be used to initialize file system in test.
// Should be called before the service is created.
// Please, make sure |drive_service| gets deleted if no system service is
// created (e.g. by calling this method with NULL).
static void set_drive_service_for_test(DriveServiceInterface* drive_service);
// Sets root path for the cache used in test. Should be called before the
// service is created.
// If |cache_root| is not empty, new string object will be created. Please,
// make sure it gets deleted if no system service is created (e.g. by calling
// this method with empty string).
static void set_cache_root_for_test(const std::string& cache_root);
private:
friend struct DefaultSingletonTraits<DriveSystemServiceFactory>;
DriveSystemServiceFactory();
virtual ~DriveSystemServiceFactory();
// ProfileKeyedServiceFactory:
virtual ProfileKeyedService* BuildServiceInstanceFor(
Profile* profile) const OVERRIDE;
};
} // namespace gdata
#endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_SYSTEM_SERVICE_H_
|