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.
5 #ifndef STORAGE_BROWSER_FILEAPI_PLUGIN_PRIVATE_FILE_SYSTEM_BACKEND_H_
6 #define STORAGE_BROWSER_FILEAPI_PLUGIN_PRIVATE_FILE_SYSTEM_BACKEND_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "storage/browser/fileapi/file_system_backend.h"
14 #include "storage/browser/fileapi/file_system_options.h"
15 #include "storage/browser/fileapi/file_system_quota_util.h"
16 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
19 class SequencedTaskRunner
;
23 class PluginPrivateFileSystemBackendTest
;
27 class SpecialStoragePolicy
;
32 class ObfuscatedFileUtil
;
35 class STORAGE_EXPORT PluginPrivateFileSystemBackend
36 : public FileSystemBackend
,
37 public FileSystemQuotaUtil
{
39 class FileSystemIDToPluginMap
;
40 typedef base::Callback
<void(base::File::Error result
)> StatusCallback
;
42 PluginPrivateFileSystemBackend(
43 base::SequencedTaskRunner
* file_task_runner
,
44 const base::FilePath
& profile_path
,
45 storage::SpecialStoragePolicy
* special_storage_policy
,
46 const FileSystemOptions
& file_system_options
);
47 ~PluginPrivateFileSystemBackend() override
;
49 // This must be used to open 'private' filesystem instead of regular
51 // |plugin_id| must be an identifier string for per-plugin
52 // isolation, e.g. name, MIME type etc.
53 // NOTE: |plugin_id| must be sanitized ASCII string that doesn't
54 // include *any* dangerous character like '/'.
55 void OpenPrivateFileSystem(
56 const GURL
& origin_url
,
58 const std::string
& filesystem_id
,
59 const std::string
& plugin_id
,
60 OpenFileSystemMode mode
,
61 const StatusCallback
& callback
);
63 // FileSystemBackend overrides.
64 bool CanHandleType(FileSystemType type
) const override
;
65 void Initialize(FileSystemContext
* context
) override
;
66 void ResolveURL(const FileSystemURL
& url
,
67 OpenFileSystemMode mode
,
68 const OpenFileSystemCallback
& callback
) override
;
69 AsyncFileUtil
* GetAsyncFileUtil(FileSystemType type
) override
;
70 WatcherManager
* GetWatcherManager(FileSystemType type
) override
;
71 CopyOrMoveFileValidatorFactory
* GetCopyOrMoveFileValidatorFactory(
73 base::File::Error
* error_code
) override
;
74 FileSystemOperation
* CreateFileSystemOperation(
75 const FileSystemURL
& url
,
76 FileSystemContext
* context
,
77 base::File::Error
* error_code
) const override
;
78 bool SupportsStreaming(const FileSystemURL
& url
) const override
;
79 bool HasInplaceCopyImplementation(
80 storage::FileSystemType type
) const override
;
81 scoped_ptr
<storage::FileStreamReader
> CreateFileStreamReader(
82 const FileSystemURL
& url
,
84 int64 max_bytes_to_read
,
85 const base::Time
& expected_modification_time
,
86 FileSystemContext
* context
) const override
;
87 scoped_ptr
<FileStreamWriter
> CreateFileStreamWriter(
88 const FileSystemURL
& url
,
90 FileSystemContext
* context
) const override
;
91 FileSystemQuotaUtil
* GetQuotaUtil() override
;
92 const UpdateObserverList
* GetUpdateObservers(
93 FileSystemType type
) const override
;
94 const ChangeObserverList
* GetChangeObservers(
95 FileSystemType type
) const override
;
96 const AccessObserverList
* GetAccessObservers(
97 FileSystemType type
) const override
;
99 // FileSystemQuotaUtil overrides.
100 base::File::Error
DeleteOriginDataOnFileTaskRunner(
101 FileSystemContext
* context
,
102 storage::QuotaManagerProxy
* proxy
,
103 const GURL
& origin_url
,
104 FileSystemType type
) override
;
105 void GetOriginsForTypeOnFileTaskRunner(FileSystemType type
,
106 std::set
<GURL
>* origins
) override
;
107 void GetOriginsForHostOnFileTaskRunner(FileSystemType type
,
108 const std::string
& host
,
109 std::set
<GURL
>* origins
) override
;
110 int64
GetOriginUsageOnFileTaskRunner(FileSystemContext
* context
,
111 const GURL
& origin_url
,
112 FileSystemType type
) override
;
113 scoped_refptr
<QuotaReservation
> CreateQuotaReservationOnFileTaskRunner(
114 const GURL
& origin_url
,
115 FileSystemType type
) override
;
118 friend class content::PluginPrivateFileSystemBackendTest
;
120 ObfuscatedFileUtil
* obfuscated_file_util();
121 const base::FilePath
& base_path() const { return base_path_
; }
123 scoped_refptr
<base::SequencedTaskRunner
> file_task_runner_
;
124 const FileSystemOptions file_system_options_
;
125 const base::FilePath base_path_
;
126 scoped_ptr
<AsyncFileUtil
> file_util_
;
127 FileSystemIDToPluginMap
* plugin_map_
; // Owned by file_util_.
128 base::WeakPtrFactory
<PluginPrivateFileSystemBackend
> weak_factory_
;
130 DISALLOW_COPY_AND_ASSIGN(PluginPrivateFileSystemBackend
);
133 } // namespace storage
135 #endif // STORAGE_BROWSER_FILEAPI_PLUGIN_PRIVATE_FILE_SYSTEM_BACKEND_H_