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

Side by Side Diff: webkit/fileapi/local_file_system_operation.cc

Issue 10834021: Outsource FileSystemOperationContext from LocalFileSystemOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix again Created 8 years, 4 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/local_file_system_operation.h" 5 #include "webkit/fileapi/local_file_system_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/sequenced_task_runner.h" 8 #include "base/sequenced_task_runner.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); 167 DCHECK(SetPendingOperationType(kOperationDirectoryExists));
168 168
169 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 169 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
170 if (result != base::PLATFORM_FILE_OK) { 170 if (result != base::PLATFORM_FILE_OK) {
171 callback.Run(result); 171 callback.Run(result);
172 delete this; 172 delete this;
173 return; 173 return;
174 } 174 }
175 175
176 FileSystemFileUtilProxy::GetFileInfo( 176 FileSystemFileUtilProxy::GetFileInfo(
177 &operation_context_, src_util_, url, 177 operation_context_.get(), src_util_, url,
178 base::Bind(&LocalFileSystemOperation::DidDirectoryExists, 178 base::Bind(&LocalFileSystemOperation::DidDirectoryExists,
179 base::Owned(this), callback)); 179 base::Owned(this), callback));
180 } 180 }
181 181
182 void LocalFileSystemOperation::FileExists(const FileSystemURL& url, 182 void LocalFileSystemOperation::FileExists(const FileSystemURL& url,
183 const StatusCallback& callback) { 183 const StatusCallback& callback) {
184 DCHECK(SetPendingOperationType(kOperationFileExists)); 184 DCHECK(SetPendingOperationType(kOperationFileExists));
185 185
186 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 186 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
187 if (result != base::PLATFORM_FILE_OK) { 187 if (result != base::PLATFORM_FILE_OK) {
188 callback.Run(result); 188 callback.Run(result);
189 delete this; 189 delete this;
190 return; 190 return;
191 } 191 }
192 192
193 FileSystemFileUtilProxy::GetFileInfo( 193 FileSystemFileUtilProxy::GetFileInfo(
194 &operation_context_, src_util_, url, 194 operation_context_.get(), src_util_, url,
195 base::Bind(&LocalFileSystemOperation::DidFileExists, 195 base::Bind(&LocalFileSystemOperation::DidFileExists,
196 base::Owned(this), callback)); 196 base::Owned(this), callback));
197 } 197 }
198 198
199 void LocalFileSystemOperation::GetMetadata( 199 void LocalFileSystemOperation::GetMetadata(
200 const FileSystemURL& url, const GetMetadataCallback& callback) { 200 const FileSystemURL& url, const GetMetadataCallback& callback) {
201 DCHECK(SetPendingOperationType(kOperationGetMetadata)); 201 DCHECK(SetPendingOperationType(kOperationGetMetadata));
202 202
203 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 203 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
204 if (result != base::PLATFORM_FILE_OK) { 204 if (result != base::PLATFORM_FILE_OK) {
205 callback.Run(result, base::PlatformFileInfo(), FilePath()); 205 callback.Run(result, base::PlatformFileInfo(), FilePath());
206 delete this; 206 delete this;
207 return; 207 return;
208 } 208 }
209 209
210 FileSystemFileUtilProxy::GetFileInfo( 210 FileSystemFileUtilProxy::GetFileInfo(
211 &operation_context_, src_util_, url, 211 operation_context_.get(), src_util_, url,
212 base::Bind(&LocalFileSystemOperation::DidGetMetadata, 212 base::Bind(&LocalFileSystemOperation::DidGetMetadata,
213 base::Owned(this), callback)); 213 base::Owned(this), callback));
214 } 214 }
215 215
216 void LocalFileSystemOperation::ReadDirectory( 216 void LocalFileSystemOperation::ReadDirectory(
217 const FileSystemURL& url, const ReadDirectoryCallback& callback) { 217 const FileSystemURL& url, const ReadDirectoryCallback& callback) {
218 DCHECK(SetPendingOperationType(kOperationReadDirectory)); 218 DCHECK(SetPendingOperationType(kOperationReadDirectory));
219 219
220 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 220 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
221 if (result != base::PLATFORM_FILE_OK) { 221 if (result != base::PLATFORM_FILE_OK) {
222 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); 222 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
223 delete this; 223 delete this;
224 return; 224 return;
225 } 225 }
226 226
227 FileSystemFileUtilProxy::ReadDirectory( 227 FileSystemFileUtilProxy::ReadDirectory(
228 &operation_context_, src_util_, url, 228 operation_context_.get(), src_util_, url,
229 base::Bind(&LocalFileSystemOperation::DidReadDirectory, 229 base::Bind(&LocalFileSystemOperation::DidReadDirectory,
230 base::Owned(this), callback)); 230 base::Owned(this), callback));
231 } 231 }
232 232
233 void LocalFileSystemOperation::Remove(const FileSystemURL& url, 233 void LocalFileSystemOperation::Remove(const FileSystemURL& url,
234 bool recursive, 234 bool recursive,
235 const StatusCallback& callback) { 235 const StatusCallback& callback) {
236 DCHECK(SetPendingOperationType(kOperationRemove)); 236 DCHECK(SetPendingOperationType(kOperationRemove));
237 237
238 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); 238 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
239 if (result != base::PLATFORM_FILE_OK) { 239 if (result != base::PLATFORM_FILE_OK) {
240 callback.Run(result); 240 callback.Run(result);
241 delete this; 241 delete this;
242 return; 242 return;
243 } 243 }
244 244
245 scoped_quota_notifier_.reset(new ScopedQuotaNotifier( 245 scoped_quota_notifier_.reset(new ScopedQuotaNotifier(
246 file_system_context(), url.origin(), url.type())); 246 file_system_context(), url.origin(), url.type()));
247 247
248 FileSystemFileUtilProxy::Delete( 248 FileSystemFileUtilProxy::Delete(
249 &operation_context_, src_util_, url, recursive, 249 operation_context_.get(), src_util_, url, recursive,
250 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 250 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
251 base::Owned(this), callback)); 251 base::Owned(this), callback));
252 } 252 }
253 253
254 void LocalFileSystemOperation::Write( 254 void LocalFileSystemOperation::Write(
255 const net::URLRequestContext* url_request_context, 255 const net::URLRequestContext* url_request_context,
256 const FileSystemURL& url, 256 const FileSystemURL& url,
257 const GURL& blob_url, 257 const GURL& blob_url,
258 int64 offset, 258 int64 offset,
259 const WriteCallback& callback) { 259 const WriteCallback& callback) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 DCHECK(SetPendingOperationType(kOperationTouchFile)); 318 DCHECK(SetPendingOperationType(kOperationTouchFile));
319 319
320 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); 320 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
321 if (result != base::PLATFORM_FILE_OK) { 321 if (result != base::PLATFORM_FILE_OK) {
322 callback.Run(result); 322 callback.Run(result);
323 delete this; 323 delete this;
324 return; 324 return;
325 } 325 }
326 326
327 FileSystemFileUtilProxy::Touch( 327 FileSystemFileUtilProxy::Touch(
328 &operation_context_, src_util_, url, 328 operation_context_.get(), src_util_, url,
329 last_access_time, last_modified_time, 329 last_access_time, last_modified_time,
330 base::Bind(&LocalFileSystemOperation::DidTouchFile, 330 base::Bind(&LocalFileSystemOperation::DidTouchFile,
331 base::Owned(this), callback)); 331 base::Owned(this), callback));
332 } 332 }
333 333
334 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, 334 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url,
335 int file_flags, 335 int file_flags,
336 base::ProcessHandle peer_handle, 336 base::ProcessHandle peer_handle,
337 const OpenFileCallback& callback) { 337 const OpenFileCallback& callback) {
338 DCHECK(SetPendingOperationType(kOperationOpenFile)); 338 DCHECK(SetPendingOperationType(kOperationOpenFile));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, 422 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url,
423 FilePath* platform_path) { 423 FilePath* platform_path) {
424 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); 424 DCHECK(SetPendingOperationType(kOperationGetLocalPath));
425 425
426 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 426 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
427 if (result != base::PLATFORM_FILE_OK) { 427 if (result != base::PLATFORM_FILE_OK) {
428 delete this; 428 delete this;
429 return; 429 return;
430 } 430 }
431 431
432 src_util_->GetLocalFilePath(&operation_context_, url, platform_path); 432 src_util_->GetLocalFilePath(operation_context_.get(), url, platform_path);
433 433
434 delete this; 434 delete this;
435 } 435 }
436 436
437 void LocalFileSystemOperation::CreateSnapshotFile( 437 void LocalFileSystemOperation::CreateSnapshotFile(
438 const FileSystemURL& url, 438 const FileSystemURL& url,
439 const SnapshotFileCallback& callback) { 439 const SnapshotFileCallback& callback) {
440 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); 440 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
441 441
442 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 442 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
443 if (result != base::PLATFORM_FILE_OK) { 443 if (result != base::PLATFORM_FILE_OK) {
444 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL); 444 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL);
445 delete this; 445 delete this;
446 return; 446 return;
447 } 447 }
448 448
449 FileSystemFileUtilProxy::CreateSnapshotFile( 449 FileSystemFileUtilProxy::CreateSnapshotFile(
450 &operation_context_, src_util_, url, 450 operation_context_.get(), src_util_, url,
451 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, 451 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile,
452 base::Owned(this), callback)); 452 base::Owned(this), callback));
453 } 453 }
454 454
455 LocalFileSystemOperation::LocalFileSystemOperation( 455 LocalFileSystemOperation::LocalFileSystemOperation(
456 FileSystemContext* file_system_context) 456 FileSystemContext* file_system_context,
457 : operation_context_(file_system_context), 457 scoped_ptr<FileSystemOperationContext> operation_context)
458 : operation_context_(operation_context.Pass()),
458 src_util_(NULL), 459 src_util_(NULL),
459 dest_util_(NULL), 460 dest_util_(NULL),
460 peer_handle_(base::kNullProcessHandle), 461 peer_handle_(base::kNullProcessHandle),
461 pending_operation_(kOperationNone), 462 pending_operation_(kOperationNone),
462 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 463 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
464 DCHECK(operation_context_.get());
463 } 465 }
464 466
465 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( 467 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask(
466 const FileSystemURL& url, 468 const FileSystemURL& url,
467 const base::Closure& task, 469 const base::Closure& task,
468 const base::Closure& error_callback) { 470 const base::Closure& error_callback) {
469 quota::QuotaManagerProxy* quota_manager_proxy = 471 quota::QuotaManagerProxy* quota_manager_proxy =
470 file_system_context()->quota_manager_proxy(); 472 file_system_context()->quota_manager_proxy();
471 if (!quota_manager_proxy || 473 if (!quota_manager_proxy ||
472 !file_system_context()->GetQuotaUtil(url.type())) { 474 !file_system_context()->GetQuotaUtil(url.type())) {
473 // If we don't have the quota manager or the requested filesystem type 475 // If we don't have the quota manager or the requested filesystem type
474 // does not support quota, we should be able to let it go. 476 // does not support quota, we should be able to let it go.
475 operation_context_.set_allowed_bytes_growth(kint64max); 477 operation_context_->set_allowed_bytes_growth(kint64max);
476 task.Run(); 478 task.Run();
477 return; 479 return;
478 } 480 }
479 481
480 TaskParamsForDidGetQuota params; 482 TaskParamsForDidGetQuota params;
481 params.url = url; 483 params.url = url;
482 params.task = task; 484 params.task = task;
483 params.error_callback = error_callback; 485 params.error_callback = error_callback;
484 486
485 DCHECK(quota_manager_proxy); 487 DCHECK(quota_manager_proxy);
486 DCHECK(quota_manager_proxy->quota_manager()); 488 DCHECK(quota_manager_proxy->quota_manager());
487 quota_manager_proxy->quota_manager()->GetUsageAndQuota( 489 quota_manager_proxy->quota_manager()->GetUsageAndQuota(
488 url.origin(), 490 url.origin(),
489 FileSystemTypeToQuotaStorageType(url.type()), 491 FileSystemTypeToQuotaStorageType(url.type()),
490 base::Bind(&LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask, 492 base::Bind(&LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask,
491 weak_factory_.GetWeakPtr(), params)); 493 weak_factory_.GetWeakPtr(), params));
492 } 494 }
493 495
494 void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask( 496 void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask(
495 const TaskParamsForDidGetQuota& params, 497 const TaskParamsForDidGetQuota& params,
496 quota::QuotaStatusCode status, 498 quota::QuotaStatusCode status,
497 int64 usage, int64 quota) { 499 int64 usage, int64 quota) {
498 if (status != quota::kQuotaStatusOk) { 500 if (status != quota::kQuotaStatusOk) {
499 LOG(WARNING) << "Got unexpected quota error : " << status; 501 LOG(WARNING) << "Got unexpected quota error : " << status;
500 params.error_callback.Run(); 502 params.error_callback.Run();
501 return; 503 return;
502 } 504 }
503 505
504 operation_context_.set_allowed_bytes_growth(quota - usage); 506 operation_context_->set_allowed_bytes_growth(quota - usage);
505 scoped_quota_notifier_.reset(new ScopedQuotaNotifier( 507 scoped_quota_notifier_.reset(new ScopedQuotaNotifier(
506 file_system_context(), params.url.origin(), params.url.type())); 508 file_system_context(), params.url.origin(), params.url.type()));
507 509
508 params.task.Run(); 510 params.task.Run();
509 } 511 }
510 512
511 void LocalFileSystemOperation::DoCreateFile( 513 void LocalFileSystemOperation::DoCreateFile(
512 const FileSystemURL& url, 514 const FileSystemURL& url,
513 const StatusCallback& callback, 515 const StatusCallback& callback,
514 bool exclusive) { 516 bool exclusive) {
515 FileSystemFileUtilProxy::EnsureFileExists( 517 FileSystemFileUtilProxy::EnsureFileExists(
516 &operation_context_, 518 operation_context_.get(),
517 src_util_, url, 519 src_util_, url,
518 base::Bind( 520 base::Bind(
519 exclusive ? 521 exclusive ?
520 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : 522 &LocalFileSystemOperation::DidEnsureFileExistsExclusive :
521 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, 523 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive,
522 base::Owned(this), callback)); 524 base::Owned(this), callback));
523 } 525 }
524 526
525 void LocalFileSystemOperation::DoCreateDirectory( 527 void LocalFileSystemOperation::DoCreateDirectory(
526 const FileSystemURL& url, 528 const FileSystemURL& url,
527 const StatusCallback& callback, 529 const StatusCallback& callback,
528 bool exclusive, bool recursive) { 530 bool exclusive, bool recursive) {
529 FileSystemFileUtilProxy::CreateDirectory( 531 FileSystemFileUtilProxy::CreateDirectory(
530 &operation_context_, 532 operation_context_.get(),
531 src_util_, url, exclusive, recursive, 533 src_util_, url, exclusive, recursive,
532 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 534 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
533 base::Owned(this), callback)); 535 base::Owned(this), callback));
534 } 536 }
535 537
536 void LocalFileSystemOperation::DoCopy(const FileSystemURL& src_url, 538 void LocalFileSystemOperation::DoCopy(const FileSystemURL& src_url,
537 const FileSystemURL& dest_url, 539 const FileSystemURL& dest_url,
538 const StatusCallback& callback) { 540 const StatusCallback& callback) {
539 FileSystemFileUtilProxy::Copy( 541 FileSystemFileUtilProxy::Copy(
540 &operation_context_, 542 operation_context_.get(),
541 src_util_, dest_util_, 543 src_util_, dest_util_,
542 src_url, dest_url, 544 src_url, dest_url,
543 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 545 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
544 base::Owned(this), callback)); 546 base::Owned(this), callback));
545 } 547 }
546 548
547 void LocalFileSystemOperation::DoMove(const FileSystemURL& src_url, 549 void LocalFileSystemOperation::DoMove(const FileSystemURL& src_url,
548 const FileSystemURL& dest_url, 550 const FileSystemURL& dest_url,
549 const StatusCallback& callback) { 551 const StatusCallback& callback) {
550 FileSystemFileUtilProxy::Move( 552 FileSystemFileUtilProxy::Move(
551 &operation_context_, 553 operation_context_.get(),
552 src_util_, dest_util_, 554 src_util_, dest_util_,
553 src_url, dest_url, 555 src_url, dest_url,
554 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 556 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
555 base::Owned(this), callback)); 557 base::Owned(this), callback));
556 } 558 }
557 559
558 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, 560 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url,
559 const StatusCallback& callback, 561 const StatusCallback& callback,
560 int64 length) { 562 int64 length) {
561 FileSystemFileUtilProxy::Truncate( 563 FileSystemFileUtilProxy::Truncate(
562 &operation_context_, src_util_, url, length, 564 operation_context_.get(), src_util_, url, length,
563 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 565 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
564 base::Owned(this), callback)); 566 base::Owned(this), callback));
565 } 567 }
566 568
567 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url, 569 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url,
568 const OpenFileCallback& callback, 570 const OpenFileCallback& callback,
569 int file_flags) { 571 int file_flags) {
570 FileSystemFileUtilProxy::CreateOrOpen( 572 FileSystemFileUtilProxy::CreateOrOpen(
571 &operation_context_, src_util_, url, file_flags, 573 operation_context_.get(), src_util_, url, file_flags,
572 base::Bind(&LocalFileSystemOperation::DidOpenFile, 574 base::Bind(&LocalFileSystemOperation::DidOpenFile,
573 base::Owned(this), callback)); 575 base::Owned(this), callback));
574 } 576 }
575 577
576 void LocalFileSystemOperation::DidEnsureFileExistsExclusive( 578 void LocalFileSystemOperation::DidEnsureFileExistsExclusive(
577 const StatusCallback& callback, 579 const StatusCallback& callback,
578 base::PlatformFileError rv, bool created) { 580 base::PlatformFileError rv, bool created) {
579 if (rv == base::PLATFORM_FILE_OK && !created) { 581 if (rv == base::PLATFORM_FILE_OK && !created) {
580 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); 582 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
581 } else { 583 } else {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 } 732 }
731 733
732 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { 734 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) {
733 if (pending_operation_ != kOperationNone) 735 if (pending_operation_ != kOperationNone)
734 return false; 736 return false;
735 pending_operation_ = type; 737 pending_operation_ = type;
736 return true; 738 return true;
737 } 739 }
738 740
739 } // namespace fileapi 741 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/local_file_system_operation.h ('k') | webkit/fileapi/local_file_system_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698