| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/fileapi/syncable/local_file_sync_context.h" | 5 #include "webkit/fileapi/syncable/local_file_sync_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 make_scoped_refptr(file_system_context), | 196 make_scoped_refptr(file_system_context), |
| 197 change, local_path, url, callback)); | 197 change, local_path, url, callback)); |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 200 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 201 DCHECK(!sync_status()->IsWritable(url)); | 201 DCHECK(!sync_status()->IsWritable(url)); |
| 202 DCHECK(!sync_status()->IsWriting(url)); | 202 DCHECK(!sync_status()->IsWriting(url)); |
| 203 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( | 203 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( |
| 204 file_system_context); | 204 file_system_context); |
| 205 DCHECK(operation); | 205 DCHECK(operation); |
| 206 FileSystemOperation::StatusCallback operation_callback = | 206 |
| 207 base::Bind(&LocalFileSyncContext::DidApplyRemoteChange, | 207 FileSystemOperation::StatusCallback operation_callback; |
| 208 this, url, callback); | 208 if (change.change() == FileChange::FILE_CHANGE_ADD_OR_UPDATE) { |
| 209 switch (change.change()) { | 209 operation_callback = base::Bind( |
| 210 case FileChange::FILE_CHANGE_ADD_OR_UPDATE: | 210 &LocalFileSyncContext::DidRemoveExistingEntryForApplyRemoteChange, |
| 211 switch (change.file_type()) { | 211 this, |
| 212 case SYNC_FILE_TYPE_FILE: { | 212 make_scoped_refptr(file_system_context), |
| 213 DCHECK(!local_path.empty()); | 213 change, |
| 214 base::FilePath dir_path = | 214 local_path, |
| 215 fileapi::VirtualPath::DirName(url.path()); | 215 url, |
| 216 if (dir_path.empty() || | 216 callback); |
| 217 fileapi::VirtualPath::DirName(dir_path) == dir_path) { | 217 } else { |
| 218 // Copying into the root directory. | 218 DCHECK_EQ(FileChange::FILE_CHANGE_DELETE, change.change()); |
| 219 operation->CopyInForeignFile(local_path, url, operation_callback); | 219 operation_callback = base::Bind( |
| 220 } else { | 220 &LocalFileSyncContext::DidApplyRemoteChange, this, url, callback); |
| 221 FileSystemURL dir_url = | 221 } |
| 222 file_system_context->CreateCrackedFileSystemURL( | 222 operation->Remove(url, true /* recursive */, operation_callback); |
| 223 url.origin(), url.mount_type(), | 223 } |
| 224 fileapi::VirtualPath::DirName(url.virtual_path())); | 224 |
| 225 operation->CreateDirectory( | 225 void LocalFileSyncContext::DidRemoveExistingEntryForApplyRemoteChange( |
| 226 dir_url, false /* exclusive */, true /* recursive */, | 226 FileSystemContext* file_system_context, |
| 227 base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn, | 227 const FileChange& change, |
| 228 this, make_scoped_refptr(file_system_context), | 228 const base::FilePath& local_path, |
| 229 local_path, url, operation_callback)); | 229 const FileSystemURL& url, |
| 230 } | 230 const SyncStatusCallback& callback, |
| 231 break; | 231 base::PlatformFileError error) { |
| 232 } | 232 // Remove() may fail if the target entry does not exist (which is ok), |
| 233 case SYNC_FILE_TYPE_DIRECTORY: | 233 // so we ignore |error| here. |
| 234 operation->CreateDirectory( | 234 |
| 235 url, false /* exclusive */, true /* recursive */, | 235 if (!sync_status()) { |
| 236 operation_callback); | 236 callback.Run(SYNC_FILE_ERROR_ABORT); |
| 237 break; | 237 return; |
| 238 case SYNC_FILE_TYPE_UNKNOWN: | 238 } |
| 239 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; | 239 |
| 240 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 241 DCHECK(!sync_status()->IsWritable(url)); |
| 242 DCHECK(!sync_status()->IsWriting(url)); |
| 243 LocalFileSystemOperation* operation = |
| 244 CreateFileSystemOperationForSync(file_system_context); |
| 245 DCHECK(operation); |
| 246 FileSystemOperation::StatusCallback operation_callback = base::Bind( |
| 247 &LocalFileSyncContext::DidApplyRemoteChange, this, url, callback); |
| 248 |
| 249 DCHECK_EQ(FileChange::FILE_CHANGE_ADD_OR_UPDATE, change.change()); |
| 250 switch (change.file_type()) { |
| 251 case SYNC_FILE_TYPE_FILE: { |
| 252 DCHECK(!local_path.empty()); |
| 253 base::FilePath dir_path = fileapi::VirtualPath::DirName(url.path()); |
| 254 if (dir_path.empty() || |
| 255 fileapi::VirtualPath::DirName(dir_path) == dir_path) { |
| 256 // Copying into the root directory. |
| 257 operation->CopyInForeignFile(local_path, url, operation_callback); |
| 258 } else { |
| 259 FileSystemURL dir_url = file_system_context->CreateCrackedFileSystemURL( |
| 260 url.origin(), |
| 261 url.mount_type(), |
| 262 fileapi::VirtualPath::DirName(url.virtual_path())); |
| 263 operation->CreateDirectory( |
| 264 dir_url, |
| 265 false /* exclusive */, |
| 266 true /* recursive */, |
| 267 base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn, |
| 268 this, |
| 269 make_scoped_refptr(file_system_context), |
| 270 local_path, |
| 271 url, |
| 272 operation_callback)); |
| 240 } | 273 } |
| 241 break; | 274 break; |
| 242 case FileChange::FILE_CHANGE_DELETE: | 275 } |
| 243 operation->Remove(url, true /* recursive */, operation_callback); | 276 case SYNC_FILE_TYPE_DIRECTORY: |
| 277 operation->CreateDirectory( |
| 278 url, false /* exclusive */, true /* recursive */, operation_callback); |
| 244 break; | 279 break; |
| 280 case SYNC_FILE_TYPE_UNKNOWN: |
| 281 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; |
| 245 } | 282 } |
| 246 } | 283 } |
| 247 | 284 |
| 248 void LocalFileSyncContext::RecordFakeLocalChange( | 285 void LocalFileSyncContext::RecordFakeLocalChange( |
| 249 FileSystemContext* file_system_context, | 286 FileSystemContext* file_system_context, |
| 250 const FileSystemURL& url, | 287 const FileSystemURL& url, |
| 251 const FileChange& change, | 288 const FileChange& change, |
| 252 const SyncStatusCallback& callback) { | 289 const SyncStatusCallback& callback) { |
| 253 // This is called on UI thread and to be relayed to FILE thread. | 290 // This is called on UI thread and to be relayed to FILE thread. |
| 254 DCHECK(file_system_context); | 291 DCHECK(file_system_context); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 return; | 727 return; |
| 691 } | 728 } |
| 692 | 729 |
| 693 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( | 730 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( |
| 694 file_system_context); | 731 file_system_context); |
| 695 DCHECK(operation); | 732 DCHECK(operation); |
| 696 operation->CopyInForeignFile(local_path, dest_url, callback); | 733 operation->CopyInForeignFile(local_path, dest_url, callback); |
| 697 } | 734 } |
| 698 | 735 |
| 699 } // namespace sync_file_system | 736 } // namespace sync_file_system |
| OLD | NEW |