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

Side by Side Diff: chrome/browser/sync_file_system/local/syncable_file_system_operation.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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 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/syncable_file_system_operation.h " 5 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h "
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" 8 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
9 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 9 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
10 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h " 10 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h "
11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
12 #include "net/url_request/url_request.h" 12 #include "net/url_request/url_request.h"
13 #include "webkit/browser/fileapi/file_system_context.h" 13 #include "webkit/browser/fileapi/file_system_context.h"
14 #include "webkit/browser/fileapi/file_system_operation.h" 14 #include "webkit/browser/fileapi/file_system_operation.h"
15 #include "webkit/browser/fileapi/file_system_operation_context.h" 15 #include "webkit/browser/fileapi/file_system_operation_context.h"
16 #include "webkit/browser/fileapi/file_system_url.h" 16 #include "webkit/browser/fileapi/file_system_url.h"
17 #include "webkit/browser/fileapi/file_writer_delegate.h" 17 #include "webkit/browser/fileapi/file_writer_delegate.h"
18 #include "webkit/common/blob/shareable_file_reference.h" 18 #include "webkit/common/blob/shareable_file_reference.h"
19 19
20 using fileapi::FileSystemURL; 20 using fileapi::FileSystemURL;
21 21
22 namespace sync_file_system { 22 namespace sync_file_system {
23 23
24 namespace { 24 namespace {
25 25
26 void WriteCallbackAdapter( 26 void WriteCallbackAdapter(
27 const SyncableFileSystemOperation::WriteCallback& callback, 27 const SyncableFileSystemOperation::WriteCallback& callback,
28 base::PlatformFileError status) { 28 base::File::Error status) {
29 callback.Run(status, 0, true); 29 callback.Run(status, 0, true);
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 class SyncableFileSystemOperation::QueueableTask 34 class SyncableFileSystemOperation::QueueableTask
35 : public SyncableFileOperationRunner::Task { 35 : public SyncableFileOperationRunner::Task {
36 public: 36 public:
37 QueueableTask(base::WeakPtr<SyncableFileSystemOperation> operation, 37 QueueableTask(base::WeakPtr<SyncableFileSystemOperation> operation,
38 const base::Closure& task) 38 const base::Closure& task)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 }; 72 };
73 73
74 SyncableFileSystemOperation::~SyncableFileSystemOperation() {} 74 SyncableFileSystemOperation::~SyncableFileSystemOperation() {}
75 75
76 void SyncableFileSystemOperation::CreateFile( 76 void SyncableFileSystemOperation::CreateFile(
77 const FileSystemURL& url, 77 const FileSystemURL& url,
78 bool exclusive, 78 bool exclusive,
79 const StatusCallback& callback) { 79 const StatusCallback& callback) {
80 DCHECK(CalledOnValidThread()); 80 DCHECK(CalledOnValidThread());
81 if (!operation_runner_.get()) { 81 if (!operation_runner_.get()) {
82 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); 82 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
83 return; 83 return;
84 } 84 }
85 DCHECK(operation_runner_.get()); 85 DCHECK(operation_runner_.get());
86 target_paths_.push_back(url); 86 target_paths_.push_back(url);
87 completion_callback_ = callback; 87 completion_callback_ = callback;
88 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 88 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
89 weak_factory_.GetWeakPtr(), 89 weak_factory_.GetWeakPtr(),
90 base::Bind(&FileSystemOperation::CreateFile, 90 base::Bind(&FileSystemOperation::CreateFile,
91 base::Unretained(impl_.get()), 91 base::Unretained(impl_.get()),
92 url, exclusive, 92 url, exclusive,
93 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); 93 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr()))));
94 operation_runner_->PostOperationTask(task.Pass()); 94 operation_runner_->PostOperationTask(task.Pass());
95 } 95 }
96 96
97 void SyncableFileSystemOperation::CreateDirectory( 97 void SyncableFileSystemOperation::CreateDirectory(
98 const FileSystemURL& url, 98 const FileSystemURL& url,
99 bool exclusive, 99 bool exclusive,
100 bool recursive, 100 bool recursive,
101 const StatusCallback& callback) { 101 const StatusCallback& callback) {
102 DCHECK(CalledOnValidThread()); 102 DCHECK(CalledOnValidThread());
103 if (!operation_runner_.get()) { 103 if (!operation_runner_.get()) {
104 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); 104 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
105 return; 105 return;
106 } 106 }
107 if (!is_directory_operation_enabled_) { 107 if (!is_directory_operation_enabled_) {
108 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); 108 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
109 return; 109 return;
110 } 110 }
111 DCHECK(operation_runner_.get()); 111 DCHECK(operation_runner_.get());
112 target_paths_.push_back(url); 112 target_paths_.push_back(url);
113 completion_callback_ = callback; 113 completion_callback_ = callback;
114 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 114 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
115 weak_factory_.GetWeakPtr(), 115 weak_factory_.GetWeakPtr(),
116 base::Bind(&FileSystemOperation::CreateDirectory, 116 base::Bind(&FileSystemOperation::CreateDirectory,
117 base::Unretained(impl_.get()), 117 base::Unretained(impl_.get()),
118 url, exclusive, recursive, 118 url, exclusive, recursive,
119 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); 119 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr()))));
120 operation_runner_->PostOperationTask(task.Pass()); 120 operation_runner_->PostOperationTask(task.Pass());
121 } 121 }
122 122
123 void SyncableFileSystemOperation::Copy( 123 void SyncableFileSystemOperation::Copy(
124 const FileSystemURL& src_url, 124 const FileSystemURL& src_url,
125 const FileSystemURL& dest_url, 125 const FileSystemURL& dest_url,
126 CopyOrMoveOption option, 126 CopyOrMoveOption option,
127 const CopyProgressCallback& progress_callback, 127 const CopyProgressCallback& progress_callback,
128 const StatusCallback& callback) { 128 const StatusCallback& callback) {
129 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
130 if (!operation_runner_.get()) { 130 if (!operation_runner_.get()) {
131 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); 131 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
132 return; 132 return;
133 } 133 }
134 DCHECK(operation_runner_.get()); 134 DCHECK(operation_runner_.get());
135 target_paths_.push_back(dest_url); 135 target_paths_.push_back(dest_url);
136 completion_callback_ = callback; 136 completion_callback_ = callback;
137 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 137 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
138 weak_factory_.GetWeakPtr(), 138 weak_factory_.GetWeakPtr(),
139 base::Bind(&FileSystemOperation::Copy, 139 base::Bind(&FileSystemOperation::Copy,
140 base::Unretained(impl_.get()), 140 base::Unretained(impl_.get()),
141 src_url, dest_url, option, progress_callback, 141 src_url, dest_url, option, progress_callback,
142 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); 142 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr()))));
143 operation_runner_->PostOperationTask(task.Pass()); 143 operation_runner_->PostOperationTask(task.Pass());
144 } 144 }
145 145
146 void SyncableFileSystemOperation::Move( 146 void SyncableFileSystemOperation::Move(
147 const FileSystemURL& src_url, 147 const FileSystemURL& src_url,
148 const FileSystemURL& dest_url, 148 const FileSystemURL& dest_url,
149 CopyOrMoveOption option, 149 CopyOrMoveOption option,
150 const StatusCallback& callback) { 150 const StatusCallback& callback) {
151 DCHECK(CalledOnValidThread()); 151 DCHECK(CalledOnValidThread());
152 if (!operation_runner_.get()) { 152 if (!operation_runner_.get()) {
153 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); 153 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
154 return; 154 return;
155 } 155 }
156 DCHECK(operation_runner_.get()); 156 DCHECK(operation_runner_.get());
157 target_paths_.push_back(src_url); 157 target_paths_.push_back(src_url);
158 target_paths_.push_back(dest_url); 158 target_paths_.push_back(dest_url);
159 completion_callback_ = callback; 159 completion_callback_ = callback;
160 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 160 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
161 weak_factory_.GetWeakPtr(), 161 weak_factory_.GetWeakPtr(),
162 base::Bind(&FileSystemOperation::Move, 162 base::Bind(&FileSystemOperation::Move,
163 base::Unretained(impl_.get()), 163 base::Unretained(impl_.get()),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // directory operation is disabled. (And we should allow this if it's made 195 // directory operation is disabled. (And we should allow this if it's made
196 // on the root directory) 196 // on the root directory)
197 impl_->ReadDirectory(url, callback); 197 impl_->ReadDirectory(url, callback);
198 } 198 }
199 199
200 void SyncableFileSystemOperation::Remove( 200 void SyncableFileSystemOperation::Remove(
201 const FileSystemURL& url, bool recursive, 201 const FileSystemURL& url, bool recursive,
202 const StatusCallback& callback) { 202 const StatusCallback& callback) {
203 DCHECK(CalledOnValidThread()); 203 DCHECK(CalledOnValidThread());
204 if (!operation_runner_.get()) { 204 if (!operation_runner_.get()) {
205 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); 205 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
206 return; 206 return;
207 } 207 }
208 DCHECK(operation_runner_.get()); 208 DCHECK(operation_runner_.get());
209 target_paths_.push_back(url); 209 target_paths_.push_back(url);
210 completion_callback_ = callback; 210 completion_callback_ = callback;
211 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 211 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
212 weak_factory_.GetWeakPtr(), 212 weak_factory_.GetWeakPtr(),
213 base::Bind(&FileSystemOperation::Remove, 213 base::Bind(&FileSystemOperation::Remove,
214 base::Unretained(impl_.get()), 214 base::Unretained(impl_.get()),
215 url, recursive, 215 url, recursive,
216 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); 216 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr()))));
217 operation_runner_->PostOperationTask(task.Pass()); 217 operation_runner_->PostOperationTask(task.Pass());
218 } 218 }
219 219
220 void SyncableFileSystemOperation::Write( 220 void SyncableFileSystemOperation::Write(
221 const FileSystemURL& url, 221 const FileSystemURL& url,
222 scoped_ptr<fileapi::FileWriterDelegate> writer_delegate, 222 scoped_ptr<fileapi::FileWriterDelegate> writer_delegate,
223 scoped_ptr<net::URLRequest> blob_request, 223 scoped_ptr<net::URLRequest> blob_request,
224 const WriteCallback& callback) { 224 const WriteCallback& callback) {
225 DCHECK(CalledOnValidThread()); 225 DCHECK(CalledOnValidThread());
226 if (!operation_runner_.get()) { 226 if (!operation_runner_.get()) {
227 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, 0, true); 227 callback.Run(base::File::FILE_ERROR_NOT_FOUND, 0, true);
228 return; 228 return;
229 } 229 }
230 DCHECK(operation_runner_.get()); 230 DCHECK(operation_runner_.get());
231 target_paths_.push_back(url); 231 target_paths_.push_back(url);
232 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback); 232 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback);
233 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 233 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
234 weak_factory_.GetWeakPtr(), 234 weak_factory_.GetWeakPtr(),
235 base::Bind(&FileSystemOperation::Write, 235 base::Bind(&FileSystemOperation::Write,
236 base::Unretained(impl_.get()), 236 base::Unretained(impl_.get()),
237 url, 237 url,
238 base::Passed(&writer_delegate), 238 base::Passed(&writer_delegate),
239 base::Passed(&blob_request), 239 base::Passed(&blob_request),
240 base::Bind(&self::DidWrite, weak_factory_.GetWeakPtr(), 240 base::Bind(&self::DidWrite, weak_factory_.GetWeakPtr(),
241 callback)))); 241 callback))));
242 operation_runner_->PostOperationTask(task.Pass()); 242 operation_runner_->PostOperationTask(task.Pass());
243 } 243 }
244 244
245 void SyncableFileSystemOperation::Truncate( 245 void SyncableFileSystemOperation::Truncate(
246 const FileSystemURL& url, int64 length, 246 const FileSystemURL& url, int64 length,
247 const StatusCallback& callback) { 247 const StatusCallback& callback) {
248 DCHECK(CalledOnValidThread()); 248 DCHECK(CalledOnValidThread());
249 if (!operation_runner_.get()) { 249 if (!operation_runner_.get()) {
250 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); 250 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
251 return; 251 return;
252 } 252 }
253 DCHECK(operation_runner_.get()); 253 DCHECK(operation_runner_.get());
254 target_paths_.push_back(url); 254 target_paths_.push_back(url);
255 completion_callback_ = callback; 255 completion_callback_ = callback;
256 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 256 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
257 weak_factory_.GetWeakPtr(), 257 weak_factory_.GetWeakPtr(),
258 base::Bind(&FileSystemOperation::Truncate, 258 base::Bind(&FileSystemOperation::Truncate,
259 base::Unretained(impl_.get()), 259 base::Unretained(impl_.get()),
260 url, length, 260 url, length,
(...skipping 29 matching lines...) Expand all
290 DCHECK(CalledOnValidThread()); 290 DCHECK(CalledOnValidThread());
291 impl_->CreateSnapshotFile(path, callback); 291 impl_->CreateSnapshotFile(path, callback);
292 } 292 }
293 293
294 void SyncableFileSystemOperation::CopyInForeignFile( 294 void SyncableFileSystemOperation::CopyInForeignFile(
295 const base::FilePath& src_local_disk_path, 295 const base::FilePath& src_local_disk_path,
296 const FileSystemURL& dest_url, 296 const FileSystemURL& dest_url,
297 const StatusCallback& callback) { 297 const StatusCallback& callback) {
298 DCHECK(CalledOnValidThread()); 298 DCHECK(CalledOnValidThread());
299 if (!operation_runner_.get()) { 299 if (!operation_runner_.get()) {
300 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); 300 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
301 return; 301 return;
302 } 302 }
303 DCHECK(operation_runner_.get()); 303 DCHECK(operation_runner_.get());
304 target_paths_.push_back(dest_url); 304 target_paths_.push_back(dest_url);
305 completion_callback_ = callback; 305 completion_callback_ = callback;
306 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( 306 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask(
307 weak_factory_.GetWeakPtr(), 307 weak_factory_.GetWeakPtr(),
308 base::Bind(&FileSystemOperation::CopyInForeignFile, 308 base::Bind(&FileSystemOperation::CopyInForeignFile,
309 base::Unretained(impl_.get()), 309 base::Unretained(impl_.get()),
310 src_local_disk_path, dest_url, 310 src_local_disk_path, dest_url,
(...skipping 27 matching lines...) Expand all
338 338
339 void SyncableFileSystemOperation::MoveFileLocal( 339 void SyncableFileSystemOperation::MoveFileLocal(
340 const FileSystemURL& src_url, 340 const FileSystemURL& src_url,
341 const FileSystemURL& dest_url, 341 const FileSystemURL& dest_url,
342 CopyOrMoveOption option, 342 CopyOrMoveOption option,
343 const StatusCallback& callback) { 343 const StatusCallback& callback) {
344 DCHECK(CalledOnValidThread()); 344 DCHECK(CalledOnValidThread());
345 impl_->MoveFileLocal(src_url, dest_url, option, callback); 345 impl_->MoveFileLocal(src_url, dest_url, option, callback);
346 } 346 }
347 347
348 base::PlatformFileError SyncableFileSystemOperation::SyncGetPlatformPath( 348 base::File::Error SyncableFileSystemOperation::SyncGetPlatformPath(
349 const FileSystemURL& url, 349 const FileSystemURL& url,
350 base::FilePath* platform_path) { 350 base::FilePath* platform_path) {
351 return impl_->SyncGetPlatformPath(url, platform_path); 351 return impl_->SyncGetPlatformPath(url, platform_path);
352 } 352 }
353 353
354 SyncableFileSystemOperation::SyncableFileSystemOperation( 354 SyncableFileSystemOperation::SyncableFileSystemOperation(
355 const FileSystemURL& url, 355 const FileSystemURL& url,
356 fileapi::FileSystemContext* file_system_context, 356 fileapi::FileSystemContext* file_system_context,
357 scoped_ptr<fileapi::FileSystemOperationContext> operation_context) 357 scoped_ptr<fileapi::FileSystemOperationContext> operation_context)
358 : url_(url), 358 : url_(url),
359 weak_factory_(this) { 359 weak_factory_(this) {
360 DCHECK(file_system_context); 360 DCHECK(file_system_context);
361 SyncFileSystemBackend* backend = 361 SyncFileSystemBackend* backend =
362 SyncFileSystemBackend::GetBackend(file_system_context); 362 SyncFileSystemBackend::GetBackend(file_system_context);
363 DCHECK(backend); 363 DCHECK(backend);
364 if (!backend->sync_context()) { 364 if (!backend->sync_context()) {
365 // Syncable FileSystem is opened in a file system context which doesn't 365 // Syncable FileSystem is opened in a file system context which doesn't
366 // support (or is not initialized for) the API. 366 // support (or is not initialized for) the API.
367 // Returning here to leave operation_runner_ as NULL. 367 // Returning here to leave operation_runner_ as NULL.
368 return; 368 return;
369 } 369 }
370 impl_.reset(fileapi::FileSystemOperation::Create( 370 impl_.reset(fileapi::FileSystemOperation::Create(
371 url_, file_system_context, operation_context.Pass())); 371 url_, file_system_context, operation_context.Pass()));
372 operation_runner_ = backend->sync_context()->operation_runner(); 372 operation_runner_ = backend->sync_context()->operation_runner();
373 is_directory_operation_enabled_ = IsSyncFSDirectoryOperationEnabled( 373 is_directory_operation_enabled_ = IsSyncFSDirectoryOperationEnabled(
374 url.origin()); 374 url.origin());
375 } 375 }
376 376
377 void SyncableFileSystemOperation::DidFinish(base::PlatformFileError status) { 377 void SyncableFileSystemOperation::DidFinish(base::File::Error status) {
378 DCHECK(CalledOnValidThread()); 378 DCHECK(CalledOnValidThread());
379 DCHECK(!completion_callback_.is_null()); 379 DCHECK(!completion_callback_.is_null());
380 if (operation_runner_.get()) 380 if (operation_runner_.get())
381 operation_runner_->OnOperationCompleted(target_paths_); 381 operation_runner_->OnOperationCompleted(target_paths_);
382 completion_callback_.Run(status); 382 completion_callback_.Run(status);
383 } 383 }
384 384
385 void SyncableFileSystemOperation::DidWrite( 385 void SyncableFileSystemOperation::DidWrite(
386 const WriteCallback& callback, 386 const WriteCallback& callback,
387 base::PlatformFileError result, 387 base::File::Error result,
388 int64 bytes, 388 int64 bytes,
389 bool complete) { 389 bool complete) {
390 DCHECK(CalledOnValidThread()); 390 DCHECK(CalledOnValidThread());
391 if (!complete) { 391 if (!complete) {
392 callback.Run(result, bytes, complete); 392 callback.Run(result, bytes, complete);
393 return; 393 return;
394 } 394 }
395 if (operation_runner_.get()) 395 if (operation_runner_.get())
396 operation_runner_->OnOperationCompleted(target_paths_); 396 operation_runner_->OnOperationCompleted(target_paths_);
397 callback.Run(result, bytes, complete); 397 callback.Run(result, bytes, complete);
398 } 398 }
399 399
400 void SyncableFileSystemOperation::OnCancelled() { 400 void SyncableFileSystemOperation::OnCancelled() {
401 DCHECK(!completion_callback_.is_null()); 401 DCHECK(!completion_callback_.is_null());
402 completion_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT); 402 completion_callback_.Run(base::File::FILE_ERROR_ABORT);
403 } 403 }
404 404
405 } // namespace sync_file_system 405 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698