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_DRIVE_DRIVE_SYSTEM_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYSTEM_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYSTEM_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYSTEM_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
16 #include "chrome/browser/chromeos/drive/drive_file_error.h" | 16 #include "chrome/browser/chromeos/drive/drive_file_error.h" |
17 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
18 #include "chrome/browser/chromeos/drive/drive_scheduler.h" | 18 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
19 #include "chrome/browser/google_apis/drive_notification_observer.h" | |
20 #include "chrome/browser/profiles/profile_keyed_service.h" | 19 #include "chrome/browser/profiles/profile_keyed_service.h" |
21 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 20 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 21 #include "sync/notifier/invalidation_handler.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class FilePath; | 24 class FilePath; |
25 } | 25 } |
26 | 26 |
27 namespace google_apis { | 27 namespace google_apis { |
28 class DriveServiceInterface; | 28 class DriveServiceInterface; |
29 } | 29 } |
30 | 30 |
31 namespace drive { | 31 namespace drive { |
(...skipping 26 matching lines...) Expand all Loading... |
58 protected: | 58 protected: |
59 virtual ~DriveSystemServiceObserver() {} | 59 virtual ~DriveSystemServiceObserver() {} |
60 }; | 60 }; |
61 | 61 |
62 // DriveSystemService runs the Drive system, including the Drive file system | 62 // DriveSystemService runs the Drive system, including the Drive file system |
63 // implementation for the file manager, and some other sub systems. | 63 // implementation for the file manager, and some other sub systems. |
64 // | 64 // |
65 // The class is essentially a container that manages lifetime of the objects | 65 // The class is essentially a container that manages lifetime of the objects |
66 // that are used to run the Drive system. The DriveSystemService object is | 66 // that are used to run the Drive system. The DriveSystemService object is |
67 // created per-profile. | 67 // created per-profile. |
68 class DriveSystemService | 68 class DriveSystemService : public ProfileKeyedService, |
69 : public ProfileKeyedService, | 69 public syncer::InvalidationHandler { |
70 public google_apis::DriveNotificationObserver { | |
71 public: | 70 public: |
72 // test_drive_service, test_cache_root and test_file_system are used by tests | 71 // test_drive_service, test_cache_root and test_file_system are used by tests |
73 // to inject customized instances. | 72 // to inject customized instances. |
74 // Pass NULL or the empty value when not interested. | 73 // Pass NULL or the empty value when not interested. |
75 DriveSystemService(Profile* profile, | 74 DriveSystemService(Profile* profile, |
76 google_apis::DriveServiceInterface* test_drive_service, | 75 google_apis::DriveServiceInterface* test_drive_service, |
77 const base::FilePath& test_cache_root, | 76 const base::FilePath& test_cache_root, |
78 DriveFileSystemInterface* test_file_system); | 77 DriveFileSystemInterface* test_file_system); |
79 virtual ~DriveSystemService(); | 78 virtual ~DriveSystemService(); |
80 | 79 |
81 // Initializes the object. This function should be called before any | 80 // Initializes the object. This function should be called before any |
82 // other functions. | 81 // other functions. |
83 void Initialize(); | 82 void Initialize(); |
84 | 83 |
85 // ProfileKeyedService override: | 84 // ProfileKeyedService override: |
86 virtual void Shutdown() OVERRIDE; | 85 virtual void Shutdown() OVERRIDE; |
87 | 86 |
88 // Adds and removes the observer. | 87 // Adds and removes the observer. |
89 void AddObserver(DriveSystemServiceObserver* observer); | 88 void AddObserver(DriveSystemServiceObserver* observer); |
90 void RemoveObserver(DriveSystemServiceObserver* observer); | 89 void RemoveObserver(DriveSystemServiceObserver* observer); |
91 | 90 |
92 // google_apis::DriveNotificationObserver implementation. | |
93 virtual void OnNotificationReceived() OVERRIDE; | |
94 | |
95 google_apis::DriveServiceInterface* drive_service() { | 91 google_apis::DriveServiceInterface* drive_service() { |
96 return drive_service_.get(); | 92 return drive_service_.get(); |
97 } | 93 } |
98 | 94 |
99 DriveCache* cache() { return cache_.get(); } | 95 DriveCache* cache() { return cache_.get(); } |
100 DriveFileSystemInterface* file_system() { return file_system_.get(); } | 96 DriveFileSystemInterface* file_system() { return file_system_.get(); } |
101 FileWriteHelper* file_write_helper() { return file_write_helper_.get(); } | 97 FileWriteHelper* file_write_helper() { return file_write_helper_.get(); } |
102 DriveDownloadHandler* download_handler() { return download_handler_.get(); } | 98 DriveDownloadHandler* download_handler() { return download_handler_.get(); } |
103 DriveWebAppsRegistry* webapps_registry() { return webapps_registry_.get(); } | 99 DriveWebAppsRegistry* webapps_registry() { return webapps_registry_.get(); } |
104 EventLogger* event_logger() { return event_logger_.get(); } | 100 EventLogger* event_logger() { return event_logger_.get(); } |
105 JobListInterface* job_list() { return scheduler_.get(); } | 101 JobListInterface* job_list() { return scheduler_.get(); } |
106 | 102 |
107 // Clears all the local cache files and in-memory data, and remounts the | 103 // Clears all the local cache files and in-memory data, and remounts the |
108 // file system. |callback| is called with true when this operation is done | 104 // file system. |callback| is called with true when this operation is done |
109 // successfully. Otherwise, |callback| is called with false. | 105 // successfully. Otherwise, |callback| is called with false. |
110 // |callback| must not be null. | 106 // |callback| must not be null. |
111 void ClearCacheAndRemountFileSystem( | 107 void ClearCacheAndRemountFileSystem( |
112 const base::Callback<void(bool)>& callback); | 108 const base::Callback<void(bool)>& callback); |
113 | 109 |
114 // Reloads and remounts the file system. | 110 // Reloads and remounts the file system. |
115 void ReloadAndRemountFileSystem(); | 111 void ReloadAndRemountFileSystem(); |
116 | 112 |
| 113 // Returns true if the push notification is enabled. |
| 114 bool PushNotificationEnabled(); |
| 115 |
117 private: | 116 private: |
| 117 // syncer::InvalidationHandler implementation. |
| 118 virtual void OnInvalidatorStateChange( |
| 119 syncer::InvalidatorState state) OVERRIDE; |
| 120 virtual void OnIncomingInvalidation( |
| 121 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
| 122 |
118 // Returns true if Drive is enabled. | 123 // Returns true if Drive is enabled. |
119 // Must be called on UI thread. | 124 // Must be called on UI thread. |
120 bool IsDriveEnabled(); | 125 bool IsDriveEnabled(); |
121 | 126 |
122 // Registers remote file system proxy for drive mount point. | 127 // Registers remote file system proxy for drive mount point. |
123 void AddDriveMountPoint(); | 128 void AddDriveMountPoint(); |
124 // Unregisters drive mount point from File API. | 129 // Unregisters drive mount point from File API. |
125 void RemoveDriveMountPoint(); | 130 void RemoveDriveMountPoint(); |
126 | 131 |
127 // Reinitializes |resource_metadata_|. | 132 // Reinitializes |resource_metadata_|. |
(...skipping 19 matching lines...) Expand all Loading... |
147 // the Drive cache failed). | 152 // the Drive cache failed). |
148 // Must be called on UI thread. | 153 // Must be called on UI thread. |
149 void DisableDrive(); | 154 void DisableDrive(); |
150 | 155 |
151 friend class DriveSystemServiceFactory; | 156 friend class DriveSystemServiceFactory; |
152 | 157 |
153 Profile* profile_; | 158 Profile* profile_; |
154 // True if Drive is disabled due to initialization errors. | 159 // True if Drive is disabled due to initialization errors. |
155 bool drive_disabled_; | 160 bool drive_disabled_; |
156 | 161 |
| 162 // True once this is registered to listen to the Drive updates. |
| 163 bool push_notification_registered_; |
| 164 |
157 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 165 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
158 scoped_ptr<EventLogger> event_logger_; | 166 scoped_ptr<EventLogger> event_logger_; |
159 scoped_ptr<DriveCache, util::DestroyHelper> cache_; | 167 scoped_ptr<DriveCache, util::DestroyHelper> cache_; |
160 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; | 168 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; |
161 scoped_ptr<DriveScheduler> scheduler_; | 169 scoped_ptr<DriveScheduler> scheduler_; |
162 scoped_ptr<DriveWebAppsRegistry> webapps_registry_; | 170 scoped_ptr<DriveWebAppsRegistry> webapps_registry_; |
163 scoped_ptr<DriveResourceMetadata, util::DestroyHelper> resource_metadata_; | 171 scoped_ptr<DriveResourceMetadata, util::DestroyHelper> resource_metadata_; |
164 scoped_ptr<DriveFileSystemInterface> file_system_; | 172 scoped_ptr<DriveFileSystemInterface> file_system_; |
165 scoped_ptr<FileWriteHelper> file_write_helper_; | 173 scoped_ptr<FileWriteHelper> file_write_helper_; |
166 scoped_ptr<DriveDownloadHandler> download_handler_; | 174 scoped_ptr<DriveDownloadHandler> download_handler_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // ProfileKeyedServiceFactory: | 231 // ProfileKeyedServiceFactory: |
224 virtual ProfileKeyedService* BuildServiceInstanceFor( | 232 virtual ProfileKeyedService* BuildServiceInstanceFor( |
225 Profile* profile) const OVERRIDE; | 233 Profile* profile) const OVERRIDE; |
226 | 234 |
227 FactoryCallback factory_for_test_; | 235 FactoryCallback factory_for_test_; |
228 }; | 236 }; |
229 | 237 |
230 } // namespace drive | 238 } // namespace drive |
231 | 239 |
232 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYSTEM_SERVICE_H_ | 240 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYSTEM_SERVICE_H_ |
OLD | NEW |