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 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h " | 5 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h " |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 tracker.tracker_id(), &path)) | 32 tracker.tracker_id(), &path)) |
33 return false; | 33 return false; |
34 | 34 |
35 GURL origin = | 35 GURL origin = |
36 extensions::Extension::GetBaseURLFromExtensionId(tracker.app_id()); | 36 extensions::Extension::GetBaseURLFromExtensionId(tracker.app_id()); |
37 *url = sync_file_system::CreateSyncableFileSystemURL(origin, path); | 37 *url = sync_file_system::CreateSyncableFileSystemURL(origin, path); |
38 | 38 |
39 return true; | 39 return true; |
40 } | 40 } |
41 | 41 |
42 bool HasFolderAsParent(const FileDetails& details, | |
43 const std::string& folder_id) { | |
44 for (int i = 0; i < details.parent_folder_ids_size(); ++i) { | |
45 if (details.parent_folder_ids(i) == folder_id) | |
46 return true; | |
47 } | |
48 return false; | |
49 } | |
50 | |
51 bool HasDisabledAppRoot(MetadataDatabase* database, | |
52 const FileTracker& tracker) { | |
53 DCHECK(tracker.active()); | |
54 FileTracker app_root_tracker; | |
55 if (database->FindAppRootTracker(tracker.app_id(), &app_root_tracker)) { | |
56 DCHECK(app_root_tracker.tracker_kind() == TRACKER_KIND_APP_ROOT || | |
57 app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT); | |
58 return app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT; | |
59 } | |
60 return false; | |
61 } | |
62 | |
63 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, | |
64 const std::string& file_id) { | |
65 scoped_ptr<FileMetadata> metadata(new FileMetadata); | |
66 if (!database->FindFileByFileID(file_id, metadata.get())) | |
67 metadata.reset(); | |
68 return metadata.Pass(); | |
69 } | |
70 | |
42 } // namespace | 71 } // namespace |
43 | 72 |
44 RemoteToLocalSyncer::RemoteToLocalSyncer(SyncEngineContext* sync_context, | 73 RemoteToLocalSyncer::RemoteToLocalSyncer(SyncEngineContext* sync_context, |
45 int priorities) | 74 int priorities) |
46 : sync_context_(sync_context), | 75 : sync_context_(sync_context), |
47 priorities_(priorities), | 76 priorities_(priorities), |
48 missing_remote_details_(false), | |
49 missing_synced_details_(false), | |
50 deleted_remote_details_(false), | |
51 deleted_synced_details_(false), | |
52 title_changed_(false), | |
53 content_changed_(false), | |
54 needs_folder_listing_(false), | |
55 missing_parent_(false), | |
56 sync_root_modification_(false), | |
57 weak_ptr_factory_(this) { | 77 weak_ptr_factory_(this) { |
58 } | 78 } |
59 | 79 |
60 RemoteToLocalSyncer::~RemoteToLocalSyncer() { | 80 RemoteToLocalSyncer::~RemoteToLocalSyncer() { |
61 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
62 } | 82 } |
63 | 83 |
64 void RemoteToLocalSyncer::Run(const SyncStatusCallback& callback) { | 84 void RemoteToLocalSyncer::Run(const SyncStatusCallback& callback) { |
65 if (priorities_ & PRIORITY_NORMAL) { | 85 if (priorities_ & PRIORITY_NORMAL) { |
66 if (metadata_database()->GetNormalPriorityDirtyTracker(&dirty_tracker_)) { | 86 dirty_tracker_ = make_scoped_ptr(new FileTracker); |
87 if (metadata_database()->GetNormalPriorityDirtyTracker( | |
88 dirty_tracker_.get())) { | |
67 ResolveRemoteChange(callback); | 89 ResolveRemoteChange(callback); |
68 return; | 90 return; |
69 } | 91 } |
70 } | 92 } |
71 | 93 |
72 if (priorities_ & PRIORITY_LOW) { | 94 if (priorities_ & PRIORITY_LOW) { |
73 if (metadata_database()->GetLowPriorityDirtyTracker(&dirty_tracker_)) { | 95 dirty_tracker_ = make_scoped_ptr(new FileTracker); |
96 if (metadata_database()->GetLowPriorityDirtyTracker(dirty_tracker_.get())) { | |
74 ResolveRemoteChange(callback); | 97 ResolveRemoteChange(callback); |
75 return; | 98 return; |
76 } | 99 } |
77 } | 100 } |
78 | 101 |
79 base::MessageLoopProxy::current()->PostTask( | 102 base::MessageLoopProxy::current()->PostTask( |
80 FROM_HERE, | 103 FROM_HERE, |
81 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC)); | 104 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC)); |
82 } | 105 } |
83 | 106 |
84 void RemoteToLocalSyncer::AnalyzeCurrentDirtyTracker() { | |
85 if (!metadata_database()->FindFileByFileID( | |
86 dirty_tracker_.file_id(), &remote_metadata_)) { | |
87 missing_remote_details_ = true; | |
88 return; | |
89 } | |
90 missing_remote_details_ = false; | |
91 | |
92 if (dirty_tracker_.has_synced_details() && | |
93 !dirty_tracker_.synced_details().title().empty()) { // Just in case | |
94 missing_synced_details_ = true; | |
95 return; | |
96 } | |
97 missing_synced_details_ = false; | |
98 | |
99 const FileDetails& synced_details = dirty_tracker_.synced_details(); | |
100 const FileDetails& remote_details = remote_metadata_.details(); | |
101 | |
102 deleted_remote_details_ = remote_details.deleted(); | |
103 deleted_synced_details_ = synced_details.deleted(); | |
104 title_changed_ = synced_details.title() != remote_details.title(); | |
105 | |
106 switch (dirty_tracker_.synced_details().file_kind()) { | |
107 case FILE_KIND_UNSUPPORTED: | |
108 break; | |
109 case FILE_KIND_FILE: | |
110 content_changed_ = synced_details.md5() != remote_details.md5(); | |
111 break; | |
112 case FILE_KIND_FOLDER: | |
113 needs_folder_listing_ = dirty_tracker_.needs_folder_listing(); | |
114 break; | |
115 } | |
116 | |
117 bool unknown_parent = !metadata_database()->FindTrackerByTrackerID( | |
118 dirty_tracker_.parent_tracker_id(), &parent_tracker_); | |
119 if (unknown_parent) { | |
120 DCHECK_EQ(metadata_database()->GetSyncRootTrackerID(), | |
121 dirty_tracker_.tracker_id()); | |
122 sync_root_modification_ = true; | |
123 } else { | |
124 missing_parent_ = true; | |
125 std::string parent_folder_id = parent_tracker_.file_id(); | |
126 for (int i = 0; i < remote_details.parent_folder_ids_size(); ++i) { | |
127 if (remote_details.parent_folder_ids(i) == parent_folder_id) { | |
128 missing_parent_ = false; | |
129 break; | |
130 } | |
131 } | |
132 } | |
133 } | |
134 | |
135 void RemoteToLocalSyncer::ResolveRemoteChange( | 107 void RemoteToLocalSyncer::ResolveRemoteChange( |
136 const SyncStatusCallback& callback) { | 108 const SyncStatusCallback& callback) { |
137 AnalyzeCurrentDirtyTracker(); | 109 DCHECK(dirty_tracker_); |
110 remote_metadata_ = GetFileMetadata( | |
111 metadata_database(), dirty_tracker_->file_id()); | |
138 | 112 |
139 if (missing_remote_details_) { | 113 if (!remote_metadata_ || !remote_metadata_->has_details()) { |
140 GetRemoteResource(callback); | 114 if (remote_metadata_ && !remote_metadata_->has_details()) { |
115 LOG(ERROR) << "Missing details of a remote file: " | |
116 << remote_metadata_->file_id(); | |
117 NOTREACHED(); | |
118 } | |
119 HandleMissingRemoteMetadata(callback); | |
141 return; | 120 return; |
142 } | 121 } |
143 | 122 |
144 if (missing_synced_details_) { | 123 DCHECK(remote_metadata_); |
145 if (deleted_remote_details_) { | 124 DCHECK(remote_metadata_->has_details()); |
125 const FileDetails& remote_details = remote_metadata_->details(); | |
126 | |
127 if (!dirty_tracker_->active() || | |
128 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)) { | |
129 HandleInactiveTracker(callback); | |
130 return; | |
131 } | |
132 DCHECK(dirty_tracker_->active()); | |
133 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
134 | |
135 if (!dirty_tracker_->has_synced_details() || | |
136 dirty_tracker_->synced_details().deleted()) { | |
137 if (remote_details.deleted()) { | |
138 if (dirty_tracker_->has_synced_details() && | |
139 dirty_tracker_->synced_details().deleted()) { | |
140 // This should be handled by MetadataDatabase. | |
141 // MetadataDatabase should drop a tracker that marked as deleted if | |
142 // corresponding file metadata is marked as deleted. | |
143 LOG(ERROR) << "Found a stray deleted tracker: " | |
144 << dirty_tracker_->file_id(); | |
145 NOTREACHED(); | |
146 } | |
146 SyncCompleted(callback); | 147 SyncCompleted(callback); |
147 return; | 148 return; |
148 } | 149 } |
149 HandleNewFile(callback); | 150 DCHECK(!remote_details.deleted()); |
150 return; | |
151 } | |
152 | 151 |
153 if (!dirty_tracker_.active()) { | 152 if (remote_details.file_kind() == FILE_KIND_UNSUPPORTED) { |
154 HandleOfflineSolvable(callback); | 153 // All unsupported file must be inactive. |
155 return; | 154 LOG(ERROR) << "Found an unsupported active file: " |
156 } | 155 << remote_metadata_->file_id(); |
156 NOTREACHED(); | |
157 callback.Run(SYNC_STATUS_FAILED); | |
158 return; | |
159 } | |
160 DCHECK(remote_details.file_kind() == FILE_KIND_FILE || | |
161 remote_details.file_kind() == FILE_KIND_FOLDER); | |
157 | 162 |
158 if (deleted_synced_details_) { | 163 if (remote_details.file_kind() == FILE_KIND_FILE) { |
159 if (deleted_remote_details_) { | 164 HandleNewFile(callback); |
160 SyncCompleted(callback); | |
161 return; | 165 return; |
162 } | 166 } |
163 | 167 |
164 HandleNewFile(callback); | 168 DCHECK(remote_details.file_kind() == FILE_KIND_FOLDER); |
169 HandleNewFolder(callback); | |
165 return; | 170 return; |
166 } | 171 } |
172 DCHECK(dirty_tracker_->has_synced_details()); | |
173 DCHECK(!dirty_tracker_->synced_details().deleted()); | |
174 const FileDetails& synced_details = dirty_tracker_->synced_details(); | |
167 | 175 |
168 if (deleted_remote_details_) { | 176 if (remote_details.deleted()) { |
169 HandleDeletion(callback); | 177 HandleDeletion(callback); |
170 return; | 178 return; |
171 } | 179 } |
172 | 180 |
173 if (title_changed_) { | 181 // Most of remote_details field is valid from here. |
182 DCHECK(!remote_details.deleted()); | |
183 | |
184 if (synced_details.file_kind() != remote_details.file_kind()) { | |
185 LOG(ERROR) << "Found type mismatch between remote and local file: " | |
186 << dirty_tracker_->file_id() | |
187 << " type: " << synced_details.file_kind() << " vs " | |
188 << remote_details.file_kind(); | |
nhiroki
2013/11/11 03:37:17
nit: Line 184 says "remote and local", but line 18
tzik
2013/11/11 04:45:34
Done.
| |
189 NOTREACHED(); | |
190 callback.Run(SYNC_STATUS_FAILED); | |
191 return; | |
192 } | |
193 DCHECK_EQ(synced_details.file_kind(), remote_details.file_kind()); | |
194 | |
195 if (synced_details.file_kind() == FILE_KIND_UNSUPPORTED) { | |
196 LOG(ERROR) << "Found an unsupported active file: " | |
197 << remote_metadata_->file_id(); | |
198 NOTREACHED(); | |
199 callback.Run(SYNC_STATUS_FAILED); | |
200 return; | |
201 } | |
202 DCHECK(remote_details.file_kind() == FILE_KIND_FILE || | |
203 remote_details.file_kind() == FILE_KIND_FOLDER); | |
204 | |
205 if (synced_details.title() != remote_details.title()) { | |
174 HandleRename(callback); | 206 HandleRename(callback); |
175 return; | 207 return; |
176 } | 208 } |
209 DCHECK_EQ(synced_details.title(), remote_details.title()); | |
177 | 210 |
178 if (content_changed_) { | 211 if (dirty_tracker_->tracker_id() != |
179 HandleContentUpdate(callback); | 212 metadata_database()->GetSyncRootTrackerID()) { |
180 return; | 213 FileTracker parent_tracker; |
214 if (!metadata_database()->FindTrackerByTrackerID( | |
215 dirty_tracker_->parent_tracker_id(), &parent_tracker)) { | |
216 LOG(ERROR) << "Missing parent tracker for a non sync-root tracker: " | |
217 << dirty_tracker_->file_id(); | |
kinuko
2013/11/09 23:33:25
Is this a valid (possible) case or notreached?
tzik
2013/11/11 04:45:34
Fixed.
It should be NOTREACHED.
| |
218 return; | |
219 } | |
220 | |
221 if (!HasFolderAsParent(remote_details, parent_tracker.file_id())) { | |
222 HandleReorganize(callback); | |
223 return; | |
224 } | |
181 } | 225 } |
182 | 226 |
183 if (needs_folder_listing_) { | 227 if (synced_details.file_kind() == FILE_KIND_FILE) { |
184 ListFolderContent(callback); | 228 if (synced_details.md5() != remote_details.md5()) { |
185 return; | 229 HandleContentUpdate(callback); |
186 } | 230 return; |
187 | 231 } |
188 if (missing_parent_) { | 232 } else { |
189 HandleReorganize(callback); | 233 DCHECK_EQ(FILE_KIND_FOLDER, synced_details.file_kind()); |
190 return; | 234 if (dirty_tracker_->needs_folder_listing()) { |
235 HandleFolderContentListing(callback); | |
236 return; | |
237 } | |
191 } | 238 } |
192 | 239 |
193 HandleOfflineSolvable(callback); | 240 HandleOfflineSolvable(callback); |
194 } | 241 } |
195 | 242 |
196 void RemoteToLocalSyncer::GetRemoteResource( | 243 void RemoteToLocalSyncer::HandleMissingRemoteMetadata( |
197 const SyncStatusCallback& callback) { | 244 const SyncStatusCallback& callback) { |
245 DCHECK(dirty_tracker_); | |
246 | |
198 drive_service()->GetResourceEntry( | 247 drive_service()->GetResourceEntry( |
199 dirty_tracker_.file_id(), | 248 dirty_tracker_->file_id(), |
200 base::Bind(&RemoteToLocalSyncer::DidGetRemoteResource, | 249 base::Bind(&RemoteToLocalSyncer::DidGetRemoteResource, |
201 weak_ptr_factory_.GetWeakPtr(), | 250 weak_ptr_factory_.GetWeakPtr(), |
202 callback, | 251 callback, |
203 metadata_database()->GetLargestKnownChangeID())); | 252 metadata_database()->GetLargestKnownChangeID())); |
204 } | 253 } |
205 | 254 |
206 void RemoteToLocalSyncer::DidGetRemoteResource( | 255 void RemoteToLocalSyncer::DidGetRemoteResource( |
207 const SyncStatusCallback& callback, | 256 const SyncStatusCallback& callback, |
208 int64 change_id, | 257 int64 change_id, |
209 google_apis::GDataErrorCode error, | 258 google_apis::GDataErrorCode error, |
210 scoped_ptr<google_apis::ResourceEntry> entry) { | 259 scoped_ptr<google_apis::ResourceEntry> entry) { |
211 metadata_database()->UpdateByFileResource( | 260 metadata_database()->UpdateByFileResource( |
212 change_id, | 261 change_id, |
213 *drive::util::ConvertResourceEntryToFileResource(*entry), | 262 *drive::util::ConvertResourceEntryToFileResource(*entry), |
214 callback); | 263 callback); |
kinuko
2013/11/09 23:33:25
We just finish sync after fetching remote details
tzik
2013/11/11 04:45:34
Changed to invoke SyncCompleted.
Finishing sync wi
| |
215 } | 264 } |
216 | 265 |
266 void RemoteToLocalSyncer::HandleInactiveTracker( | |
267 const SyncStatusCallback& callback) { | |
268 DCHECK(dirty_tracker_); | |
269 DCHECK(!dirty_tracker_->active() || | |
270 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
271 | |
272 DCHECK(remote_metadata_); | |
273 DCHECK(remote_metadata_->has_details()); | |
274 | |
275 NOTIMPLEMENTED(); | |
276 callback.Run(SYNC_STATUS_FAILED); | |
277 } | |
278 | |
279 void RemoteToLocalSyncer::HandleNewFile( | |
280 const SyncStatusCallback& callback) { | |
281 DCHECK(dirty_tracker_); | |
282 DCHECK(dirty_tracker_->active()); | |
283 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
284 DCHECK(!dirty_tracker_->has_synced_details() || | |
285 dirty_tracker_->synced_details().deleted()); | |
286 | |
287 DCHECK(remote_metadata_); | |
288 DCHECK(remote_metadata_->has_details()); | |
289 DCHECK(!remote_metadata_->details().deleted()); | |
290 DCHECK_EQ(FILE_KIND_FILE, !remote_metadata_->details().file_kind()); | |
291 | |
292 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForNewFile, | |
293 weak_ptr_factory_.GetWeakPtr(), callback)); | |
294 } | |
295 | |
296 void RemoteToLocalSyncer::DidPrepareForNewFile( | |
297 const SyncStatusCallback& callback, | |
298 SyncStatusCode status) { | |
299 NOTIMPLEMENTED(); | |
300 callback.Run(SYNC_STATUS_FAILED); | |
301 } | |
302 | |
303 void RemoteToLocalSyncer::HandleNewFolder(const SyncStatusCallback& callback) { | |
304 DCHECK(dirty_tracker_); | |
305 DCHECK(dirty_tracker_->active()); | |
306 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
307 | |
308 DCHECK(remote_metadata_); | |
309 DCHECK(remote_metadata_->has_details()); | |
310 DCHECK(!remote_metadata_->details().deleted()); | |
311 DCHECK_EQ(FILE_KIND_FOLDER, | |
312 !remote_metadata_->details().file_kind()); | |
313 | |
314 NOTIMPLEMENTED(); | |
315 callback.Run(SYNC_STATUS_FAILED); | |
316 } | |
317 | |
217 void RemoteToLocalSyncer::HandleDeletion( | 318 void RemoteToLocalSyncer::HandleDeletion( |
218 const SyncStatusCallback& callback) { | 319 const SyncStatusCallback& callback) { |
320 DCHECK(dirty_tracker_); | |
321 DCHECK(dirty_tracker_->active()); | |
322 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
323 DCHECK(dirty_tracker_->has_synced_details()); | |
324 DCHECK(!dirty_tracker_->synced_details().deleted()); | |
325 | |
326 DCHECK(remote_metadata_); | |
327 DCHECK(remote_metadata_->has_details()); | |
328 DCHECK(remote_metadata_->details().deleted()); | |
329 | |
219 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, | 330 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, |
220 weak_ptr_factory_.GetWeakPtr(), callback)); | 331 weak_ptr_factory_.GetWeakPtr(), callback)); |
221 } | 332 } |
222 | 333 |
223 void RemoteToLocalSyncer::DidPrepareForDeletion( | 334 void RemoteToLocalSyncer::DidPrepareForDeletion( |
224 const SyncStatusCallback& callback, | 335 const SyncStatusCallback& callback, |
225 SyncStatusCode status) { | 336 SyncStatusCode status) { |
226 if (status != SYNC_STATUS_OK) { | 337 if (status != SYNC_STATUS_OK) { |
227 callback.Run(status); | 338 callback.Run(status); |
228 return; | 339 return; |
229 } | 340 } |
230 | 341 |
231 if (local_changes_.empty()) { | 342 if (local_changes_.empty()) { |
232 DeleteLocalFile(callback); | 343 DeleteLocalFile(callback); |
233 return; | 344 return; |
234 } | 345 } |
235 | 346 |
236 // File is locally deleted or locally updated. | 347 // File is locally deleted or locally updated. |
237 SyncCompleted(callback); | 348 SyncCompleted(callback); |
238 } | 349 } |
239 | 350 |
240 void RemoteToLocalSyncer::HandleNewFile( | 351 void RemoteToLocalSyncer::HandleRename( |
241 const SyncStatusCallback& callback) { | 352 const SyncStatusCallback& callback) { |
242 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForNewFile, | 353 DCHECK(dirty_tracker_); |
243 weak_ptr_factory_.GetWeakPtr(), callback)); | 354 DCHECK(dirty_tracker_->active()); |
355 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
356 DCHECK(dirty_tracker_->has_synced_details()); | |
357 DCHECK(!dirty_tracker_->synced_details().deleted()); | |
358 | |
359 DCHECK(remote_metadata_); | |
360 DCHECK(remote_metadata_->has_details()); | |
361 DCHECK(!remote_metadata_->details().deleted()); | |
362 | |
363 DCHECK_EQ(dirty_tracker_->synced_details().file_kind(), | |
364 remote_metadata_->details().file_kind()); | |
365 DCHECK_NE(dirty_tracker_->synced_details().title(), | |
366 remote_metadata_->details().title()); | |
367 | |
368 NOTIMPLEMENTED(); | |
369 callback.Run(SYNC_STATUS_FAILED); | |
244 } | 370 } |
245 | 371 |
246 void RemoteToLocalSyncer::DidPrepareForNewFile( | 372 void RemoteToLocalSyncer::HandleReorganize( |
247 const SyncStatusCallback& callback, | 373 const SyncStatusCallback& callback) { |
248 SyncStatusCode status) { | 374 DCHECK(dirty_tracker_); |
375 DCHECK(dirty_tracker_->active()); | |
376 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
377 DCHECK(dirty_tracker_->has_synced_details()); | |
378 DCHECK(!dirty_tracker_->synced_details().deleted()); | |
379 | |
380 DCHECK(remote_metadata_); | |
381 DCHECK(remote_metadata_->has_details()); | |
382 DCHECK(!remote_metadata_->details().deleted()); | |
383 | |
249 NOTIMPLEMENTED(); | 384 NOTIMPLEMENTED(); |
250 callback.Run(SYNC_STATUS_FAILED); | 385 callback.Run(SYNC_STATUS_FAILED); |
251 } | 386 } |
252 | 387 |
253 void RemoteToLocalSyncer::HandleContentUpdate( | 388 void RemoteToLocalSyncer::HandleContentUpdate( |
254 const SyncStatusCallback& callback) { | 389 const SyncStatusCallback& callback) { |
390 DCHECK(dirty_tracker_); | |
391 DCHECK(dirty_tracker_->active()); | |
392 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
393 DCHECK(dirty_tracker_->has_synced_details()); | |
394 DCHECK(!dirty_tracker_->synced_details().deleted()); | |
395 DCHECK_EQ(FILE_KIND_FILE, dirty_tracker_->synced_details().file_kind()); | |
396 | |
397 DCHECK(remote_metadata_); | |
398 DCHECK(remote_metadata_->has_details()); | |
399 DCHECK(!remote_metadata_->details().deleted()); | |
400 | |
401 DCHECK_NE(dirty_tracker_->synced_details().md5(), | |
402 remote_metadata_->details().md5()); | |
403 | |
255 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForContentUpdate, | 404 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForContentUpdate, |
256 weak_ptr_factory_.GetWeakPtr(), callback)); | 405 weak_ptr_factory_.GetWeakPtr(), callback)); |
257 } | 406 } |
258 | 407 |
259 void RemoteToLocalSyncer::DidPrepareForContentUpdate( | 408 void RemoteToLocalSyncer::DidPrepareForContentUpdate( |
260 const SyncStatusCallback& callback, | 409 const SyncStatusCallback& callback, |
261 SyncStatusCode status) { | 410 SyncStatusCode status) { |
262 NOTIMPLEMENTED(); | 411 NOTIMPLEMENTED(); |
263 callback.Run(SYNC_STATUS_FAILED); | 412 callback.Run(SYNC_STATUS_FAILED); |
264 } | 413 } |
265 | 414 |
266 void RemoteToLocalSyncer::ListFolderContent( | 415 void RemoteToLocalSyncer::HandleFolderContentListing( |
267 const SyncStatusCallback& callback) { | 416 const SyncStatusCallback& callback) { |
417 DCHECK(dirty_tracker_); | |
418 DCHECK(dirty_tracker_->active()); | |
419 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
420 DCHECK(dirty_tracker_->has_synced_details()); | |
421 DCHECK(!dirty_tracker_->synced_details().deleted()); | |
422 DCHECK_EQ(FILE_KIND_FOLDER, dirty_tracker_->synced_details().file_kind()); | |
423 DCHECK(dirty_tracker_->needs_folder_listing()); | |
424 | |
425 DCHECK(remote_metadata_); | |
426 DCHECK(remote_metadata_->has_details()); | |
427 DCHECK(!remote_metadata_->details().deleted()); | |
428 | |
268 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForFolderListing, | 429 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForFolderListing, |
269 weak_ptr_factory_.GetWeakPtr(), callback)); | 430 weak_ptr_factory_.GetWeakPtr(), callback)); |
270 } | 431 } |
271 | 432 |
272 void RemoteToLocalSyncer::DidPrepareForFolderListing( | 433 void RemoteToLocalSyncer::DidPrepareForFolderListing( |
273 const SyncStatusCallback& callback, | 434 const SyncStatusCallback& callback, |
274 SyncStatusCode status) { | 435 SyncStatusCode status) { |
275 NOTIMPLEMENTED(); | 436 NOTIMPLEMENTED(); |
276 callback.Run(SYNC_STATUS_FAILED); | 437 callback.Run(SYNC_STATUS_FAILED); |
277 } | 438 } |
278 | 439 |
279 void RemoteToLocalSyncer::HandleRename( | |
280 const SyncStatusCallback& callback) { | |
281 NOTIMPLEMENTED(); | |
282 callback.Run(SYNC_STATUS_FAILED); | |
283 } | |
284 | |
285 void RemoteToLocalSyncer::HandleReorganize( | |
286 const SyncStatusCallback& callback) { | |
287 NOTIMPLEMENTED(); | |
288 callback.Run(SYNC_STATUS_FAILED); | |
289 } | |
290 | |
291 void RemoteToLocalSyncer::HandleOfflineSolvable( | 440 void RemoteToLocalSyncer::HandleOfflineSolvable( |
292 const SyncStatusCallback& callback) { | 441 const SyncStatusCallback& callback) { |
442 DCHECK(dirty_tracker_); | |
443 DCHECK(dirty_tracker_->active()); | |
444 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | |
445 DCHECK(dirty_tracker_->has_synced_details()); | |
446 DCHECK(!dirty_tracker_->synced_details().deleted()); | |
447 | |
448 DCHECK((dirty_tracker_->synced_details().file_kind() == FILE_KIND_FOLDER && | |
449 !dirty_tracker_->needs_folder_listing()) || | |
450 (dirty_tracker_->synced_details().file_kind() == FILE_KIND_FILE && | |
451 dirty_tracker_->synced_details().md5() == | |
452 remote_metadata_->details().md5())); | |
453 | |
454 DCHECK(remote_metadata_); | |
455 DCHECK(remote_metadata_->has_details()); | |
456 DCHECK(!remote_metadata_->details().deleted()); | |
457 | |
293 NOTIMPLEMENTED(); | 458 NOTIMPLEMENTED(); |
294 callback.Run(SYNC_STATUS_FAILED); | 459 callback.Run(SYNC_STATUS_FAILED); |
295 } | 460 } |
296 | 461 |
297 void RemoteToLocalSyncer::SyncCompleted( | 462 void RemoteToLocalSyncer::SyncCompleted( |
298 const SyncStatusCallback& callback) { | 463 const SyncStatusCallback& callback) { |
299 NOTIMPLEMENTED(); | 464 NOTIMPLEMENTED(); |
300 callback.Run(SYNC_STATUS_FAILED); | 465 callback.Run(SYNC_STATUS_FAILED); |
301 | 466 |
302 // TODO(tzik): Clear dirty mark of the |dirty_tracker|, report operation log | 467 // TODO(tzik): Clear dirty mark of the |dirty_tracker|, report operation log |
303 // the observer. | 468 // the observer. |
304 } | 469 } |
305 | 470 |
306 void RemoteToLocalSyncer::Prepare(const SyncStatusCallback& callback) { | 471 void RemoteToLocalSyncer::Prepare(const SyncStatusCallback& callback) { |
307 bool should_success = BuildFileSystemURL( | 472 bool should_success = BuildFileSystemURL( |
308 metadata_database(), dirty_tracker_, &url_); | 473 metadata_database(), *dirty_tracker_, &url_); |
309 DCHECK(should_success); | 474 DCHECK(should_success); |
310 remote_change_processor()->PrepareForProcessRemoteChange( | 475 remote_change_processor()->PrepareForProcessRemoteChange( |
311 url_, | 476 url_, |
312 base::Bind(&RemoteToLocalSyncer::DidPrepare, | 477 base::Bind(&RemoteToLocalSyncer::DidPrepare, |
313 weak_ptr_factory_.GetWeakPtr(), | 478 weak_ptr_factory_.GetWeakPtr(), |
314 callback)); | 479 callback)); |
315 } | 480 } |
316 | 481 |
317 void RemoteToLocalSyncer::DidPrepare(const SyncStatusCallback& callback, | 482 void RemoteToLocalSyncer::DidPrepare(const SyncStatusCallback& callback, |
318 SyncStatusCode status, | 483 SyncStatusCode status, |
319 const SyncFileMetadata& local_metadata, | 484 const SyncFileMetadata& local_metadata, |
320 const FileChangeList& local_changes) { | 485 const FileChangeList& local_changes) { |
321 if (status != SYNC_STATUS_OK) { | 486 if (status != SYNC_STATUS_OK) { |
322 callback.Run(status); | 487 callback.Run(status); |
323 return; | 488 return; |
324 } | 489 } |
325 | 490 |
326 local_metadata_ = local_metadata; | 491 local_metadata_ = local_metadata; |
327 local_changes_ = local_changes; | 492 local_changes_ = local_changes; |
328 | 493 |
329 callback.Run(status); | 494 callback.Run(status); |
330 } | 495 } |
331 | 496 |
332 void RemoteToLocalSyncer::DeleteLocalFile(const SyncStatusCallback& callback) { | 497 void RemoteToLocalSyncer::DeleteLocalFile(const SyncStatusCallback& callback) { |
333 if (sync_root_modification_) { | 498 if (dirty_tracker_->tracker_id() == |
499 metadata_database()->GetSyncRootTrackerID()) { | |
334 // TODO(tzik): Sync-root is deleted. Needs special handling. | 500 // TODO(tzik): Sync-root is deleted. Needs special handling. |
335 NOTIMPLEMENTED(); | 501 NOTIMPLEMENTED(); |
336 callback.Run(SYNC_STATUS_FAILED); | 502 callback.Run(SYNC_STATUS_FAILED); |
337 return; | 503 return; |
338 } | 504 } |
339 | 505 |
340 if (dirty_tracker_.tracker_kind() == TRACKER_KIND_APP_ROOT) { | 506 if (dirty_tracker_->tracker_kind() == TRACKER_KIND_APP_ROOT) { |
341 // TODO(tzik): Active app-root is deleted. Needs special handling. | 507 // TODO(tzik): Active app-root is deleted. Needs special handling. |
342 NOTIMPLEMENTED(); | 508 NOTIMPLEMENTED(); |
343 callback.Run(SYNC_STATUS_FAILED); | 509 callback.Run(SYNC_STATUS_FAILED); |
344 return; | 510 return; |
345 } | 511 } |
346 | 512 |
347 remote_change_processor()->ApplyRemoteChange( | 513 remote_change_processor()->ApplyRemoteChange( |
348 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), | 514 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), |
349 base::FilePath(), | 515 base::FilePath(), |
350 url_, | 516 url_, |
(...skipping 20 matching lines...) Expand all Loading... | |
371 return sync_context_->GetMetadataDatabase(); | 537 return sync_context_->GetMetadataDatabase(); |
372 } | 538 } |
373 | 539 |
374 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { | 540 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { |
375 DCHECK(sync_context_->GetRemoteChangeProcessor()); | 541 DCHECK(sync_context_->GetRemoteChangeProcessor()); |
376 return sync_context_->GetRemoteChangeProcessor(); | 542 return sync_context_->GetRemoteChangeProcessor(); |
377 } | 543 } |
378 | 544 |
379 } // namespace drive_backend | 545 } // namespace drive_backend |
380 } // namespace sync_file_system | 546 } // namespace sync_file_system |
OLD | NEW |