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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_->RunsTasksOnCurrentThread()); |
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, base::Bind(callback, SYNC_STATUS_OK)); | 74 ui_task_runner_->PostTask(FROM_HERE, |
| 75 base::BindOnce(callback, SYNC_STATUS_OK)); |
75 return; | 76 return; |
76 } | 77 } |
77 | 78 |
78 StatusCallbackQueue& callback_queue = | 79 StatusCallbackQueue& callback_queue = |
79 pending_initialize_callbacks_[file_system_context]; | 80 pending_initialize_callbacks_[file_system_context]; |
80 callback_queue.push_back(callback); | 81 callback_queue.push_back(callback); |
81 if (callback_queue.size() > 1) | 82 if (callback_queue.size() > 1) |
82 return; | 83 return; |
83 | 84 |
84 // The sync service always expects the origin (app) is initialized | 85 // The sync service always expects the origin (app) is initialized |
85 // for writable way (even when MaybeInitializeFileSystemContext is called | 86 // for writable way (even when MaybeInitializeFileSystemContext is called |
86 // from read-only OpenFileSystem), so open the filesystem with | 87 // from read-only OpenFileSystem), so open the filesystem with |
87 // CREATE_IF_NONEXISTENT here. | 88 // CREATE_IF_NONEXISTENT here. |
88 storage::FileSystemBackend::OpenFileSystemCallback open_filesystem_callback = | 89 storage::FileSystemBackend::OpenFileSystemCallback open_filesystem_callback = |
89 base::Bind(&LocalFileSyncContext::InitializeFileSystemContextOnIOThread, | 90 base::Bind(&LocalFileSyncContext::InitializeFileSystemContextOnIOThread, |
90 this, source_url, base::RetainedRef(file_system_context)); | 91 this, source_url, base::RetainedRef(file_system_context)); |
91 io_task_runner_->PostTask( | 92 io_task_runner_->PostTask( |
92 FROM_HERE, | 93 FROM_HERE, |
93 base::Bind(&storage::SandboxFileSystemBackendDelegate::OpenFileSystem, | 94 base::BindOnce(&storage::SandboxFileSystemBackendDelegate::OpenFileSystem, |
94 base::Unretained(file_system_context->sandbox_delegate()), | 95 base::Unretained(file_system_context->sandbox_delegate()), |
95 source_url, | 96 source_url, storage::kFileSystemTypeSyncable, |
96 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, | |
99 GURL())); | |
100 } | 99 } |
101 | 100 |
102 void LocalFileSyncContext::ShutdownOnUIThread() { | 101 void LocalFileSyncContext::ShutdownOnUIThread() { |
103 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 102 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
104 shutdown_on_ui_ = true; | 103 shutdown_on_ui_ = true; |
105 io_task_runner_->PostTask( | 104 io_task_runner_->PostTask( |
106 FROM_HERE, | 105 FROM_HERE, |
107 base::Bind(&LocalFileSyncContext::ShutdownOnIOThread, this)); | 106 base::BindOnce(&LocalFileSyncContext::ShutdownOnIOThread, this)); |
108 } | 107 } |
109 | 108 |
110 void LocalFileSyncContext::GetFileForLocalSync( | 109 void LocalFileSyncContext::GetFileForLocalSync( |
111 FileSystemContext* file_system_context, | 110 FileSystemContext* file_system_context, |
112 const LocalFileSyncInfoCallback& callback) { | 111 const LocalFileSyncInfoCallback& callback) { |
113 DCHECK(file_system_context); | 112 DCHECK(file_system_context); |
114 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 113 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
115 | 114 |
116 base::PostTaskAndReplyWithResult( | 115 base::PostTaskAndReplyWithResult( |
117 file_system_context->default_file_task_runner(), FROM_HERE, | 116 file_system_context->default_file_task_runner(), FROM_HERE, |
118 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, this, | 117 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, this, |
119 base::RetainedRef(file_system_context)), | 118 base::RetainedRef(file_system_context)), |
120 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, this, | 119 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, this, |
121 base::RetainedRef(file_system_context), callback)); | 120 base::RetainedRef(file_system_context), callback)); |
122 } | 121 } |
123 | 122 |
124 void LocalFileSyncContext::ClearChangesForURL( | 123 void LocalFileSyncContext::ClearChangesForURL( |
125 FileSystemContext* file_system_context, | 124 FileSystemContext* file_system_context, |
126 const FileSystemURL& url, | 125 const FileSystemURL& url, |
127 const base::Closure& done_callback) { | 126 const base::Closure& done_callback) { |
128 // 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. |
129 DCHECK(file_system_context); | 128 DCHECK(file_system_context); |
130 if (!file_system_context->default_file_task_runner()-> | 129 if (!file_system_context->default_file_task_runner()-> |
131 RunsTasksOnCurrentThread()) { | 130 RunsTasksOnCurrentThread()) { |
132 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 131 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
133 file_system_context->default_file_task_runner()->PostTask( | 132 file_system_context->default_file_task_runner()->PostTask( |
134 FROM_HERE, | 133 FROM_HERE, base::BindOnce(&LocalFileSyncContext::ClearChangesForURL, |
135 base::Bind(&LocalFileSyncContext::ClearChangesForURL, this, | 134 this, base::RetainedRef(file_system_context), |
136 base::RetainedRef(file_system_context), url, done_callback)); | 135 url, done_callback)); |
137 return; | 136 return; |
138 } | 137 } |
139 | 138 |
140 SyncFileSystemBackend* backend = | 139 SyncFileSystemBackend* backend = |
141 SyncFileSystemBackend::GetBackend(file_system_context); | 140 SyncFileSystemBackend::GetBackend(file_system_context); |
142 DCHECK(backend); | 141 DCHECK(backend); |
143 DCHECK(backend->change_tracker()); | 142 DCHECK(backend->change_tracker()); |
144 backend->change_tracker()->ClearChangesForURL(url); | 143 backend->change_tracker()->ClearChangesForURL(url); |
145 | 144 |
146 // Call the completion callback on UI thread. | 145 // Call the completion callback on UI thread. |
147 ui_task_runner_->PostTask(FROM_HERE, done_callback); | 146 ui_task_runner_->PostTask(FROM_HERE, done_callback); |
148 } | 147 } |
149 | 148 |
150 void LocalFileSyncContext::FinalizeSnapshotSync( | 149 void LocalFileSyncContext::FinalizeSnapshotSync( |
151 storage::FileSystemContext* file_system_context, | 150 storage::FileSystemContext* file_system_context, |
152 const storage::FileSystemURL& url, | 151 const storage::FileSystemURL& url, |
153 SyncStatusCode sync_finish_status, | 152 SyncStatusCode sync_finish_status, |
154 const base::Closure& done_callback) { | 153 const base::Closure& done_callback) { |
155 DCHECK(file_system_context); | 154 DCHECK(file_system_context); |
156 DCHECK(url.is_valid()); | 155 DCHECK(url.is_valid()); |
157 if (!file_system_context->default_file_task_runner()-> | 156 if (!file_system_context->default_file_task_runner()-> |
158 RunsTasksOnCurrentThread()) { | 157 RunsTasksOnCurrentThread()) { |
159 file_system_context->default_file_task_runner()->PostTask( | 158 file_system_context->default_file_task_runner()->PostTask( |
160 FROM_HERE, base::Bind(&LocalFileSyncContext::FinalizeSnapshotSync, this, | 159 FROM_HERE, base::BindOnce(&LocalFileSyncContext::FinalizeSnapshotSync, |
161 base::RetainedRef(file_system_context), url, | 160 this, base::RetainedRef(file_system_context), |
162 sync_finish_status, done_callback)); | 161 url, sync_finish_status, done_callback)); |
163 return; | 162 return; |
164 } | 163 } |
165 | 164 |
166 SyncFileSystemBackend* backend = | 165 SyncFileSystemBackend* backend = |
167 SyncFileSystemBackend::GetBackend(file_system_context); | 166 SyncFileSystemBackend::GetBackend(file_system_context); |
168 DCHECK(backend); | 167 DCHECK(backend); |
169 DCHECK(backend->change_tracker()); | 168 DCHECK(backend->change_tracker()); |
170 | 169 |
171 if (sync_finish_status == SYNC_STATUS_OK || | 170 if (sync_finish_status == SYNC_STATUS_OK || |
172 sync_finish_status == SYNC_STATUS_HAS_CONFLICT) { | 171 sync_finish_status == SYNC_STATUS_HAS_CONFLICT) { |
173 // Commit the in-memory mirror change. | 172 // Commit the in-memory mirror change. |
174 backend->change_tracker()->ResetToMirrorAndCommitChangesForURL(url); | 173 backend->change_tracker()->ResetToMirrorAndCommitChangesForURL(url); |
175 } else { | 174 } else { |
176 // Abort in-memory mirror change. | 175 // Abort in-memory mirror change. |
177 backend->change_tracker()->RemoveMirrorAndCommitChangesForURL(url); | 176 backend->change_tracker()->RemoveMirrorAndCommitChangesForURL(url); |
178 } | 177 } |
179 | 178 |
180 // We've been keeping it in writing mode, so clear the writing counter | 179 // We've been keeping it in writing mode, so clear the writing counter |
181 // to unblock sync activities. | 180 // to unblock sync activities. |
182 io_task_runner_->PostTask( | 181 io_task_runner_->PostTask( |
183 FROM_HERE, base::Bind( | 182 FROM_HERE, |
184 &LocalFileSyncContext::FinalizeSnapshotSyncOnIOThread, this, url)); | 183 base::BindOnce(&LocalFileSyncContext::FinalizeSnapshotSyncOnIOThread, |
| 184 this, url)); |
185 | 185 |
186 // Call the completion callback on UI thread. | 186 // Call the completion callback on UI thread. |
187 ui_task_runner_->PostTask(FROM_HERE, done_callback); | 187 ui_task_runner_->PostTask(FROM_HERE, done_callback); |
188 } | 188 } |
189 | 189 |
190 void LocalFileSyncContext::FinalizeExclusiveSync( | 190 void LocalFileSyncContext::FinalizeExclusiveSync( |
191 storage::FileSystemContext* file_system_context, | 191 storage::FileSystemContext* file_system_context, |
192 const storage::FileSystemURL& url, | 192 const storage::FileSystemURL& url, |
193 bool clear_local_changes, | 193 bool clear_local_changes, |
194 const base::Closure& done_callback) { | 194 const base::Closure& done_callback) { |
195 DCHECK(file_system_context); | 195 DCHECK(file_system_context); |
196 if (!url.is_valid()) { | 196 if (!url.is_valid()) { |
197 done_callback.Run(); | 197 done_callback.Run(); |
198 return; | 198 return; |
199 } | 199 } |
200 | 200 |
201 if (clear_local_changes) { | 201 if (clear_local_changes) { |
202 ClearChangesForURL(file_system_context, url, | 202 ClearChangesForURL(file_system_context, url, |
203 base::Bind(&LocalFileSyncContext::FinalizeExclusiveSync, | 203 base::Bind(&LocalFileSyncContext::FinalizeExclusiveSync, |
204 this, base::RetainedRef(file_system_context), | 204 this, base::RetainedRef(file_system_context), |
205 url, false, done_callback)); | 205 url, false, done_callback)); |
206 return; | 206 return; |
207 } | 207 } |
208 | 208 |
209 io_task_runner_->PostTask( | 209 io_task_runner_->PostTask( |
210 FROM_HERE, | 210 FROM_HERE, base::BindOnce(&LocalFileSyncContext::ClearSyncFlagOnIOThread, |
211 base::Bind(&LocalFileSyncContext::ClearSyncFlagOnIOThread, | 211 this, url, false /* for_snapshot_sync */)); |
212 this, url, false /* for_snapshot_sync */)); | |
213 | 212 |
214 done_callback.Run(); | 213 done_callback.Run(); |
215 } | 214 } |
216 | 215 |
217 void LocalFileSyncContext::PrepareForSync( | 216 void LocalFileSyncContext::PrepareForSync( |
218 FileSystemContext* file_system_context, | 217 FileSystemContext* file_system_context, |
219 const FileSystemURL& url, | 218 const FileSystemURL& url, |
220 SyncMode sync_mode, | 219 SyncMode sync_mode, |
221 const LocalFileSyncInfoCallback& callback) { | 220 const LocalFileSyncInfoCallback& callback) { |
222 // 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. |
223 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 222 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
224 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 223 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
225 io_task_runner_->PostTask( | 224 io_task_runner_->PostTask( |
226 FROM_HERE, base::Bind(&LocalFileSyncContext::PrepareForSync, this, | 225 FROM_HERE, base::BindOnce(&LocalFileSyncContext::PrepareForSync, this, |
227 base::RetainedRef(file_system_context), url, | 226 base::RetainedRef(file_system_context), url, |
228 sync_mode, callback)); | 227 sync_mode, callback)); |
229 return; | 228 return; |
230 } | 229 } |
231 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 230 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
232 const bool syncable = sync_status()->IsSyncable(url); | 231 const bool syncable = sync_status()->IsSyncable(url); |
233 // Disable writing if it's ready to be synced. | 232 // Disable writing if it's ready to be synced. |
234 if (syncable) | 233 if (syncable) |
235 sync_status()->StartSyncing(url); | 234 sync_status()->StartSyncing(url); |
236 ui_task_runner_->PostTask( | 235 ui_task_runner_->PostTask( |
237 FROM_HERE, base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, | 236 FROM_HERE, |
238 this, base::RetainedRef(file_system_context), | 237 base::BindOnce(&LocalFileSyncContext::DidGetWritingStatusForSync, this, |
239 syncable ? SYNC_STATUS_OK : SYNC_STATUS_FILE_BUSY, | 238 base::RetainedRef(file_system_context), |
240 url, sync_mode, callback)); | 239 syncable ? SYNC_STATUS_OK : SYNC_STATUS_FILE_BUSY, url, |
| 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_->RunsTasksOnCurrentThread()) { |
248 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 248 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
249 io_task_runner_->PostTask( | 249 io_task_runner_->PostTask( |
250 FROM_HERE, | 250 FROM_HERE, |
251 base::Bind(&LocalFileSyncContext::RegisterURLForWaitingSync, | 251 base::BindOnce(&LocalFileSyncContext::RegisterURLForWaitingSync, this, |
252 this, 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_->RunsTasksOnCurrentThread()); |
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_->RunsTasksOnCurrentThread()) { |
274 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 274 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
275 io_task_runner_->PostTask( | 275 io_task_runner_->PostTask( |
276 FROM_HERE, base::Bind(&LocalFileSyncContext::ApplyRemoteChange, this, | 276 FROM_HERE, base::BindOnce(&LocalFileSyncContext::ApplyRemoteChange, |
277 base::RetainedRef(file_system_context), change, | 277 this, base::RetainedRef(file_system_context), |
278 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_->RunsTasksOnCurrentThread()); |
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); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 RunsTasksOnCurrentThread()) { |
411 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 411 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
412 file_system_context->default_file_task_runner()->PostTask( | 412 file_system_context->default_file_task_runner()->PostTask( |
413 FROM_HERE, base::Bind(&LocalFileSyncContext::RecordFakeLocalChange, | 413 FROM_HERE, base::BindOnce(&LocalFileSyncContext::RecordFakeLocalChange, |
414 this, base::RetainedRef(file_system_context), url, | 414 this, base::RetainedRef(file_system_context), |
415 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::Bind(callback, | 428 base::BindOnce(callback, SYNC_STATUS_OK)); |
429 SYNC_STATUS_OK)); | |
430 } | 429 } |
431 | 430 |
432 void LocalFileSyncContext::GetFileMetadata( | 431 void LocalFileSyncContext::GetFileMetadata( |
433 FileSystemContext* file_system_context, | 432 FileSystemContext* file_system_context, |
434 const FileSystemURL& url, | 433 const FileSystemURL& url, |
435 const SyncFileMetadataCallback& callback) { | 434 const SyncFileMetadataCallback& callback) { |
436 // 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. |
437 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 436 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
438 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 437 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
439 io_task_runner_->PostTask( | 438 io_task_runner_->PostTask( |
440 FROM_HERE, | 439 FROM_HERE, |
441 base::Bind(&LocalFileSyncContext::GetFileMetadata, this, | 440 base::BindOnce(&LocalFileSyncContext::GetFileMetadata, this, |
442 base::RetainedRef(file_system_context), url, callback)); | 441 base::RetainedRef(file_system_context), url, callback)); |
443 return; | 442 return; |
444 } | 443 } |
445 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 444 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
446 | 445 |
447 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 446 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
448 file_system_context, url); | 447 file_system_context, url); |
449 file_system_context->operation_runner()->GetMetadata( | 448 file_system_context->operation_runner()->GetMetadata( |
450 url_for_sync, FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | | 449 url_for_sync, FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | |
451 FileSystemOperation::GET_METADATA_FIELD_SIZE | | 450 FileSystemOperation::GET_METADATA_FIELD_SIZE | |
452 FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, | 451 FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, |
453 base::Bind(&LocalFileSyncContext::DidGetFileMetadata, this, callback)); | 452 base::Bind(&LocalFileSyncContext::DidGetFileMetadata, this, callback)); |
454 } | 453 } |
455 | 454 |
456 void LocalFileSyncContext::HasPendingLocalChanges( | 455 void LocalFileSyncContext::HasPendingLocalChanges( |
457 FileSystemContext* file_system_context, | 456 FileSystemContext* file_system_context, |
458 const FileSystemURL& url, | 457 const FileSystemURL& url, |
459 const HasPendingLocalChangeCallback& callback) { | 458 const HasPendingLocalChangeCallback& callback) { |
460 // 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. |
461 DCHECK(file_system_context); | 460 DCHECK(file_system_context); |
462 if (!file_system_context->default_file_task_runner()-> | 461 if (!file_system_context->default_file_task_runner()-> |
463 RunsTasksOnCurrentThread()) { | 462 RunsTasksOnCurrentThread()) { |
464 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 463 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
465 file_system_context->default_file_task_runner()->PostTask( | 464 file_system_context->default_file_task_runner()->PostTask( |
466 FROM_HERE, | 465 FROM_HERE, |
467 base::Bind(&LocalFileSyncContext::HasPendingLocalChanges, this, | 466 base::BindOnce(&LocalFileSyncContext::HasPendingLocalChanges, this, |
468 base::RetainedRef(file_system_context), url, callback)); | 467 base::RetainedRef(file_system_context), url, callback)); |
469 return; | 468 return; |
470 } | 469 } |
471 | 470 |
472 SyncFileSystemBackend* backend = | 471 SyncFileSystemBackend* backend = |
473 SyncFileSystemBackend::GetBackend(file_system_context); | 472 SyncFileSystemBackend::GetBackend(file_system_context); |
474 DCHECK(backend); | 473 DCHECK(backend); |
475 DCHECK(backend->change_tracker()); | 474 DCHECK(backend->change_tracker()); |
476 FileChangeList changes; | 475 FileChangeList changes; |
477 backend->change_tracker()->GetChangesForURL(url, &changes); | 476 backend->change_tracker()->GetChangesForURL(url, &changes); |
478 | 477 |
479 // Fire the callback on UI thread. | 478 // Fire the callback on UI thread. |
480 ui_task_runner_->PostTask(FROM_HERE, | 479 ui_task_runner_->PostTask( |
481 base::Bind(callback, | 480 FROM_HERE, base::BindOnce(callback, SYNC_STATUS_OK, !changes.empty())); |
482 SYNC_STATUS_OK, | |
483 !changes.empty())); | |
484 } | 481 } |
485 | 482 |
486 void LocalFileSyncContext::PromoteDemotedChanges( | 483 void LocalFileSyncContext::PromoteDemotedChanges( |
487 const GURL& origin, | 484 const GURL& origin, |
488 storage::FileSystemContext* file_system_context, | 485 storage::FileSystemContext* file_system_context, |
489 const base::Closure& callback) { | 486 const base::Closure& callback) { |
490 // 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. |
491 DCHECK(file_system_context); | 488 DCHECK(file_system_context); |
492 if (!file_system_context->default_file_task_runner()-> | 489 if (!file_system_context->default_file_task_runner()-> |
493 RunsTasksOnCurrentThread()) { | 490 RunsTasksOnCurrentThread()) { |
494 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 491 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
495 file_system_context->default_file_task_runner()->PostTask( | 492 file_system_context->default_file_task_runner()->PostTask( |
496 FROM_HERE, | 493 FROM_HERE, |
497 base::Bind(&LocalFileSyncContext::PromoteDemotedChanges, this, origin, | 494 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChanges, this, |
498 base::RetainedRef(file_system_context), callback)); | 495 origin, base::RetainedRef(file_system_context), |
| 496 callback)); |
499 return; | 497 return; |
500 } | 498 } |
501 | 499 |
502 SyncFileSystemBackend* backend = | 500 SyncFileSystemBackend* backend = |
503 SyncFileSystemBackend::GetBackend(file_system_context); | 501 SyncFileSystemBackend::GetBackend(file_system_context); |
504 DCHECK(backend); | 502 DCHECK(backend); |
505 DCHECK(backend->change_tracker()); | 503 DCHECK(backend->change_tracker()); |
506 if (!backend->change_tracker()->PromoteDemotedChanges()) { | 504 if (!backend->change_tracker()->PromoteDemotedChanges()) { |
507 ui_task_runner_->PostTask(FROM_HERE, callback); | 505 ui_task_runner_->PostTask(FROM_HERE, callback); |
508 return; | 506 return; |
509 } | 507 } |
510 | 508 |
511 io_task_runner_->PostTask( | 509 io_task_runner_->PostTask( |
512 FROM_HERE, | 510 FROM_HERE, base::BindOnce(&LocalFileSyncContext::UpdateChangesForOrigin, |
513 base::Bind(&LocalFileSyncContext::UpdateChangesForOrigin, | 511 this, origin, callback)); |
514 this, origin, callback)); | |
515 } | 512 } |
516 | 513 |
517 void LocalFileSyncContext::UpdateChangesForOrigin( | 514 void LocalFileSyncContext::UpdateChangesForOrigin( |
518 const GURL& origin, | 515 const GURL& origin, |
519 const base::Closure& callback) { | 516 const base::Closure& callback) { |
520 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 517 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
521 if (shutdown_on_io_) | 518 if (shutdown_on_io_) |
522 return; | 519 return; |
523 origins_with_pending_changes_.insert(origin); | 520 origins_with_pending_changes_.insert(origin); |
524 ScheduleNotifyChangesUpdatedOnIOThread(callback); | 521 ScheduleNotifyChangesUpdatedOnIOThread(callback); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 void LocalFileSyncContext::NotifyAvailableChangesOnIOThread() { | 585 void LocalFileSyncContext::NotifyAvailableChangesOnIOThread() { |
589 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 586 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
590 if (shutdown_on_io_) | 587 if (shutdown_on_io_) |
591 return; | 588 return; |
592 | 589 |
593 std::vector<base::Closure> completion_callbacks; | 590 std::vector<base::Closure> completion_callbacks; |
594 completion_callbacks.swap(pending_completion_callbacks_); | 591 completion_callbacks.swap(pending_completion_callbacks_); |
595 | 592 |
596 ui_task_runner_->PostTask( | 593 ui_task_runner_->PostTask( |
597 FROM_HERE, | 594 FROM_HERE, |
598 base::Bind(&LocalFileSyncContext::NotifyAvailableChanges, | 595 base::BindOnce(&LocalFileSyncContext::NotifyAvailableChanges, this, |
599 this, origins_with_pending_changes_, | 596 origins_with_pending_changes_, completion_callbacks)); |
600 completion_callbacks)); | |
601 last_notified_changes_ = base::Time::Now(); | 597 last_notified_changes_ = base::Time::Now(); |
602 origins_with_pending_changes_.clear(); | 598 origins_with_pending_changes_.clear(); |
603 } | 599 } |
604 | 600 |
605 void LocalFileSyncContext::NotifyAvailableChanges( | 601 void LocalFileSyncContext::NotifyAvailableChanges( |
606 const std::set<GURL>& origins, | 602 const std::set<GURL>& origins, |
607 const std::vector<base::Closure>& callbacks) { | 603 const std::vector<base::Closure>& callbacks) { |
608 for (auto& observer : origin_change_observers_) | 604 for (auto& observer : origin_change_observers_) |
609 observer.OnChangesAvailableInOrigins(origins); | 605 observer.OnChangesAvailableInOrigins(origins); |
610 for (const auto& callback : callbacks) | 606 for (const auto& callback : callbacks) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 base::File::FILE_OK); | 725 base::File::FILE_OK); |
730 } | 726 } |
731 | 727 |
732 void LocalFileSyncContext::DidInitialize( | 728 void LocalFileSyncContext::DidInitialize( |
733 const GURL& source_url, | 729 const GURL& source_url, |
734 FileSystemContext* file_system_context, | 730 FileSystemContext* file_system_context, |
735 SyncStatusCode status) { | 731 SyncStatusCode status) { |
736 if (!ui_task_runner_->RunsTasksOnCurrentThread()) { | 732 if (!ui_task_runner_->RunsTasksOnCurrentThread()) { |
737 ui_task_runner_->PostTask( | 733 ui_task_runner_->PostTask( |
738 FROM_HERE, | 734 FROM_HERE, |
739 base::Bind(&LocalFileSyncContext::DidInitialize, this, source_url, | 735 base::BindOnce(&LocalFileSyncContext::DidInitialize, this, source_url, |
740 base::RetainedRef(file_system_context), status)); | 736 base::RetainedRef(file_system_context), status)); |
741 return; | 737 return; |
742 } | 738 } |
743 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 739 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
744 DCHECK(!base::ContainsKey(file_system_contexts_, file_system_context)); | 740 DCHECK(!base::ContainsKey(file_system_contexts_, file_system_context)); |
745 DCHECK(base::ContainsKey(pending_initialize_callbacks_, file_system_context)); | 741 DCHECK(base::ContainsKey(pending_initialize_callbacks_, file_system_context)); |
746 | 742 |
747 SyncFileSystemBackend* backend = | 743 SyncFileSystemBackend* backend = |
748 SyncFileSystemBackend::GetBackend(file_system_context); | 744 SyncFileSystemBackend::GetBackend(file_system_context); |
749 DCHECK(backend); | 745 DCHECK(backend); |
750 DCHECK(backend->change_tracker()); | 746 DCHECK(backend->change_tracker()); |
751 | 747 |
752 file_system_contexts_.insert(file_system_context); | 748 file_system_contexts_.insert(file_system_context); |
753 | 749 |
754 StatusCallbackQueue& callback_queue = | 750 StatusCallbackQueue& callback_queue = |
755 pending_initialize_callbacks_[file_system_context]; | 751 pending_initialize_callbacks_[file_system_context]; |
756 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); | 752 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); |
757 iter != callback_queue.end(); ++iter) { | 753 iter != callback_queue.end(); ++iter) { |
758 ui_task_runner_->PostTask(FROM_HERE, base::Bind(*iter, status)); | 754 ui_task_runner_->PostTask(FROM_HERE, base::BindOnce(*iter, status)); |
759 } | 755 } |
760 pending_initialize_callbacks_.erase(file_system_context); | 756 pending_initialize_callbacks_.erase(file_system_context); |
761 } | 757 } |
762 | 758 |
763 std::unique_ptr<LocalFileSyncContext::FileSystemURLQueue> | 759 std::unique_ptr<LocalFileSyncContext::FileSystemURLQueue> |
764 LocalFileSyncContext::GetNextURLsForSyncOnFileThread( | 760 LocalFileSyncContext::GetNextURLsForSyncOnFileThread( |
765 FileSystemContext* file_system_context) { | 761 FileSystemContext* file_system_context) { |
766 DCHECK(file_system_context); | 762 DCHECK(file_system_context); |
767 DCHECK(file_system_context->default_file_task_runner()-> | 763 DCHECK(file_system_context->default_file_task_runner()-> |
768 RunsTasksOnCurrentThread()); | 764 RunsTasksOnCurrentThread()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 FileSystemContext* file_system_context, | 830 FileSystemContext* file_system_context, |
835 const FileSystemURL& url) { | 831 const FileSystemURL& url) { |
836 DCHECK(file_system_context); | 832 DCHECK(file_system_context); |
837 if (!file_system_context->default_file_task_runner()-> | 833 if (!file_system_context->default_file_task_runner()-> |
838 RunsTasksOnCurrentThread()) { | 834 RunsTasksOnCurrentThread()) { |
839 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 835 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
840 if (shutdown_on_ui_) | 836 if (shutdown_on_ui_) |
841 return; | 837 return; |
842 file_system_context->default_file_task_runner()->PostTask( | 838 file_system_context->default_file_task_runner()->PostTask( |
843 FROM_HERE, | 839 FROM_HERE, |
844 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURL, this, | 840 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChangesForURL, this, |
845 base::RetainedRef(file_system_context), url)); | 841 base::RetainedRef(file_system_context), url)); |
846 return; | 842 return; |
847 } | 843 } |
848 | 844 |
849 SyncFileSystemBackend* backend = | 845 SyncFileSystemBackend* backend = |
850 SyncFileSystemBackend::GetBackend(file_system_context); | 846 SyncFileSystemBackend::GetBackend(file_system_context); |
851 DCHECK(backend); | 847 DCHECK(backend); |
852 DCHECK(backend->change_tracker()); | 848 DCHECK(backend->change_tracker()); |
853 backend->change_tracker()->PromoteDemotedChangesForURL(url); | 849 backend->change_tracker()->PromoteDemotedChangesForURL(url); |
854 } | 850 } |
855 | 851 |
856 void LocalFileSyncContext::PromoteDemotedChangesForURLs( | 852 void LocalFileSyncContext::PromoteDemotedChangesForURLs( |
857 FileSystemContext* file_system_context, | 853 FileSystemContext* file_system_context, |
858 std::unique_ptr<FileSystemURLQueue> urls) { | 854 std::unique_ptr<FileSystemURLQueue> urls) { |
859 DCHECK(file_system_context); | 855 DCHECK(file_system_context); |
860 if (!file_system_context->default_file_task_runner()-> | 856 if (!file_system_context->default_file_task_runner()-> |
861 RunsTasksOnCurrentThread()) { | 857 RunsTasksOnCurrentThread()) { |
862 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 858 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
863 if (shutdown_on_ui_) | 859 if (shutdown_on_ui_) |
864 return; | 860 return; |
865 file_system_context->default_file_task_runner()->PostTask( | 861 file_system_context->default_file_task_runner()->PostTask( |
866 FROM_HERE, | 862 FROM_HERE, |
867 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURLs, this, | 863 base::BindOnce(&LocalFileSyncContext::PromoteDemotedChangesForURLs, |
868 base::RetainedRef(file_system_context), | 864 this, base::RetainedRef(file_system_context), |
869 base::Passed(&urls))); | 865 base::Passed(&urls))); |
870 return; | 866 return; |
871 } | 867 } |
872 | 868 |
873 for (FileSystemURLQueue::iterator iter = urls->begin(); | 869 for (FileSystemURLQueue::iterator iter = urls->begin(); |
874 iter != urls->end(); ++iter) | 870 iter != urls->end(); ++iter) |
875 PromoteDemotedChangesForURL(file_system_context, *iter); | 871 PromoteDemotedChangesForURL(file_system_context, *iter); |
876 } | 872 } |
877 | 873 |
878 void LocalFileSyncContext::DidGetWritingStatusForSync( | 874 void LocalFileSyncContext::DidGetWritingStatusForSync( |
879 FileSystemContext* file_system_context, | 875 FileSystemContext* file_system_context, |
880 SyncStatusCode status, | 876 SyncStatusCode status, |
881 const FileSystemURL& url, | 877 const FileSystemURL& url, |
882 SyncMode sync_mode, | 878 SyncMode sync_mode, |
883 const LocalFileSyncInfoCallback& callback) { | 879 const LocalFileSyncInfoCallback& callback) { |
884 // 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. |
885 DCHECK(file_system_context); | 881 DCHECK(file_system_context); |
886 if (!file_system_context->default_file_task_runner()-> | 882 if (!file_system_context->default_file_task_runner()-> |
887 RunsTasksOnCurrentThread()) { | 883 RunsTasksOnCurrentThread()) { |
888 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 884 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
889 if (shutdown_on_ui_) { | 885 if (shutdown_on_ui_) { |
890 callback.Run( | 886 callback.Run( |
891 SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); | 887 SYNC_STATUS_ABORT, LocalFileSyncInfo(), storage::ScopedFile()); |
892 return; | 888 return; |
893 } | 889 } |
894 file_system_context->default_file_task_runner()->PostTask( | 890 file_system_context->default_file_task_runner()->PostTask( |
895 FROM_HERE, base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, | 891 FROM_HERE, |
896 this, base::RetainedRef(file_system_context), | 892 base::BindOnce(&LocalFileSyncContext::DidGetWritingStatusForSync, this, |
897 status, url, sync_mode, callback)); | 893 base::RetainedRef(file_system_context), status, url, |
| 894 sync_mode, callback)); |
898 return; | 895 return; |
899 } | 896 } |
900 | 897 |
901 SyncFileSystemBackend* backend = | 898 SyncFileSystemBackend* backend = |
902 SyncFileSystemBackend::GetBackend(file_system_context); | 899 SyncFileSystemBackend::GetBackend(file_system_context); |
903 DCHECK(backend); | 900 DCHECK(backend); |
904 DCHECK(backend->change_tracker()); | 901 DCHECK(backend->change_tracker()); |
905 FileChangeList changes; | 902 FileChangeList changes; |
906 backend->change_tracker()->GetChangesForURL(url, &changes); | 903 backend->change_tracker()->GetChangesForURL(url, &changes); |
907 | 904 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 // changes to both mirror and original records during sync), so that | 954 // changes to both mirror and original records during sync), so that |
958 // we can reset to the mirror when the sync succeeds. | 955 // we can reset to the mirror when the sync succeeds. |
959 backend->change_tracker()->CreateFreshMirrorForURL(url); | 956 backend->change_tracker()->CreateFreshMirrorForURL(url); |
960 } | 957 } |
961 | 958 |
962 // 'Unlock' the file for snapshot sync. | 959 // 'Unlock' the file for snapshot sync. |
963 // (But keep it in writing status so that no other sync starts on | 960 // (But keep it in writing status so that no other sync starts on |
964 // the same URL) | 961 // the same URL) |
965 io_task_runner_->PostTask( | 962 io_task_runner_->PostTask( |
966 FROM_HERE, | 963 FROM_HERE, |
967 base::Bind(&LocalFileSyncContext::ClearSyncFlagOnIOThread, | 964 base::BindOnce(&LocalFileSyncContext::ClearSyncFlagOnIOThread, this, |
968 this, url, true /* for_snapshot_sync */)); | 965 url, true /* for_snapshot_sync */)); |
969 } | 966 } |
970 | 967 |
971 ui_task_runner_->PostTask(FROM_HERE, | 968 ui_task_runner_->PostTask(FROM_HERE, |
972 base::Bind(callback, status, sync_file_info, | 969 base::BindOnce(callback, status, sync_file_info, |
973 base::Passed(&snapshot))); | 970 base::Passed(&snapshot))); |
974 } | 971 } |
975 | 972 |
976 void LocalFileSyncContext::ClearSyncFlagOnIOThread( | 973 void LocalFileSyncContext::ClearSyncFlagOnIOThread( |
977 const FileSystemURL& url, | 974 const FileSystemURL& url, |
978 bool for_snapshot_sync) { | 975 bool for_snapshot_sync) { |
979 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 976 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
980 if (shutdown_on_io_) | 977 if (shutdown_on_io_) |
981 return; | 978 return; |
982 sync_status()->EndSyncing(url); | 979 sync_status()->EndSyncing(url); |
983 | 980 |
(...skipping 19 matching lines...) Expand all Loading... |
1003 } | 1000 } |
1004 | 1001 |
1005 void LocalFileSyncContext::DidApplyRemoteChange( | 1002 void LocalFileSyncContext::DidApplyRemoteChange( |
1006 const FileSystemURL& url, | 1003 const FileSystemURL& url, |
1007 const SyncStatusCallback& callback_on_ui, | 1004 const SyncStatusCallback& callback_on_ui, |
1008 base::File::Error file_error) { | 1005 base::File::Error file_error) { |
1009 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 1006 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
1010 root_delete_helper_.reset(); | 1007 root_delete_helper_.reset(); |
1011 ui_task_runner_->PostTask( | 1008 ui_task_runner_->PostTask( |
1012 FROM_HERE, | 1009 FROM_HERE, |
1013 base::Bind(callback_on_ui, FileErrorToSyncStatusCode(file_error))); | 1010 base::BindOnce(callback_on_ui, FileErrorToSyncStatusCode(file_error))); |
1014 } | 1011 } |
1015 | 1012 |
1016 void LocalFileSyncContext::DidGetFileMetadata( | 1013 void LocalFileSyncContext::DidGetFileMetadata( |
1017 const SyncFileMetadataCallback& callback, | 1014 const SyncFileMetadataCallback& callback, |
1018 base::File::Error file_error, | 1015 base::File::Error file_error, |
1019 const base::File::Info& file_info) { | 1016 const base::File::Info& file_info) { |
1020 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 1017 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
1021 SyncFileMetadata metadata; | 1018 SyncFileMetadata metadata; |
1022 if (file_error == base::File::FILE_OK) { | 1019 if (file_error == base::File::FILE_OK) { |
1023 metadata.file_type = file_info.is_directory ? | 1020 metadata.file_type = file_info.is_directory ? |
1024 SYNC_FILE_TYPE_DIRECTORY : SYNC_FILE_TYPE_FILE; | 1021 SYNC_FILE_TYPE_DIRECTORY : SYNC_FILE_TYPE_FILE; |
1025 metadata.size = file_info.size; | 1022 metadata.size = file_info.size; |
1026 metadata.last_modified = file_info.last_modified; | 1023 metadata.last_modified = file_info.last_modified; |
1027 } | 1024 } |
1028 ui_task_runner_->PostTask( | 1025 ui_task_runner_->PostTask( |
1029 FROM_HERE, | 1026 FROM_HERE, base::BindOnce(callback, FileErrorToSyncStatusCode(file_error), |
1030 base::Bind(callback, FileErrorToSyncStatusCode(file_error), metadata)); | 1027 metadata)); |
1031 } | 1028 } |
1032 | 1029 |
1033 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() { | 1030 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() { |
1034 if (mock_notify_changes_duration_in_sec_ >= 0) | 1031 if (mock_notify_changes_duration_in_sec_ >= 0) |
1035 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_); | 1032 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_); |
1036 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec); | 1033 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec); |
1037 } | 1034 } |
1038 | 1035 |
1039 void LocalFileSyncContext::DidCreateDirectoryForCopyIn( | 1036 void LocalFileSyncContext::DidCreateDirectoryForCopyIn( |
1040 FileSystemContext* file_system_context, | 1037 FileSystemContext* file_system_context, |
1041 const base::FilePath& local_path, | 1038 const base::FilePath& local_path, |
1042 const FileSystemURL& dest_url, | 1039 const FileSystemURL& dest_url, |
1043 const StatusCallback& callback, | 1040 const StatusCallback& callback, |
1044 base::File::Error error) { | 1041 base::File::Error error) { |
1045 if (error != base::File::FILE_OK) { | 1042 if (error != base::File::FILE_OK) { |
1046 callback.Run(error); | 1043 callback.Run(error); |
1047 return; | 1044 return; |
1048 } | 1045 } |
1049 | 1046 |
1050 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 1047 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
1051 file_system_context, dest_url); | 1048 file_system_context, dest_url); |
1052 file_system_context->operation_runner()->CopyInForeignFile( | 1049 file_system_context->operation_runner()->CopyInForeignFile( |
1053 local_path, url_for_sync, callback); | 1050 local_path, url_for_sync, callback); |
1054 } | 1051 } |
1055 | 1052 |
1056 } // namespace sync_file_system | 1053 } // namespace sync_file_system |
OLD | NEW |