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

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

Issue 14352004: Split Media-related code from IsolatedMountPointProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 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/isolated_mount_point_provider.h" 5 #include "webkit/fileapi/isolated_mount_point_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "webkit/blob/local_file_stream_reader.h" 15 #include "webkit/blob/local_file_stream_reader.h"
16 #include "webkit/fileapi/async_file_util_adapter.h" 16 #include "webkit/fileapi/async_file_util_adapter.h"
17 #include "webkit/fileapi/copy_or_move_file_validator.h" 17 #include "webkit/fileapi/copy_or_move_file_validator.h"
18 #include "webkit/fileapi/file_system_callback_dispatcher.h" 18 #include "webkit/fileapi/file_system_callback_dispatcher.h"
19 #include "webkit/fileapi/file_system_context.h" 19 #include "webkit/fileapi/file_system_context.h"
20 #include "webkit/fileapi/file_system_file_stream_reader.h" 20 #include "webkit/fileapi/file_system_file_stream_reader.h"
21 #include "webkit/fileapi/file_system_operation_context.h" 21 #include "webkit/fileapi/file_system_operation_context.h"
22 #include "webkit/fileapi/file_system_task_runners.h" 22 #include "webkit/fileapi/file_system_task_runners.h"
23 #include "webkit/fileapi/file_system_types.h" 23 #include "webkit/fileapi/file_system_types.h"
24 #include "webkit/fileapi/file_system_util.h" 24 #include "webkit/fileapi/file_system_util.h"
25 #include "webkit/fileapi/isolated_context.h" 25 #include "webkit/fileapi/isolated_context.h"
26 #include "webkit/fileapi/isolated_file_util.h" 26 #include "webkit/fileapi/isolated_file_util.h"
27 #include "webkit/fileapi/local_file_stream_writer.h" 27 #include "webkit/fileapi/local_file_stream_writer.h"
28 #include "webkit/fileapi/local_file_system_operation.h" 28 #include "webkit/fileapi/local_file_system_operation.h"
29 #include "webkit/fileapi/media/media_path_filter.h"
30 #include "webkit/fileapi/media/native_media_file_util.h"
31 #include "webkit/fileapi/native_file_util.h" 29 #include "webkit/fileapi/native_file_util.h"
32 30
33 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
34 #include "webkit/fileapi/media/device_media_async_file_util.h"
35 #endif
36
37 namespace fileapi { 31 namespace fileapi {
38 32
39 const char IsolatedMountPointProvider::kMediaPathFilterKey[] = 33 IsolatedMountPointProvider::IsolatedMountPointProvider()
40 "MediaPathFilterKey"; 34 : isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())),
41 const char IsolatedMountPointProvider::kMTPDeviceDelegateURLKey[] = 35 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())) {
42 "MTPDeviceDelegateKey";
43
44 IsolatedMountPointProvider::IsolatedMountPointProvider(
45 const base::FilePath& profile_path)
46 : profile_path_(profile_path),
47 media_path_filter_(new MediaPathFilter()),
48 isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())),
49 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
50 native_media_file_util_(
51 new AsyncFileUtilAdapter(new NativeMediaFileUtil())) {
52 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
53 // TODO(kmadhusu): Initialize |device_media_file_util_| in
54 // initialization list.
55 device_media_async_file_util_.reset(
56 DeviceMediaAsyncFileUtil::Create(profile_path_));
57 #endif
58 } 36 }
59 37
60 IsolatedMountPointProvider::~IsolatedMountPointProvider() { 38 IsolatedMountPointProvider::~IsolatedMountPointProvider() {
61 } 39 }
62 40
63 bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const { 41 bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const {
64 switch (type) { 42 switch (type) {
65 case kFileSystemTypeIsolated: 43 case kFileSystemTypeIsolated:
66 case kFileSystemTypeDragged: 44 case kFileSystemTypeDragged:
67 case kFileSystemTypeNativeMedia:
68 case kFileSystemTypeDeviceMedia:
69 return true; 45 return true;
70 #if !defined(OS_CHROMEOS) 46 #if !defined(OS_CHROMEOS)
71 case kFileSystemTypeNativeLocal: 47 case kFileSystemTypeNativeLocal:
72 case kFileSystemTypeNativeForPlatformApp: 48 case kFileSystemTypeNativeForPlatformApp:
73 return true; 49 return true;
74 #endif 50 #endif
75 default: 51 default:
76 return false; 52 return false;
77 } 53 }
78 } 54 }
(...skipping 17 matching lines...) Expand all
96 return base::FilePath(); 72 return base::FilePath();
97 } 73 }
98 74
99 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( 75 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
100 FileSystemType type) { 76 FileSystemType type) {
101 switch (type) { 77 switch (type) {
102 case kFileSystemTypeNativeLocal: 78 case kFileSystemTypeNativeLocal:
103 return isolated_file_util_->sync_file_util(); 79 return isolated_file_util_->sync_file_util();
104 case kFileSystemTypeDragged: 80 case kFileSystemTypeDragged:
105 return dragged_file_util_->sync_file_util(); 81 return dragged_file_util_->sync_file_util();
106 case kFileSystemTypeNativeMedia:
107 return native_media_file_util_->sync_file_util();
108 default: 82 default:
109 NOTREACHED(); 83 NOTREACHED();
110 } 84 }
111 return NULL; 85 return NULL;
112 } 86 }
113 87
114 AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil( 88 AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil(
115 FileSystemType type) { 89 FileSystemType type) {
116 switch (type) { 90 switch (type) {
117 case kFileSystemTypeNativeLocal: 91 case kFileSystemTypeNativeLocal:
118 return isolated_file_util_.get(); 92 return isolated_file_util_.get();
119 case kFileSystemTypeDragged: 93 case kFileSystemTypeDragged:
120 return dragged_file_util_.get(); 94 return dragged_file_util_.get();
121 case kFileSystemTypeNativeMedia:
122 return native_media_file_util_.get();
123 case kFileSystemTypeDeviceMedia:
124 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
125 return device_media_async_file_util_.get();
126 #endif
127 default: 95 default:
128 NOTREACHED(); 96 NOTREACHED();
129 } 97 }
130 return NULL; 98 return NULL;
131 } 99 }
132 100
133 CopyOrMoveFileValidatorFactory* 101 CopyOrMoveFileValidatorFactory*
134 IsolatedMountPointProvider::GetCopyOrMoveFileValidatorFactory( 102 IsolatedMountPointProvider::GetCopyOrMoveFileValidatorFactory(
135 FileSystemType type, base::PlatformFileError* error_code) { 103 FileSystemType type, base::PlatformFileError* error_code) {
136 DCHECK(error_code); 104 DCHECK(error_code);
137 *error_code = base::PLATFORM_FILE_OK; 105 *error_code = base::PLATFORM_FILE_OK;
138 switch (type) {
139 case kFileSystemTypeNativeLocal:
140 case kFileSystemTypeDragged:
141 return NULL;
142 case kFileSystemTypeNativeMedia:
143 case kFileSystemTypeDeviceMedia:
144 if (!media_copy_or_move_file_validator_factory_) {
145 *error_code = base::PLATFORM_FILE_ERROR_SECURITY;
146 return NULL;
147 }
148 return media_copy_or_move_file_validator_factory_.get();
149 default:
150 NOTREACHED();
151 }
152 return NULL; 106 return NULL;
153 } 107 }
154 108
155 void IsolatedMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( 109 void IsolatedMountPointProvider::InitializeCopyOrMoveFileValidatorFactory(
156 FileSystemType type, 110 FileSystemType type,
157 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { 111 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) {
158 switch (type) { 112 DCHECK(!factory);
159 case kFileSystemTypeNativeLocal:
160 case kFileSystemTypeDragged:
161 DCHECK(factory == NULL);
162 break;
163 case kFileSystemTypeNativeMedia:
164 case kFileSystemTypeDeviceMedia:
165 if (!media_copy_or_move_file_validator_factory_)
166 media_copy_or_move_file_validator_factory_.reset(factory.release());
167 break;
168 default:
169 NOTREACHED();
170 }
171 } 113 }
172 114
173 FilePermissionPolicy IsolatedMountPointProvider::GetPermissionPolicy( 115 FilePermissionPolicy IsolatedMountPointProvider::GetPermissionPolicy(
174 const FileSystemURL& url, int permissions) const { 116 const FileSystemURL& url, int permissions) const {
175 if (url.type() == kFileSystemTypeDragged && url.path().empty()) { 117 if (url.type() == kFileSystemTypeDragged && url.path().empty()) {
176 // The root directory of the dragged filesystem must be always read-only. 118 // The root directory of the dragged filesystem must be always read-only.
177 if (permissions & ~fileapi::kReadFilePermissions) 119 if (permissions & ~fileapi::kReadFilePermissions)
178 return FILE_PERMISSION_ALWAYS_DENY; 120 return FILE_PERMISSION_ALWAYS_DENY;
179 } 121 }
180 // Access to isolated file systems should be checked using per-filesystem 122 // Access to isolated file systems should be checked using per-filesystem
181 // access permission. 123 // access permission.
182 return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; 124 return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION;
183 } 125 }
184 126
185 FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation( 127 FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation(
186 const FileSystemURL& url, 128 const FileSystemURL& url,
187 FileSystemContext* context, 129 FileSystemContext* context,
188 base::PlatformFileError* error_code) const { 130 base::PlatformFileError* error_code) const {
189 if (url.type() != kFileSystemTypeNativeMedia && 131 return new LocalFileSystemOperation(
190 url.type() != kFileSystemTypeDeviceMedia) { 132 context, make_scoped_ptr(new FileSystemOperationContext(context)));
191 return new LocalFileSystemOperation(
192 context, make_scoped_ptr(new FileSystemOperationContext(context)));
193 }
194
195 // For media filesystems.
196 scoped_ptr<FileSystemOperationContext> operation_context(
197 new FileSystemOperationContext(
198 context, context->task_runners()->media_task_runner()));
199
200 operation_context->SetUserValue(kMediaPathFilterKey,
201 media_path_filter_.get());
202
203 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
204 if (url.type() == kFileSystemTypeDeviceMedia) {
205 operation_context->SetUserValue(kMTPDeviceDelegateURLKey,
206 url.filesystem_id());
207 }
208 #endif
209
210 return new LocalFileSystemOperation(context, operation_context.Pass());
211 } 133 }
212 134
213 scoped_ptr<webkit_blob::FileStreamReader> 135 scoped_ptr<webkit_blob::FileStreamReader>
214 IsolatedMountPointProvider::CreateFileStreamReader( 136 IsolatedMountPointProvider::CreateFileStreamReader(
215 const FileSystemURL& url, 137 const FileSystemURL& url,
216 int64 offset, 138 int64 offset,
217 const base::Time& expected_modification_time, 139 const base::Time& expected_modification_time,
218 FileSystemContext* context) const { 140 FileSystemContext* context) const {
219 return scoped_ptr<webkit_blob::FileStreamReader>( 141 return scoped_ptr<webkit_blob::FileStreamReader>(
220 new webkit_blob::LocalFileStreamReader( 142 new webkit_blob::LocalFileStreamReader(
(...skipping 17 matching lines...) Expand all
238 void IsolatedMountPointProvider::DeleteFileSystem( 160 void IsolatedMountPointProvider::DeleteFileSystem(
239 const GURL& origin_url, 161 const GURL& origin_url,
240 FileSystemType type, 162 FileSystemType type,
241 FileSystemContext* context, 163 FileSystemContext* context,
242 const DeleteFileSystemCallback& callback) { 164 const DeleteFileSystemCallback& callback) {
243 NOTREACHED(); 165 NOTREACHED();
244 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); 166 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
245 } 167 }
246 168
247 } // namespace fileapi 169 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/isolated_mount_point_provider.h ('k') | webkit/fileapi/media/device_media_async_file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698