Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: webkit/fileapi/syncable/local_file_sync_context.cc

Issue 14623008: [SyncFileSystem] Remove existing entry on LocalFileSyncContext::ApplyRemoteChange call. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: testfix Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.virtual_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(), dir_path); 223 }
224 operation->CreateDirectory( 224
225 dir_url, false /* exclusive */, true /* recursive */, 225 void LocalFileSyncContext::DidRemoveExistingEntryForApplyRemoteChange(
226 base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn, 226 FileSystemContext* file_system_context,
227 this, make_scoped_refptr(file_system_context), 227 const FileChange& change,
228 local_path, url, operation_callback)); 228 const base::FilePath& local_path,
229 } 229 const FileSystemURL& url,
230 break; 230 const SyncStatusCallback& callback,
231 } 231 base::PlatformFileError error) {
kinuko 2013/04/30 13:31:09 Can you add a comment about: we intentionally igno
tzik 2013/04/30 13:54:40 Done.
232 case SYNC_FILE_TYPE_DIRECTORY: 232 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
233 operation->CreateDirectory( 233 DCHECK(!sync_status()->IsWritable(url));
234 url, false /* exclusive */, true /* recursive */, 234 DCHECK(!sync_status()->IsWriting(url));
235 operation_callback); 235 LocalFileSystemOperation* operation =
236 break; 236 CreateFileSystemOperationForSync(file_system_context);
237 case SYNC_FILE_TYPE_UNKNOWN: 237 DCHECK(operation);
238 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; 238 FileSystemOperation::StatusCallback operation_callback = base::Bind(
239 &LocalFileSyncContext::DidApplyRemoteChange, this, url, callback);
240
241 DCHECK_EQ(FileChange::FILE_CHANGE_ADD_OR_UPDATE, change.change());
242 switch (change.file_type()) {
243 case SYNC_FILE_TYPE_FILE: {
244 DCHECK(!local_path.empty());
245 base::FilePath dir_path =
246 fileapi::VirtualPath::DirName(url.virtual_path());
247 if (dir_path.empty() ||
248 fileapi::VirtualPath::DirName(dir_path) == dir_path) {
249 // Copying into the root directory.
250 operation->CopyInForeignFile(local_path, url, operation_callback);
251 } else {
252 FileSystemURL dir_url = file_system_context->CreateCrackedFileSystemURL(
253 url.origin(), url.mount_type(), dir_path);
254 operation->CreateDirectory(
255 dir_url,
256 false /* exclusive */,
257 true /* recursive */,
258 base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn,
259 this,
260 make_scoped_refptr(file_system_context),
261 local_path,
262 url,
263 operation_callback));
239 } 264 }
240 break; 265 break;
241 case FileChange::FILE_CHANGE_DELETE: 266 }
242 operation->Remove(url, true /* recursive */, operation_callback); 267 case SYNC_FILE_TYPE_DIRECTORY:
268 operation->CreateDirectory(
269 url, false /* exclusive */, true /* recursive */, operation_callback);
243 break; 270 break;
271 case SYNC_FILE_TYPE_UNKNOWN:
272 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change";
244 } 273 }
245 } 274 }
246 275
247 void LocalFileSyncContext::RecordFakeLocalChange( 276 void LocalFileSyncContext::RecordFakeLocalChange(
248 FileSystemContext* file_system_context, 277 FileSystemContext* file_system_context,
249 const FileSystemURL& url, 278 const FileSystemURL& url,
250 const FileChange& change, 279 const FileChange& change,
251 const SyncStatusCallback& callback) { 280 const SyncStatusCallback& callback) {
252 // This is called on UI thread and to be relayed to FILE thread. 281 // This is called on UI thread and to be relayed to FILE thread.
253 DCHECK(file_system_context); 282 DCHECK(file_system_context);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 return; 718 return;
690 } 719 }
691 720
692 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( 721 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync(
693 file_system_context); 722 file_system_context);
694 DCHECK(operation); 723 DCHECK(operation);
695 operation->CopyInForeignFile(local_path, dest_url, callback); 724 operation->CopyInForeignFile(local_path, dest_url, callback);
696 } 725 }
697 726
698 } // namespace sync_file_system 727 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698