OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ |
7 | 7 |
8 #include <set> | |
9 #include <string> | 8 #include <string> |
10 | 9 |
10 #include "base/files/file_path.h" | |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "chrome/browser/drive/drive_notification_observer.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/drive/drive_service_interface.h" | |
16 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" | 15 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" |
17 #include "chrome/browser/sync_file_system/local_change_processor.h" | 16 #include "chrome/browser/sync_file_system/drive_backend/sync_worker_interface.h" |
17 #include "chrome/browser/sync_file_system/file_change.h" | |
18 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" | 18 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" |
19 #include "chrome/browser/sync_file_system/sync_action.h" | 19 #include "chrome/browser/sync_file_system/sync_action.h" |
20 #include "chrome/browser/sync_file_system/sync_callbacks.h" | |
20 #include "chrome/browser/sync_file_system/sync_direction.h" | 21 #include "chrome/browser/sync_file_system/sync_direction.h" |
22 #include "chrome/browser/sync_file_system/sync_file_metadata.h" | |
21 #include "chrome/browser/sync_file_system/task_logger.h" | 23 #include "chrome/browser/sync_file_system/task_logger.h" |
22 #include "net/base/network_change_notifier.h" | 24 #include "net/base/network_change_notifier.h" |
25 #include "url/gurl.h" | |
26 #include "webkit/browser/fileapi/file_system_url.h" | |
tzik
2014/06/09 08:04:23
I think file_path, gurl and file_system_url can be
peria
2014/06/10 04:31:07
Done.
| |
23 | 27 |
24 class ExtensionServiceInterface; | 28 class ExtensionServiceInterface; |
25 | 29 |
26 namespace base { | |
27 class SequencedTaskRunner; | |
28 } | |
29 | |
30 namespace drive { | 30 namespace drive { |
31 class DriveServiceInterface; | 31 class DriveServiceInterface; |
32 class DriveNotificationManager; | |
33 class DriveUploaderInterface; | 32 class DriveUploaderInterface; |
34 } | 33 } |
35 | 34 |
36 namespace leveldb { | 35 namespace leveldb { |
37 class Env; | 36 class Env; |
38 } | 37 } |
39 | 38 |
40 namespace sync_file_system { | 39 namespace sync_file_system { |
41 | |
42 class RemoteChangeProcessor; | |
43 | |
44 namespace drive_backend { | 40 namespace drive_backend { |
45 | 41 |
46 class LocalToRemoteSyncer; | 42 class LocalToRemoteSyncer; |
47 class MetadataDatabase; | 43 class MetadataDatabase; |
48 class RemoteChangeProcessorOnWorker; | 44 class RemoteChangeProcessorOnWorker; |
49 class RemoteToLocalSyncer; | 45 class RemoteToLocalSyncer; |
50 class SyncEngineContext; | 46 class SyncEngineContext; |
51 class SyncEngineInitializer; | 47 class SyncEngineInitializer; |
52 | 48 |
53 class SyncWorker : public SyncTaskManager::Client { | 49 class SyncWorker : public SyncWorkerInterface, |
50 public SyncTaskManager::Client { | |
54 public: | 51 public: |
55 enum AppStatus { | 52 enum AppStatus { |
56 APP_STATUS_ENABLED, | 53 APP_STATUS_ENABLED, |
57 APP_STATUS_DISABLED, | 54 APP_STATUS_DISABLED, |
58 APP_STATUS_UNINSTALLED, | 55 APP_STATUS_UNINSTALLED, |
59 }; | 56 }; |
60 | 57 |
61 typedef base::hash_map<std::string, AppStatus> AppStatusMap; | 58 typedef base::hash_map<std::string, AppStatus> AppStatusMap; |
62 | 59 |
63 class Observer { | 60 class Observer { |
(...skipping 10 matching lines...) Expand all Loading... | |
74 virtual ~Observer() {} | 71 virtual ~Observer() {} |
75 }; | 72 }; |
76 | 73 |
77 SyncWorker(const base::FilePath& base_dir, | 74 SyncWorker(const base::FilePath& base_dir, |
78 const base::WeakPtr<ExtensionServiceInterface>& extension_service, | 75 const base::WeakPtr<ExtensionServiceInterface>& extension_service, |
79 scoped_ptr<SyncEngineContext> sync_engine_context, | 76 scoped_ptr<SyncEngineContext> sync_engine_context, |
80 leveldb::Env* env_override); | 77 leveldb::Env* env_override); |
81 | 78 |
82 virtual ~SyncWorker(); | 79 virtual ~SyncWorker(); |
83 | 80 |
84 void Initialize(); | 81 virtual void Initialize() OVERRIDE; |
85 | 82 |
86 // SyncTaskManager::Client overrides | 83 // SyncTaskManager::Client overrides |
87 virtual void MaybeScheduleNextTask() OVERRIDE; | 84 virtual void MaybeScheduleNextTask() OVERRIDE; |
88 virtual void NotifyLastOperationStatus( | 85 virtual void NotifyLastOperationStatus( |
89 SyncStatusCode sync_status, bool used_network) OVERRIDE; | 86 SyncStatusCode sync_status, bool used_network) OVERRIDE; |
90 virtual void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) OVERRIDE; | 87 virtual void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) OVERRIDE; |
91 | 88 |
92 void RegisterOrigin(const GURL& origin, const SyncStatusCallback& callback); | 89 // SyncWorkerInterface overrides |
93 void EnableOrigin(const GURL& origin, const SyncStatusCallback& callback); | 90 virtual void RegisterOrigin(const GURL& origin, |
94 void DisableOrigin(const GURL& origin, const SyncStatusCallback& callback); | 91 const SyncStatusCallback& callback) OVERRIDE; |
95 void UninstallOrigin( | 92 virtual void EnableOrigin(const GURL& origin, |
93 const SyncStatusCallback& callback) OVERRIDE; | |
94 virtual void DisableOrigin(const GURL& origin, | |
95 const SyncStatusCallback& callback) OVERRIDE; | |
nhiroki
2014/06/10 04:00:48
nit: Can you make arguments of these functions ali
peria
2014/06/10 04:31:07
Done.
| |
96 virtual void UninstallOrigin( | |
96 const GURL& origin, | 97 const GURL& origin, |
97 RemoteFileSyncService::UninstallFlag flag, | 98 RemoteFileSyncService::UninstallFlag flag, |
98 const SyncStatusCallback& callback); | 99 const SyncStatusCallback& callback) OVERRIDE; |
99 void ProcessRemoteChange(const SyncFileCallback& callback); | 100 virtual void ProcessRemoteChange(const SyncFileCallback& callback) OVERRIDE; |
100 void SetRemoteChangeProcessor( | 101 virtual void SetRemoteChangeProcessor( |
101 RemoteChangeProcessorOnWorker* remote_change_processor_on_worker); | 102 RemoteChangeProcessorOnWorker* remote_change_processor_on_worker) |
102 RemoteServiceState GetCurrentState() const; | 103 OVERRIDE; |
103 void GetOriginStatusMap( | 104 virtual RemoteServiceState GetCurrentState() const OVERRIDE; |
104 const RemoteFileSyncService::StatusMapCallback& callback); | 105 virtual void GetOriginStatusMap( |
105 scoped_ptr<base::ListValue> DumpFiles(const GURL& origin); | 106 const RemoteFileSyncService::StatusMapCallback& callback) OVERRIDE; |
106 scoped_ptr<base::ListValue> DumpDatabase(); | 107 virtual scoped_ptr<base::ListValue> DumpFiles(const GURL& origin) OVERRIDE; |
107 void SetSyncEnabled(bool enabled); | 108 virtual scoped_ptr<base::ListValue> DumpDatabase() OVERRIDE; |
108 void PromoteDemotedChanges(); | 109 virtual void SetSyncEnabled(bool enabled) OVERRIDE; |
109 SyncStatusCode SetDefaultConflictResolutionPolicy( | 110 virtual void PromoteDemotedChanges() OVERRIDE; |
110 ConflictResolutionPolicy policy); | |
111 SyncStatusCode SetConflictResolutionPolicy( | |
112 const GURL& origin, | |
113 ConflictResolutionPolicy policy); | |
114 ConflictResolutionPolicy GetDefaultConflictResolutionPolicy() | |
115 const; | |
116 ConflictResolutionPolicy GetConflictResolutionPolicy( | |
117 const GURL& origin) const; | |
118 | 111 |
119 void ApplyLocalChange( | 112 virtual void ApplyLocalChange( |
120 const FileChange& local_change, | 113 const FileChange& local_change, |
121 const base::FilePath& local_path, | 114 const base::FilePath& local_path, |
122 const SyncFileMetadata& local_metadata, | 115 const SyncFileMetadata& local_metadata, |
123 const fileapi::FileSystemURL& url, | 116 const fileapi::FileSystemURL& url, |
124 const SyncStatusCallback& callback); | 117 const SyncStatusCallback& callback) OVERRIDE; |
125 | 118 |
126 void OnNotificationReceived(); | 119 virtual void OnNotificationReceived() OVERRIDE; |
127 | 120 |
128 void OnReadyToSendRequests(const std::string& account_id); | 121 virtual void OnReadyToSendRequests(const std::string& account_id) OVERRIDE; |
129 void OnRefreshTokenInvalid(); | 122 virtual void OnRefreshTokenInvalid() OVERRIDE; |
130 | 123 |
131 void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type); | 124 virtual void OnNetworkChanged( |
125 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
132 | 126 |
133 drive::DriveServiceInterface* GetDriveService(); | 127 virtual drive::DriveServiceInterface* GetDriveService() OVERRIDE; |
134 drive::DriveUploaderInterface* GetDriveUploader(); | 128 virtual drive::DriveUploaderInterface* GetDriveUploader() OVERRIDE; |
135 MetadataDatabase* GetMetadataDatabase(); | 129 virtual MetadataDatabase* GetMetadataDatabase() OVERRIDE; |
136 SyncTaskManager* GetSyncTaskManager(); | 130 virtual SyncTaskManager* GetSyncTaskManager() OVERRIDE; |
131 | |
132 virtual void DetachFromSequence() OVERRIDE; | |
137 | 133 |
138 void AddObserver(Observer* observer); | 134 void AddObserver(Observer* observer); |
139 | 135 |
140 void DetachFromSequence(); | |
141 | |
142 private: | 136 private: |
143 friend class SyncEngineTest; | 137 friend class SyncEngineTest; |
144 | 138 |
139 // SyncWorkerInterface overrides. | |
140 // TODO(peria): Remove this interface after making FakeSyncWorker class. | |
141 virtual void SetHasRefreshToken(bool has_refresh_token) OVERRIDE; | |
142 | |
145 void DoDisableApp(const std::string& app_id, | 143 void DoDisableApp(const std::string& app_id, |
146 const SyncStatusCallback& callback); | 144 const SyncStatusCallback& callback); |
147 void DoEnableApp(const std::string& app_id, | 145 void DoEnableApp(const std::string& app_id, |
148 const SyncStatusCallback& callback); | 146 const SyncStatusCallback& callback); |
149 | 147 |
150 void PostInitializeTask(); | 148 void PostInitializeTask(); |
151 void DidInitialize(SyncEngineInitializer* initializer, | 149 void DidInitialize(SyncEngineInitializer* initializer, |
152 SyncStatusCode status); | 150 SyncStatusCode status); |
153 void UpdateRegisteredApp(); | 151 void UpdateRegisteredApp(); |
154 void DidQueryAppStatus(const AppStatusMap* app_status); | 152 void DidQueryAppStatus(const AppStatusMap* app_status); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 base::SequenceChecker sequence_checker_; | 195 base::SequenceChecker sequence_checker_; |
198 | 196 |
199 base::WeakPtrFactory<SyncWorker> weak_ptr_factory_; | 197 base::WeakPtrFactory<SyncWorker> weak_ptr_factory_; |
200 DISALLOW_COPY_AND_ASSIGN(SyncWorker); | 198 DISALLOW_COPY_AND_ASSIGN(SyncWorker); |
201 }; | 199 }; |
202 | 200 |
203 } // namespace drive_backend | 201 } // namespace drive_backend |
204 } // namespace sync_file_system | 202 } // namespace sync_file_system |
205 | 203 |
206 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ | 204 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_H_ |
OLD | NEW |