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/local/local_file_sync_context.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 callback_queue.push_back(callback); | 79 callback_queue.push_back(callback); |
80 if (callback_queue.size() > 1) | 80 if (callback_queue.size() > 1) |
81 return; | 81 return; |
82 | 82 |
83 // The sync service always expects the origin (app) is initialized | 83 // The sync service always expects the origin (app) is initialized |
84 // for writable way (even when MaybeInitializeFileSystemContext is called | 84 // for writable way (even when MaybeInitializeFileSystemContext is called |
85 // from read-only OpenFileSystem), so open the filesystem with | 85 // from read-only OpenFileSystem), so open the filesystem with |
86 // CREATE_IF_NONEXISTENT here. | 86 // CREATE_IF_NONEXISTENT here. |
87 storage::FileSystemBackend::OpenFileSystemCallback open_filesystem_callback = | 87 storage::FileSystemBackend::OpenFileSystemCallback open_filesystem_callback = |
88 base::Bind(&LocalFileSyncContext::InitializeFileSystemContextOnIOThread, | 88 base::Bind(&LocalFileSyncContext::InitializeFileSystemContextOnIOThread, |
89 this, | 89 this, source_url, base::RetainedRef(file_system_context)); |
90 source_url, | |
91 make_scoped_refptr(file_system_context)); | |
92 io_task_runner_->PostTask( | 90 io_task_runner_->PostTask( |
93 FROM_HERE, | 91 FROM_HERE, |
94 base::Bind(&storage::SandboxFileSystemBackendDelegate::OpenFileSystem, | 92 base::Bind(&storage::SandboxFileSystemBackendDelegate::OpenFileSystem, |
95 base::Unretained(file_system_context->sandbox_delegate()), | 93 base::Unretained(file_system_context->sandbox_delegate()), |
96 source_url, | 94 source_url, |
97 storage::kFileSystemTypeSyncable, | 95 storage::kFileSystemTypeSyncable, |
98 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 96 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
99 open_filesystem_callback, | 97 open_filesystem_callback, |
100 GURL())); | 98 GURL())); |
101 } | 99 } |
102 | 100 |
103 void LocalFileSyncContext::ShutdownOnUIThread() { | 101 void LocalFileSyncContext::ShutdownOnUIThread() { |
104 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 102 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
105 shutdown_on_ui_ = true; | 103 shutdown_on_ui_ = true; |
106 io_task_runner_->PostTask( | 104 io_task_runner_->PostTask( |
107 FROM_HERE, | 105 FROM_HERE, |
108 base::Bind(&LocalFileSyncContext::ShutdownOnIOThread, this)); | 106 base::Bind(&LocalFileSyncContext::ShutdownOnIOThread, this)); |
109 } | 107 } |
110 | 108 |
111 void LocalFileSyncContext::GetFileForLocalSync( | 109 void LocalFileSyncContext::GetFileForLocalSync( |
112 FileSystemContext* file_system_context, | 110 FileSystemContext* file_system_context, |
113 const LocalFileSyncInfoCallback& callback) { | 111 const LocalFileSyncInfoCallback& callback) { |
114 DCHECK(file_system_context); | 112 DCHECK(file_system_context); |
115 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 113 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
116 | 114 |
117 base::PostTaskAndReplyWithResult( | 115 base::PostTaskAndReplyWithResult( |
118 file_system_context->default_file_task_runner(), | 116 file_system_context->default_file_task_runner(), FROM_HERE, |
119 FROM_HERE, | 117 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, this, |
120 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, | 118 base::RetainedRef(file_system_context)), |
121 this, make_scoped_refptr(file_system_context)), | 119 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, this, |
122 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, | 120 base::RetainedRef(file_system_context), callback)); |
123 this, make_scoped_refptr(file_system_context), callback)); | |
124 } | 121 } |
125 | 122 |
126 void LocalFileSyncContext::ClearChangesForURL( | 123 void LocalFileSyncContext::ClearChangesForURL( |
127 FileSystemContext* file_system_context, | 124 FileSystemContext* file_system_context, |
128 const FileSystemURL& url, | 125 const FileSystemURL& url, |
129 const base::Closure& done_callback) { | 126 const base::Closure& done_callback) { |
130 // This is initially called on UI thread and to be relayed to FILE thread. | 127 // This is initially called on UI thread and to be relayed to FILE thread. |
131 DCHECK(file_system_context); | 128 DCHECK(file_system_context); |
132 if (!file_system_context->default_file_task_runner()-> | 129 if (!file_system_context->default_file_task_runner()-> |
133 RunsTasksOnCurrentThread()) { | 130 RunsTasksOnCurrentThread()) { |
134 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 131 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
135 file_system_context->default_file_task_runner()->PostTask( | 132 file_system_context->default_file_task_runner()->PostTask( |
136 FROM_HERE, | 133 FROM_HERE, |
137 base::Bind(&LocalFileSyncContext::ClearChangesForURL, | 134 base::Bind(&LocalFileSyncContext::ClearChangesForURL, this, |
138 this, make_scoped_refptr(file_system_context), | 135 base::RetainedRef(file_system_context), url, done_callback)); |
139 url, done_callback)); | |
140 return; | 136 return; |
141 } | 137 } |
142 | 138 |
143 SyncFileSystemBackend* backend = | 139 SyncFileSystemBackend* backend = |
144 SyncFileSystemBackend::GetBackend(file_system_context); | 140 SyncFileSystemBackend::GetBackend(file_system_context); |
145 DCHECK(backend); | 141 DCHECK(backend); |
146 DCHECK(backend->change_tracker()); | 142 DCHECK(backend->change_tracker()); |
147 backend->change_tracker()->ClearChangesForURL(url); | 143 backend->change_tracker()->ClearChangesForURL(url); |
148 | 144 |
149 // Call the completion callback on UI thread. | 145 // Call the completion callback on UI thread. |
150 ui_task_runner_->PostTask(FROM_HERE, done_callback); | 146 ui_task_runner_->PostTask(FROM_HERE, done_callback); |
151 } | 147 } |
152 | 148 |
153 void LocalFileSyncContext::FinalizeSnapshotSync( | 149 void LocalFileSyncContext::FinalizeSnapshotSync( |
154 storage::FileSystemContext* file_system_context, | 150 storage::FileSystemContext* file_system_context, |
155 const storage::FileSystemURL& url, | 151 const storage::FileSystemURL& url, |
156 SyncStatusCode sync_finish_status, | 152 SyncStatusCode sync_finish_status, |
157 const base::Closure& done_callback) { | 153 const base::Closure& done_callback) { |
158 DCHECK(file_system_context); | 154 DCHECK(file_system_context); |
159 DCHECK(url.is_valid()); | 155 DCHECK(url.is_valid()); |
160 if (!file_system_context->default_file_task_runner()-> | 156 if (!file_system_context->default_file_task_runner()-> |
161 RunsTasksOnCurrentThread()) { | 157 RunsTasksOnCurrentThread()) { |
162 file_system_context->default_file_task_runner()->PostTask( | 158 file_system_context->default_file_task_runner()->PostTask( |
163 FROM_HERE, | 159 FROM_HERE, base::Bind(&LocalFileSyncContext::FinalizeSnapshotSync, this, |
164 base::Bind(&LocalFileSyncContext::FinalizeSnapshotSync, | 160 base::RetainedRef(file_system_context), url, |
165 this, make_scoped_refptr(file_system_context), | 161 sync_finish_status, done_callback)); |
166 url, sync_finish_status, done_callback)); | |
167 return; | 162 return; |
168 } | 163 } |
169 | 164 |
170 SyncFileSystemBackend* backend = | 165 SyncFileSystemBackend* backend = |
171 SyncFileSystemBackend::GetBackend(file_system_context); | 166 SyncFileSystemBackend::GetBackend(file_system_context); |
172 DCHECK(backend); | 167 DCHECK(backend); |
173 DCHECK(backend->change_tracker()); | 168 DCHECK(backend->change_tracker()); |
174 | 169 |
175 if (sync_finish_status == SYNC_STATUS_OK || | 170 if (sync_finish_status == SYNC_STATUS_OK || |
176 sync_finish_status == SYNC_STATUS_HAS_CONFLICT) { | 171 sync_finish_status == SYNC_STATUS_HAS_CONFLICT) { |
(...skipping 21 matching lines...) Expand all Loading... |
198 const base::Closure& done_callback) { | 193 const base::Closure& done_callback) { |
199 DCHECK(file_system_context); | 194 DCHECK(file_system_context); |
200 if (!url.is_valid()) { | 195 if (!url.is_valid()) { |
201 done_callback.Run(); | 196 done_callback.Run(); |
202 return; | 197 return; |
203 } | 198 } |
204 | 199 |
205 if (clear_local_changes) { | 200 if (clear_local_changes) { |
206 ClearChangesForURL(file_system_context, url, | 201 ClearChangesForURL(file_system_context, url, |
207 base::Bind(&LocalFileSyncContext::FinalizeExclusiveSync, | 202 base::Bind(&LocalFileSyncContext::FinalizeExclusiveSync, |
208 this, make_scoped_refptr(file_system_context), | 203 this, base::RetainedRef(file_system_context), |
209 url, false, done_callback)); | 204 url, false, done_callback)); |
210 return; | 205 return; |
211 } | 206 } |
212 | 207 |
213 io_task_runner_->PostTask( | 208 io_task_runner_->PostTask( |
214 FROM_HERE, | 209 FROM_HERE, |
215 base::Bind(&LocalFileSyncContext::ClearSyncFlagOnIOThread, | 210 base::Bind(&LocalFileSyncContext::ClearSyncFlagOnIOThread, |
216 this, url, false /* for_snapshot_sync */)); | 211 this, url, false /* for_snapshot_sync */)); |
217 | 212 |
218 done_callback.Run(); | 213 done_callback.Run(); |
219 } | 214 } |
220 | 215 |
221 void LocalFileSyncContext::PrepareForSync( | 216 void LocalFileSyncContext::PrepareForSync( |
222 FileSystemContext* file_system_context, | 217 FileSystemContext* file_system_context, |
223 const FileSystemURL& url, | 218 const FileSystemURL& url, |
224 SyncMode sync_mode, | 219 SyncMode sync_mode, |
225 const LocalFileSyncInfoCallback& callback) { | 220 const LocalFileSyncInfoCallback& callback) { |
226 // This is initially called on UI thread and to be relayed to IO thread. | 221 // This is initially called on UI thread and to be relayed to IO thread. |
227 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 222 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
228 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 223 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
229 io_task_runner_->PostTask( | 224 io_task_runner_->PostTask( |
230 FROM_HERE, | 225 FROM_HERE, base::Bind(&LocalFileSyncContext::PrepareForSync, this, |
231 base::Bind(&LocalFileSyncContext::PrepareForSync, this, | 226 base::RetainedRef(file_system_context), url, |
232 make_scoped_refptr(file_system_context), url, | 227 sync_mode, callback)); |
233 sync_mode, callback)); | |
234 return; | 228 return; |
235 } | 229 } |
236 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 230 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
237 const bool syncable = sync_status()->IsSyncable(url); | 231 const bool syncable = sync_status()->IsSyncable(url); |
238 // Disable writing if it's ready to be synced. | 232 // Disable writing if it's ready to be synced. |
239 if (syncable) | 233 if (syncable) |
240 sync_status()->StartSyncing(url); | 234 sync_status()->StartSyncing(url); |
241 ui_task_runner_->PostTask( | 235 ui_task_runner_->PostTask( |
242 FROM_HERE, | 236 FROM_HERE, base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, |
243 base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, | 237 this, base::RetainedRef(file_system_context), |
244 this, make_scoped_refptr(file_system_context), | 238 syncable ? SYNC_STATUS_OK : SYNC_STATUS_FILE_BUSY, |
245 syncable ? SYNC_STATUS_OK : | 239 url, sync_mode, callback)); |
246 SYNC_STATUS_FILE_BUSY, | |
247 url, sync_mode, callback)); | |
248 } | 240 } |
249 | 241 |
250 void LocalFileSyncContext::RegisterURLForWaitingSync( | 242 void LocalFileSyncContext::RegisterURLForWaitingSync( |
251 const FileSystemURL& url, | 243 const FileSystemURL& url, |
252 const base::Closure& on_syncable_callback) { | 244 const base::Closure& on_syncable_callback) { |
253 // This is initially called on UI thread and to be relayed to IO thread. | 245 // This is initially called on UI thread and to be relayed to IO thread. |
254 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 246 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
255 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 247 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
256 io_task_runner_->PostTask( | 248 io_task_runner_->PostTask( |
257 FROM_HERE, | 249 FROM_HERE, |
(...skipping 15 matching lines...) Expand all Loading... |
273 | 265 |
274 void LocalFileSyncContext::ApplyRemoteChange( | 266 void LocalFileSyncContext::ApplyRemoteChange( |
275 FileSystemContext* file_system_context, | 267 FileSystemContext* file_system_context, |
276 const FileChange& change, | 268 const FileChange& change, |
277 const base::FilePath& local_path, | 269 const base::FilePath& local_path, |
278 const FileSystemURL& url, | 270 const FileSystemURL& url, |
279 const SyncStatusCallback& callback) { | 271 const SyncStatusCallback& callback) { |
280 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 272 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
281 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 273 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
282 io_task_runner_->PostTask( | 274 io_task_runner_->PostTask( |
283 FROM_HERE, | 275 FROM_HERE, base::Bind(&LocalFileSyncContext::ApplyRemoteChange, this, |
284 base::Bind(&LocalFileSyncContext::ApplyRemoteChange, this, | 276 base::RetainedRef(file_system_context), change, |
285 make_scoped_refptr(file_system_context), | 277 local_path, url, callback)); |
286 change, local_path, url, callback)); | |
287 return; | 278 return; |
288 } | 279 } |
289 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 280 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
290 DCHECK(!sync_status()->IsWritable(url)); | 281 DCHECK(!sync_status()->IsWritable(url)); |
291 DCHECK(!sync_status()->IsWriting(url)); | 282 DCHECK(!sync_status()->IsWriting(url)); |
292 | 283 |
293 FileSystemOperation::StatusCallback operation_callback; | 284 FileSystemOperation::StatusCallback operation_callback; |
294 switch (change.change()) { | 285 switch (change.change()) { |
295 case FileChange::FILE_CHANGE_DELETE: | 286 case FileChange::FILE_CHANGE_DELETE: |
296 HandleRemoteDelete(file_system_context, url, callback); | 287 HandleRemoteDelete(file_system_context, url, callback); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 330 |
340 if (storage::VirtualPath::IsRootPath(url.path())) { | 331 if (storage::VirtualPath::IsRootPath(url.path())) { |
341 DidApplyRemoteChange(url, callback, base::File::FILE_OK); | 332 DidApplyRemoteChange(url, callback, base::File::FILE_OK); |
342 return; | 333 return; |
343 } | 334 } |
344 | 335 |
345 file_system_context->operation_runner()->Remove( | 336 file_system_context->operation_runner()->Remove( |
346 url_for_sync, true /* recursive */, | 337 url_for_sync, true /* recursive */, |
347 base::Bind( | 338 base::Bind( |
348 &LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate, | 339 &LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate, |
349 this, | 340 this, base::RetainedRef(file_system_context), change, local_path, url, |
350 make_scoped_refptr(file_system_context), | |
351 change, | |
352 local_path, | |
353 url, | |
354 callback)); | 341 callback)); |
355 } | 342 } |
356 | 343 |
357 void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate( | 344 void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate( |
358 FileSystemContext* file_system_context, | 345 FileSystemContext* file_system_context, |
359 const FileChange& change, | 346 const FileChange& change, |
360 const base::FilePath& local_path, | 347 const base::FilePath& local_path, |
361 const FileSystemURL& url, | 348 const FileSystemURL& url, |
362 const SyncStatusCallback& callback, | 349 const SyncStatusCallback& callback, |
363 base::File::Error error) { | 350 base::File::Error error) { |
(...skipping 23 matching lines...) Expand all Loading... |
387 storage::VirtualPath::DirName(dir_path) == dir_path) { | 374 storage::VirtualPath::DirName(dir_path) == dir_path) { |
388 // Copying into the root directory. | 375 // Copying into the root directory. |
389 file_system_context->operation_runner()->CopyInForeignFile( | 376 file_system_context->operation_runner()->CopyInForeignFile( |
390 local_path, url_for_sync, operation_callback); | 377 local_path, url_for_sync, operation_callback); |
391 } else { | 378 } else { |
392 FileSystemURL dir_url = file_system_context->CreateCrackedFileSystemURL( | 379 FileSystemURL dir_url = file_system_context->CreateCrackedFileSystemURL( |
393 url_for_sync.origin(), | 380 url_for_sync.origin(), |
394 url_for_sync.mount_type(), | 381 url_for_sync.mount_type(), |
395 storage::VirtualPath::DirName(url_for_sync.virtual_path())); | 382 storage::VirtualPath::DirName(url_for_sync.virtual_path())); |
396 file_system_context->operation_runner()->CreateDirectory( | 383 file_system_context->operation_runner()->CreateDirectory( |
397 dir_url, | 384 dir_url, false /* exclusive */, true /* recursive */, |
398 false /* exclusive */, | 385 base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn, this, |
399 true /* recursive */, | 386 base::RetainedRef(file_system_context), local_path, url, |
400 base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn, | |
401 this, | |
402 make_scoped_refptr(file_system_context), | |
403 local_path, | |
404 url, | |
405 operation_callback)); | 387 operation_callback)); |
406 } | 388 } |
407 break; | 389 break; |
408 } | 390 } |
409 case SYNC_FILE_TYPE_DIRECTORY: | 391 case SYNC_FILE_TYPE_DIRECTORY: |
410 file_system_context->operation_runner()->CreateDirectory( | 392 file_system_context->operation_runner()->CreateDirectory( |
411 url_for_sync, false /* exclusive */, true /* recursive */, | 393 url_for_sync, false /* exclusive */, true /* recursive */, |
412 operation_callback); | 394 operation_callback); |
413 break; | 395 break; |
414 case SYNC_FILE_TYPE_UNKNOWN: | 396 case SYNC_FILE_TYPE_UNKNOWN: |
415 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; | 397 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; |
416 } | 398 } |
417 } | 399 } |
418 | 400 |
419 void LocalFileSyncContext::RecordFakeLocalChange( | 401 void LocalFileSyncContext::RecordFakeLocalChange( |
420 FileSystemContext* file_system_context, | 402 FileSystemContext* file_system_context, |
421 const FileSystemURL& url, | 403 const FileSystemURL& url, |
422 const FileChange& change, | 404 const FileChange& change, |
423 const SyncStatusCallback& callback) { | 405 const SyncStatusCallback& callback) { |
424 // This is called on UI thread and to be relayed to FILE thread. | 406 // This is called on UI thread and to be relayed to FILE thread. |
425 DCHECK(file_system_context); | 407 DCHECK(file_system_context); |
426 if (!file_system_context->default_file_task_runner()-> | 408 if (!file_system_context->default_file_task_runner()-> |
427 RunsTasksOnCurrentThread()) { | 409 RunsTasksOnCurrentThread()) { |
428 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 410 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
429 file_system_context->default_file_task_runner()->PostTask( | 411 file_system_context->default_file_task_runner()->PostTask( |
430 FROM_HERE, | 412 FROM_HERE, base::Bind(&LocalFileSyncContext::RecordFakeLocalChange, |
431 base::Bind(&LocalFileSyncContext::RecordFakeLocalChange, | 413 this, base::RetainedRef(file_system_context), url, |
432 this, make_scoped_refptr(file_system_context), | 414 change, callback)); |
433 url, change, callback)); | |
434 return; | 415 return; |
435 } | 416 } |
436 | 417 |
437 SyncFileSystemBackend* backend = | 418 SyncFileSystemBackend* backend = |
438 SyncFileSystemBackend::GetBackend(file_system_context); | 419 SyncFileSystemBackend::GetBackend(file_system_context); |
439 DCHECK(backend); | 420 DCHECK(backend); |
440 DCHECK(backend->change_tracker()); | 421 DCHECK(backend->change_tracker()); |
441 backend->change_tracker()->MarkDirtyOnDatabase(url); | 422 backend->change_tracker()->MarkDirtyOnDatabase(url); |
442 backend->change_tracker()->RecordChange(url, change); | 423 backend->change_tracker()->RecordChange(url, change); |
443 | 424 |
444 // Fire the callback on UI thread. | 425 // Fire the callback on UI thread. |
445 ui_task_runner_->PostTask(FROM_HERE, | 426 ui_task_runner_->PostTask(FROM_HERE, |
446 base::Bind(callback, | 427 base::Bind(callback, |
447 SYNC_STATUS_OK)); | 428 SYNC_STATUS_OK)); |
448 } | 429 } |
449 | 430 |
450 void LocalFileSyncContext::GetFileMetadata( | 431 void LocalFileSyncContext::GetFileMetadata( |
451 FileSystemContext* file_system_context, | 432 FileSystemContext* file_system_context, |
452 const FileSystemURL& url, | 433 const FileSystemURL& url, |
453 const SyncFileMetadataCallback& callback) { | 434 const SyncFileMetadataCallback& callback) { |
454 // This is initially called on UI thread and to be relayed to IO thread. | 435 // This is initially called on UI thread and to be relayed to IO thread. |
455 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 436 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
456 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 437 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
457 io_task_runner_->PostTask( | 438 io_task_runner_->PostTask( |
458 FROM_HERE, | 439 FROM_HERE, |
459 base::Bind(&LocalFileSyncContext::GetFileMetadata, this, | 440 base::Bind(&LocalFileSyncContext::GetFileMetadata, this, |
460 make_scoped_refptr(file_system_context), url, callback)); | 441 base::RetainedRef(file_system_context), url, callback)); |
461 return; | 442 return; |
462 } | 443 } |
463 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 444 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
464 | 445 |
465 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 446 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
466 file_system_context, url); | 447 file_system_context, url); |
467 file_system_context->operation_runner()->GetMetadata( | 448 file_system_context->operation_runner()->GetMetadata( |
468 url_for_sync, FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | | 449 url_for_sync, FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | |
469 FileSystemOperation::GET_METADATA_FIELD_SIZE | | 450 FileSystemOperation::GET_METADATA_FIELD_SIZE | |
470 FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, | 451 FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, |
471 base::Bind(&LocalFileSyncContext::DidGetFileMetadata, this, callback)); | 452 base::Bind(&LocalFileSyncContext::DidGetFileMetadata, this, callback)); |
472 } | 453 } |
473 | 454 |
474 void LocalFileSyncContext::HasPendingLocalChanges( | 455 void LocalFileSyncContext::HasPendingLocalChanges( |
475 FileSystemContext* file_system_context, | 456 FileSystemContext* file_system_context, |
476 const FileSystemURL& url, | 457 const FileSystemURL& url, |
477 const HasPendingLocalChangeCallback& callback) { | 458 const HasPendingLocalChangeCallback& callback) { |
478 // This gets called on UI thread and relays the task on FILE thread. | 459 // This gets called on UI thread and relays the task on FILE thread. |
479 DCHECK(file_system_context); | 460 DCHECK(file_system_context); |
480 if (!file_system_context->default_file_task_runner()-> | 461 if (!file_system_context->default_file_task_runner()-> |
481 RunsTasksOnCurrentThread()) { | 462 RunsTasksOnCurrentThread()) { |
482 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 463 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
483 file_system_context->default_file_task_runner()->PostTask( | 464 file_system_context->default_file_task_runner()->PostTask( |
484 FROM_HERE, | 465 FROM_HERE, |
485 base::Bind(&LocalFileSyncContext::HasPendingLocalChanges, | 466 base::Bind(&LocalFileSyncContext::HasPendingLocalChanges, this, |
486 this, make_scoped_refptr(file_system_context), | 467 base::RetainedRef(file_system_context), url, callback)); |
487 url, callback)); | |
488 return; | 468 return; |
489 } | 469 } |
490 | 470 |
491 SyncFileSystemBackend* backend = | 471 SyncFileSystemBackend* backend = |
492 SyncFileSystemBackend::GetBackend(file_system_context); | 472 SyncFileSystemBackend::GetBackend(file_system_context); |
493 DCHECK(backend); | 473 DCHECK(backend); |
494 DCHECK(backend->change_tracker()); | 474 DCHECK(backend->change_tracker()); |
495 FileChangeList changes; | 475 FileChangeList changes; |
496 backend->change_tracker()->GetChangesForURL(url, &changes); | 476 backend->change_tracker()->GetChangesForURL(url, &changes); |
497 | 477 |
498 // Fire the callback on UI thread. | 478 // Fire the callback on UI thread. |
499 ui_task_runner_->PostTask(FROM_HERE, | 479 ui_task_runner_->PostTask(FROM_HERE, |
500 base::Bind(callback, | 480 base::Bind(callback, |
501 SYNC_STATUS_OK, | 481 SYNC_STATUS_OK, |
502 !changes.empty())); | 482 !changes.empty())); |
503 } | 483 } |
504 | 484 |
505 void LocalFileSyncContext::PromoteDemotedChanges( | 485 void LocalFileSyncContext::PromoteDemotedChanges( |
506 const GURL& origin, | 486 const GURL& origin, |
507 storage::FileSystemContext* file_system_context, | 487 storage::FileSystemContext* file_system_context, |
508 const base::Closure& callback) { | 488 const base::Closure& callback) { |
509 // This is initially called on UI thread and to be relayed to FILE thread. | 489 // This is initially called on UI thread and to be relayed to FILE thread. |
510 DCHECK(file_system_context); | 490 DCHECK(file_system_context); |
511 if (!file_system_context->default_file_task_runner()-> | 491 if (!file_system_context->default_file_task_runner()-> |
512 RunsTasksOnCurrentThread()) { | 492 RunsTasksOnCurrentThread()) { |
513 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 493 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
514 file_system_context->default_file_task_runner()->PostTask( | 494 file_system_context->default_file_task_runner()->PostTask( |
515 FROM_HERE, | 495 FROM_HERE, |
516 base::Bind(&LocalFileSyncContext::PromoteDemotedChanges, | 496 base::Bind(&LocalFileSyncContext::PromoteDemotedChanges, this, origin, |
517 this, origin, make_scoped_refptr(file_system_context), | 497 base::RetainedRef(file_system_context), callback)); |
518 callback)); | |
519 return; | 498 return; |
520 } | 499 } |
521 | 500 |
522 SyncFileSystemBackend* backend = | 501 SyncFileSystemBackend* backend = |
523 SyncFileSystemBackend::GetBackend(file_system_context); | 502 SyncFileSystemBackend::GetBackend(file_system_context); |
524 DCHECK(backend); | 503 DCHECK(backend); |
525 DCHECK(backend->change_tracker()); | 504 DCHECK(backend->change_tracker()); |
526 if (!backend->change_tracker()->PromoteDemotedChanges()) { | 505 if (!backend->change_tracker()->PromoteDemotedChanges()) { |
527 ui_task_runner_->PostTask(FROM_HERE, callback); | 506 ui_task_runner_->PostTask(FROM_HERE, callback); |
528 return; | 507 return; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 SyncFileSystemBackend* backend = | 637 SyncFileSystemBackend* backend = |
659 SyncFileSystemBackend::GetBackend(file_system_context); | 638 SyncFileSystemBackend::GetBackend(file_system_context); |
660 DCHECK(backend); | 639 DCHECK(backend); |
661 if (!backend->change_tracker()) { | 640 if (!backend->change_tracker()) { |
662 // Create and initialize LocalFileChangeTracker and call back this method | 641 // Create and initialize LocalFileChangeTracker and call back this method |
663 // later again. | 642 // later again. |
664 std::set<GURL>* origins_with_changes = new std::set<GURL>; | 643 std::set<GURL>* origins_with_changes = new std::set<GURL>; |
665 scoped_ptr<LocalFileChangeTracker>* tracker_ptr( | 644 scoped_ptr<LocalFileChangeTracker>* tracker_ptr( |
666 new scoped_ptr<LocalFileChangeTracker>); | 645 new scoped_ptr<LocalFileChangeTracker>); |
667 base::PostTaskAndReplyWithResult( | 646 base::PostTaskAndReplyWithResult( |
668 file_system_context->default_file_task_runner(), | 647 file_system_context->default_file_task_runner(), FROM_HERE, |
669 FROM_HERE, | |
670 base::Bind(&LocalFileSyncContext::InitializeChangeTrackerOnFileThread, | 648 base::Bind(&LocalFileSyncContext::InitializeChangeTrackerOnFileThread, |
671 this, tracker_ptr, | 649 this, tracker_ptr, base::RetainedRef(file_system_context), |
672 make_scoped_refptr(file_system_context), | |
673 origins_with_changes), | 650 origins_with_changes), |
674 base::Bind(&LocalFileSyncContext::DidInitializeChangeTrackerOnIOThread, | 651 base::Bind(&LocalFileSyncContext::DidInitializeChangeTrackerOnIOThread, |
675 this, base::Owned(tracker_ptr), | 652 this, base::Owned(tracker_ptr), source_url, |
676 source_url, | 653 base::RetainedRef(file_system_context), |
677 make_scoped_refptr(file_system_context), | |
678 base::Owned(origins_with_changes))); | 654 base::Owned(origins_with_changes))); |
679 return; | 655 return; |
680 } | 656 } |
681 if (!operation_runner_) { | 657 if (!operation_runner_) { |
682 DCHECK(!sync_status_); | 658 DCHECK(!sync_status_); |
683 DCHECK(!timer_on_io_); | 659 DCHECK(!timer_on_io_); |
684 sync_status_.reset(new LocalFileSyncStatus); | 660 sync_status_.reset(new LocalFileSyncStatus); |
685 timer_on_io_.reset(new base::OneShotTimer); | 661 timer_on_io_.reset(new base::OneShotTimer); |
686 operation_runner_.reset(new SyncableFileOperationRunner( | 662 operation_runner_.reset(new SyncableFileOperationRunner( |
687 kMaxConcurrentSyncableOperation, | 663 kMaxConcurrentSyncableOperation, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 base::File::FILE_OK); | 728 base::File::FILE_OK); |
753 } | 729 } |
754 | 730 |
755 void LocalFileSyncContext::DidInitialize( | 731 void LocalFileSyncContext::DidInitialize( |
756 const GURL& source_url, | 732 const GURL& source_url, |
757 FileSystemContext* file_system_context, | 733 FileSystemContext* file_system_context, |
758 SyncStatusCode status) { | 734 SyncStatusCode status) { |
759 if (!ui_task_runner_->RunsTasksOnCurrentThread()) { | 735 if (!ui_task_runner_->RunsTasksOnCurrentThread()) { |
760 ui_task_runner_->PostTask( | 736 ui_task_runner_->PostTask( |
761 FROM_HERE, | 737 FROM_HERE, |
762 base::Bind(&LocalFileSyncContext::DidInitialize, | 738 base::Bind(&LocalFileSyncContext::DidInitialize, this, source_url, |
763 this, source_url, | 739 base::RetainedRef(file_system_context), status)); |
764 make_scoped_refptr(file_system_context), status)); | |
765 return; | 740 return; |
766 } | 741 } |
767 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 742 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
768 DCHECK(!ContainsKey(file_system_contexts_, file_system_context)); | 743 DCHECK(!ContainsKey(file_system_contexts_, file_system_context)); |
769 DCHECK(ContainsKey(pending_initialize_callbacks_, file_system_context)); | 744 DCHECK(ContainsKey(pending_initialize_callbacks_, file_system_context)); |
770 | 745 |
771 SyncFileSystemBackend* backend = | 746 SyncFileSystemBackend* backend = |
772 SyncFileSystemBackend::GetBackend(file_system_context); | 747 SyncFileSystemBackend::GetBackend(file_system_context); |
773 DCHECK(backend); | 748 DCHECK(backend); |
774 DCHECK(backend->change_tracker()); | 749 DCHECK(backend->change_tracker()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 if (urls->empty()) { | 794 if (urls->empty()) { |
820 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, | 795 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, |
821 LocalFileSyncInfo(), | 796 LocalFileSyncInfo(), |
822 storage::ScopedFile()); | 797 storage::ScopedFile()); |
823 return; | 798 return; |
824 } | 799 } |
825 | 800 |
826 const FileSystemURL url = urls->front(); | 801 const FileSystemURL url = urls->front(); |
827 urls->pop_front(); | 802 urls->pop_front(); |
828 | 803 |
829 PrepareForSync( | 804 PrepareForSync(file_system_context, url, SYNC_SNAPSHOT, |
830 file_system_context, url, SYNC_SNAPSHOT, | 805 base::Bind(&LocalFileSyncContext::DidTryPrepareForLocalSync, |
831 base::Bind(&LocalFileSyncContext::DidTryPrepareForLocalSync, | 806 this, base::RetainedRef(file_system_context), |
832 this, make_scoped_refptr(file_system_context), | 807 base::Passed(&urls), callback)); |
833 base::Passed(&urls), callback)); | |
834 } | 808 } |
835 | 809 |
836 void LocalFileSyncContext::DidTryPrepareForLocalSync( | 810 void LocalFileSyncContext::DidTryPrepareForLocalSync( |
837 FileSystemContext* file_system_context, | 811 FileSystemContext* file_system_context, |
838 scoped_ptr<FileSystemURLQueue> remaining_urls, | 812 scoped_ptr<FileSystemURLQueue> remaining_urls, |
839 const LocalFileSyncInfoCallback& callback, | 813 const LocalFileSyncInfoCallback& callback, |
840 SyncStatusCode status, | 814 SyncStatusCode status, |
841 const LocalFileSyncInfo& sync_file_info, | 815 const LocalFileSyncInfo& sync_file_info, |
842 storage::ScopedFile snapshot) { | 816 storage::ScopedFile snapshot) { |
843 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 817 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 15 matching lines...) Expand all Loading... |
859 FileSystemContext* file_system_context, | 833 FileSystemContext* file_system_context, |
860 const FileSystemURL& url) { | 834 const FileSystemURL& url) { |
861 DCHECK(file_system_context); | 835 DCHECK(file_system_context); |
862 if (!file_system_context->default_file_task_runner()-> | 836 if (!file_system_context->default_file_task_runner()-> |
863 RunsTasksOnCurrentThread()) { | 837 RunsTasksOnCurrentThread()) { |
864 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 838 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
865 if (shutdown_on_ui_) | 839 if (shutdown_on_ui_) |
866 return; | 840 return; |
867 file_system_context->default_file_task_runner()->PostTask( | 841 file_system_context->default_file_task_runner()->PostTask( |
868 FROM_HERE, | 842 FROM_HERE, |
869 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURL, | 843 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURL, this, |
870 this, make_scoped_refptr(file_system_context), url)); | 844 base::RetainedRef(file_system_context), url)); |
871 return; | 845 return; |
872 } | 846 } |
873 | 847 |
874 SyncFileSystemBackend* backend = | 848 SyncFileSystemBackend* backend = |
875 SyncFileSystemBackend::GetBackend(file_system_context); | 849 SyncFileSystemBackend::GetBackend(file_system_context); |
876 DCHECK(backend); | 850 DCHECK(backend); |
877 DCHECK(backend->change_tracker()); | 851 DCHECK(backend->change_tracker()); |
878 backend->change_tracker()->PromoteDemotedChangesForURL(url); | 852 backend->change_tracker()->PromoteDemotedChangesForURL(url); |
879 } | 853 } |
880 | 854 |
881 void LocalFileSyncContext::PromoteDemotedChangesForURLs( | 855 void LocalFileSyncContext::PromoteDemotedChangesForURLs( |
882 FileSystemContext* file_system_context, | 856 FileSystemContext* file_system_context, |
883 scoped_ptr<FileSystemURLQueue> urls) { | 857 scoped_ptr<FileSystemURLQueue> urls) { |
884 DCHECK(file_system_context); | 858 DCHECK(file_system_context); |
885 if (!file_system_context->default_file_task_runner()-> | 859 if (!file_system_context->default_file_task_runner()-> |
886 RunsTasksOnCurrentThread()) { | 860 RunsTasksOnCurrentThread()) { |
887 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 861 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
888 if (shutdown_on_ui_) | 862 if (shutdown_on_ui_) |
889 return; | 863 return; |
890 file_system_context->default_file_task_runner()->PostTask( | 864 file_system_context->default_file_task_runner()->PostTask( |
891 FROM_HERE, | 865 FROM_HERE, |
892 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURLs, | 866 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURLs, this, |
893 this, make_scoped_refptr(file_system_context), | 867 base::RetainedRef(file_system_context), |
894 base::Passed(&urls))); | 868 base::Passed(&urls))); |
895 return; | 869 return; |
896 } | 870 } |
897 | 871 |
898 for (FileSystemURLQueue::iterator iter = urls->begin(); | 872 for (FileSystemURLQueue::iterator iter = urls->begin(); |
899 iter != urls->end(); ++iter) | 873 iter != urls->end(); ++iter) |
900 PromoteDemotedChangesForURL(file_system_context, *iter); | 874 PromoteDemotedChangesForURL(file_system_context, *iter); |
901 } | 875 } |
902 | 876 |
903 void LocalFileSyncContext::DidGetWritingStatusForSync( | 877 void LocalFileSyncContext::DidGetWritingStatusForSync( |
904 FileSystemContext* file_system_context, | 878 FileSystemContext* file_system_context, |
905 SyncStatusCode status, | 879 SyncStatusCode status, |
906 const FileSystemURL& url, | 880 const FileSystemURL& url, |
907 SyncMode sync_mode, | 881 SyncMode sync_mode, |
908 const LocalFileSyncInfoCallback& callback) { | 882 const LocalFileSyncInfoCallback& callback) { |
909 // This gets called on UI thread and relays the task on FILE thread. | 883 // This gets called on UI thread and relays the task on FILE thread. |
910 DCHECK(file_system_context); | 884 DCHECK(file_system_context); |
911 if (!file_system_context->default_file_task_runner()-> | 885 if (!file_system_context->default_file_task_runner()-> |
912 RunsTasksOnCurrentThread()) { | 886 RunsTasksOnCurrentThread()) { |
913 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 887 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
914 if (shutdown_on_ui_) { | 888 if (shutdown_on_ui_) { |
915 callback.Run( | 889 callback.Run( |
916 SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); | 890 SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); |
917 return; | 891 return; |
918 } | 892 } |
919 file_system_context->default_file_task_runner()->PostTask( | 893 file_system_context->default_file_task_runner()->PostTask( |
920 FROM_HERE, | 894 FROM_HERE, base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, |
921 base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, | 895 this, base::RetainedRef(file_system_context), |
922 this, make_scoped_refptr(file_system_context), | 896 status, url, sync_mode, callback)); |
923 status, url, sync_mode, callback)); | |
924 return; | 897 return; |
925 } | 898 } |
926 | 899 |
927 SyncFileSystemBackend* backend = | 900 SyncFileSystemBackend* backend = |
928 SyncFileSystemBackend::GetBackend(file_system_context); | 901 SyncFileSystemBackend::GetBackend(file_system_context); |
929 DCHECK(backend); | 902 DCHECK(backend); |
930 DCHECK(backend->change_tracker()); | 903 DCHECK(backend->change_tracker()); |
931 FileChangeList changes; | 904 FileChangeList changes; |
932 backend->change_tracker()->GetChangesForURL(url, &changes); | 905 backend->change_tracker()->GetChangesForURL(url, &changes); |
933 | 906 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 return; | 1049 return; |
1077 } | 1050 } |
1078 | 1051 |
1079 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 1052 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
1080 file_system_context, dest_url); | 1053 file_system_context, dest_url); |
1081 file_system_context->operation_runner()->CopyInForeignFile( | 1054 file_system_context->operation_runner()->CopyInForeignFile( |
1082 local_path, url_for_sync, callback); | 1055 local_path, url_for_sync, callback); |
1083 } | 1056 } |
1084 | 1057 |
1085 } // namespace sync_file_system | 1058 } // namespace sync_file_system |
OLD | NEW |