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