blob: 424f1faf8ff6d48c7ce522977c27d40673eae8d5 [file] [log] [blame]
[email protected]e7e46732012-01-05 11:45:551// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]073a04f2011-03-24 00:49:402// 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_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_
6#define WEBKIT_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_
7
[email protected]5caeb202011-05-17 07:42:078#include <set>
[email protected]073a04f2011-03-24 00:49:409#include <string>
[email protected]b777b332011-04-16 04:01:0810#include <vector>
[email protected]073a04f2011-03-24 00:49:4011
[email protected]b7d38af72012-05-23 02:51:0912#include "base/compiler_specific.h"
[email protected]073a04f2011-03-24 00:49:4013#include "base/file_path.h"
[email protected]b7d38af72012-05-23 02:51:0914#include "base/memory/ref_counted.h"
[email protected]3cfc10f2012-05-24 01:20:4115#include "base/memory/scoped_ptr.h"
[email protected]d247b842012-05-08 06:43:3616#include "base/memory/weak_ptr.h"
[email protected]073a04f2011-03-24 00:49:4017#include "googleurl/src/gurl.h"
[email protected]0b38b4e52012-05-30 08:14:2718#include "webkit/fileapi/fileapi_export.h"
[email protected]073a04f2011-03-24 00:49:4019#include "webkit/fileapi/file_system_mount_point_provider.h"
[email protected]e7e46732012-01-05 11:45:5520#include "webkit/fileapi/file_system_options.h"
[email protected]5caeb202011-05-17 07:42:0721#include "webkit/fileapi/file_system_quota_util.h"
[email protected]caf66702012-09-07 07:02:2022#include "webkit/fileapi/task_runner_bound_observer_list.h"
[email protected]073a04f2011-03-24 00:49:4023
[email protected]073a04f2011-03-24 00:49:4024namespace base {
[email protected]bcbd98d2012-05-07 04:10:1025class SequencedTaskRunner;
[email protected]073a04f2011-03-24 00:49:4026}
27
[email protected]5caeb202011-05-17 07:42:0728namespace quota {
29class QuotaManagerProxy;
30}
31
[email protected]073a04f2011-03-24 00:49:4032namespace fileapi {
33
[email protected]7878ece2011-09-05 11:41:4934class ObfuscatedFileUtil;
[email protected]caf66702012-09-07 07:02:2035class SandboxQuotaObserver;
[email protected]e5006b92011-05-17 11:53:5136
[email protected]4f9b1432011-12-20 11:10:1637// An interface to construct or crack sandboxed filesystem paths for
38// TEMPORARY or PERSISTENT filesystems, which are placed under the user's
39// profile directory in a sandboxed way.
40// This interface also lets one enumerate and remove storage for the origins
41// that use the filesystem.
[email protected]0b38b4e52012-05-30 08:14:2742class FILEAPI_EXPORT SandboxMountPointProvider
[email protected]5caeb202011-05-17 07:42:0743 : public FileSystemMountPointProvider,
44 public FileSystemQuotaUtil {
[email protected]073a04f2011-03-24 00:49:4045 public:
[email protected]d5e08552012-08-02 21:43:4046 using FileSystemMountPointProvider::ValidateFileSystemCallback;
47 using FileSystemMountPointProvider::DeleteFileSystemCallback;
[email protected]e7e46732012-01-05 11:45:5548
[email protected]c62983a72011-05-09 06:29:5949 // Origin enumerator interface.
50 // An instance of this interface is assumed to be called on the file thread.
51 class OriginEnumerator {
52 public:
53 virtual ~OriginEnumerator() {}
54
55 // Returns the next origin. Returns empty if there are no more origins.
56 virtual GURL Next() = 0;
57
58 // Returns the current origin's information.
59 virtual bool HasFileSystemType(FileSystemType type) const = 0;
60 };
[email protected]073a04f2011-03-24 00:49:4061
[email protected]054702d2011-05-28 01:12:1862 // The legacy [pre-obfuscation] FileSystem directory name, kept around for
63 // migration and migration testing.
64 static const FilePath::CharType kOldFileSystemDirectory[];
[email protected]073a04f2011-03-24 00:49:4065 // The FileSystem directory name.
[email protected]054702d2011-05-28 01:12:1866 static const FilePath::CharType kNewFileSystemDirectory[];
67 // Where we move the old filesystem directory if migration fails.
68 static const FilePath::CharType kRenamedOldFileSystemDirectory[];
[email protected]073a04f2011-03-24 00:49:4069
[email protected]caf66702012-09-07 07:02:2070 static bool CanHandleType(FileSystemType type);
71
[email protected]bcbd98d2012-05-07 04:10:1072 // |file_task_runner| is used to validate the root directory and delete the
73 // obfuscated file util.
[email protected]3c48b532011-12-20 12:42:4474 SandboxMountPointProvider(
[email protected]caf66702012-09-07 07:02:2075 quota::QuotaManagerProxy* quota_manager_proxy,
[email protected]bcbd98d2012-05-07 04:10:1076 base::SequencedTaskRunner* file_task_runner,
[email protected]e7e46732012-01-05 11:45:5577 const FilePath& profile_path,
78 const FileSystemOptions& file_system_options);
[email protected]3c48b532011-12-20 12:42:4479 virtual ~SandboxMountPointProvider();
80
81 // FileSystemMountPointProvider overrides.
[email protected]60f60f82012-01-11 10:26:1082 virtual void ValidateFileSystemRoot(
83 const GURL& origin_url,
84 FileSystemType type,
85 bool create,
86 const ValidateFileSystemCallback& callback) OVERRIDE;
87 virtual FilePath GetFileSystemRootPathOnFileThread(
88 const GURL& origin_url,
89 FileSystemType type,
90 const FilePath& virtual_path,
91 bool create) OVERRIDE;
[email protected]5aeeb7c62012-08-27 11:34:1392 virtual bool IsAccessAllowed(const FileSystemURL& url) OVERRIDE;
[email protected]3c48b532011-12-20 12:42:4493 virtual bool IsRestrictedFileName(const FilePath& filename) const OVERRIDE;
[email protected]d6afd112012-07-25 22:55:0494 virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
[email protected]22121e32012-03-01 05:24:5995 virtual FilePath GetPathForPermissionsCheck(const FilePath& virtual_path)
96 const OVERRIDE;
[email protected]8e3bc3e2012-08-24 13:12:5397 virtual FileSystemOperation* CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:0998 const FileSystemURL& url,
[email protected]d23a00cc2012-09-11 17:38:1399 FileSystemContext* context,
100 base::PlatformFileError* error_code) const OVERRIDE;
[email protected]c4ca3b452012-05-31 03:15:46101 virtual webkit_blob::FileStreamReader* CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09102 const FileSystemURL& url,
103 int64 offset,
[email protected]a1057832012-10-15 13:28:06104 const base::Time& expected_modification_time,
[email protected]949f25a2012-06-27 01:53:09105 FileSystemContext* context) const OVERRIDE;
[email protected]7e836a3d2012-05-31 05:14:59106 virtual FileStreamWriter* CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09107 const FileSystemURL& url,
108 int64 offset,
109 FileSystemContext* context) const OVERRIDE;
[email protected]6faad822012-05-11 12:58:29110 virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
[email protected]d5e08552012-08-02 21:43:40111 virtual void DeleteFileSystem(
112 const GURL& origin_url,
113 FileSystemType type,
114 FileSystemContext* context,
115 const DeleteFileSystemCallback& callback) OVERRIDE;
[email protected]3c48b532011-12-20 12:42:44116
[email protected]054702d2011-05-28 01:12:18117 FilePath old_base_path() const;
118 FilePath new_base_path() const;
119 FilePath renamed_old_base_path() const;
[email protected]073a04f2011-03-24 00:49:40120
[email protected]c62983a72011-05-09 06:29:59121 // Returns an origin enumerator of this provider.
[email protected]054702d2011-05-28 01:12:18122 // This method can only be called on the file thread.
[email protected]c62983a72011-05-09 06:29:59123 OriginEnumerator* CreateOriginEnumerator() const;
[email protected]073a04f2011-03-24 00:49:40124
125 // Gets a base directory path of the sandboxed filesystem that is
[email protected]c62983a72011-05-09 06:29:59126 // specified by |origin_url| and |type|.
127 // (The path is similar to the origin's root path but doesn't contain
128 // the 'unique' part.)
129 // Returns an empty path if the given type is invalid.
[email protected]fcc2d5f2011-05-23 22:06:26130 // This method can only be called on the file thread.
[email protected]c62983a72011-05-09 06:29:59131 FilePath GetBaseDirectoryForOriginAndType(
132 const GURL& origin_url,
[email protected]054702d2011-05-28 01:12:18133 FileSystemType type,
[email protected]fcc2d5f2011-05-23 22:06:26134 bool create) const;
[email protected]073a04f2011-03-24 00:49:40135
[email protected]5caeb202011-05-17 07:42:07136 // Deletes the data on the origin and reports the amount of deleted data
137 // to the quota manager via |proxy|.
[email protected]d5e08552012-08-02 21:43:40138 base::PlatformFileError DeleteOriginDataOnFileThread(
[email protected]22894522012-05-23 07:14:58139 FileSystemContext* context,
[email protected]5caeb202011-05-17 07:42:07140 quota::QuotaManagerProxy* proxy,
141 const GURL& origin_url,
[email protected]054702d2011-05-28 01:12:18142 FileSystemType type);
[email protected]5caeb202011-05-17 07:42:07143
[email protected]caf66702012-09-07 07:02:20144 // FileSystemQuotaUtil overrides.
[email protected]5caeb202011-05-17 07:42:07145 virtual void GetOriginsForTypeOnFileThread(
[email protected]054702d2011-05-28 01:12:18146 FileSystemType type,
[email protected]5caeb202011-05-17 07:42:07147 std::set<GURL>* origins) OVERRIDE;
148 virtual void GetOriginsForHostOnFileThread(
[email protected]054702d2011-05-28 01:12:18149 FileSystemType type,
[email protected]5caeb202011-05-17 07:42:07150 const std::string& host,
151 std::set<GURL>* origins) OVERRIDE;
152 virtual int64 GetOriginUsageOnFileThread(
[email protected]22894522012-05-23 07:14:58153 FileSystemContext* context,
[email protected]5caeb202011-05-17 07:42:07154 const GURL& origin_url,
[email protected]054702d2011-05-28 01:12:18155 FileSystemType type) OVERRIDE;
[email protected]caf66702012-09-07 07:02:20156
[email protected]34583332011-08-31 08:59:47157 virtual void InvalidateUsageCache(const GURL& origin_url,
158 FileSystemType type) OVERRIDE;
[email protected]5caeb202011-05-17 07:42:07159
[email protected]d247b842012-05-08 06:43:36160 void CollectOpenFileSystemMetrics(base::PlatformFileError error_code);
[email protected]5caeb202011-05-17 07:42:07161
[email protected]caf66702012-09-07 07:02:20162 // Returns update observers for the given type.
163 const UpdateObserverList* GetUpdateObservers(FileSystemType type) const;
164
[email protected]2ef2e2742012-10-09 14:18:13165 void AddSyncableFileUpdateObserver(FileUpdateObserver* observer,
166 base::SequencedTaskRunner* task_runner);
167 void AddSyncableFileChangeObserver(FileChangeObserver* observer,
168 base::SequencedTaskRunner* task_runner);
[email protected]caf66702012-09-07 07:02:20169
[email protected]073a04f2011-03-24 00:49:40170 private:
[email protected]caf66702012-09-07 07:02:20171 friend class SandboxQuotaObserver;
172
[email protected]5caeb202011-05-17 07:42:07173 // Returns a path to the usage cache file.
174 FilePath GetUsageCachePathForOriginAndType(
175 const GURL& origin_url,
[email protected]054702d2011-05-28 01:12:18176 FileSystemType type) const;
177
178 FilePath OldCreateFileSystemRootPath(
179 const GURL& origin_url, FileSystemType type);
[email protected]5caeb202011-05-17 07:42:07180
[email protected]e7e46732012-01-05 11:45:55181 // Returns true if the given |url|'s scheme is allowed to access
182 // filesystem.
183 bool IsAllowedScheme(const GURL& url) const;
184
[email protected]02a60542012-07-24 20:05:33185 friend class LocalFileSystemTestOriginHelper;
[email protected]054702d2011-05-28 01:12:18186 friend class SandboxMountPointProviderMigrationTest;
187 friend class SandboxMountPointProviderOriginEnumeratorTest;
[email protected]e5006b92011-05-17 11:53:51188
[email protected]bcbd98d2012-05-07 04:10:10189 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
[email protected]073a04f2011-03-24 00:49:40190
[email protected]054702d2011-05-28 01:12:18191 const FilePath profile_path_;
[email protected]073a04f2011-03-24 00:49:40192
[email protected]e7e46732012-01-05 11:45:55193 FileSystemOptions file_system_options_;
194
[email protected]3cfc10f2012-05-24 01:20:41195 scoped_ptr<ObfuscatedFileUtil> sandbox_file_util_;
[email protected]d4905e2e2011-05-13 21:56:32196
[email protected]caf66702012-09-07 07:02:20197 scoped_ptr<SandboxQuotaObserver> quota_observer_;
198
[email protected]5caeb202011-05-17 07:42:07199 // Acccessed only on the file thread.
200 std::set<GURL> visited_origins_;
201
[email protected]caf66702012-09-07 07:02:20202 // Observers.
203 UpdateObserverList update_observers_;
204 AccessObserverList access_observers_;
205
[email protected]2ef2e2742012-10-09 14:18:13206 // Observers for syncable file systems.
207 UpdateObserverList syncable_update_observers_;
208 ChangeObserverList syncable_change_observers_;
209
[email protected]d247b842012-05-08 06:43:36210 base::Time next_release_time_for_open_filesystem_stat_;
211
212 base::WeakPtrFactory<SandboxMountPointProvider> weak_factory_;
213
[email protected]073a04f2011-03-24 00:49:40214 DISALLOW_COPY_AND_ASSIGN(SandboxMountPointProvider);
215};
216
217} // namespace fileapi
218
219#endif // WEBKIT_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_