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