| 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_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "chrome/browser/google_apis/drive_notification_observer.h" | 19 #include "chrome/browser/google_apis/drive_notification_observer.h" |
| 20 #include "chrome/browser/sync_file_system/drive/api_util_interface.h" | 20 #include "chrome/browser/sync_file_system/drive/api_util_interface.h" |
| 21 #include "chrome/browser/sync_file_system/drive_metadata_store.h" | 21 #include "chrome/browser/sync_file_system/drive_metadata_store.h" |
| 22 #include "chrome/browser/sync_file_system/local_change_processor.h" | 22 #include "chrome/browser/sync_file_system/local_change_processor.h" |
| 23 #include "chrome/browser/sync_file_system/local_sync_operation_resolver.h" | 23 #include "chrome/browser/sync_file_system/local_sync_operation_resolver.h" |
| 24 #include "chrome/browser/sync_file_system/remote_change_handler.h" | 24 #include "chrome/browser/sync_file_system/remote_change_handler.h" |
| 25 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" | 25 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" |
| 26 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" |
| 26 #include "webkit/fileapi/syncable/file_change.h" | 27 #include "webkit/fileapi/syncable/file_change.h" |
| 27 #include "webkit/fileapi/syncable/sync_action.h" | 28 #include "webkit/fileapi/syncable/sync_action.h" |
| 28 #include "webkit/fileapi/syncable/sync_callbacks.h" | 29 #include "webkit/fileapi/syncable/sync_callbacks.h" |
| 29 #include "webkit/fileapi/syncable/sync_direction.h" | 30 #include "webkit/fileapi/syncable/sync_direction.h" |
| 30 #include "webkit/fileapi/syncable/sync_status_code.h" | 31 #include "webkit/fileapi/syncable/sync_status_code.h" |
| 31 | 32 |
| 32 class ExtensionService; | 33 class ExtensionService; |
| 33 | 34 |
| 34 namespace google_apis { | 35 namespace google_apis { |
| 35 class ResourceList; | 36 class ResourceList; |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace tracked_objects { | 39 namespace tracked_objects { |
| 39 class Location; | 40 class Location; |
| 40 } | 41 } |
| 41 | 42 |
| 42 namespace sync_file_system { | 43 namespace sync_file_system { |
| 43 | 44 |
| 45 namespace drive { |
| 46 class ApplyLocalChangeDelegate; |
| 47 } |
| 48 |
| 44 class DriveFileSyncTaskManager; | 49 class DriveFileSyncTaskManager; |
| 45 | 50 |
| 46 // Maintains remote file changes. | 51 // Maintains remote file changes. |
| 47 // Owned by SyncFileSystemService (which is a per-profile object). | 52 // Owned by SyncFileSystemService (which is a per-profile object). |
| 48 class DriveFileSyncService : public RemoteFileSyncService, | 53 class DriveFileSyncService : public RemoteFileSyncService, |
| 49 public LocalChangeProcessor, | 54 public LocalChangeProcessor, |
| 50 public drive::APIUtilObserver, | 55 public drive::APIUtilObserver, |
| 51 public base::NonThreadSafe, | 56 public base::NonThreadSafe, |
| 52 public base::SupportsWeakPtr<DriveFileSyncService>, | 57 public base::SupportsWeakPtr<DriveFileSyncService>, |
| 53 public google_apis::DriveNotificationObserver { | 58 public google_apis::DriveNotificationObserver { |
| 54 public: | 59 public: |
| 60 enum ConflictResolutionResult { |
| 61 CONFLICT_RESOLUTION_MARK_CONFLICT, |
| 62 CONFLICT_RESOLUTION_LOCAL_WIN, |
| 63 CONFLICT_RESOLUTION_REMOTE_WIN, |
| 64 }; |
| 65 |
| 55 typedef base::Callback<void(const SyncStatusCallback& callback)> Task; | 66 typedef base::Callback<void(const SyncStatusCallback& callback)> Task; |
| 56 | 67 |
| 57 static const char kServiceName[]; | 68 static const char kServiceName[]; |
| 58 static ConflictResolutionPolicy kDefaultPolicy; | 69 static ConflictResolutionPolicy kDefaultPolicy; |
| 59 | 70 |
| 60 virtual ~DriveFileSyncService(); | 71 virtual ~DriveFileSyncService(); |
| 61 | 72 |
| 62 // Creates DriveFileSyncService. | 73 // Creates DriveFileSyncService. |
| 63 static scoped_ptr<DriveFileSyncService> Create(Profile* profile); | 74 static scoped_ptr<DriveFileSyncService> Create(Profile* profile); |
| 64 | 75 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // google_apis::DriveNotificationObserver implementation. | 131 // google_apis::DriveNotificationObserver implementation. |
| 121 virtual void OnNotificationReceived() OVERRIDE; | 132 virtual void OnNotificationReceived() OVERRIDE; |
| 122 | 133 |
| 123 // Called from DriveFileSyncTaskManager. | 134 // Called from DriveFileSyncTaskManager. |
| 124 // TODO: factor out as an interface. | 135 // TODO: factor out as an interface. |
| 125 void MaybeScheduleNextTask(); | 136 void MaybeScheduleNextTask(); |
| 126 void NotifyLastOperationStatus( | 137 void NotifyLastOperationStatus( |
| 127 SyncStatusCode sync_status, | 138 SyncStatusCode sync_status, |
| 128 google_apis::GDataErrorCode gdata_error); | 139 google_apis::GDataErrorCode gdata_error); |
| 129 | 140 |
| 141 static std::string PathToTitle(const base::FilePath& path); |
| 142 static base::FilePath TitleToPath(const std::string& title); |
| 143 static DriveMetadata::ResourceType SyncFileTypeToDriveMetadataResourceType( |
| 144 SyncFileType file_type); |
| 145 |
| 130 private: | 146 private: |
| 131 friend class DriveFileSyncTaskManager; | 147 friend class DriveFileSyncTaskManager; |
| 148 friend class drive::ApplyLocalChangeDelegate; |
| 149 |
| 132 friend class DriveFileSyncServiceMockTest; | 150 friend class DriveFileSyncServiceMockTest; |
| 133 friend class DriveFileSyncServiceSyncTest; | 151 friend class DriveFileSyncServiceSyncTest; |
| 134 struct ApplyLocalChangeParam; | 152 struct ApplyLocalChangeParam; |
| 135 struct ProcessRemoteChangeParam; | 153 struct ProcessRemoteChangeParam; |
| 136 | 154 |
| 137 typedef base::Callback<void(const base::Time& time, | 155 typedef base::Callback<void(const base::Time& time, |
| 138 SyncFileType remote_file_type, | 156 SyncFileType remote_file_type, |
| 139 SyncStatusCode status)> UpdatedTimeCallback; | 157 SyncStatusCode status)> UpdatedTimeCallback; |
| 140 typedef base::Callback< | 158 typedef base::Callback< |
| 141 void(SyncStatusCode status, | 159 void(SyncStatusCode status, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 const FileChange& change, | 204 const FileChange& change, |
| 187 const base::FilePath& local_file_path, | 205 const base::FilePath& local_file_path, |
| 188 const SyncFileMetadata& local_file_metadata, | 206 const SyncFileMetadata& local_file_metadata, |
| 189 const fileapi::FileSystemURL& url, | 207 const fileapi::FileSystemURL& url, |
| 190 const SyncStatusCallback& callback); | 208 const SyncStatusCallback& callback); |
| 191 | 209 |
| 192 // Local synchronization related methods. | 210 // Local synchronization related methods. |
| 193 // Resolves LocalSync operation type. If non-null |param| is given | 211 // Resolves LocalSync operation type. If non-null |param| is given |
| 194 // the method also populates param->has_drive_metadata and | 212 // the method also populates param->has_drive_metadata and |
| 195 // param->drive_metadata fields. | 213 // param->drive_metadata fields. |
| 196 void ApplyLocalChangeInternal( | 214 ConflictResolutionResult ResolveConflictForLocalSync( |
| 197 scoped_ptr<ApplyLocalChangeParam> param, | 215 SyncFileType local_file_type, |
| 198 SyncStatusCode status, | 216 const base::Time& local_update_time, |
| 199 const std::string& resource_id); | |
| 200 void DidDeleteForResolveToLocalForLocalSync( | |
| 201 const std::string& origin_resource_id, | |
| 202 const base::FilePath& local_file_path, | |
| 203 const fileapi::FileSystemURL& url, | |
| 204 scoped_ptr<ApplyLocalChangeParam> param, | |
| 205 google_apis::GDataErrorCode error); | |
| 206 void DidApplyLocalChange( | |
| 207 scoped_ptr<ApplyLocalChangeParam> param, | |
| 208 const google_apis::GDataErrorCode error, | |
| 209 SyncStatusCode status); | |
| 210 void DidResolveConflictToRemoteChange( | |
| 211 scoped_ptr<ApplyLocalChangeParam> param, | |
| 212 SyncStatusCode status); | |
| 213 void DidUploadNewFileForLocalSync( | |
| 214 scoped_ptr<ApplyLocalChangeParam> param, | |
| 215 google_apis::GDataErrorCode error, | |
| 216 const std::string& resource_id, | |
| 217 const std::string& file_md5); | |
| 218 void DidCreateDirectoryForLocalSync( | |
| 219 scoped_ptr<ApplyLocalChangeParam> param, | |
| 220 google_apis::GDataErrorCode error, | |
| 221 const std::string& resource_id); | |
| 222 void DidUploadExistingFileForLocalSync( | |
| 223 scoped_ptr<ApplyLocalChangeParam> param, | |
| 224 google_apis::GDataErrorCode error, | |
| 225 const std::string& resource_id, | |
| 226 const std::string& file_md5); | |
| 227 void DidDeleteFileForLocalSync( | |
| 228 scoped_ptr<ApplyLocalChangeParam> param, | |
| 229 google_apis::GDataErrorCode error); | |
| 230 void HandleConflictForLocalSync( | |
| 231 scoped_ptr<ApplyLocalChangeParam> param); | |
| 232 void ResolveConflictForLocalSync( | |
| 233 scoped_ptr<ApplyLocalChangeParam> param, | |
| 234 const base::Time& remote_updated_time, | |
| 235 SyncFileType remote_file_type, | 217 SyncFileType remote_file_type, |
| 236 SyncStatusCode status); | 218 const base::Time& remote_update_time); |
| 237 void StartOverLocalSync( | |
| 238 scoped_ptr<ApplyLocalChangeParam> param, | |
| 239 SyncStatusCode status); | |
| 240 void ResolveConflictToRemoteForLocalSync( | |
| 241 scoped_ptr<ApplyLocalChangeParam> param, | |
| 242 SyncFileType remote_file_type); | |
| 243 void DidEnsureOriginRootForUploadNewFile( | |
| 244 scoped_ptr<ApplyLocalChangeParam> param, | |
| 245 SyncStatusCode status, | |
| 246 const std::string& parent_resource_id); | |
| 247 | 219 |
| 248 void UpdateRegisteredOrigins(); | 220 void UpdateRegisteredOrigins(); |
| 249 | 221 |
| 250 void StartBatchSync(const SyncStatusCallback& callback); | 222 void StartBatchSync(const SyncStatusCallback& callback); |
| 251 void GetDriveDirectoryForOrigin(const GURL& origin, | 223 void GetDriveDirectoryForOrigin(const GURL& origin, |
| 252 const SyncStatusCallback& callback, | 224 const SyncStatusCallback& callback, |
| 253 const std::string& sync_root_resource_id); | 225 const std::string& sync_root_resource_id); |
| 254 void DidGetDriveDirectoryForOrigin(const GURL& origin, | 226 void DidGetDriveDirectoryForOrigin(const GURL& origin, |
| 255 const SyncStatusCallback& callback, | 227 const SyncStatusCallback& callback, |
| 256 SyncStatusCode status, | 228 SyncStatusCode status, |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 RemoteChangeProcessor* remote_change_processor_; | 417 RemoteChangeProcessor* remote_change_processor_; |
| 446 | 418 |
| 447 ConflictResolutionPolicy conflict_resolution_; | 419 ConflictResolutionPolicy conflict_resolution_; |
| 448 | 420 |
| 449 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); | 421 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); |
| 450 }; | 422 }; |
| 451 | 423 |
| 452 } // namespace sync_file_system | 424 } // namespace sync_file_system |
| 453 | 425 |
| 454 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 426 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
| OLD | NEW |