OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_REMOTE_TO_LOCAL_SYNCER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_REMOTE_TO_LOCAL_SYNCER_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_REMOTE_TO_LOCAL_SYNCER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_REMOTE_TO_LOCAL_SYNCER_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "chrome/browser/google_apis/gdata_errorcode.h" | 9 #include "chrome/browser/google_apis/gdata_errorcode.h" |
10 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" | 10 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 PRIORITY_NORMAL = 1 << 0, | 34 PRIORITY_NORMAL = 1 << 0, |
35 PRIORITY_LOW = 1 << 1, | 35 PRIORITY_LOW = 1 << 1, |
36 }; | 36 }; |
37 | 37 |
38 // |priorities| must be a bitwise-or'd value of Priority. | 38 // |priorities| must be a bitwise-or'd value of Priority. |
39 // Conflicting trackers will have low priority for RemoteToLocalSyncer so that | 39 // Conflicting trackers will have low priority for RemoteToLocalSyncer so that |
40 // it should be resolved by LocatToRemoteSyncer. | 40 // it should be resolved by LocatToRemoteSyncer. |
41 RemoteToLocalSyncer(SyncEngineContext* sync_context, | 41 RemoteToLocalSyncer(SyncEngineContext* sync_context, |
42 int priorities); | 42 int priorities); |
43 virtual ~RemoteToLocalSyncer(); | 43 virtual ~RemoteToLocalSyncer(); |
44 | |
44 virtual void Run(const SyncStatusCallback& callback) OVERRIDE; | 45 virtual void Run(const SyncStatusCallback& callback) OVERRIDE; |
45 | 46 |
46 private: | 47 private: |
47 void AnalyzeCurrentDirtyTracker(); | 48 // Dispatches remote change to handleing functions or to SyncCompleted() |
kinuko
2013/11/09 23:33:25
handleing -> handler or handling
tzik
2013/11/11 04:45:34
Done.
| |
48 | 49 // directly. |
50 // This function uses information only in MetadataDatabase. | |
51 // | |
52 // If the tracker doesn't have remote metadata: | |
53 // # The file is listed in a folder soon before this operation. | |
kinuko
2013/11/09 23:33:25
soon before -> you mean 'right before' ?
tzik
2013/11/11 04:45:34
Done.
| |
54 // - Dispatch to HandleMissingRemoteMetadata to fetch remote metadata. | |
55 // Else, if the tracker is not active or the dominating app-root is disabled: | |
56 // # Assume the file has remote metadata. | |
57 // - Dispatch to HandleInactiveFile() to resolve offline solvable dirtiness. | |
58 // Else, if the tracker doesn't have synced metadata: | |
59 // # Assume the tracker has remote metadata and the tracker is active. | |
60 // # The tracker is not yet synced ever. | |
61 // - If the file is remotely deleted, do nothing to local file and dispatch | |
62 // directly to SyncCompleted(). | |
63 // - Else, if the file is a regular file, dispatch to HandleNewFile(). | |
64 // - Else, if the file is a folder, dispatch to HandleNewFolder(). | |
65 // - Else, the file should be a unsupported active file. This should not | |
66 // happen. | |
67 // Else, if the remote metadata is marked as deleted: | |
68 // # Most of the remote metadata is missing including title, kind and md5. | |
69 // - Dispatch to HandleDeletion(). | |
70 // Else, if the tracker have different title between its synced metadata and | |
71 // remote metadata: | |
72 // # Assume the tracker is active and has remote metetadata and synced | |
73 // metadata. | |
74 // # The file is remotely renamed. | |
75 // # Maybe, this can be decomposed to delete and update. | |
76 // - Dispatch to HandleRemoteRename(). | |
77 // Else, if the tracker's parent is not a parent of the remote metadata: | |
78 // # The file has reorganized. | |
79 // # Maybe, this can be decomposed to delete and update. | |
80 // - Dispatch to HandreReorganize(). | |
81 // Else, if the folder is a regular file and the md5 in remote metadata does | |
82 // not match the md5 in synced metadata: | |
83 // # The file is modified remotely. | |
84 // - Dispatch to HandleContentUpdate(). | |
85 // Else, if the tracker is a folder and it has needs_folder_listing flag: | |
86 // - Dispatch to HandleFolderListing() | |
87 // Else, there should be no change to sync. | |
88 // - Dispatch to HandleOfflineSolvable() | |
49 void ResolveRemoteChange(const SyncStatusCallback& callback); | 89 void ResolveRemoteChange(const SyncStatusCallback& callback); |
50 | 90 |
51 void GetRemoteResource(const SyncStatusCallback& callback); | 91 // Handles missing remote metadata case. |
92 // Fetches remote metadata and updates MetadataDatabase by that. The sync | |
93 // operation itself will be deferred to the next sync round. | |
94 // Note: if the file is not found, it should be handled as if deleted. | |
95 void HandleMissingRemoteMetadata(const SyncStatusCallback& callback); | |
52 void DidGetRemoteResource(const SyncStatusCallback& callback, | 96 void DidGetRemoteResource(const SyncStatusCallback& callback, |
53 int64 change_id, | 97 int64 change_id, |
54 google_apis::GDataErrorCode error, | 98 google_apis::GDataErrorCode error, |
55 scoped_ptr<google_apis::ResourceEntry> entry); | 99 scoped_ptr<google_apis::ResourceEntry> entry); |
56 | 100 |
101 // Handles modification to inactive or disabled-app tracker. | |
102 // TODO(tzik): Write details and implement this. | |
103 void HandleInactiveTracker(const SyncStatusCallback& callback); | |
104 | |
105 // Handles remotely added file. Needs Prepare() call. | |
106 // TODO(tzik): Write details and implement this. | |
107 void HandleNewFile(const SyncStatusCallback& callback); | |
108 void DidPrepareForNewFile(const SyncStatusCallback& callback, | |
109 SyncStatusCode status); | |
110 | |
111 // Handles remotely added folder. Needs Prepare() call. | |
112 // TODO(tzik): Write details and implement this. | |
113 void HandleNewFolder(const SyncStatusCallback& callback); | |
114 | |
115 // Handles deleted remote file. Needs Prepare() call. | |
116 // If the deleted tracker is the sync-root: | |
117 // - TODO(tzik): Needs special handling. | |
118 // Else, if the deleted tracker is a app-root: | |
119 // - TODO(tzik): Needs special handling. | |
120 // Else, if the local file is already deleted: | |
121 // - Do nothing anymore to the local, call SyncCompleted(). | |
122 // Else, if the local file is modified: | |
123 // - Do nothing to the local file, call SyncCompleted(). | |
124 // Else, if the local file is not modified: | |
125 // - Delete local file. | |
126 // # Note: if the local file is a folder, delete recursively. | |
57 void HandleDeletion(const SyncStatusCallback& callback); | 127 void HandleDeletion(const SyncStatusCallback& callback); |
58 void DidPrepareForDeletion(const SyncStatusCallback& callback, | 128 void DidPrepareForDeletion(const SyncStatusCallback& callback, |
59 SyncStatusCode status); | 129 SyncStatusCode status); |
60 | 130 |
61 void HandleNewFile(const SyncStatusCallback& callback); | 131 // TODO(tzik): Write details and implement this. |
62 void DidPrepareForNewFile(const SyncStatusCallback& callback, | 132 void HandleRename(const SyncStatusCallback& callback); |
63 SyncStatusCode status); | |
64 | 133 |
134 // TODO(tzik): Write details and implement this. | |
135 void HandleReorganize(const SyncStatusCallback& callback); | |
136 | |
137 // Handles new file. Needs Prepare() call. | |
65 void HandleContentUpdate(const SyncStatusCallback& callback); | 138 void HandleContentUpdate(const SyncStatusCallback& callback); |
66 void DidPrepareForContentUpdate(const SyncStatusCallback& callback, | 139 void DidPrepareForContentUpdate(const SyncStatusCallback& callback, |
67 SyncStatusCode status); | 140 SyncStatusCode status); |
68 | 141 |
69 void ListFolderContent(const SyncStatusCallback& callback); | 142 void HandleFolderContentListing(const SyncStatusCallback& callback); |
70 void DidPrepareForFolderListing(const SyncStatusCallback& callback, | 143 void DidPrepareForFolderListing(const SyncStatusCallback& callback, |
71 SyncStatusCode status); | 144 SyncStatusCode status); |
72 | 145 |
73 void HandleRename(const SyncStatusCallback& callback); | |
74 void HandleReorganize(const SyncStatusCallback& callback); | |
75 void HandleOfflineSolvable(const SyncStatusCallback& callback); | 146 void HandleOfflineSolvable(const SyncStatusCallback& callback); |
76 | 147 |
77 void SyncCompleted(const SyncStatusCallback& callback); | 148 void SyncCompleted(const SyncStatusCallback& callback); |
78 | 149 |
79 void Prepare(const SyncStatusCallback& callback); | 150 void Prepare(const SyncStatusCallback& callback); |
80 void DidPrepare(const SyncStatusCallback& callback, | 151 void DidPrepare(const SyncStatusCallback& callback, |
81 SyncStatusCode status, | 152 SyncStatusCode status, |
82 const SyncFileMetadata& metadata, | 153 const SyncFileMetadata& metadata, |
83 const FileChangeList& changes); | 154 const FileChangeList& changes); |
84 | 155 |
85 void DeleteLocalFile(const SyncStatusCallback& callback); | 156 void DeleteLocalFile(const SyncStatusCallback& callback); |
86 void DidDeleteLocalFile(const SyncStatusCallback& callback, | 157 void DidDeleteLocalFile(const SyncStatusCallback& callback, |
87 SyncStatusCode status); | 158 SyncStatusCode status); |
88 | 159 |
89 drive::DriveServiceInterface* drive_service(); | 160 drive::DriveServiceInterface* drive_service(); |
90 MetadataDatabase* metadata_database(); | 161 MetadataDatabase* metadata_database(); |
91 RemoteChangeProcessor* remote_change_processor(); | 162 RemoteChangeProcessor* remote_change_processor(); |
92 | 163 |
93 SyncEngineContext* sync_context_; // Not owned. | 164 SyncEngineContext* sync_context_; // Not owned. |
94 | 165 |
95 int priorities_; | 166 int priorities_; |
96 FileTracker dirty_tracker_; | 167 scoped_ptr<FileTracker> dirty_tracker_; |
97 FileTracker parent_tracker_; | 168 scoped_ptr<FileMetadata> remote_metadata_; |
98 FileMetadata remote_metadata_; | |
99 | |
100 bool missing_remote_details_; | |
101 bool missing_synced_details_; | |
102 bool deleted_remote_details_; | |
103 bool deleted_synced_details_; | |
104 bool title_changed_; | |
105 bool content_changed_; | |
106 bool needs_folder_listing_; | |
107 bool missing_parent_; | |
108 | |
109 bool sync_root_modification_; | |
110 | 169 |
111 fileapi::FileSystemURL url_; | 170 fileapi::FileSystemURL url_; |
112 | 171 |
113 SyncFileMetadata local_metadata_; | 172 SyncFileMetadata local_metadata_; |
114 FileChangeList local_changes_; | 173 FileChangeList local_changes_; |
115 | 174 |
116 base::WeakPtrFactory<RemoteToLocalSyncer> weak_ptr_factory_; | 175 base::WeakPtrFactory<RemoteToLocalSyncer> weak_ptr_factory_; |
117 | 176 |
118 DISALLOW_COPY_AND_ASSIGN(RemoteToLocalSyncer); | 177 DISALLOW_COPY_AND_ASSIGN(RemoteToLocalSyncer); |
119 }; | 178 }; |
120 | 179 |
121 } // namespace drive_backend | 180 } // namespace drive_backend |
122 } // namespace sync_file_system | 181 } // namespace sync_file_system |
123 | 182 |
124 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_REMOTE_TO_LOCAL_SYNCER_ H_ | 183 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_REMOTE_TO_LOCAL_SYNCER_ H_ |
OLD | NEW |