1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_LOCAL_SYNC_DELEGATE_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_LOCAL_SYNC_DELEGATE_H_
10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_service.h"
13 #include "chrome/browser/sync_file_system/file_change.h"
14 #include "chrome/browser/sync_file_system/sync_callbacks.h"
15 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
16 #include "chrome/browser/sync_file_system/sync_file_system.pb.h"
17 #include "webkit/browser/fileapi/file_system_url.h"
19 namespace sync_file_system
{
21 class ConflictResolutionResolver
;
22 class DriveMetadataStore
;
24 namespace drive_backend
{
28 // This class handles ApplyLocalChange in LocalChangeProcessor, and its instance
29 // represents single ApplyLocalChange operation.
30 // The caller is responsible to own the instance, and can cancel operation by
31 // deleting the instance or |sync_service|.
32 class LocalSyncDelegate
{
34 typedef RemoteChangeHandler::RemoteChange RemoteChange
;
36 LocalSyncDelegate(DriveFileSyncService
* sync_service
,
37 const FileChange
& change
,
38 const base::FilePath
& local_file_path
,
39 const SyncFileMetadata
& local_file_metadata
,
40 const fileapi::FileSystemURL
& url
);
43 void Run(const SyncStatusCallback
& callback
);
46 void DidGetOriginRoot(const SyncStatusCallback
& callback
,
47 SyncStatusCode status
,
48 const std::string
& resource_id
);
49 void UploadNewFile(const SyncStatusCallback
& callback
);
50 void DidUploadNewFile(const SyncStatusCallback
& callback
,
51 google_apis::GDataErrorCode error
,
52 const std::string
& resource_id
,
53 const std::string
& md5
);
54 void CreateDirectory(const SyncStatusCallback
& callback
);
55 void DidCreateDirectory(
56 const SyncStatusCallback
& callback
,
57 google_apis::GDataErrorCode error
,
58 const std::string
& resource_id
);
59 void UploadExistingFile(const SyncStatusCallback
& callback
);
60 void DidUploadExistingFile(
61 const SyncStatusCallback
& callback
,
62 google_apis::GDataErrorCode error
,
63 const std::string
& resource_id
,
64 const std::string
& md5
);
65 void Delete(const SyncStatusCallback
& callback
);
66 void DidDelete(const SyncStatusCallback
& callback
,
67 google_apis::GDataErrorCode error
);
68 void DidDeleteMetadataForDeletionConflict(
69 const SyncStatusCallback
& callback
,
70 SyncStatusCode status
);
71 void ResolveToLocal(const SyncStatusCallback
& callback
);
72 void DidDeleteFileToResolveToLocal(
73 const SyncStatusCallback
& callback
,
74 google_apis::GDataErrorCode error
);
75 void ResolveToRemote(const SyncStatusCallback
& callback
,
76 SyncFileType remote_file_type
);
77 void DidResolveToRemote(const SyncStatusCallback
& callback
,
78 SyncStatusCode status
);
79 void DidApplyLocalChange(
80 const SyncStatusCallback
& callback
,
81 const google_apis::GDataErrorCode error
,
82 SyncStatusCode status
);
84 // Metadata manipulation.
85 void UpdateMetadata(const std::string
& resource_id
,
86 const std::string
& md5
,
87 DriveMetadata::ResourceType type
,
88 const SyncStatusCallback
& callback
);
89 void ResetMetadataForStartOver(const SyncStatusCallback
& callback
);
90 void SetMetadataToBeFetched(DriveMetadata::ResourceType type
,
91 const SyncStatusCallback
& callback
);
92 void DeleteMetadata(const SyncStatusCallback
& callback
);
93 void SetMetadataConflict(const SyncStatusCallback
& callback
);
96 void HandleCreationConflict(
97 const std::string
& resource_id
,
98 DriveMetadata::ResourceType type
,
99 const SyncStatusCallback
& callback
);
100 void HandleConflict(const SyncStatusCallback
& callback
);
101 void DidGetEntryForConflictResolution(
102 const SyncStatusCallback
& callback
,
103 google_apis::GDataErrorCode error
,
104 scoped_ptr
<google_apis::ResourceEntry
> entry
);
106 void HandleManualResolutionCase(const SyncStatusCallback
& callback
);
107 void DidMarkConflict(const SyncStatusCallback
& callback
,
108 SyncStatusCode status
);
110 void HandleLocalWinCase(const SyncStatusCallback
& callback
);
111 void HandleRemoteWinCase(const SyncStatusCallback
& callback
,
112 SyncFileType remote_file_type
);
113 void StartOver(const SyncStatusCallback
& callback
, SyncStatusCode status
);
115 SyncStatusCode
GDataErrorCodeToSyncStatusCodeWrapper(
116 google_apis::GDataErrorCode error
);
118 DriveMetadataStore
* metadata_store();
119 APIUtilInterface
* api_util();
120 RemoteChangeHandler
* remote_change_handler();
121 ConflictResolutionResolver
* conflict_resolution_resolver();
123 DriveFileSyncService
* sync_service_
; // Not owned.
125 SyncOperationType operation_
;
127 fileapi::FileSystemURL url_
;
128 FileChange local_change_
;
129 base::FilePath local_path_
;
130 SyncFileMetadata local_metadata_
;
131 DriveMetadata drive_metadata_
;
132 bool has_drive_metadata_
;
133 RemoteChange remote_change_
;
134 bool has_remote_change_
;
136 std::string origin_resource_id_
;
138 base::WeakPtrFactory
<LocalSyncDelegate
> weak_factory_
;
140 DISALLOW_COPY_AND_ASSIGN(LocalSyncDelegate
);
143 } // namespace drive_backend
144 } // namespace sync_file_system
146 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_LOCAL_SYNC_DELEGATE_H_