1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "base/files/file_path.h" 12 #include "base/memory/ref_counted.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 15 #include "webkit/browser/fileapi/file_system_backend.h" 16 17 namespace base { 18 class SequencedTaskRunner; 19 } 20 21 namespace fileapi { 22 class FileSystemURL; 23 } 24 25 namespace net { 26 class URLRequest; 27 } 28 29 class MediaPathFilter; 30 class DeviceMediaAsyncFileUtil; 31 32 class MediaFileSystemBackend : public fileapi::FileSystemBackend { 33 public: 34 static const char kMediaTaskRunnerName[]; 35 36 MediaFileSystemBackend( 37 const base::FilePath& profile_path, 38 base::SequencedTaskRunner* media_task_runner); 39 virtual ~MediaFileSystemBackend(); 40 41 static bool CurrentlyOnMediaTaskRunnerThread(); 42 static scoped_refptr<base::SequencedTaskRunner> MediaTaskRunner(); 43 44 // Construct the mount point for the gallery specified by |pref_id| in 45 // the profile located in |profile_path|. 46 static std::string ConstructMountName(const base::FilePath& profile_path, 47 const std::string& extension_id, 48 MediaGalleryPrefId pref_id); 49 50 static bool AttemptAutoMountForURLRequest( 51 const net::URLRequest* url_request, 52 const fileapi::FileSystemURL& filesystem_url, 53 const std::string& storage_domain, 54 const base::Callback<void(base::File::Error result)>& callback); 55 56 // FileSystemBackend implementation. 57 virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; 58 virtual void Initialize(fileapi::FileSystemContext* context) OVERRIDE; 59 virtual void ResolveURL(const fileapi::FileSystemURL& url, 60 fileapi::OpenFileSystemMode mode, 61 const OpenFileSystemCallback& callback) OVERRIDE; 62 virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( 63 fileapi::FileSystemType type) OVERRIDE; 64 virtual fileapi::CopyOrMoveFileValidatorFactory* 65 GetCopyOrMoveFileValidatorFactory( 66 fileapi::FileSystemType type, 67 base::File::Error* error_code) OVERRIDE; 68 virtual fileapi::FileSystemOperation* CreateFileSystemOperation( 69 const fileapi::FileSystemURL& url, 70 fileapi::FileSystemContext* context, 71 base::File::Error* error_code) const OVERRIDE; 72 virtual bool SupportsStreaming( 73 const fileapi::FileSystemURL& url) const OVERRIDE; 74 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( 75 const fileapi::FileSystemURL& url, 76 int64 offset, 77 const base::Time& expected_modification_time, 78 fileapi::FileSystemContext* context) const OVERRIDE; 79 virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( 80 const fileapi::FileSystemURL& url, 81 int64 offset, 82 fileapi::FileSystemContext* context) const OVERRIDE; 83 virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; 84 85 private: 86 // Store the profile path. We need this to create temporary snapshot files. 87 const base::FilePath profile_path_; 88 89 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; 90 91 scoped_ptr<MediaPathFilter> media_path_filter_; 92 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> 93 media_copy_or_move_file_validator_factory_; 94 95 scoped_ptr<fileapi::AsyncFileUtil> native_media_file_util_; 96 scoped_ptr<DeviceMediaAsyncFileUtil> device_media_async_file_util_; 97 #if defined(OS_WIN) || defined(OS_MACOSX) 98 scoped_ptr<fileapi::AsyncFileUtil> picasa_file_util_; 99 scoped_ptr<fileapi::AsyncFileUtil> itunes_file_util_; 100 #endif // defined(OS_WIN) || defined(OS_MACOSX) 101 #if defined(OS_MACOSX) 102 scoped_ptr<fileapi::AsyncFileUtil> iphoto_file_util_; 103 #endif // defined(OS_MACOSX) 104 105 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemBackend); 106 }; 107 108 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_ 109