| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 base::SingleThreadTaskRunner* ui_task_runner, | 53 base::SingleThreadTaskRunner* ui_task_runner, |
| 54 base::SingleThreadTaskRunner* io_task_runner) | 54 base::SingleThreadTaskRunner* io_task_runner) |
| 55 : local_base_path_(base_path.Append(FILE_PATH_LITERAL("local"))), | 55 : local_base_path_(base_path.Append(FILE_PATH_LITERAL("local"))), |
| 56 env_override_(env_override), | 56 env_override_(env_override), |
| 57 ui_task_runner_(ui_task_runner), | 57 ui_task_runner_(ui_task_runner), |
| 58 io_task_runner_(io_task_runner), | 58 io_task_runner_(io_task_runner), |
| 59 shutdown_on_ui_(false), | 59 shutdown_on_ui_(false), |
| 60 shutdown_on_io_(false), | 60 shutdown_on_io_(false), |
| 61 mock_notify_changes_duration_in_sec_(-1) { | 61 mock_notify_changes_duration_in_sec_(-1) { |
| 62 DCHECK(base_path.IsAbsolute()); | 62 DCHECK(base_path.IsAbsolute()); |
| 63 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 63 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void LocalFileSyncContext::MaybeInitializeFileSystemContext( | 66 void LocalFileSyncContext::MaybeInitializeFileSystemContext( |
| 67 const GURL& source_url, | 67 const GURL& source_url, |
| 68 FileSystemContext* file_system_context, | 68 FileSystemContext* file_system_context, |
| 69 const SyncStatusCallback& callback) { | 69 const SyncStatusCallback& callback) { |
| 70 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 70 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 71 if (base::ContainsKey(file_system_contexts_, file_system_context)) { | 71 if (base::ContainsKey(file_system_contexts_, file_system_context)) { |
| 72 // The context has been already initialized. Just dispatch the callback | 72 // The context has been already initialized. Just dispatch the callback |
| 73 // with SYNC_STATUS_OK. | 73 // with SYNC_STATUS_OK. |
| 74 ui_task_runner_->PostTask(FROM_HERE, | 74 ui_task_runner_->PostTask(FROM_HERE, |
| 75 base::BindOnce(callback, SYNC_STATUS_OK)); | 75 base::BindOnce(callback, SYNC_STATUS_OK)); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 StatusCallbackQueue& callback_queue = | 79 StatusCallbackQueue& callback_queue = |
| 80 pending_initialize_callbacks_[file_system_context]; | 80 pending_initialize_callbacks_[file_system_context]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 io_task_runner_->PostTask( | 92 io_task_runner_->PostTask( |
| 93 FROM_HERE, | 93 FROM_HERE, |
| 94 base::BindOnce(&storage::SandboxFileSystemBackendDelegate::OpenFileSystem, | 94 base::BindOnce(&storage::SandboxFileSystemBackendDelegate::OpenFileSystem, |
| 95 base::Unretained(file_system_context->sandbox_delegate()), | 95 base::Unretained(file_system_context->sandbox_delegate()), |
| 96 source_url, storage::kFileSystemTypeSyncable, | 96 source_url, storage::kFileSystemTypeSyncable, |
| 97 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 97 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 98 open_filesystem_callback, GURL())); | 98 open_filesystem_callback, GURL())); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void LocalFileSyncContext::ShutdownOnUIThread() { | 101 void LocalFileSyncContext::ShutdownOnUIThread() { |
| 102 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 102 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 103 shutdown_on_ui_ = true; | 103 shutdown_on_ui_ = true; |
| 104 io_task_runner_->PostTask( | 104 io_task_runner_->PostTask( |
| 105 FROM_HERE, | 105 FROM_HERE, |
| 106 base::BindOnce(&LocalFileSyncContext::ShutdownOnIOThread, this)); | 106 base::BindOnce(&LocalFileSyncContext::ShutdownOnIOThread, this)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void LocalFileSyncContext::GetFileForLocalSync( | 109 void LocalFileSyncContext::GetFileForLocalSync( |
| 110 FileSystemContext* file_system_context, | 110 FileSystemContext* file_system_context, |
| 111 const LocalFileSyncInfoCallback& callback) { | 111 const LocalFileSyncInfoCallback& callback) { |
| 112 DCHECK(file_system_context); | 112 DCHECK(file_system_context); |
| 113 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 113 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 114 | 114 |
| 115 base::PostTaskAndReplyWithResult( | 115 base::PostTaskAndReplyWithResult( |
| 116 file_system_context->default_file_task_runner(), FROM_HERE, | 116 file_system_context->default_file_task_runner(), FROM_HERE, |
| 117 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, this, | 117 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, this, |
| 118 base::RetainedRef(file_system_context)), | 118 base::RetainedRef(file_system_context)), |
| 119 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, this, | 119 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, this, |
| 120 base::RetainedRef(file_system_context), callback)); | 120 base::RetainedRef(file_system_context), callback)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void LocalFileSyncContext::ClearChangesForURL( | 123 void LocalFileSyncContext::ClearChangesForURL( |
| 124 FileSystemContext* file_system_context, | 124 FileSystemContext* file_system_context, |
| 125 const FileSystemURL& url, | 125 const FileSystemURL& url, |
| 126 const base::Closure& done_callback) { | 126 const base::Closure& done_callback) { |
| 127 // 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. |
| 128 DCHECK(file_system_context); | 128 DCHECK(file_system_context); |
| 129 if (!file_system_context->default_file_task_runner()-> | 129 if (!file_system_context->default_file_task_runner()-> |
| 130 RunsTasksOnCurrentThread()) { | 130 RunsTasksInCurrentSequence()) { |
| 131 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 131 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 132 file_system_context->default_file_task_runner()->PostTask( | 132 file_system_context->default_file_task_runner()->PostTask( |
| 133 FROM_HERE, base::BindOnce(&LocalFileSyncContext::ClearChangesForURL, | 133 FROM_HERE, base::BindOnce(&LocalFileSyncContext::ClearChangesForURL, |
| 134 this, base::RetainedRef(file_system_context), | 134 this, base::RetainedRef(file_system_context), |
| 135 url, done_callback)); | 135 url, done_callback)); |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 SyncFileSystemBackend* backend = | 139 SyncFileSystemBackend* backend = |
| 140 SyncFileSystemBackend::GetBackend(file_system_context); | 140 SyncFileSystemBackend::GetBackend(file_system_context); |
| 141 DCHECK(backend); | 141 DCHECK(backend); |
| 142 DCHECK(backend->change_tracker()); | 142 DCHECK(backend->change_tracker()); |
| 143 backend->change_tracker()->ClearChangesForURL(url); | 143 backend->change_tracker()->ClearChangesForURL(url); |
| 144 | 144 |
| 145 // Call the completion callback on UI thread. | 145 // Call the completion callback on UI thread. |
| 146 ui_task_runner_->PostTask(FROM_HERE, done_callback); | 146 ui_task_runner_->PostTask(FROM_HERE, done_callback); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void LocalFileSyncContext::FinalizeSnapshotSync( | 149 void LocalFileSyncContext::FinalizeSnapshotSync( |
| 150 storage::FileSystemContext* file_system_context, | 150 storage::FileSystemContext* file_system_context, |
| 151 const storage::FileSystemURL& url, | 151 const storage::FileSystemURL& url, |
| 152 SyncStatusCode sync_finish_status, | 152 SyncStatusCode sync_finish_status, |
| 153 const base::Closure& done_callback) { | 153 const base::Closure& done_callback) { |
| 154 DCHECK(file_system_context); | 154 DCHECK(file_system_context); |
| 155 DCHECK(url.is_valid()); | 155 DCHECK(url.is_valid()); |
| 156 if (!file_system_context->default_file_task_runner()-> | 156 if (!file_system_context->default_file_task_runner()-> |
| 157 RunsTasksOnCurrentThread()) { | 157 RunsTasksInCurrentSequence()) { |
| 158 file_system_context->default_file_task_runner()->PostTask( | 158 file_system_context->default_file_task_runner()->PostTask( |
| 159 FROM_HERE, base::BindOnce(&LocalFileSyncContext::FinalizeSnapshotSync, | 159 FROM_HERE, base::BindOnce(&LocalFileSyncContext::FinalizeSnapshotSync, |
| 160 this, base::RetainedRef(file_system_context), | 160 this, base::RetainedRef(file_system_context), |
| 161 url, sync_finish_status, done_callback)); | 161 url, sync_finish_status, done_callback)); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 | 164 |
| 165 SyncFileSystemBackend* backend = | 165 SyncFileSystemBackend* backend = |
| 166 SyncFileSystemBackend::GetBackend(file_system_context); | 166 SyncFileSystemBackend::GetBackend(file_system_context); |
| 167 DCHECK(backend); | 167 DCHECK(backend); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 done_callback.Run(); | 213 done_callback.Run(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void LocalFileSyncContext::PrepareForSync( | 216 void LocalFileSyncContext::PrepareForSync( |
| 217 FileSystemContext* file_system_context, | 217 FileSystemContext* file_system_context, |
| 218 const FileSystemURL& url, | 218 const FileSystemURL& url, |
| 219 SyncMode sync_mode, | 219 SyncMode sync_mode, |
| 220 const LocalFileSyncInfoCallback& callback) { | 220 const LocalFileSyncInfoCallback& callback) { |
| 221 // 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. |
| 222 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 222 if (!io_task_runner_->RunsTasksInCurrentSequence()) { |
| 223 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 223 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 224 io_task_runner_->PostTask( | 224 io_task_runner_->PostTask( |
| 225 FROM_HERE, base::BindOnce(&LocalFileSyncContext::PrepareForSync, this, | 225 FROM_HERE, base::BindOnce(&LocalFileSyncContext::PrepareForSync, this, |
| 226 base::RetainedRef(file_system_context), url, | 226 base::RetainedRef(file_system_context), url, |
| 227 sync_mode, callback)); | 227 sync_mode, callback)); |
| 228 return; | 228 return; |
| 229 } | 229 } |
| 230 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 230 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 231 const bool syncable = sync_status()->IsSyncable(url); | 231 const bool syncable = sync_status()->IsSyncable(url); |
| 232 // Disable writing if it's ready to be synced. | 232 // Disable writing if it's ready to be synced. |
| 233 if (syncable) | 233 if (syncable) |
| 234 sync_status()->StartSyncing(url); | 234 sync_status()->StartSyncing(url); |
| 235 ui_task_runner_->PostTask( | 235 ui_task_runner_->PostTask( |
| 236 FROM_HERE, | 236 FROM_HERE, |
| 237 base::BindOnce(&LocalFileSyncContext::DidGetWritingStatusForSync, this, | 237 base::BindOnce(&LocalFileSyncContext::DidGetWritingStatusForSync, this, |
| 238 base::RetainedRef(file_system_context), | 238 base::RetainedRef(file_system_context), |
| 239 syncable ? SYNC_STATUS_OK : SYNC_STATUS_FILE_BUSY, url, | 239 syncable ? SYNC_STATUS_OK : SYNC_STATUS_FILE_BUSY, url, |
| 240 sync_mode, callback)); | 240 sync_mode, callback)); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void LocalFileSyncContext::RegisterURLForWaitingSync( | 243 void LocalFileSyncContext::RegisterURLForWaitingSync( |
| 244 const FileSystemURL& url, | 244 const FileSystemURL& url, |
| 245 const base::Closure& on_syncable_callback) { | 245 const base::Closure& on_syncable_callback) { |
| 246 // This is initially called on UI thread and to be relayed to IO thread. | 246 // This is initially called on UI thread and to be relayed to IO thread. |
| 247 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 247 if (!io_task_runner_->RunsTasksInCurrentSequence()) { |
| 248 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 248 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 249 io_task_runner_->PostTask( | 249 io_task_runner_->PostTask( |
| 250 FROM_HERE, | 250 FROM_HERE, |
| 251 base::BindOnce(&LocalFileSyncContext::RegisterURLForWaitingSync, this, | 251 base::BindOnce(&LocalFileSyncContext::RegisterURLForWaitingSync, this, |
| 252 url, on_syncable_callback)); | 252 url, on_syncable_callback)); |
| 253 return; | 253 return; |
| 254 } | 254 } |
| 255 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 255 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 256 if (shutdown_on_io_) | 256 if (shutdown_on_io_) |
| 257 return; | 257 return; |
| 258 if (sync_status()->IsSyncable(url)) { | 258 if (sync_status()->IsSyncable(url)) { |
| 259 // No need to register; fire the callback now. | 259 // No need to register; fire the callback now. |
| 260 ui_task_runner_->PostTask(FROM_HERE, on_syncable_callback); | 260 ui_task_runner_->PostTask(FROM_HERE, on_syncable_callback); |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 url_waiting_sync_on_io_ = url; | 263 url_waiting_sync_on_io_ = url; |
| 264 url_syncable_callback_ = on_syncable_callback; | 264 url_syncable_callback_ = on_syncable_callback; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void LocalFileSyncContext::ApplyRemoteChange( | 267 void LocalFileSyncContext::ApplyRemoteChange( |
| 268 FileSystemContext* file_system_context, | 268 FileSystemContext* file_system_context, |
| 269 const FileChange& change, | 269 const FileChange& change, |
| 270 const base::FilePath& local_path, | 270 const base::FilePath& local_path, |
| 271 const FileSystemURL& url, | 271 const FileSystemURL& url, |
| 272 const SyncStatusCallback& callback) { | 272 const SyncStatusCallback& callback) { |
| 273 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 273 if (!io_task_runner_->RunsTasksInCurrentSequence()) { |
| 274 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 274 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 275 io_task_runner_->PostTask( | 275 io_task_runner_->PostTask( |
| 276 FROM_HERE, base::BindOnce(&LocalFileSyncContext::ApplyRemoteChange, | 276 FROM_HERE, base::BindOnce(&LocalFileSyncContext::ApplyRemoteChange, |
| 277 this, base::RetainedRef(file_system_context), | 277 this, base::RetainedRef(file_system_context), |
| 278 change, local_path, url, callback)); | 278 change, local_path, url, callback)); |
| 279 return; | 279 return; |
| 280 } | 280 } |
| 281 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 281 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 282 DCHECK(!sync_status()->IsWritable(url)); | 282 DCHECK(!sync_status()->IsWritable(url)); |
| 283 DCHECK(!sync_status()->IsWriting(url)); | 283 DCHECK(!sync_status()->IsWriting(url)); |
| 284 | 284 |
| 285 FileSystemOperation::StatusCallback operation_callback; | 285 FileSystemOperation::StatusCallback operation_callback; |
| 286 switch (change.change()) { | 286 switch (change.change()) { |
| 287 case FileChange::FILE_CHANGE_DELETE: | 287 case FileChange::FILE_CHANGE_DELETE: |
| 288 HandleRemoteDelete(file_system_context, url, callback); | 288 HandleRemoteDelete(file_system_context, url, callback); |
| 289 return; | 289 return; |
| 290 case FileChange::FILE_CHANGE_ADD_OR_UPDATE: | 290 case FileChange::FILE_CHANGE_ADD_OR_UPDATE: |
| 291 HandleRemoteAddOrUpdate( | 291 HandleRemoteAddOrUpdate( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 const SyncStatusCallback& callback, | 350 const SyncStatusCallback& callback, |
| 351 base::File::Error error) { | 351 base::File::Error error) { |
| 352 // Remove() may fail if the target entry does not exist (which is ok), | 352 // Remove() may fail if the target entry does not exist (which is ok), |
| 353 // so we ignore |error| here. | 353 // so we ignore |error| here. |
| 354 | 354 |
| 355 if (shutdown_on_io_) { | 355 if (shutdown_on_io_) { |
| 356 callback.Run(SYNC_FILE_ERROR_ABORT); | 356 callback.Run(SYNC_FILE_ERROR_ABORT); |
| 357 return; | 357 return; |
| 358 } | 358 } |
| 359 | 359 |
| 360 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 360 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 361 DCHECK(!sync_status()->IsWritable(url)); | 361 DCHECK(!sync_status()->IsWritable(url)); |
| 362 DCHECK(!sync_status()->IsWriting(url)); | 362 DCHECK(!sync_status()->IsWriting(url)); |
| 363 | 363 |
| 364 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 364 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
| 365 file_system_context, url); | 365 file_system_context, url); |
| 366 FileSystemOperation::StatusCallback operation_callback = base::Bind( | 366 FileSystemOperation::StatusCallback operation_callback = base::Bind( |
| 367 &LocalFileSyncContext::DidApplyRemoteChange, this, url, callback); | 367 &LocalFileSyncContext::DidApplyRemoteChange, this, url, callback); |
| 368 | 368 |
| 369 DCHECK_EQ(FileChange::FILE_CHANGE_ADD_OR_UPDATE, change.change()); | 369 DCHECK_EQ(FileChange::FILE_CHANGE_ADD_OR_UPDATE, change.change()); |
| 370 switch (change.file_type()) { | 370 switch (change.file_type()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 400 } | 400 } |
| 401 | 401 |
| 402 void LocalFileSyncContext::RecordFakeLocalChange( | 402 void LocalFileSyncContext::RecordFakeLocalChange( |
| 403 FileSystemContext* file_system_context, | 403 FileSystemContext* file_system_context, |
| 404 const FileSystemURL& url, | 404 const FileSystemURL& url, |
| 405 const FileChange& change, | 405 const FileChange& change, |
| 406 const SyncStatusCallback& callback) { | 406 const SyncStatusCallback& callback) { |
| 407 // This is called on UI thread and to be relayed to FILE thread. | 407 // This is called on UI thread and to be relayed to FILE thread. |
| 408 DCHECK(file_system_context); | 408 DCHECK(file_system_context); |
| 409 if (!file_system_context->default_file_task_runner()-> | 409 if (!file_system_context->default_file_task_runner()-> |
| 410 RunsTasksOnCurrentThread()) { | 410 RunsTasksInCurrentSequence()) { |
| 411 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 411 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 412 file_system_context->default_file_task_runner()->PostTask( | 412 file_system_context->default_file_task_runner()->PostTask( |
| 413 FROM_HERE, base::BindOnce(&LocalFileSyncContext::RecordFakeLocalChange, | 413 FROM_HERE, base::BindOnce(&LocalFileSyncContext::RecordFakeLocalChange, |
| 414 this, base::RetainedRef(file_system_context), | 414 this, base::RetainedRef(file_system_context), |
| 415 url, change, callback)); | 415 url, change, callback)); |
| 416 return; | 416 return; |
| 417 } | 417 } |
| 418 | 418 |
| 419 SyncFileSystemBackend* backend = | 419 SyncFileSystemBackend* backend = |
| 420 SyncFileSystemBackend::GetBackend(file_system_context); | 420 SyncFileSystemBackend::GetBackend(file_system_context); |
| 421 DCHECK(backend); | 421 DCHECK(backend); |
| 422 DCHECK(backend->change_tracker()); | 422 DCHECK(backend->change_tracker()); |
| 423 backend->change_tracker()->MarkDirtyOnDatabase(url); | 423 backend->change_tracker()->MarkDirtyOnDatabase(url); |
| 424 backend->change_tracker()->RecordChange(url, change); | 424 backend->change_tracker()->RecordChange(url, change); |
| 425 | 425 |
| 426 // Fire the callback on UI thread. | 426 // Fire the callback on UI thread. |
| 427 ui_task_runner_->PostTask(FROM_HERE, | 427 ui_task_runner_->PostTask(FROM_HERE, |
| 428 base::BindOnce(callback, SYNC_STATUS_OK)); | 428 base::BindOnce(callback, SYNC_STATUS_OK)); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void LocalFileSyncContext::GetFileMetadata( | 431 void LocalFileSyncContext::GetFileMetadata( |
| 432 FileSystemContext* file_system_context, | 432 FileSystemContext* file_system_context, |
| 433 const FileSystemURL& url, | 433 const FileSystemURL& url, |
| 434 const SyncFileMetadataCallback& callback) { | 434 const SyncFileMetadataCallback& callback) { |
| 435 // 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. |
| 436 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 436 if (!io_task_runner_->RunsTasksInCurrentSequence()) { |
| 437 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 437 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 438 io_task_runner_->PostTask( | 438 io_task_runner_->PostTask( |
| 439 FROM_HERE, | 439 FROM_HERE, |
| 440 base::BindOnce(&LocalFileSyncContext::GetFileMetadata, this, | 440 base::BindOnce(&LocalFileSyncContext::GetFileMetadata, this, |
| 441 base::RetainedRef(file_system_context), url, callback)); | 441 base::RetainedRef(file_system_context), url, callback)); |
| 442 return; | 442 return; |
| 443 } | 443 } |
| 444 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 444 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 445 | 445 |
| 446 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 446 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
| 447 file_system_context, url); | 447 file_system_context, url); |
| 448 file_system_context->operation_runner()->GetMetadata( | 448 file_system_context->operation_runner()->GetMetadata( |
| 449 url_for_sync, FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | | 449 url_for_sync, FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | |
| 450 FileSystemOperation::GET_METADATA_FIELD_SIZE | | 450 FileSystemOperation::GET_METADATA_FIELD_SIZE | |
| 451 FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, | 451 FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, |
| 452 base::Bind(&LocalFileSyncContext::DidGetFileMetadata, this, callback)); | 452 base::Bind(&LocalFileSyncContext::DidGetFileMetadata, this, callback)); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void LocalFileSyncContext::HasPendingLocalChanges( | 455 void LocalFileSyncContext::HasPendingLocalChanges( |
| 456 FileSystemContext* file_system_context, | 456 FileSystemContext* file_system_context, |
| 457 const FileSystemURL& url, | 457 const FileSystemURL& url, |
| 458 const HasPendingLocalChangeCallback& callback) { | 458 const HasPendingLocalChangeCallback& callback) { |
| 459 // 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. |
| 460 DCHECK(file_system_context); | 460 DCHECK(file_system_context); |
| 461 if (!file_system_context->default_file_task_runner()-> | 461 if (!file_system_context->default_file_task_runner()-> |
| 462 RunsTasksOnCurrentThread()) { | 462 RunsTasksInCurrentSequence()) { |
| 463 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 463 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 464 file_system_context->default_file_task_runner()->PostTask( | 464 file_system_context->default_file_task_runner()->PostTask( |
| 465 FROM_HERE, | 465 FROM_HERE, |
| 466 base::BindOnce(&LocalFileSyncContext::HasPendingLocalChanges, this, | 466 base::BindOnce(&LocalFileSyncContext::HasPendingLocalChanges, this, |
| 467 base::RetainedRef(file_system_context), url, callback)); | 467 base::RetainedRef(file_system_context), url, callback)); |
| 468 return; | 468 return; |
| 469 } | 469 } |
| 470 | 470 |
| 471 SyncFileSystemBackend* backend = | 471 SyncFileSystemBackend* backend = |
| 472 SyncFileSystemBackend::GetBackend(file_system_context); | 472 SyncFileSystemBackend::GetBackend(file_system_context); |
| 473 DCHECK(backend); | 473 DCHECK(backend); |
| 474 DCHECK(backend->change_tracker()); | 474 DCHECK(backend->change_tracker()); |
| 475 FileChangeList changes; | 475 FileChangeList changes; |
| 476 backend->change_tracker()->GetChangesForURL(url, &changes); | 476 backend->change_tracker()->GetChangesForURL(url, &changes); |
| 477 | 477 |
| 478 // Fire the callback on UI thread. | 478 // Fire the callback on UI thread. |
| 479 ui_task_runner_->PostTask( | 479 ui_task_runner_->PostTask( |
| 480 FROM_HERE, base::BindOnce(callback, SYNC_STATUS_OK, !changes.empty())); | 480 FROM_HERE, base::BindOnce(callback, SYNC_STATUS_OK, !changes.empty())); |
| 481 } | 481 } |
| 482 | 482 |
| 483 void LocalFileSyncContext::PromoteDemotedChanges( | 483 void LocalFileSyncContext::PromoteDemotedChanges( |
| 484 const GURL& origin, | 484 const GURL& origin, |
| 485 storage::FileSystemContext* file_system_context, | 485 storage::FileSystemContext* file_system_context, |
| 486 const base::Closure& callback) { | 486 const base::Closure& callback) { |
| 487 // This is initially called on UI thread and to be relayed to FILE thread. | 487 // This is initially called on UI thread and to be relayed to FILE thread. |
| 488 DCHECK(file_system_context); | 488 DCHECK(file_system_context); |
| 489 if (!file_system_context->default_file_task_runner()-> | 489 if (!file_system_context->default_file_task_runner()-> |
| 490 RunsTasksOnCurrentThread()) { | 490 RunsTasksInCurrentSequence()) { |
| 491 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 491 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 492 file_system_context->default_file_task_runner()->PostTask( | 492 file_system_context->default_file_task_runner()->PostTask( |
| 493 FROM_HERE, | 493 FROM_HERE, |
| 494 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChanges, this, | 494 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChanges, this, |
| 495 origin, base::RetainedRef(file_system_context), | 495 origin, base::RetainedRef(file_system_context), |
| 496 callback)); | 496 callback)); |
| 497 return; | 497 return; |
| 498 } | 498 } |
| 499 | 499 |
| 500 SyncFileSystemBackend* backend = | 500 SyncFileSystemBackend* backend = |
| 501 SyncFileSystemBackend::GetBackend(file_system_context); | 501 SyncFileSystemBackend::GetBackend(file_system_context); |
| 502 DCHECK(backend); | 502 DCHECK(backend); |
| 503 DCHECK(backend->change_tracker()); | 503 DCHECK(backend->change_tracker()); |
| 504 if (!backend->change_tracker()->PromoteDemotedChanges()) { | 504 if (!backend->change_tracker()->PromoteDemotedChanges()) { |
| 505 ui_task_runner_->PostTask(FROM_HERE, callback); | 505 ui_task_runner_->PostTask(FROM_HERE, callback); |
| 506 return; | 506 return; |
| 507 } | 507 } |
| 508 | 508 |
| 509 io_task_runner_->PostTask( | 509 io_task_runner_->PostTask( |
| 510 FROM_HERE, base::BindOnce(&LocalFileSyncContext::UpdateChangesForOrigin, | 510 FROM_HERE, base::BindOnce(&LocalFileSyncContext::UpdateChangesForOrigin, |
| 511 this, origin, callback)); | 511 this, origin, callback)); |
| 512 } | 512 } |
| 513 | 513 |
| 514 void LocalFileSyncContext::UpdateChangesForOrigin( | 514 void LocalFileSyncContext::UpdateChangesForOrigin( |
| 515 const GURL& origin, | 515 const GURL& origin, |
| 516 const base::Closure& callback) { | 516 const base::Closure& callback) { |
| 517 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 517 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 518 if (shutdown_on_io_) | 518 if (shutdown_on_io_) |
| 519 return; | 519 return; |
| 520 origins_with_pending_changes_.insert(origin); | 520 origins_with_pending_changes_.insert(origin); |
| 521 ScheduleNotifyChangesUpdatedOnIOThread(callback); | 521 ScheduleNotifyChangesUpdatedOnIOThread(callback); |
| 522 } | 522 } |
| 523 | 523 |
| 524 void LocalFileSyncContext::AddOriginChangeObserver( | 524 void LocalFileSyncContext::AddOriginChangeObserver( |
| 525 LocalOriginChangeObserver* observer) { | 525 LocalOriginChangeObserver* observer) { |
| 526 origin_change_observers_.AddObserver(observer); | 526 origin_change_observers_.AddObserver(observer); |
| 527 } | 527 } |
| 528 | 528 |
| 529 void LocalFileSyncContext::RemoveOriginChangeObserver( | 529 void LocalFileSyncContext::RemoveOriginChangeObserver( |
| 530 LocalOriginChangeObserver* observer) { | 530 LocalOriginChangeObserver* observer) { |
| 531 origin_change_observers_.RemoveObserver(observer); | 531 origin_change_observers_.RemoveObserver(observer); |
| 532 } | 532 } |
| 533 | 533 |
| 534 base::WeakPtr<SyncableFileOperationRunner> | 534 base::WeakPtr<SyncableFileOperationRunner> |
| 535 LocalFileSyncContext::operation_runner() const { | 535 LocalFileSyncContext::operation_runner() const { |
| 536 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 536 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 537 if (operation_runner_) | 537 if (operation_runner_) |
| 538 return operation_runner_->AsWeakPtr(); | 538 return operation_runner_->AsWeakPtr(); |
| 539 return base::WeakPtr<SyncableFileOperationRunner>(); | 539 return base::WeakPtr<SyncableFileOperationRunner>(); |
| 540 } | 540 } |
| 541 | 541 |
| 542 LocalFileSyncStatus* LocalFileSyncContext::sync_status() const { | 542 LocalFileSyncStatus* LocalFileSyncContext::sync_status() const { |
| 543 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 543 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 544 return sync_status_.get(); | 544 return sync_status_.get(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 void LocalFileSyncContext::OnSyncEnabled(const FileSystemURL& url) { | 547 void LocalFileSyncContext::OnSyncEnabled(const FileSystemURL& url) { |
| 548 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 548 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 549 if (shutdown_on_io_) | 549 if (shutdown_on_io_) |
| 550 return; | 550 return; |
| 551 UpdateChangesForOrigin(url.origin(), NoopClosure()); | 551 UpdateChangesForOrigin(url.origin(), NoopClosure()); |
| 552 if (url_syncable_callback_.is_null() || | 552 if (url_syncable_callback_.is_null() || |
| 553 sync_status()->IsWriting(url_waiting_sync_on_io_)) { | 553 sync_status()->IsWriting(url_waiting_sync_on_io_)) { |
| 554 return; | 554 return; |
| 555 } | 555 } |
| 556 // TODO(kinuko): may want to check how many pending tasks we have. | 556 // TODO(kinuko): may want to check how many pending tasks we have. |
| 557 ui_task_runner_->PostTask(FROM_HERE, url_syncable_callback_); | 557 ui_task_runner_->PostTask(FROM_HERE, url_syncable_callback_); |
| 558 url_syncable_callback_.Reset(); | 558 url_syncable_callback_.Reset(); |
| 559 } | 559 } |
| 560 | 560 |
| 561 void LocalFileSyncContext::OnWriteEnabled(const FileSystemURL& url) { | 561 void LocalFileSyncContext::OnWriteEnabled(const FileSystemURL& url) { |
| 562 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 562 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 563 // Nothing to do for now. | 563 // Nothing to do for now. |
| 564 } | 564 } |
| 565 | 565 |
| 566 LocalFileSyncContext::~LocalFileSyncContext() { | 566 LocalFileSyncContext::~LocalFileSyncContext() { |
| 567 } | 567 } |
| 568 | 568 |
| 569 void LocalFileSyncContext::ScheduleNotifyChangesUpdatedOnIOThread( | 569 void LocalFileSyncContext::ScheduleNotifyChangesUpdatedOnIOThread( |
| 570 const base::Closure& callback) { | 570 const base::Closure& callback) { |
| 571 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 571 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 572 if (shutdown_on_io_) | 572 if (shutdown_on_io_) |
| 573 return; | 573 return; |
| 574 pending_completion_callbacks_.push_back(callback); | 574 pending_completion_callbacks_.push_back(callback); |
| 575 if (base::Time::Now() > last_notified_changes_ + NotifyChangesDuration()) { | 575 if (base::Time::Now() > last_notified_changes_ + NotifyChangesDuration()) { |
| 576 NotifyAvailableChangesOnIOThread(); | 576 NotifyAvailableChangesOnIOThread(); |
| 577 } else if (!timer_on_io_->IsRunning()) { | 577 } else if (!timer_on_io_->IsRunning()) { |
| 578 timer_on_io_->Start( | 578 timer_on_io_->Start( |
| 579 FROM_HERE, NotifyChangesDuration(), | 579 FROM_HERE, NotifyChangesDuration(), |
| 580 base::Bind(&LocalFileSyncContext::NotifyAvailableChangesOnIOThread, | 580 base::Bind(&LocalFileSyncContext::NotifyAvailableChangesOnIOThread, |
| 581 base::Unretained(this))); | 581 base::Unretained(this))); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 | 584 |
| 585 void LocalFileSyncContext::NotifyAvailableChangesOnIOThread() { | 585 void LocalFileSyncContext::NotifyAvailableChangesOnIOThread() { |
| 586 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 586 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 587 if (shutdown_on_io_) | 587 if (shutdown_on_io_) |
| 588 return; | 588 return; |
| 589 | 589 |
| 590 std::vector<base::Closure> completion_callbacks; | 590 std::vector<base::Closure> completion_callbacks; |
| 591 completion_callbacks.swap(pending_completion_callbacks_); | 591 completion_callbacks.swap(pending_completion_callbacks_); |
| 592 | 592 |
| 593 ui_task_runner_->PostTask( | 593 ui_task_runner_->PostTask( |
| 594 FROM_HERE, | 594 FROM_HERE, |
| 595 base::BindOnce(&LocalFileSyncContext::NotifyAvailableChanges, this, | 595 base::BindOnce(&LocalFileSyncContext::NotifyAvailableChanges, this, |
| 596 origins_with_pending_changes_, completion_callbacks)); | 596 origins_with_pending_changes_, completion_callbacks)); |
| 597 last_notified_changes_ = base::Time::Now(); | 597 last_notified_changes_ = base::Time::Now(); |
| 598 origins_with_pending_changes_.clear(); | 598 origins_with_pending_changes_.clear(); |
| 599 } | 599 } |
| 600 | 600 |
| 601 void LocalFileSyncContext::NotifyAvailableChanges( | 601 void LocalFileSyncContext::NotifyAvailableChanges( |
| 602 const std::set<GURL>& origins, | 602 const std::set<GURL>& origins, |
| 603 const std::vector<base::Closure>& callbacks) { | 603 const std::vector<base::Closure>& callbacks) { |
| 604 for (auto& observer : origin_change_observers_) | 604 for (auto& observer : origin_change_observers_) |
| 605 observer.OnChangesAvailableInOrigins(origins); | 605 observer.OnChangesAvailableInOrigins(origins); |
| 606 for (const auto& callback : callbacks) | 606 for (const auto& callback : callbacks) |
| 607 callback.Run(); | 607 callback.Run(); |
| 608 } | 608 } |
| 609 | 609 |
| 610 void LocalFileSyncContext::ShutdownOnIOThread() { | 610 void LocalFileSyncContext::ShutdownOnIOThread() { |
| 611 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 611 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 612 shutdown_on_io_ = true; | 612 shutdown_on_io_ = true; |
| 613 operation_runner_.reset(); | 613 operation_runner_.reset(); |
| 614 root_delete_helper_.reset(); | 614 root_delete_helper_.reset(); |
| 615 sync_status_.reset(); | 615 sync_status_.reset(); |
| 616 timer_on_io_.reset(); | 616 timer_on_io_.reset(); |
| 617 } | 617 } |
| 618 | 618 |
| 619 void LocalFileSyncContext::InitializeFileSystemContextOnIOThread( | 619 void LocalFileSyncContext::InitializeFileSystemContextOnIOThread( |
| 620 const GURL& source_url, | 620 const GURL& source_url, |
| 621 FileSystemContext* file_system_context, | 621 FileSystemContext* file_system_context, |
| 622 const GURL& /* root */, | 622 const GURL& /* root */, |
| 623 const std::string& /* name */, | 623 const std::string& /* name */, |
| 624 base::File::Error error) { | 624 base::File::Error error) { |
| 625 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 625 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 626 if (shutdown_on_io_) | 626 if (shutdown_on_io_) |
| 627 error = base::File::FILE_ERROR_ABORT; | 627 error = base::File::FILE_ERROR_ABORT; |
| 628 if (error != base::File::FILE_OK) { | 628 if (error != base::File::FILE_OK) { |
| 629 DidInitialize(source_url, file_system_context, | 629 DidInitialize(source_url, file_system_context, |
| 630 FileErrorToSyncStatusCode(error)); | 630 FileErrorToSyncStatusCode(error)); |
| 631 return; | 631 return; |
| 632 } | 632 } |
| 633 DCHECK(file_system_context); | 633 DCHECK(file_system_context); |
| 634 SyncFileSystemBackend* backend = | 634 SyncFileSystemBackend* backend = |
| 635 SyncFileSystemBackend::GetBackend(file_system_context); | 635 SyncFileSystemBackend::GetBackend(file_system_context); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 694 |
| 695 return status; | 695 return status; |
| 696 } | 696 } |
| 697 | 697 |
| 698 void LocalFileSyncContext::DidInitializeChangeTrackerOnIOThread( | 698 void LocalFileSyncContext::DidInitializeChangeTrackerOnIOThread( |
| 699 std::unique_ptr<LocalFileChangeTracker>* tracker_ptr, | 699 std::unique_ptr<LocalFileChangeTracker>* tracker_ptr, |
| 700 const GURL& source_url, | 700 const GURL& source_url, |
| 701 FileSystemContext* file_system_context, | 701 FileSystemContext* file_system_context, |
| 702 std::set<GURL>* origins_with_changes, | 702 std::set<GURL>* origins_with_changes, |
| 703 SyncStatusCode status) { | 703 SyncStatusCode status) { |
| 704 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 704 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 705 DCHECK(file_system_context); | 705 DCHECK(file_system_context); |
| 706 DCHECK(origins_with_changes); | 706 DCHECK(origins_with_changes); |
| 707 if (shutdown_on_io_) | 707 if (shutdown_on_io_) |
| 708 status = SYNC_STATUS_ABORT; | 708 status = SYNC_STATUS_ABORT; |
| 709 if (status != SYNC_STATUS_OK) { | 709 if (status != SYNC_STATUS_OK) { |
| 710 DidInitialize(source_url, file_system_context, status); | 710 DidInitialize(source_url, file_system_context, status); |
| 711 return; | 711 return; |
| 712 } | 712 } |
| 713 | 713 |
| 714 SyncFileSystemBackend* backend = | 714 SyncFileSystemBackend* backend = |
| 715 SyncFileSystemBackend::GetBackend(file_system_context); | 715 SyncFileSystemBackend::GetBackend(file_system_context); |
| 716 DCHECK(backend); | 716 DCHECK(backend); |
| 717 backend->SetLocalFileChangeTracker(std::move(*tracker_ptr)); | 717 backend->SetLocalFileChangeTracker(std::move(*tracker_ptr)); |
| 718 | 718 |
| 719 origins_with_pending_changes_.insert(origins_with_changes->begin(), | 719 origins_with_pending_changes_.insert(origins_with_changes->begin(), |
| 720 origins_with_changes->end()); | 720 origins_with_changes->end()); |
| 721 ScheduleNotifyChangesUpdatedOnIOThread(NoopClosure()); | 721 ScheduleNotifyChangesUpdatedOnIOThread(NoopClosure()); |
| 722 | 722 |
| 723 InitializeFileSystemContextOnIOThread(source_url, file_system_context, | 723 InitializeFileSystemContextOnIOThread(source_url, file_system_context, |
| 724 GURL(), std::string(), | 724 GURL(), std::string(), |
| 725 base::File::FILE_OK); | 725 base::File::FILE_OK); |
| 726 } | 726 } |
| 727 | 727 |
| 728 void LocalFileSyncContext::DidInitialize( | 728 void LocalFileSyncContext::DidInitialize( |
| 729 const GURL& source_url, | 729 const GURL& source_url, |
| 730 FileSystemContext* file_system_context, | 730 FileSystemContext* file_system_context, |
| 731 SyncStatusCode status) { | 731 SyncStatusCode status) { |
| 732 if (!ui_task_runner_->RunsTasksOnCurrentThread()) { | 732 if (!ui_task_runner_->RunsTasksInCurrentSequence()) { |
| 733 ui_task_runner_->PostTask( | 733 ui_task_runner_->PostTask( |
| 734 FROM_HERE, | 734 FROM_HERE, |
| 735 base::BindOnce(&LocalFileSyncContext::DidInitialize, this, source_url, | 735 base::BindOnce(&LocalFileSyncContext::DidInitialize, this, source_url, |
| 736 base::RetainedRef(file_system_context), status)); | 736 base::RetainedRef(file_system_context), status)); |
| 737 return; | 737 return; |
| 738 } | 738 } |
| 739 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 739 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 740 DCHECK(!base::ContainsKey(file_system_contexts_, file_system_context)); | 740 DCHECK(!base::ContainsKey(file_system_contexts_, file_system_context)); |
| 741 DCHECK(base::ContainsKey(pending_initialize_callbacks_, file_system_context)); | 741 DCHECK(base::ContainsKey(pending_initialize_callbacks_, file_system_context)); |
| 742 | 742 |
| 743 SyncFileSystemBackend* backend = | 743 SyncFileSystemBackend* backend = |
| 744 SyncFileSystemBackend::GetBackend(file_system_context); | 744 SyncFileSystemBackend::GetBackend(file_system_context); |
| 745 DCHECK(backend); | 745 DCHECK(backend); |
| 746 DCHECK(backend->change_tracker()); | 746 DCHECK(backend->change_tracker()); |
| 747 | 747 |
| 748 file_system_contexts_.insert(file_system_context); | 748 file_system_contexts_.insert(file_system_context); |
| 749 | 749 |
| 750 StatusCallbackQueue& callback_queue = | 750 StatusCallbackQueue& callback_queue = |
| 751 pending_initialize_callbacks_[file_system_context]; | 751 pending_initialize_callbacks_[file_system_context]; |
| 752 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); | 752 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); |
| 753 iter != callback_queue.end(); ++iter) { | 753 iter != callback_queue.end(); ++iter) { |
| 754 ui_task_runner_->PostTask(FROM_HERE, base::BindOnce(*iter, status)); | 754 ui_task_runner_->PostTask(FROM_HERE, base::BindOnce(*iter, status)); |
| 755 } | 755 } |
| 756 pending_initialize_callbacks_.erase(file_system_context); | 756 pending_initialize_callbacks_.erase(file_system_context); |
| 757 } | 757 } |
| 758 | 758 |
| 759 std::unique_ptr<LocalFileSyncContext::FileSystemURLQueue> | 759 std::unique_ptr<LocalFileSyncContext::FileSystemURLQueue> |
| 760 LocalFileSyncContext::GetNextURLsForSyncOnFileThread( | 760 LocalFileSyncContext::GetNextURLsForSyncOnFileThread( |
| 761 FileSystemContext* file_system_context) { | 761 FileSystemContext* file_system_context) { |
| 762 DCHECK(file_system_context); | 762 DCHECK(file_system_context); |
| 763 DCHECK(file_system_context->default_file_task_runner()-> | 763 DCHECK(file_system_context->default_file_task_runner()-> |
| 764 RunsTasksOnCurrentThread()); | 764 RunsTasksInCurrentSequence()); |
| 765 SyncFileSystemBackend* backend = | 765 SyncFileSystemBackend* backend = |
| 766 SyncFileSystemBackend::GetBackend(file_system_context); | 766 SyncFileSystemBackend::GetBackend(file_system_context); |
| 767 DCHECK(backend); | 767 DCHECK(backend); |
| 768 DCHECK(backend->change_tracker()); | 768 DCHECK(backend->change_tracker()); |
| 769 std::unique_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue); | 769 std::unique_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue); |
| 770 backend->change_tracker()->GetNextChangedURLs( | 770 backend->change_tracker()->GetNextChangedURLs( |
| 771 urls.get(), kMaxURLsToFetchForLocalSync); | 771 urls.get(), kMaxURLsToFetchForLocalSync); |
| 772 for (FileSystemURLQueue::iterator iter = urls->begin(); | 772 for (FileSystemURLQueue::iterator iter = urls->begin(); |
| 773 iter != urls->end(); ++iter) | 773 iter != urls->end(); ++iter) |
| 774 backend->change_tracker()->DemoteChangesForURL(*iter); | 774 backend->change_tracker()->DemoteChangesForURL(*iter); |
| 775 | 775 |
| 776 return urls; | 776 return urls; |
| 777 } | 777 } |
| 778 | 778 |
| 779 void LocalFileSyncContext::TryPrepareForLocalSync( | 779 void LocalFileSyncContext::TryPrepareForLocalSync( |
| 780 FileSystemContext* file_system_context, | 780 FileSystemContext* file_system_context, |
| 781 const LocalFileSyncInfoCallback& callback, | 781 const LocalFileSyncInfoCallback& callback, |
| 782 std::unique_ptr<FileSystemURLQueue> urls) { | 782 std::unique_ptr<FileSystemURLQueue> urls) { |
| 783 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 783 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 784 DCHECK(urls); | 784 DCHECK(urls); |
| 785 | 785 |
| 786 if (shutdown_on_ui_) { | 786 if (shutdown_on_ui_) { |
| 787 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); | 787 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); |
| 788 return; | 788 return; |
| 789 } | 789 } |
| 790 | 790 |
| 791 if (urls->empty()) { | 791 if (urls->empty()) { |
| 792 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, | 792 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, |
| 793 LocalFileSyncInfo(), | 793 LocalFileSyncInfo(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 804 base::Passed(&urls), callback)); | 804 base::Passed(&urls), callback)); |
| 805 } | 805 } |
| 806 | 806 |
| 807 void LocalFileSyncContext::DidTryPrepareForLocalSync( | 807 void LocalFileSyncContext::DidTryPrepareForLocalSync( |
| 808 FileSystemContext* file_system_context, | 808 FileSystemContext* file_system_context, |
| 809 std::unique_ptr<FileSystemURLQueue> remaining_urls, | 809 std::unique_ptr<FileSystemURLQueue> remaining_urls, |
| 810 const LocalFileSyncInfoCallback& callback, | 810 const LocalFileSyncInfoCallback& callback, |
| 811 SyncStatusCode status, | 811 SyncStatusCode status, |
| 812 const LocalFileSyncInfo& sync_file_info, | 812 const LocalFileSyncInfo& sync_file_info, |
| 813 storage::ScopedFile snapshot) { | 813 storage::ScopedFile snapshot) { |
| 814 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 814 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 815 if (status != SYNC_STATUS_FILE_BUSY) { | 815 if (status != SYNC_STATUS_FILE_BUSY) { |
| 816 PromoteDemotedChangesForURLs(file_system_context, | 816 PromoteDemotedChangesForURLs(file_system_context, |
| 817 std::move(remaining_urls)); | 817 std::move(remaining_urls)); |
| 818 callback.Run(status, sync_file_info, std::move(snapshot)); | 818 callback.Run(status, sync_file_info, std::move(snapshot)); |
| 819 return; | 819 return; |
| 820 } | 820 } |
| 821 | 821 |
| 822 PromoteDemotedChangesForURL(file_system_context, sync_file_info.url); | 822 PromoteDemotedChangesForURL(file_system_context, sync_file_info.url); |
| 823 | 823 |
| 824 // Recursively call TryPrepareForLocalSync with remaining_urls. | 824 // Recursively call TryPrepareForLocalSync with remaining_urls. |
| 825 TryPrepareForLocalSync(file_system_context, callback, | 825 TryPrepareForLocalSync(file_system_context, callback, |
| 826 std::move(remaining_urls)); | 826 std::move(remaining_urls)); |
| 827 } | 827 } |
| 828 | 828 |
| 829 void LocalFileSyncContext::PromoteDemotedChangesForURL( | 829 void LocalFileSyncContext::PromoteDemotedChangesForURL( |
| 830 FileSystemContext* file_system_context, | 830 FileSystemContext* file_system_context, |
| 831 const FileSystemURL& url) { | 831 const FileSystemURL& url) { |
| 832 DCHECK(file_system_context); | 832 DCHECK(file_system_context); |
| 833 if (!file_system_context->default_file_task_runner()-> | 833 if (!file_system_context->default_file_task_runner()-> |
| 834 RunsTasksOnCurrentThread()) { | 834 RunsTasksInCurrentSequence()) { |
| 835 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 835 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 836 if (shutdown_on_ui_) | 836 if (shutdown_on_ui_) |
| 837 return; | 837 return; |
| 838 file_system_context->default_file_task_runner()->PostTask( | 838 file_system_context->default_file_task_runner()->PostTask( |
| 839 FROM_HERE, | 839 FROM_HERE, |
| 840 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChangesForURL, this, | 840 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChangesForURL, this, |
| 841 base::RetainedRef(file_system_context), url)); | 841 base::RetainedRef(file_system_context), url)); |
| 842 return; | 842 return; |
| 843 } | 843 } |
| 844 | 844 |
| 845 SyncFileSystemBackend* backend = | 845 SyncFileSystemBackend* backend = |
| 846 SyncFileSystemBackend::GetBackend(file_system_context); | 846 SyncFileSystemBackend::GetBackend(file_system_context); |
| 847 DCHECK(backend); | 847 DCHECK(backend); |
| 848 DCHECK(backend->change_tracker()); | 848 DCHECK(backend->change_tracker()); |
| 849 backend->change_tracker()->PromoteDemotedChangesForURL(url); | 849 backend->change_tracker()->PromoteDemotedChangesForURL(url); |
| 850 } | 850 } |
| 851 | 851 |
| 852 void LocalFileSyncContext::PromoteDemotedChangesForURLs( | 852 void LocalFileSyncContext::PromoteDemotedChangesForURLs( |
| 853 FileSystemContext* file_system_context, | 853 FileSystemContext* file_system_context, |
| 854 std::unique_ptr<FileSystemURLQueue> urls) { | 854 std::unique_ptr<FileSystemURLQueue> urls) { |
| 855 DCHECK(file_system_context); | 855 DCHECK(file_system_context); |
| 856 if (!file_system_context->default_file_task_runner()-> | 856 if (!file_system_context->default_file_task_runner()-> |
| 857 RunsTasksOnCurrentThread()) { | 857 RunsTasksInCurrentSequence()) { |
| 858 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 858 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 859 if (shutdown_on_ui_) | 859 if (shutdown_on_ui_) |
| 860 return; | 860 return; |
| 861 file_system_context->default_file_task_runner()->PostTask( | 861 file_system_context->default_file_task_runner()->PostTask( |
| 862 FROM_HERE, | 862 FROM_HERE, |
| 863 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChangesForURLs, | 863 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChangesForURLs, |
| 864 this, base::RetainedRef(file_system_context), | 864 this, base::RetainedRef(file_system_context), |
| 865 base::Passed(&urls))); | 865 base::Passed(&urls))); |
| 866 return; | 866 return; |
| 867 } | 867 } |
| 868 | 868 |
| 869 for (FileSystemURLQueue::iterator iter = urls->begin(); | 869 for (FileSystemURLQueue::iterator iter = urls->begin(); |
| 870 iter != urls->end(); ++iter) | 870 iter != urls->end(); ++iter) |
| 871 PromoteDemotedChangesForURL(file_system_context, *iter); | 871 PromoteDemotedChangesForURL(file_system_context, *iter); |
| 872 } | 872 } |
| 873 | 873 |
| 874 void LocalFileSyncContext::DidGetWritingStatusForSync( | 874 void LocalFileSyncContext::DidGetWritingStatusForSync( |
| 875 FileSystemContext* file_system_context, | 875 FileSystemContext* file_system_context, |
| 876 SyncStatusCode status, | 876 SyncStatusCode status, |
| 877 const FileSystemURL& url, | 877 const FileSystemURL& url, |
| 878 SyncMode sync_mode, | 878 SyncMode sync_mode, |
| 879 const LocalFileSyncInfoCallback& callback) { | 879 const LocalFileSyncInfoCallback& callback) { |
| 880 // This gets called on UI thread and relays the task on FILE thread. | 880 // This gets called on UI thread and relays the task on FILE thread. |
| 881 DCHECK(file_system_context); | 881 DCHECK(file_system_context); |
| 882 if (!file_system_context->default_file_task_runner()-> | 882 if (!file_system_context->default_file_task_runner()-> |
| 883 RunsTasksOnCurrentThread()) { | 883 RunsTasksInCurrentSequence()) { |
| 884 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 884 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 885 if (shutdown_on_ui_) { | 885 if (shutdown_on_ui_) { |
| 886 callback.Run( | 886 callback.Run( |
| 887 SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); | 887 SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); |
| 888 return; | 888 return; |
| 889 } | 889 } |
| 890 file_system_context->default_file_task_runner()->PostTask( | 890 file_system_context->default_file_task_runner()->PostTask( |
| 891 FROM_HERE, | 891 FROM_HERE, |
| 892 base::BindOnce(&LocalFileSyncContext::DidGetWritingStatusForSync, this, | 892 base::BindOnce(&LocalFileSyncContext::DidGetWritingStatusForSync, this, |
| 893 base::RetainedRef(file_system_context), status, url, | 893 base::RetainedRef(file_system_context), status, url, |
| 894 sync_mode, callback)); | 894 sync_mode, callback)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 } | 966 } |
| 967 | 967 |
| 968 ui_task_runner_->PostTask(FROM_HERE, | 968 ui_task_runner_->PostTask(FROM_HERE, |
| 969 base::BindOnce(callback, status, sync_file_info, | 969 base::BindOnce(callback, status, sync_file_info, |
| 970 base::Passed(&snapshot))); | 970 base::Passed(&snapshot))); |
| 971 } | 971 } |
| 972 | 972 |
| 973 void LocalFileSyncContext::ClearSyncFlagOnIOThread( | 973 void LocalFileSyncContext::ClearSyncFlagOnIOThread( |
| 974 const FileSystemURL& url, | 974 const FileSystemURL& url, |
| 975 bool for_snapshot_sync) { | 975 bool for_snapshot_sync) { |
| 976 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 976 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 977 if (shutdown_on_io_) | 977 if (shutdown_on_io_) |
| 978 return; | 978 return; |
| 979 sync_status()->EndSyncing(url); | 979 sync_status()->EndSyncing(url); |
| 980 | 980 |
| 981 if (for_snapshot_sync) { | 981 if (for_snapshot_sync) { |
| 982 // The caller will hold shared lock on this one. | 982 // The caller will hold shared lock on this one. |
| 983 sync_status()->StartWriting(url); | 983 sync_status()->StartWriting(url); |
| 984 return; | 984 return; |
| 985 } | 985 } |
| 986 | 986 |
| 987 // Since a sync has finished the number of changes must have been updated. | 987 // Since a sync has finished the number of changes must have been updated. |
| 988 UpdateChangesForOrigin(url.origin(), NoopClosure()); | 988 UpdateChangesForOrigin(url.origin(), NoopClosure()); |
| 989 } | 989 } |
| 990 | 990 |
| 991 void LocalFileSyncContext::FinalizeSnapshotSyncOnIOThread( | 991 void LocalFileSyncContext::FinalizeSnapshotSyncOnIOThread( |
| 992 const FileSystemURL& url) { | 992 const FileSystemURL& url) { |
| 993 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 993 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 994 if (shutdown_on_io_) | 994 if (shutdown_on_io_) |
| 995 return; | 995 return; |
| 996 sync_status()->EndWriting(url); | 996 sync_status()->EndWriting(url); |
| 997 | 997 |
| 998 // Since a sync has finished the number of changes must have been updated. | 998 // Since a sync has finished the number of changes must have been updated. |
| 999 UpdateChangesForOrigin(url.origin(), NoopClosure()); | 999 UpdateChangesForOrigin(url.origin(), NoopClosure()); |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 void LocalFileSyncContext::DidApplyRemoteChange( | 1002 void LocalFileSyncContext::DidApplyRemoteChange( |
| 1003 const FileSystemURL& url, | 1003 const FileSystemURL& url, |
| 1004 const SyncStatusCallback& callback_on_ui, | 1004 const SyncStatusCallback& callback_on_ui, |
| 1005 base::File::Error file_error) { | 1005 base::File::Error file_error) { |
| 1006 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 1006 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 1007 root_delete_helper_.reset(); | 1007 root_delete_helper_.reset(); |
| 1008 ui_task_runner_->PostTask( | 1008 ui_task_runner_->PostTask( |
| 1009 FROM_HERE, | 1009 FROM_HERE, |
| 1010 base::BindOnce(callback_on_ui, FileErrorToSyncStatusCode(file_error))); | 1010 base::BindOnce(callback_on_ui, FileErrorToSyncStatusCode(file_error))); |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 void LocalFileSyncContext::DidGetFileMetadata( | 1013 void LocalFileSyncContext::DidGetFileMetadata( |
| 1014 const SyncFileMetadataCallback& callback, | 1014 const SyncFileMetadataCallback& callback, |
| 1015 base::File::Error file_error, | 1015 base::File::Error file_error, |
| 1016 const base::File::Info& file_info) { | 1016 const base::File::Info& file_info) { |
| 1017 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 1017 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 1018 SyncFileMetadata metadata; | 1018 SyncFileMetadata metadata; |
| 1019 if (file_error == base::File::FILE_OK) { | 1019 if (file_error == base::File::FILE_OK) { |
| 1020 metadata.file_type = file_info.is_directory ? | 1020 metadata.file_type = file_info.is_directory ? |
| 1021 SYNC_FILE_TYPE_DIRECTORY : SYNC_FILE_TYPE_FILE; | 1021 SYNC_FILE_TYPE_DIRECTORY : SYNC_FILE_TYPE_FILE; |
| 1022 metadata.size = file_info.size; | 1022 metadata.size = file_info.size; |
| 1023 metadata.last_modified = file_info.last_modified; | 1023 metadata.last_modified = file_info.last_modified; |
| 1024 } | 1024 } |
| 1025 ui_task_runner_->PostTask( | 1025 ui_task_runner_->PostTask( |
| 1026 FROM_HERE, base::BindOnce(callback, FileErrorToSyncStatusCode(file_error), | 1026 FROM_HERE, base::BindOnce(callback, FileErrorToSyncStatusCode(file_error), |
| 1027 metadata)); | 1027 metadata)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1044 return; | 1044 return; |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 1047 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
| 1048 file_system_context, dest_url); | 1048 file_system_context, dest_url); |
| 1049 file_system_context->operation_runner()->CopyInForeignFile( | 1049 file_system_context->operation_runner()->CopyInForeignFile( |
| 1050 local_path, url_for_sync, callback); | 1050 local_path, url_for_sync, callback); |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 } // namespace sync_file_system | 1053 } // namespace sync_file_system |
| OLD | NEW |