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