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 3 // found in the LICENSE file. 4 5 #ifndef WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_SYSTEM_BACKEND_H_ 6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_SYSTEM_BACKEND_H_ 7 8 #include <set> 9 #include <string> 10 11 #include "base/compiler_specific.h" 12 #include "base/files/file_path.h" 13 #include "base/memory/ref_counted.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "webkit/browser/fileapi/file_system_backend.h" 16 #include "webkit/browser/fileapi/file_system_quota_util.h" 17 #include "webkit/browser/fileapi/sandbox_context.h" 18 #include "webkit/browser/fileapi/task_runner_bound_observer_list.h" 19 #include "webkit/browser/quota/special_storage_policy.h" 20 #include "webkit/browser/webkit_storage_browser_export.h" 21 22 namespace fileapi { 23 24 // An interface to construct or crack sandboxed filesystem paths for 25 // TEMPORARY or PERSISTENT filesystems, which are placed under the user's 26 // profile directory in a sandboxed way. 27 // This interface also lets one enumerate and remove storage for the origins 28 // that use the filesystem. 29 class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackend 30 : public FileSystemBackend, 31 public FileSystemQuotaUtil { 32 public: 33 explicit SandboxFileSystemBackend(SandboxContext* sandbox_context); 34 virtual ~SandboxFileSystemBackend(); 35 36 // FileSystemBackend overrides. 37 virtual bool CanHandleType(FileSystemType type) const OVERRIDE; 38 virtual void Initialize(FileSystemContext* context) OVERRIDE; 39 virtual void OpenFileSystem( 40 const GURL& origin_url, 41 FileSystemType type, 42 OpenFileSystemMode mode, 43 const OpenFileSystemCallback& callback) OVERRIDE; 44 virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE; 45 virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE; 46 virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( 47 FileSystemType type, 48 base::PlatformFileError* error_code) OVERRIDE; 49 virtual FileSystemOperation* CreateFileSystemOperation( 50 const FileSystemURL& url, 51 FileSystemContext* context, 52 base::PlatformFileError* error_code) const OVERRIDE; 53 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( 54 const FileSystemURL& url, 55 int64 offset, 56 const base::Time& expected_modification_time, 57 FileSystemContext* context) const OVERRIDE; 58 virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter( 59 const FileSystemURL& url, 60 int64 offset, 61 FileSystemContext* context) const OVERRIDE; 62 virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; 63 64 // Returns an origin enumerator of this backend. 65 // This method can only be called on the file thread. 66 SandboxContext::OriginEnumerator* CreateOriginEnumerator(); 67 68 // FileSystemQuotaUtil overrides. 69 virtual base::PlatformFileError DeleteOriginDataOnFileThread( 70 FileSystemContext* context, 71 quota::QuotaManagerProxy* proxy, 72 const GURL& origin_url, 73 FileSystemType type) OVERRIDE; 74 virtual void GetOriginsForTypeOnFileThread( 75 FileSystemType type, 76 std::set<GURL>* origins) OVERRIDE; 77 virtual void GetOriginsForHostOnFileThread( 78 FileSystemType type, 79 const std::string& host, 80 std::set<GURL>* origins) OVERRIDE; 81 virtual int64 GetOriginUsageOnFileThread( 82 FileSystemContext* context, 83 const GURL& origin_url, 84 FileSystemType type) OVERRIDE; 85 virtual void InvalidateUsageCache( 86 const GURL& origin_url, 87 FileSystemType type) OVERRIDE; 88 virtual void StickyInvalidateUsageCache( 89 const GURL& origin_url, 90 FileSystemType type) OVERRIDE; 91 virtual void AddFileUpdateObserver( 92 FileSystemType type, 93 FileUpdateObserver* observer, 94 base::SequencedTaskRunner* task_runner) OVERRIDE; 95 virtual void AddFileChangeObserver( 96 FileSystemType type, 97 FileChangeObserver* observer, 98 base::SequencedTaskRunner* task_runner) OVERRIDE; 99 virtual void AddFileAccessObserver( 100 FileSystemType type, 101 FileAccessObserver* observer, 102 base::SequencedTaskRunner* task_runner) OVERRIDE; 103 virtual const UpdateObserverList* GetUpdateObservers( 104 FileSystemType type) const OVERRIDE; 105 virtual const ChangeObserverList* GetChangeObservers( 106 FileSystemType type) const OVERRIDE; 107 virtual const AccessObserverList* GetAccessObservers( 108 FileSystemType type) const OVERRIDE; 109 110 void set_enable_temporary_file_system_in_incognito(bool enable) { 111 enable_temporary_file_system_in_incognito_ = enable; 112 } 113 114 private: 115 SandboxContext* sandbox_context_; // Not owned. 116 117 bool enable_temporary_file_system_in_incognito_; 118 119 // Observers. 120 UpdateObserverList update_observers_; 121 ChangeObserverList change_observers_; 122 AccessObserverList access_observers_; 123 124 DISALLOW_COPY_AND_ASSIGN(SandboxFileSystemBackend); 125 }; 126 127 } // namespace fileapi 128 129 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_SYSTEM_BACKEND_H_ 130