Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service.h

Issue 14977008: [SyncFileSystem] Separate out ApplyLocalChange from DriveFileSyncService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style fix Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 LocalChangeProcessorDelegate;
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 virtual void OnNotificationReceived() OVERRIDE; 132 virtual void OnNotificationReceived() OVERRIDE;
122 virtual void OnPushNotificationEnabled(bool enabled) OVERRIDE; 133 virtual void OnPushNotificationEnabled(bool enabled) OVERRIDE;
123 134
124 // Called from DriveFileSyncTaskManager. 135 // Called from DriveFileSyncTaskManager.
125 // TODO: factor out as an interface. 136 // TODO: factor out as an interface.
126 void MaybeScheduleNextTask(); 137 void MaybeScheduleNextTask();
127 void NotifyLastOperationStatus( 138 void NotifyLastOperationStatus(
128 SyncStatusCode sync_status, 139 SyncStatusCode sync_status,
129 google_apis::GDataErrorCode gdata_error); 140 google_apis::GDataErrorCode gdata_error);
130 141
142 static std::string PathToTitle(const base::FilePath& path);
143 static base::FilePath TitleToPath(const std::string& title);
144 static DriveMetadata::ResourceType SyncFileTypeToDriveMetadataResourceType(
145 SyncFileType file_type);
146
131 private: 147 private:
132 friend class DriveFileSyncTaskManager; 148 friend class DriveFileSyncTaskManager;
149 friend class drive::LocalChangeProcessorDelegate;
150
133 friend class DriveFileSyncServiceMockTest; 151 friend class DriveFileSyncServiceMockTest;
134 friend class DriveFileSyncServiceSyncTest; 152 friend class DriveFileSyncServiceSyncTest;
135 struct ApplyLocalChangeParam; 153 struct ApplyLocalChangeParam;
136 struct ProcessRemoteChangeParam; 154 struct ProcessRemoteChangeParam;
137 155
138 typedef base::Callback<void(const base::Time& time, 156 typedef base::Callback<void(const base::Time& time,
139 SyncFileType remote_file_type, 157 SyncFileType remote_file_type,
140 SyncStatusCode status)> UpdatedTimeCallback; 158 SyncStatusCode status)> UpdatedTimeCallback;
141 typedef base::Callback< 159 typedef base::Callback<
142 void(SyncStatusCode status, 160 void(SyncStatusCode status,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 const SyncFileCallback& sync_callback, 202 const SyncFileCallback& sync_callback,
185 const SyncStatusCallback& completion_callback); 203 const SyncStatusCallback& completion_callback);
186 void DoApplyLocalChange( 204 void DoApplyLocalChange(
187 const FileChange& change, 205 const FileChange& change,
188 const base::FilePath& local_file_path, 206 const base::FilePath& local_file_path,
189 const SyncFileMetadata& local_file_metadata, 207 const SyncFileMetadata& local_file_metadata,
190 const fileapi::FileSystemURL& url, 208 const fileapi::FileSystemURL& url,
191 const SyncStatusCallback& callback); 209 const SyncStatusCallback& callback);
192 210
193 // Local synchronization related methods. 211 // Local synchronization related methods.
194 // Resolves LocalSync operation type. If non-null |param| is given 212 ConflictResolutionResult ResolveConflictForLocalSync(
195 // the method also populates param->has_drive_metadata and 213 SyncFileType local_file_type,
196 // param->drive_metadata fields. 214 const base::Time& local_update_time,
197 void ApplyLocalChangeInternal(
198 scoped_ptr<ApplyLocalChangeParam> param,
199 SyncStatusCode status,
200 const std::string& resource_id);
201 void DidDeleteForResolveToLocalForLocalSync(
202 const std::string& origin_resource_id,
203 const base::FilePath& local_file_path,
204 const fileapi::FileSystemURL& url,
205 scoped_ptr<ApplyLocalChangeParam> param,
206 google_apis::GDataErrorCode error);
207 void DidApplyLocalChange(
208 scoped_ptr<ApplyLocalChangeParam> param,
209 const google_apis::GDataErrorCode error,
210 SyncStatusCode status);
211 void DidResolveConflictToRemoteChange(
212 scoped_ptr<ApplyLocalChangeParam> param,
213 SyncStatusCode status);
214 void DidUploadNewFileForLocalSync(
215 scoped_ptr<ApplyLocalChangeParam> param,
216 google_apis::GDataErrorCode error,
217 const std::string& resource_id,
218 const std::string& file_md5);
219 void DidCreateDirectoryForLocalSync(
220 scoped_ptr<ApplyLocalChangeParam> param,
221 google_apis::GDataErrorCode error,
222 const std::string& resource_id);
223 void DidUploadExistingFileForLocalSync(
224 scoped_ptr<ApplyLocalChangeParam> param,
225 google_apis::GDataErrorCode error,
226 const std::string& resource_id,
227 const std::string& file_md5);
228 void DidDeleteFileForLocalSync(
229 scoped_ptr<ApplyLocalChangeParam> param,
230 google_apis::GDataErrorCode error);
231 void HandleConflictForLocalSync(
232 scoped_ptr<ApplyLocalChangeParam> param);
233 void ResolveConflictForLocalSync(
234 scoped_ptr<ApplyLocalChangeParam> param,
235 const base::Time& remote_updated_time,
236 SyncFileType remote_file_type, 215 SyncFileType remote_file_type,
237 SyncStatusCode status); 216 const base::Time& remote_update_time);
238 void StartOverLocalSync( 217 void DidApplyLocalChange(const SyncStatusCallback& callback,
239 scoped_ptr<ApplyLocalChangeParam> param, 218 SyncStatusCode status);
240 SyncStatusCode status);
241 void ResolveConflictToRemoteForLocalSync(
242 scoped_ptr<ApplyLocalChangeParam> param,
243 SyncFileType remote_file_type);
244 void DidEnsureOriginRootForUploadNewFile(
245 scoped_ptr<ApplyLocalChangeParam> param,
246 SyncStatusCode status,
247 const std::string& parent_resource_id);
248 219
249 void UpdateRegisteredOrigins(); 220 void UpdateRegisteredOrigins();
250 221
251 void StartBatchSync(const SyncStatusCallback& callback); 222 void StartBatchSync(const SyncStatusCallback& callback);
252 void GetDriveDirectoryForOrigin(const GURL& origin, 223 void GetDriveDirectoryForOrigin(const GURL& origin,
253 const SyncStatusCallback& callback, 224 const SyncStatusCallback& callback,
254 const std::string& sync_root_resource_id); 225 const std::string& sync_root_resource_id);
255 void DidGetDriveDirectoryForOrigin(const GURL& origin, 226 void DidGetDriveDirectoryForOrigin(const GURL& origin,
256 const SyncStatusCallback& callback, 227 const SyncStatusCallback& callback,
257 SyncStatusCode status, 228 SyncStatusCode status,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // removed. 375 // removed.
405 std::string sync_root_resource_id(); 376 std::string sync_root_resource_id();
406 377
407 scoped_ptr<DriveMetadataStore> metadata_store_; 378 scoped_ptr<DriveMetadataStore> metadata_store_;
408 scoped_ptr<drive::APIUtilInterface> api_util_; 379 scoped_ptr<drive::APIUtilInterface> api_util_;
409 380
410 Profile* profile_; 381 Profile* profile_;
411 382
412 scoped_ptr<DriveFileSyncTaskManager> task_manager_; 383 scoped_ptr<DriveFileSyncTaskManager> task_manager_;
413 384
385 scoped_ptr<drive::LocalChangeProcessorDelegate> running_local_sync_task_;
386
414 // The current remote service state. This does NOT reflect the 387 // The current remote service state. This does NOT reflect the
415 // sync_enabled_ flag, while GetCurrentState() DOES reflect the flag 388 // sync_enabled_ flag, while GetCurrentState() DOES reflect the flag
416 // value (i.e. it returns REMOTE_SERVICE_DISABLED when sync_enabled_ 389 // value (i.e. it returns REMOTE_SERVICE_DISABLED when sync_enabled_
417 // is false even if state_ is REMOTE_SERVICE_OK). 390 // is false even if state_ is REMOTE_SERVICE_OK).
418 RemoteServiceState state_; 391 RemoteServiceState state_;
419 392
420 // Indicates if sync is enabled or not. This flag can be turned on or 393 // Indicates if sync is enabled or not. This flag can be turned on or
421 // off by SetSyncEnabled() method. To start synchronization 394 // off by SetSyncEnabled() method. To start synchronization
422 // this needs to be true and state_ needs to be REMOTE_SERVICE_OK. 395 // this needs to be true and state_ needs to be REMOTE_SERVICE_OK.
423 bool sync_enabled_; 396 bool sync_enabled_;
(...skipping 22 matching lines...) Expand all
446 RemoteChangeProcessor* remote_change_processor_; 419 RemoteChangeProcessor* remote_change_processor_;
447 420
448 ConflictResolutionPolicy conflict_resolution_; 421 ConflictResolutionPolicy conflict_resolution_;
449 422
450 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); 423 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService);
451 }; 424 };
452 425
453 } // namespace sync_file_system 426 } // namespace sync_file_system
454 427
455 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ 428 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698