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

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

Issue 10815003: Adding FileUtil::CreateSnapshotFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_util_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file_system_operation.h" 5 #include "webkit/fileapi/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"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "net/url_request/url_request_context.h" 12 #include "net/url_request/url_request_context.h"
13 #include "webkit/blob/shareable_file_reference.h" 13 #include "webkit/blob/shareable_file_reference.h"
14 #include "webkit/fileapi/file_system_context.h" 14 #include "webkit/fileapi/file_system_context.h"
15 #include "webkit/fileapi/file_system_file_util_proxy.h" 15 #include "webkit/fileapi/file_system_file_util_proxy.h"
16 #include "webkit/fileapi/file_system_mount_point_provider.h" 16 #include "webkit/fileapi/file_system_mount_point_provider.h"
17 #include "webkit/fileapi/file_system_operation_context.h" 17 #include "webkit/fileapi/file_system_operation_context.h"
18 #include "webkit/fileapi/file_system_quota_util.h" 18 #include "webkit/fileapi/file_system_quota_util.h"
19 #include "webkit/fileapi/file_system_types.h" 19 #include "webkit/fileapi/file_system_types.h"
20 #include "webkit/fileapi/file_system_url.h" 20 #include "webkit/fileapi/file_system_url.h"
21 #include "webkit/fileapi/file_system_util.h" 21 #include "webkit/fileapi/file_system_util.h"
22 #include "webkit/fileapi/file_writer_delegate.h" 22 #include "webkit/fileapi/file_writer_delegate.h"
23 #include "webkit/fileapi/sandbox_file_stream_writer.h" 23 #include "webkit/fileapi/sandbox_file_stream_writer.h"
24 #include "webkit/quota/quota_manager.h" 24 #include "webkit/quota/quota_manager.h"
25 #include "webkit/quota/quota_types.h" 25 #include "webkit/quota/quota_types.h"
26 26
27 namespace fileapi { 27 namespace fileapi {
28 28
29 namespace {
30
31 void GetMetadataForSnapshot(
32 const FileSystemOperationInterface::SnapshotFileCallback& callback,
33 base::PlatformFileError result,
34 const base::PlatformFileInfo& file_info,
35 const FilePath& platform_path) {
36 // We don't want the third party to delete our local file, so just returning
37 // NULL as |file_reference|.
38 callback.Run(result, file_info, platform_path, NULL);
39 }
40
41 } // anonymous namespace
42
43 class FileSystemOperation::ScopedQuotaNotifier { 29 class FileSystemOperation::ScopedQuotaNotifier {
44 public: 30 public:
45 ScopedQuotaNotifier(FileSystemContext* context, 31 ScopedQuotaNotifier(FileSystemContext* context,
46 const GURL& origin_url, 32 const GURL& origin_url,
47 FileSystemType type); 33 FileSystemType type);
48 ~ScopedQuotaNotifier(); 34 ~ScopedQuotaNotifier();
49 35
50 private: 36 private:
51 // Not owned; owned by the owner of this instance (i.e. FileSystemOperation). 37 // Not owned; owned by the owner of this instance (i.e. FileSystemOperation).
52 FileSystemQuotaUtil* quota_util_; 38 FileSystemQuotaUtil* quota_util_;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 423 }
438 424
439 src_util_->GetLocalFilePath(&operation_context_, url, platform_path); 425 src_util_->GetLocalFilePath(&operation_context_, url, platform_path);
440 426
441 delete this; 427 delete this;
442 } 428 }
443 429
444 void FileSystemOperation::CreateSnapshotFile( 430 void FileSystemOperation::CreateSnapshotFile(
445 const FileSystemURL& url, 431 const FileSystemURL& url,
446 const SnapshotFileCallback& callback) { 432 const SnapshotFileCallback& callback) {
447 GetMetadata(url, base::Bind(&GetMetadataForSnapshot, callback)); 433 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
434
435 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
436 if (result != base::PLATFORM_FILE_OK) {
437 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL);
438 delete this;
439 return;
440 }
441
442 FileSystemFileUtilProxy::CreateSnapshotFile(
443 &operation_context_, src_util_, url,
444 base::Bind(&FileSystemOperation::DidCreateSnapshotFile,
445 base::Owned(this), callback));
448 } 446 }
449 447
450 FileSystemOperation::FileSystemOperation( 448 FileSystemOperation::FileSystemOperation(
451 FileSystemContext* file_system_context) 449 FileSystemContext* file_system_context)
452 : operation_context_(file_system_context), 450 : operation_context_(file_system_context),
453 src_util_(NULL), 451 src_util_(NULL),
454 dest_util_(NULL), 452 dest_util_(NULL),
455 peer_handle_(base::kNullProcessHandle), 453 peer_handle_(base::kNullProcessHandle),
456 pending_operation_(kOperationNone), 454 pending_operation_(kOperationNone),
457 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 455 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 void FileSystemOperation::DidOpenFile( 654 void FileSystemOperation::DidOpenFile(
657 const OpenFileCallback& callback, 655 const OpenFileCallback& callback,
658 base::PlatformFileError rv, 656 base::PlatformFileError rv,
659 base::PassPlatformFile file, 657 base::PassPlatformFile file,
660 bool unused) { 658 bool unused) {
661 if (rv == base::PLATFORM_FILE_OK) 659 if (rv == base::PLATFORM_FILE_OK)
662 CHECK_NE(base::kNullProcessHandle, peer_handle_); 660 CHECK_NE(base::kNullProcessHandle, peer_handle_);
663 callback.Run(rv, file.ReleaseValue(), peer_handle_); 661 callback.Run(rv, file.ReleaseValue(), peer_handle_);
664 } 662 }
665 663
664 void FileSystemOperation::DidCreateSnapshotFile(
665 const SnapshotFileCallback& callback,
666 base::PlatformFileError result,
667 const base::PlatformFileInfo& file_info,
668 const FilePath& platform_path,
669 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
670 callback.Run(result, file_info, platform_path, file_ref);
671 }
672
666 base::PlatformFileError FileSystemOperation::SetUp( 673 base::PlatformFileError FileSystemOperation::SetUp(
667 const FileSystemURL& url, 674 const FileSystemURL& url,
668 FileSystemFileUtil** file_util, 675 FileSystemFileUtil** file_util,
669 SetUpMode mode) { 676 SetUpMode mode) {
670 if (!url.is_valid()) 677 if (!url.is_valid())
671 return base::PLATFORM_FILE_ERROR_INVALID_URL; 678 return base::PLATFORM_FILE_ERROR_INVALID_URL;
672 679
673 if (!file_system_context()->GetMountPointProvider( 680 if (!file_system_context()->GetMountPointProvider(
674 url.type())->IsAccessAllowed(url.origin(), url.type(), url.path())) 681 url.type())->IsAccessAllowed(url.origin(), url.type(), url.path()))
675 return base::PLATFORM_FILE_ERROR_SECURITY; 682 return base::PLATFORM_FILE_ERROR_SECURITY;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 722 }
716 723
717 bool FileSystemOperation::SetPendingOperationType(OperationType type) { 724 bool FileSystemOperation::SetPendingOperationType(OperationType type) {
718 if (pending_operation_ != kOperationNone) 725 if (pending_operation_ != kOperationNone)
719 return false; 726 return false;
720 pending_operation_ = type; 727 pending_operation_ = type;
721 return true; 728 return true;
722 } 729 }
723 730
724 } // namespace fileapi 731 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_util_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698