OLD | NEW |
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/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "chrome/browser/chromeos/fileapi/cros_mount_point_provider.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "chrome/browser/chromeos/drive/mount_point_provider_delegate.h" |
14 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" | 15 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" |
15 #include "chrome/browser/chromeos/fileapi/remote_file_stream_writer.h" | |
16 #include "chrome/browser/chromeos/fileapi/remote_file_system_operation.h" | |
17 #include "chromeos/dbus/cros_disks_client.h" | 16 #include "chromeos/dbus/cros_disks_client.h" |
| 17 #include "webkit/browser/blob/file_stream_reader.h" |
18 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 18 #include "webkit/browser/fileapi/async_file_util_adapter.h" |
19 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 19 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
20 #include "webkit/browser/fileapi/external_mount_points.h" | 20 #include "webkit/browser/fileapi/external_mount_points.h" |
21 #include "webkit/browser/fileapi/file_system_context.h" | 21 #include "webkit/browser/fileapi/file_system_context.h" |
22 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" | 22 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" |
23 #include "webkit/browser/fileapi/file_system_operation_context.h" | 23 #include "webkit/browser/fileapi/file_system_operation_context.h" |
24 #include "webkit/browser/fileapi/file_system_task_runners.h" | 24 #include "webkit/browser/fileapi/file_system_task_runners.h" |
25 #include "webkit/browser/fileapi/file_system_url.h" | 25 #include "webkit/browser/fileapi/file_system_url.h" |
26 #include "webkit/browser/fileapi/isolated_context.h" | 26 #include "webkit/browser/fileapi/isolated_context.h" |
27 #include "webkit/browser/fileapi/isolated_file_util.h" | 27 #include "webkit/browser/fileapi/isolated_file_util.h" |
(...skipping 18 matching lines...) Expand all Loading... |
46 } | 46 } |
47 | 47 |
48 CrosMountPointProvider::CrosMountPointProvider( | 48 CrosMountPointProvider::CrosMountPointProvider( |
49 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 49 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
50 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 50 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
51 fileapi::ExternalMountPoints* system_mount_points) | 51 fileapi::ExternalMountPoints* system_mount_points) |
52 : special_storage_policy_(special_storage_policy), | 52 : special_storage_policy_(special_storage_policy), |
53 file_access_permissions_(new FileAccessPermissions()), | 53 file_access_permissions_(new FileAccessPermissions()), |
54 local_file_util_(new fileapi::AsyncFileUtilAdapter( | 54 local_file_util_(new fileapi::AsyncFileUtilAdapter( |
55 new fileapi::IsolatedFileUtil())), | 55 new fileapi::IsolatedFileUtil())), |
| 56 drive_delegate_(new drive::MountPointProviderDelegate(mount_points)), |
56 mount_points_(mount_points), | 57 mount_points_(mount_points), |
57 system_mount_points_(system_mount_points) { | 58 system_mount_points_(system_mount_points) { |
58 } | 59 } |
59 | 60 |
60 CrosMountPointProvider::~CrosMountPointProvider() { | 61 CrosMountPointProvider::~CrosMountPointProvider() { |
61 } | 62 } |
62 | 63 |
63 void CrosMountPointProvider::AddSystemMountPoints() { | 64 void CrosMountPointProvider::AddSystemMountPoints() { |
64 // RegisterFileSystem() is no-op if the mount point with the same name | 65 // RegisterFileSystem() is no-op if the mount point with the same name |
65 // already exists, hence it's safe to call without checking if a mount | 66 // already exists, hence it's safe to call without checking if a mount |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 214 |
214 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( | 215 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( |
215 fileapi::FileSystemType type) { | 216 fileapi::FileSystemType type) { |
216 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 217 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
217 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 218 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
218 return local_file_util_->sync_file_util(); | 219 return local_file_util_->sync_file_util(); |
219 } | 220 } |
220 | 221 |
221 fileapi::AsyncFileUtil* CrosMountPointProvider::GetAsyncFileUtil( | 222 fileapi::AsyncFileUtil* CrosMountPointProvider::GetAsyncFileUtil( |
222 fileapi::FileSystemType type) { | 223 fileapi::FileSystemType type) { |
| 224 if (type == fileapi::kFileSystemTypeDrive) |
| 225 return drive_delegate_->GetAsyncFileUtil(type); |
| 226 |
223 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 227 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
224 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 228 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
225 return local_file_util_.get(); | 229 return local_file_util_.get(); |
226 } | 230 } |
227 | 231 |
228 fileapi::CopyOrMoveFileValidatorFactory* | 232 fileapi::CopyOrMoveFileValidatorFactory* |
229 CrosMountPointProvider::GetCopyOrMoveFileValidatorFactory( | 233 CrosMountPointProvider::GetCopyOrMoveFileValidatorFactory( |
230 fileapi::FileSystemType type, base::PlatformFileError* error_code) { | 234 fileapi::FileSystemType type, base::PlatformFileError* error_code) { |
231 DCHECK(error_code); | 235 DCHECK(error_code); |
232 *error_code = base::PLATFORM_FILE_OK; | 236 *error_code = base::PLATFORM_FILE_OK; |
233 return NULL; | 237 return NULL; |
234 } | 238 } |
235 | 239 |
236 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( | 240 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( |
237 const fileapi::FileSystemURL& url, | 241 const fileapi::FileSystemURL& url, |
238 fileapi::FileSystemContext* context, | 242 fileapi::FileSystemContext* context, |
239 base::PlatformFileError* error_code) const { | 243 base::PlatformFileError* error_code) const { |
240 DCHECK(url.is_valid()); | 244 DCHECK(url.is_valid()); |
241 | 245 |
242 if (!IsAccessAllowed(url)) { | 246 if (!IsAccessAllowed(url)) { |
243 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 247 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
244 return NULL; | 248 return NULL; |
245 } | 249 } |
246 | 250 |
247 if (url.type() == fileapi::kFileSystemTypeDrive) { | 251 if (url.type() == fileapi::kFileSystemTypeDrive) |
248 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 252 return drive_delegate_->CreateFileSystemOperation(url, context, error_code); |
249 GetRemoteProxy(url.filesystem_id()); | |
250 if (!remote_proxy) { | |
251 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
252 return NULL; | |
253 } | |
254 return new RemoteFileSystemOperation(remote_proxy); | |
255 } | |
256 | 253 |
257 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || | 254 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
258 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); | 255 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); |
259 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 256 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
260 new fileapi::FileSystemOperationContext(context)); | 257 new fileapi::FileSystemOperationContext(context)); |
261 operation_context->set_root_path(GetFileSystemRootPath(url)); | 258 operation_context->set_root_path(GetFileSystemRootPath(url)); |
262 return new fileapi::LocalFileSystemOperation(url, context, | 259 return new fileapi::LocalFileSystemOperation(url, context, |
263 operation_context.Pass()); | 260 operation_context.Pass()); |
264 } | 261 } |
265 | 262 |
266 scoped_ptr<webkit_blob::FileStreamReader> | 263 scoped_ptr<webkit_blob::FileStreamReader> |
267 CrosMountPointProvider::CreateFileStreamReader( | 264 CrosMountPointProvider::CreateFileStreamReader( |
268 const fileapi::FileSystemURL& url, | 265 const fileapi::FileSystemURL& url, |
269 int64 offset, | 266 int64 offset, |
270 const base::Time& expected_modification_time, | 267 const base::Time& expected_modification_time, |
271 fileapi::FileSystemContext* context) const { | 268 fileapi::FileSystemContext* context) const { |
272 DCHECK(url.is_valid()); | 269 DCHECK(url.is_valid()); |
273 | 270 |
274 if (!IsAccessAllowed(url)) | 271 if (!IsAccessAllowed(url)) |
275 return scoped_ptr<webkit_blob::FileStreamReader>(); | 272 return scoped_ptr<webkit_blob::FileStreamReader>(); |
276 | 273 |
277 if (url.type() == fileapi::kFileSystemTypeDrive) { | 274 if (url.type() == fileapi::kFileSystemTypeDrive) { |
278 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 275 return drive_delegate_->CreateFileStreamReader( |
279 GetRemoteProxy(url.filesystem_id()); | 276 url, offset, expected_modification_time, context); |
280 if (!remote_proxy) | |
281 return scoped_ptr<webkit_blob::FileStreamReader>(); | |
282 return remote_proxy->CreateFileStreamReader( | |
283 context->task_runners()->file_task_runner(), | |
284 url, offset, expected_modification_time); | |
285 } | 277 } |
286 | 278 |
287 return scoped_ptr<webkit_blob::FileStreamReader>( | 279 return scoped_ptr<webkit_blob::FileStreamReader>( |
288 new fileapi::FileSystemFileStreamReader( | 280 new fileapi::FileSystemFileStreamReader( |
289 context, url, offset, expected_modification_time)); | 281 context, url, offset, expected_modification_time)); |
290 } | 282 } |
291 | 283 |
292 scoped_ptr<fileapi::FileStreamWriter> | 284 scoped_ptr<fileapi::FileStreamWriter> |
293 CrosMountPointProvider::CreateFileStreamWriter( | 285 CrosMountPointProvider::CreateFileStreamWriter( |
294 const fileapi::FileSystemURL& url, | 286 const fileapi::FileSystemURL& url, |
295 int64 offset, | 287 int64 offset, |
296 fileapi::FileSystemContext* context) const { | 288 fileapi::FileSystemContext* context) const { |
297 DCHECK(url.is_valid()); | 289 DCHECK(url.is_valid()); |
298 | 290 |
299 if (!IsAccessAllowed(url)) | 291 if (!IsAccessAllowed(url)) |
300 return scoped_ptr<fileapi::FileStreamWriter>(); | 292 return scoped_ptr<fileapi::FileStreamWriter>(); |
301 | 293 |
302 if (url.type() == fileapi::kFileSystemTypeDrive) { | 294 if (url.type() == fileapi::kFileSystemTypeDrive) |
303 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 295 return drive_delegate_->CreateFileStreamWriter(url, offset, context); |
304 GetRemoteProxy(url.filesystem_id()); | |
305 if (!remote_proxy) | |
306 return scoped_ptr<fileapi::FileStreamWriter>(); | |
307 return scoped_ptr<fileapi::FileStreamWriter>( | |
308 new RemoteFileStreamWriter( | |
309 remote_proxy, url, offset, | |
310 context->task_runners()->file_task_runner())); | |
311 } | |
312 | 296 |
313 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 297 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
314 return scoped_ptr<fileapi::FileStreamWriter>(); | 298 return scoped_ptr<fileapi::FileStreamWriter>(); |
315 | 299 |
316 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 300 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
317 return scoped_ptr<fileapi::FileStreamWriter>( | 301 return scoped_ptr<fileapi::FileStreamWriter>( |
318 new fileapi::LocalFileStreamWriter( | 302 new fileapi::LocalFileStreamWriter( |
319 context->task_runners()->file_task_runner(), url.path(), offset)); | 303 context->task_runners()->file_task_runner(), url.path(), offset)); |
320 } | 304 } |
321 | 305 |
322 bool CrosMountPointProvider::GetVirtualPath( | 306 bool CrosMountPointProvider::GetVirtualPath( |
323 const base::FilePath& filesystem_path, | 307 const base::FilePath& filesystem_path, |
324 base::FilePath* virtual_path) { | 308 base::FilePath* virtual_path) { |
325 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 309 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
326 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 310 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
327 } | 311 } |
328 | 312 |
329 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( | |
330 const std::string& mount_name) const { | |
331 fileapi::RemoteFileSystemProxyInterface* proxy = | |
332 mount_points_->GetRemoteFileSystemProxy(mount_name); | |
333 if (proxy) | |
334 return proxy; | |
335 return system_mount_points_->GetRemoteFileSystemProxy(mount_name); | |
336 } | |
337 | |
338 base::FilePath CrosMountPointProvider::GetFileSystemRootPath( | 313 base::FilePath CrosMountPointProvider::GetFileSystemRootPath( |
339 const fileapi::FileSystemURL& url) const { | 314 const fileapi::FileSystemURL& url) const { |
340 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); | 315 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); |
341 if (!url.is_valid()) | 316 if (!url.is_valid()) |
342 return base::FilePath(); | 317 return base::FilePath(); |
343 | 318 |
344 base::FilePath root_path; | 319 base::FilePath root_path; |
345 std::string mount_name = url.filesystem_id(); | 320 std::string mount_name = url.filesystem_id(); |
346 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && | 321 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && |
347 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { | 322 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { |
348 return base::FilePath(); | 323 return base::FilePath(); |
349 } | 324 } |
350 | 325 |
351 return root_path.DirName(); | 326 return root_path.DirName(); |
352 } | 327 } |
353 | 328 |
354 } // namespace chromeos | 329 } // namespace chromeos |
OLD | NEW |