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

Side by Side Diff: chrome/browser/chromeos/fileapi/file_system_backend.cc

Issue 2450713002: arc: Register ARC content file system (Closed)
Patch Set: Address comments Created 4 years, 1 month 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
OLDNEW
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/file_system_backend.h" 5 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } // namespace 42 } // namespace
43 43
44 // static 44 // static
45 bool FileSystemBackend::CanHandleURL(const storage::FileSystemURL& url) { 45 bool FileSystemBackend::CanHandleURL(const storage::FileSystemURL& url) {
46 if (!url.is_valid()) 46 if (!url.is_valid())
47 return false; 47 return false;
48 return url.type() == storage::kFileSystemTypeNativeLocal || 48 return url.type() == storage::kFileSystemTypeNativeLocal ||
49 url.type() == storage::kFileSystemTypeRestrictedNativeLocal || 49 url.type() == storage::kFileSystemTypeRestrictedNativeLocal ||
50 url.type() == storage::kFileSystemTypeDrive || 50 url.type() == storage::kFileSystemTypeDrive ||
51 url.type() == storage::kFileSystemTypeProvided || 51 url.type() == storage::kFileSystemTypeProvided ||
52 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage; 52 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage ||
53 url.type() == storage::kFileSystemTypeArcContent;
53 } 54 }
54 55
55 FileSystemBackend::FileSystemBackend( 56 FileSystemBackend::FileSystemBackend(
56 FileSystemBackendDelegate* drive_delegate, 57 std::unique_ptr<FileSystemBackendDelegate> drive_delegate,
57 FileSystemBackendDelegate* file_system_provider_delegate, 58 std::unique_ptr<FileSystemBackendDelegate> file_system_provider_delegate,
58 FileSystemBackendDelegate* mtp_delegate, 59 std::unique_ptr<FileSystemBackendDelegate> mtp_delegate,
60 std::unique_ptr<FileSystemBackendDelegate> arc_content_delegate,
59 scoped_refptr<storage::ExternalMountPoints> mount_points, 61 scoped_refptr<storage::ExternalMountPoints> mount_points,
60 storage::ExternalMountPoints* system_mount_points) 62 storage::ExternalMountPoints* system_mount_points)
61 : file_access_permissions_(new FileAccessPermissions()), 63 : file_access_permissions_(new FileAccessPermissions()),
62 local_file_util_(storage::AsyncFileUtil::CreateForLocalFileSystem()), 64 local_file_util_(storage::AsyncFileUtil::CreateForLocalFileSystem()),
63 drive_delegate_(drive_delegate), 65 drive_delegate_(std::move(drive_delegate)),
64 file_system_provider_delegate_(file_system_provider_delegate), 66 file_system_provider_delegate_(std::move(file_system_provider_delegate)),
65 mtp_delegate_(mtp_delegate), 67 mtp_delegate_(std::move(mtp_delegate)),
68 arc_content_delegate_(std::move(arc_content_delegate)),
66 mount_points_(mount_points), 69 mount_points_(mount_points),
67 system_mount_points_(system_mount_points) { 70 system_mount_points_(system_mount_points) {}
68 }
69 71
70 FileSystemBackend::~FileSystemBackend() { 72 FileSystemBackend::~FileSystemBackend() {
71 } 73 }
72 74
73 void FileSystemBackend::AddSystemMountPoints() { 75 void FileSystemBackend::AddSystemMountPoints() {
74 // RegisterFileSystem() is no-op if the mount point with the same name 76 // RegisterFileSystem() is no-op if the mount point with the same name
75 // already exists, hence it's safe to call without checking if a mount 77 // already exists, hence it's safe to call without checking if a mount
76 // point already exists or not. 78 // point already exists or not.
77 system_mount_points_->RegisterFileSystem( 79 system_mount_points_->RegisterFileSystem(
78 "archive", 80 "archive",
(...skipping 13 matching lines...) Expand all
92 94
93 bool FileSystemBackend::CanHandleType(storage::FileSystemType type) const { 95 bool FileSystemBackend::CanHandleType(storage::FileSystemType type) const {
94 switch (type) { 96 switch (type) {
95 case storage::kFileSystemTypeExternal: 97 case storage::kFileSystemTypeExternal:
96 case storage::kFileSystemTypeDrive: 98 case storage::kFileSystemTypeDrive:
97 case storage::kFileSystemTypeRestrictedNativeLocal: 99 case storage::kFileSystemTypeRestrictedNativeLocal:
98 case storage::kFileSystemTypeNativeLocal: 100 case storage::kFileSystemTypeNativeLocal:
99 case storage::kFileSystemTypeNativeForPlatformApp: 101 case storage::kFileSystemTypeNativeForPlatformApp:
100 case storage::kFileSystemTypeDeviceMediaAsFileStorage: 102 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
101 case storage::kFileSystemTypeProvided: 103 case storage::kFileSystemTypeProvided:
104 case storage::kFileSystemTypeArcContent:
102 return true; 105 return true;
103 default: 106 default:
104 return false; 107 return false;
105 } 108 }
106 } 109 }
107 110
108 void FileSystemBackend::Initialize(storage::FileSystemContext* context) { 111 void FileSystemBackend::Initialize(storage::FileSystemContext* context) {
109 } 112 }
110 113
111 void FileSystemBackend::ResolveURL(const storage::FileSystemURL& url, 114 void FileSystemBackend::ResolveURL(const storage::FileSystemURL& url,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 switch (type) { 245 switch (type) {
243 case storage::kFileSystemTypeDrive: 246 case storage::kFileSystemTypeDrive:
244 return drive_delegate_->GetAsyncFileUtil(type); 247 return drive_delegate_->GetAsyncFileUtil(type);
245 case storage::kFileSystemTypeProvided: 248 case storage::kFileSystemTypeProvided:
246 return file_system_provider_delegate_->GetAsyncFileUtil(type); 249 return file_system_provider_delegate_->GetAsyncFileUtil(type);
247 case storage::kFileSystemTypeNativeLocal: 250 case storage::kFileSystemTypeNativeLocal:
248 case storage::kFileSystemTypeRestrictedNativeLocal: 251 case storage::kFileSystemTypeRestrictedNativeLocal:
249 return local_file_util_.get(); 252 return local_file_util_.get();
250 case storage::kFileSystemTypeDeviceMediaAsFileStorage: 253 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
251 return mtp_delegate_->GetAsyncFileUtil(type); 254 return mtp_delegate_->GetAsyncFileUtil(type);
255 case storage::kFileSystemTypeArcContent:
256 return arc_content_delegate_->GetAsyncFileUtil(type);
252 default: 257 default:
253 NOTREACHED(); 258 NOTREACHED();
254 } 259 }
255 return NULL; 260 return NULL;
256 } 261 }
257 262
258 storage::WatcherManager* FileSystemBackend::GetWatcherManager( 263 storage::WatcherManager* FileSystemBackend::GetWatcherManager(
259 storage::FileSystemType type) { 264 storage::FileSystemType type) {
260 if (type == storage::kFileSystemTypeProvided) 265 if (type == storage::kFileSystemTypeProvided)
261 return file_system_provider_delegate_->GetWatcherManager(type); 266 return file_system_provider_delegate_->GetWatcherManager(type);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // MTP file operations run on MediaTaskRunner. 299 // MTP file operations run on MediaTaskRunner.
295 return storage::FileSystemOperation::Create( 300 return storage::FileSystemOperation::Create(
296 url, context, 301 url, context,
297 base::MakeUnique<storage::FileSystemOperationContext>( 302 base::MakeUnique<storage::FileSystemOperationContext>(
298 context, MediaFileSystemBackend::MediaTaskRunner().get())); 303 context, MediaFileSystemBackend::MediaTaskRunner().get()));
299 } 304 }
300 305
301 DCHECK(url.type() == storage::kFileSystemTypeNativeLocal || 306 DCHECK(url.type() == storage::kFileSystemTypeNativeLocal ||
302 url.type() == storage::kFileSystemTypeRestrictedNativeLocal || 307 url.type() == storage::kFileSystemTypeRestrictedNativeLocal ||
303 url.type() == storage::kFileSystemTypeDrive || 308 url.type() == storage::kFileSystemTypeDrive ||
304 url.type() == storage::kFileSystemTypeProvided); 309 url.type() == storage::kFileSystemTypeProvided ||
310 url.type() == storage::kFileSystemTypeArcContent);
305 return storage::FileSystemOperation::Create( 311 return storage::FileSystemOperation::Create(
306 url, context, 312 url, context,
307 base::MakeUnique<storage::FileSystemOperationContext>(context)); 313 base::MakeUnique<storage::FileSystemOperationContext>(context));
308 } 314 }
309 315
310 bool FileSystemBackend::SupportsStreaming( 316 bool FileSystemBackend::SupportsStreaming(
311 const storage::FileSystemURL& url) const { 317 const storage::FileSystemURL& url) const {
312 return url.type() == storage::kFileSystemTypeDrive || 318 return url.type() == storage::kFileSystemTypeDrive ||
313 url.type() == storage::kFileSystemTypeProvided || 319 url.type() == storage::kFileSystemTypeProvided ||
314 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage; 320 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage ||
321 url.type() == storage::kFileSystemTypeArcContent;
315 } 322 }
316 323
317 bool FileSystemBackend::HasInplaceCopyImplementation( 324 bool FileSystemBackend::HasInplaceCopyImplementation(
318 storage::FileSystemType type) const { 325 storage::FileSystemType type) const {
319 switch (type) { 326 switch (type) {
320 case storage::kFileSystemTypeDrive: 327 case storage::kFileSystemTypeDrive:
321 case storage::kFileSystemTypeProvided: 328 case storage::kFileSystemTypeProvided:
322 case storage::kFileSystemTypeDeviceMediaAsFileStorage: 329 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
323 return true; 330 return true;
324 case storage::kFileSystemTypeNativeLocal: 331 case storage::kFileSystemTypeNativeLocal:
325 case storage::kFileSystemTypeRestrictedNativeLocal: 332 case storage::kFileSystemTypeRestrictedNativeLocal:
333 case storage::kFileSystemTypeArcContent:
326 return false; 334 return false;
327 default: 335 default:
328 NOTREACHED(); 336 NOTREACHED();
329 } 337 }
330 return true; 338 return true;
331 } 339 }
332 340
333 std::unique_ptr<storage::FileStreamReader> 341 std::unique_ptr<storage::FileStreamReader>
334 FileSystemBackend::CreateFileStreamReader( 342 FileSystemBackend::CreateFileStreamReader(
335 const storage::FileSystemURL& url, 343 const storage::FileSystemURL& url,
(...skipping 14 matching lines...) Expand all
350 return file_system_provider_delegate_->CreateFileStreamReader( 358 return file_system_provider_delegate_->CreateFileStreamReader(
351 url, offset, max_bytes_to_read, expected_modification_time, context); 359 url, offset, max_bytes_to_read, expected_modification_time, context);
352 case storage::kFileSystemTypeNativeLocal: 360 case storage::kFileSystemTypeNativeLocal:
353 case storage::kFileSystemTypeRestrictedNativeLocal: 361 case storage::kFileSystemTypeRestrictedNativeLocal:
354 return std::unique_ptr<storage::FileStreamReader>( 362 return std::unique_ptr<storage::FileStreamReader>(
355 storage::FileStreamReader::CreateForFileSystemFile( 363 storage::FileStreamReader::CreateForFileSystemFile(
356 context, url, offset, expected_modification_time)); 364 context, url, offset, expected_modification_time));
357 case storage::kFileSystemTypeDeviceMediaAsFileStorage: 365 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
358 return mtp_delegate_->CreateFileStreamReader( 366 return mtp_delegate_->CreateFileStreamReader(
359 url, offset, max_bytes_to_read, expected_modification_time, context); 367 url, offset, max_bytes_to_read, expected_modification_time, context);
368 case storage::kFileSystemTypeArcContent:
369 return arc_content_delegate_->CreateFileStreamReader(
370 url, offset, max_bytes_to_read, expected_modification_time, context);
360 default: 371 default:
361 NOTREACHED(); 372 NOTREACHED();
362 } 373 }
363 return std::unique_ptr<storage::FileStreamReader>(); 374 return std::unique_ptr<storage::FileStreamReader>();
364 } 375 }
365 376
366 std::unique_ptr<storage::FileStreamWriter> 377 std::unique_ptr<storage::FileStreamWriter>
367 FileSystemBackend::CreateFileStreamWriter( 378 FileSystemBackend::CreateFileStreamWriter(
368 const storage::FileSystemURL& url, 379 const storage::FileSystemURL& url,
369 int64_t offset, 380 int64_t offset,
370 storage::FileSystemContext* context) const { 381 storage::FileSystemContext* context) const {
371 DCHECK(url.is_valid()); 382 DCHECK(url.is_valid());
372 383
373 if (!IsAccessAllowed(url)) 384 if (!IsAccessAllowed(url))
374 return std::unique_ptr<storage::FileStreamWriter>(); 385 return std::unique_ptr<storage::FileStreamWriter>();
375 386
376 switch (url.type()) { 387 switch (url.type()) {
377 case storage::kFileSystemTypeDrive: 388 case storage::kFileSystemTypeDrive:
378 return drive_delegate_->CreateFileStreamWriter(url, offset, context); 389 return drive_delegate_->CreateFileStreamWriter(url, offset, context);
379 case storage::kFileSystemTypeProvided: 390 case storage::kFileSystemTypeProvided:
380 return file_system_provider_delegate_->CreateFileStreamWriter( 391 return file_system_provider_delegate_->CreateFileStreamWriter(
381 url, offset, context); 392 url, offset, context);
382 case storage::kFileSystemTypeNativeLocal: 393 case storage::kFileSystemTypeNativeLocal:
383 return std::unique_ptr<storage::FileStreamWriter>( 394 return std::unique_ptr<storage::FileStreamWriter>(
384 storage::FileStreamWriter::CreateForLocalFile( 395 storage::FileStreamWriter::CreateForLocalFile(
385 context->default_file_task_runner(), url.path(), offset, 396 context->default_file_task_runner(), url.path(), offset,
386 storage::FileStreamWriter::OPEN_EXISTING_FILE)); 397 storage::FileStreamWriter::OPEN_EXISTING_FILE));
387 case storage::kFileSystemTypeRestrictedNativeLocal:
388 // Restricted native local file system is read only.
389 return std::unique_ptr<storage::FileStreamWriter>();
390 case storage::kFileSystemTypeDeviceMediaAsFileStorage: 398 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
391 return mtp_delegate_->CreateFileStreamWriter(url, offset, context); 399 return mtp_delegate_->CreateFileStreamWriter(url, offset, context);
400 // Read only file systems.
401 case storage::kFileSystemTypeRestrictedNativeLocal:
402 case storage::kFileSystemTypeArcContent:
403 return std::unique_ptr<storage::FileStreamWriter>();
392 default: 404 default:
393 NOTREACHED(); 405 NOTREACHED();
394 } 406 }
395 return std::unique_ptr<storage::FileStreamWriter>(); 407 return std::unique_ptr<storage::FileStreamWriter>();
396 } 408 }
397 409
398 bool FileSystemBackend::GetVirtualPath(const base::FilePath& filesystem_path, 410 bool FileSystemBackend::GetVirtualPath(const base::FilePath& filesystem_path,
399 base::FilePath* virtual_path) const { 411 base::FilePath* virtual_path) const {
400 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || 412 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) ||
401 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); 413 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path);
(...skipping 13 matching lines...) Expand all
415 return; 427 return;
416 case storage::kFileSystemTypeProvided: 428 case storage::kFileSystemTypeProvided:
417 file_system_provider_delegate_->GetRedirectURLForContents(url, 429 file_system_provider_delegate_->GetRedirectURLForContents(url,
418 callback); 430 callback);
419 return; 431 return;
420 case storage::kFileSystemTypeDeviceMediaAsFileStorage: 432 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
421 mtp_delegate_->GetRedirectURLForContents(url, callback); 433 mtp_delegate_->GetRedirectURLForContents(url, callback);
422 return; 434 return;
423 case storage::kFileSystemTypeNativeLocal: 435 case storage::kFileSystemTypeNativeLocal:
424 case storage::kFileSystemTypeRestrictedNativeLocal: 436 case storage::kFileSystemTypeRestrictedNativeLocal:
437 case storage::kFileSystemTypeArcContent:
425 callback.Run(GURL()); 438 callback.Run(GURL());
426 return; 439 return;
427 default: 440 default:
428 NOTREACHED(); 441 NOTREACHED();
429 } 442 }
430 callback.Run(GURL()); 443 callback.Run(GURL());
431 } 444 }
432 445
433 storage::FileSystemURL FileSystemBackend::CreateInternalURL( 446 storage::FileSystemURL FileSystemBackend::CreateInternalURL(
434 storage::FileSystemContext* context, 447 storage::FileSystemContext* context,
435 const base::FilePath& entry_path) const { 448 const base::FilePath& entry_path) const {
436 base::FilePath virtual_path; 449 base::FilePath virtual_path;
437 if (!GetVirtualPath(entry_path, &virtual_path)) 450 if (!GetVirtualPath(entry_path, &virtual_path))
438 return storage::FileSystemURL(); 451 return storage::FileSystemURL();
439 452
440 return context->CreateCrackedFileSystemURL( 453 return context->CreateCrackedFileSystemURL(
441 GURL() /* origin */, storage::kFileSystemTypeExternal, virtual_path); 454 GURL() /* origin */, storage::kFileSystemTypeExternal, virtual_path);
442 } 455 }
443 456
444 } // namespace chromeos 457 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/fileapi/file_system_backend.h ('k') | chrome/browser/chromeos/fileapi/file_system_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698