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

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: buildfix 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.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 // Ignore |error| on this deletion.
kinuko 2013/05/01 05:05:41 nit: It's slightly confusing what this comment is
tzik 2013/05/01 05:45:21 Done.
233 case SYNC_FILE_TYPE_DIRECTORY: 233
234 operation->CreateDirectory( 234 if (!sync_status()) {
235 url, false /* exclusive */, true /* recursive */, 235 callback.Run(SYNC_FILE_ERROR_ABORT);
236 operation_callback); 236 return;
237 break; 237 }
238 case SYNC_FILE_TYPE_UNKNOWN: 238
239 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; 239 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
240 DCHECK(!sync_status()->IsWritable(url));
241 DCHECK(!sync_status()->IsWriting(url));
242 LocalFileSystemOperation* operation =
243 CreateFileSystemOperationForSync(file_system_context);
244 DCHECK(operation);
245 FileSystemOperation::StatusCallback operation_callback = base::Bind(
246 &LocalFileSyncContext::DidApplyRemoteChange, this, url, callback);
247
248 DCHECK_EQ(FileChange::FILE_CHANGE_ADD_OR_UPDATE, change.change());
249 switch (change.file_type()) {
250 case SYNC_FILE_TYPE_FILE: {
251 DCHECK(!local_path.empty());
252 base::FilePath dir_path = fileapi::VirtualPath::DirName(url.path());
253 if (dir_path.empty() ||
254 fileapi::VirtualPath::DirName(dir_path) == dir_path) {
255 // Copying into the root directory.
256 operation->CopyInForeignFile(local_path, url, operation_callback);
257 } else {
258 FileSystemURL dir_url = file_system_context->CreateCrackedFileSystemURL(
259 url.origin(),
260 url.mount_type(),
261 fileapi::VirtualPath::DirName(url.virtual_path()));
262 operation->CreateDirectory(
263 dir_url,
264 false /* exclusive */,
265 true /* recursive */,
266 base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn,
267 this,
268 make_scoped_refptr(file_system_context),
269 local_path,
270 url,
271 operation_callback));
240 } 272 }
241 break; 273 break;
242 case FileChange::FILE_CHANGE_DELETE: 274 }
243 operation->Remove(url, true /* recursive */, operation_callback); 275 case SYNC_FILE_TYPE_DIRECTORY:
276 operation->CreateDirectory(
277 url, false /* exclusive */, true /* recursive */, operation_callback);
244 break; 278 break;
279 case SYNC_FILE_TYPE_UNKNOWN:
280 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change";
245 } 281 }
246 } 282 }
247 283
248 void LocalFileSyncContext::RecordFakeLocalChange( 284 void LocalFileSyncContext::RecordFakeLocalChange(
249 FileSystemContext* file_system_context, 285 FileSystemContext* file_system_context,
250 const FileSystemURL& url, 286 const FileSystemURL& url,
251 const FileChange& change, 287 const FileChange& change,
252 const SyncStatusCallback& callback) { 288 const SyncStatusCallback& callback) {
253 // This is called on UI thread and to be relayed to FILE thread. 289 // This is called on UI thread and to be relayed to FILE thread.
254 DCHECK(file_system_context); 290 DCHECK(file_system_context);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 return; 726 return;
691 } 727 }
692 728
693 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( 729 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync(
694 file_system_context); 730 file_system_context);
695 DCHECK(operation); 731 DCHECK(operation);
696 operation->CopyInForeignFile(local_path, dest_url, callback); 732 operation->CopyInForeignFile(local_path, dest_url, callback);
697 } 733 }
698 734
699 } // namespace sync_file_system 735 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « webkit/fileapi/syncable/local_file_sync_context.h ('k') | webkit/fileapi/syncable/local_file_sync_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698