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

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

Issue 10829147: Make MediaFileUtil run on thread pool. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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/single_thread_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_task_runners.h"
19 #include "webkit/fileapi/file_system_types.h" 20 #include "webkit/fileapi/file_system_types.h"
20 #include "webkit/fileapi/file_system_url.h" 21 #include "webkit/fileapi/file_system_url.h"
21 #include "webkit/fileapi/file_system_util.h" 22 #include "webkit/fileapi/file_system_util.h"
22 #include "webkit/fileapi/file_writer_delegate.h" 23 #include "webkit/fileapi/file_writer_delegate.h"
23 #include "webkit/fileapi/sandbox_file_stream_writer.h" 24 #include "webkit/fileapi/sandbox_file_stream_writer.h"
24 #include "webkit/quota/quota_manager.h" 25 #include "webkit/quota/quota_manager.h"
25 #include "webkit/quota/quota_types.h" 26 #include "webkit/quota/quota_types.h"
26 27
27 using webkit_blob::ShareableFileReference; 28 using webkit_blob::ShareableFileReference;
28 29
29 namespace fileapi { 30 namespace fileapi {
30 31
32 namespace {
33
34 bool IsMediaFileSystemType(FileSystemType type) {
35 return type == kFileSystemTypeNativeMedia ||
36 type == kFileSystemTypeDeviceMedia;
37 }
38
39 base::PlatformFileError AllowCrossOperation(FileSystemType src_type,
kinuko 2012/08/06 19:00:14 This function name doesn't sound like a check func
tzik 2012/08/06 20:09:01 Done.
40 FileSystemType dest_type) {
41 // If two types are supposed to run on different task runners we should not
42 // allow cross FileUtil operations at this layer.
43 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type) ?
44 base::PLATFORM_FILE_OK :
45 base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
46 }
47
48 } // namespace
49
31 class LocalFileSystemOperation::ScopedQuotaNotifier { 50 class LocalFileSystemOperation::ScopedQuotaNotifier {
32 public: 51 public:
33 ScopedQuotaNotifier(FileSystemContext* context, 52 ScopedQuotaNotifier(FileSystemContext* context,
34 const GURL& origin_url, 53 const GURL& origin_url,
35 FileSystemType type); 54 FileSystemType type);
36 ~ScopedQuotaNotifier(); 55 ~ScopedQuotaNotifier();
37 56
38 private: 57 private:
39 // Not owned; owned by the owner of this instance 58 // Not owned; owned by the owner of this instance
40 // (i.e. LocalFileSystemOperation). 59 // (i.e. LocalFileSystemOperation).
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 130 }
112 131
113 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, 132 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url,
114 const FileSystemURL& dest_url, 133 const FileSystemURL& dest_url,
115 const StatusCallback& callback) { 134 const StatusCallback& callback) {
116 DCHECK(SetPendingOperationType(kOperationCopy)); 135 DCHECK(SetPendingOperationType(kOperationCopy));
117 136
118 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); 137 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ);
119 if (result == base::PLATFORM_FILE_OK) 138 if (result == base::PLATFORM_FILE_OK)
120 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); 139 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE);
140 if (result == base::PLATFORM_FILE_OK)
141 result = AllowCrossOperation(src_url.type(), dest_url.type());
121 if (result != base::PLATFORM_FILE_OK) { 142 if (result != base::PLATFORM_FILE_OK) {
122 callback.Run(result); 143 callback.Run(result);
123 delete this; 144 delete this;
124 return; 145 return;
125 } 146 }
126 147
127 GetUsageAndQuotaThenRunTask( 148 GetUsageAndQuotaThenRunTask(
128 dest_url, 149 dest_url,
129 base::Bind(&LocalFileSystemOperation::DoCopy, 150 base::Bind(&LocalFileSystemOperation::DoCopy,
130 base::Unretained(this), src_url, dest_url, callback), 151 base::Unretained(this), src_url, dest_url, callback),
131 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 152 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
132 } 153 }
133 154
134 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, 155 void LocalFileSystemOperation::Move(const FileSystemURL& src_url,
135 const FileSystemURL& dest_url, 156 const FileSystemURL& dest_url,
136 const StatusCallback& callback) { 157 const StatusCallback& callback) {
137 DCHECK(SetPendingOperationType(kOperationMove)); 158 DCHECK(SetPendingOperationType(kOperationMove));
138 scoped_ptr<LocalFileSystemOperation> deleter(this); 159 scoped_ptr<LocalFileSystemOperation> deleter(this);
139 160
140 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); 161 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE);
141 if (result == base::PLATFORM_FILE_OK) 162 if (result == base::PLATFORM_FILE_OK)
142 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); 163 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE);
164 if (result == base::PLATFORM_FILE_OK)
165 result = AllowCrossOperation(src_url.type(), dest_url.type());
143 if (result != base::PLATFORM_FILE_OK) { 166 if (result != base::PLATFORM_FILE_OK) {
144 callback.Run(result); 167 callback.Run(result);
145 return; 168 return;
146 } 169 }
147 170
148 // Temporarily disables cross-filesystem move for sandbox filesystems. 171 // Temporarily disables cross-filesystem move for sandbox filesystems.
149 // TODO(kinuko,tzik,kinaba): This special handling must be removed once 172 // TODO(kinuko,tzik,kinaba): This special handling must be removed once
150 // we support saner cross-filesystem operation. 173 // we support saner cross-filesystem operation.
151 // (See http://crbug.com/130055) 174 // (See http://crbug.com/130055)
152 if (src_url.type() != dest_url.type() && 175 if (src_url.type() != dest_url.type() &&
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 const SnapshotFileCallback& callback, 700 const SnapshotFileCallback& callback,
678 base::PlatformFileError result, 701 base::PlatformFileError result,
679 const base::PlatformFileInfo& file_info, 702 const base::PlatformFileInfo& file_info,
680 const FilePath& platform_path, 703 const FilePath& platform_path,
681 FileSystemFileUtil::SnapshotFilePolicy snapshot_policy) { 704 FileSystemFileUtil::SnapshotFilePolicy snapshot_policy) {
682 scoped_refptr<ShareableFileReference> file_ref; 705 scoped_refptr<ShareableFileReference> file_ref;
683 if (result == base::PLATFORM_FILE_OK && 706 if (result == base::PLATFORM_FILE_OK &&
684 snapshot_policy == FileSystemFileUtil::kSnapshotFileTemporary) { 707 snapshot_policy == FileSystemFileUtil::kSnapshotFileTemporary) {
685 file_ref = ShareableFileReference::GetOrCreate( 708 file_ref = ShareableFileReference::GetOrCreate(
686 platform_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, 709 platform_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE,
687 file_system_context()->file_task_runner()); 710 file_system_context()->task_runners()->file_task_runner());
688 } 711 }
689 callback.Run(result, file_info, platform_path, file_ref); 712 callback.Run(result, file_info, platform_path, file_ref);
690 } 713 }
691 714
692 base::PlatformFileError LocalFileSystemOperation::SetUp( 715 base::PlatformFileError LocalFileSystemOperation::SetUp(
693 const FileSystemURL& url, 716 const FileSystemURL& url,
694 FileSystemFileUtil** file_util, 717 FileSystemFileUtil** file_util,
695 SetUpMode mode) { 718 SetUpMode mode) {
696 if (!url.is_valid()) 719 if (!url.is_valid())
697 return base::PLATFORM_FILE_ERROR_INVALID_URL; 720 return base::PLATFORM_FILE_ERROR_INVALID_URL;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 764 }
742 765
743 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { 766 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) {
744 if (pending_operation_ != kOperationNone) 767 if (pending_operation_ != kOperationNone)
745 return false; 768 return false;
746 pending_operation_ = type; 769 pending_operation_ = type;
747 return true; 770 return true;
748 } 771 }
749 772
750 } // namespace fileapi 773 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698