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 3 // found in the LICENSE file. 4 5 #ifndef WEBKIT_BROWSER_FILEAPI_PLUGIN_PRIVATE_FILE_SYSTEM_BACKEND_H_ 6 #define WEBKIT_BROWSER_FILEAPI_PLUGIN_PRIVATE_FILE_SYSTEM_BACKEND_H_ 7 8 #include <set> 9 #include <string> 10 11 #include "base/memory/ref_counted.h" 12 #include "base/memory/weak_ptr.h" 13 #include "webkit/browser/fileapi/file_system_backend.h" 14 #include "webkit/browser/fileapi/file_system_options.h" 15 #include "webkit/browser/fileapi/file_system_quota_util.h" 16 17 namespace base { 18 class SequencedTaskRunner; 19 } 20 21 namespace quota { 22 class SpecialStoragePolicy; 23 } 24 25 namespace fileapi { 26 27 class ObfuscatedFileUtil; 28 29 class WEBKIT_STORAGE_BROWSER_EXPORT PluginPrivateFileSystemBackend 30 : public FileSystemBackend, 31 public FileSystemQuotaUtil { 32 public: 33 class FileSystemIDToPluginMap; 34 typedef base::Callback<void(base::PlatformFileError result)> StatusCallback; 35 36 PluginPrivateFileSystemBackend( 37 base::SequencedTaskRunner* file_task_runner, 38 const base::FilePath& profile_path, 39 quota::SpecialStoragePolicy* special_storage_policy, 40 const FileSystemOptions& file_system_options); 41 virtual ~PluginPrivateFileSystemBackend(); 42 43 // This must be used to open 'private' filesystem instead of regular 44 // OpenFileSystem. 45 // |plugin_id| must be an identifier string for per-plugin 46 // isolation, e.g. name, MIME type etc. 47 // NOTE: |plugin_id| must be sanitized ASCII string that doesn't 48 // include *any* dangerous character like '/'. 49 void OpenPrivateFileSystem( 50 const GURL& origin_url, 51 FileSystemType type, 52 const std::string& filesystem_id, 53 const std::string& plugin_id, 54 OpenFileSystemMode mode, 55 const StatusCallback& callback); 56 57 // FileSystemBackend overrides. 58 virtual bool CanHandleType(FileSystemType type) const OVERRIDE; 59 virtual void Initialize(FileSystemContext* context) OVERRIDE; 60 virtual void OpenFileSystem( 61 const GURL& origin_url, 62 FileSystemType type, 63 OpenFileSystemMode mode, 64 const OpenFileSystemCallback& callback) OVERRIDE; 65 virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE; 66 virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( 67 FileSystemType type, 68 base::PlatformFileError* error_code) OVERRIDE; 69 virtual FileSystemOperation* CreateFileSystemOperation( 70 const FileSystemURL& url, 71 FileSystemContext* context, 72 base::PlatformFileError* error_code) const OVERRIDE; 73 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( 74 const FileSystemURL& url, 75 int64 offset, 76 const base::Time& expected_modification_time, 77 FileSystemContext* context) const OVERRIDE; 78 virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter( 79 const FileSystemURL& url, 80 int64 offset, 81 FileSystemContext* context) const OVERRIDE; 82 virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; 83 84 // FileSystemQuotaUtil overrides. 85 virtual base::PlatformFileError DeleteOriginDataOnFileThread( 86 FileSystemContext* context, 87 quota::QuotaManagerProxy* proxy, 88 const GURL& origin_url, 89 FileSystemType type) OVERRIDE; 90 virtual void GetOriginsForTypeOnFileThread( 91 FileSystemType type, 92 std::set<GURL>* origins) OVERRIDE; 93 virtual void GetOriginsForHostOnFileThread( 94 FileSystemType type, 95 const std::string& host, 96 std::set<GURL>* origins) OVERRIDE; 97 virtual int64 GetOriginUsageOnFileThread( 98 FileSystemContext* context, 99 const GURL& origin_url, 100 FileSystemType type) OVERRIDE; 101 virtual scoped_refptr<QuotaReservation> 102 CreateQuotaReservationOnFileTaskRunner( 103 const GURL& origin_url, 104 FileSystemType type) OVERRIDE; 105 virtual void AddFileUpdateObserver( 106 FileSystemType type, 107 FileUpdateObserver* observer, 108 base::SequencedTaskRunner* task_runner) OVERRIDE; 109 virtual void AddFileChangeObserver( 110 FileSystemType type, 111 FileChangeObserver* observer, 112 base::SequencedTaskRunner* task_runner) OVERRIDE; 113 virtual void AddFileAccessObserver( 114 FileSystemType type, 115 FileAccessObserver* observer, 116 base::SequencedTaskRunner* task_runner) OVERRIDE; 117 virtual const UpdateObserverList* GetUpdateObservers( 118 FileSystemType type) const OVERRIDE; 119 virtual const ChangeObserverList* GetChangeObservers( 120 FileSystemType type) const OVERRIDE; 121 virtual const AccessObserverList* GetAccessObservers( 122 FileSystemType type) const OVERRIDE; 123 124 private: 125 friend class PluginPrivateFileSystemBackendTest; 126 127 ObfuscatedFileUtil* obfuscated_file_util(); base_path()128 const base::FilePath& base_path() const { return base_path_; } 129 130 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 131 const FileSystemOptions file_system_options_; 132 const base::FilePath base_path_; 133 scoped_ptr<AsyncFileUtil> file_util_; 134 FileSystemIDToPluginMap* plugin_map_; // Owned by file_util_. 135 base::WeakPtrFactory<PluginPrivateFileSystemBackend> weak_factory_; 136 137 DISALLOW_COPY_AND_ASSIGN(PluginPrivateFileSystemBackend); 138 }; 139 140 } // namespace fileapi 141 142 #endif // WEBKIT_BROWSER_FILEAPI_PLUGIN_PRIVATE_FILE_SYSTEM_BACKEND_H_ 143