1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/fileapi/file_system_context.h"
#include "base/bind.h"
#include "base/file_util.h"
#include "base/message_loop_proxy.h"
#include "googleurl/src/gurl.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_operation_interface.h"
#include "webkit/fileapi/file_system_options.h"
#include "webkit/fileapi/file_system_quota_client.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/isolated_mount_point_provider.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/quota_manager.h"
#include "webkit/quota/special_storage_policy.h"
#if defined(OS_CHROMEOS)
#include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
#endif
using quota::QuotaClient;
namespace fileapi {
namespace {
QuotaClient* CreateQuotaClient(
scoped_refptr<base::MessageLoopProxy> file_message_loop,
FileSystemContext* context,
bool is_incognito) {
return new FileSystemQuotaClient(file_message_loop, context, is_incognito);
}
void DidOpenFileSystem(FileSystemContext::OpenFileSystemCallback callback,
const GURL& filesystem_root,
const std::string& filesystem_name,
base::PlatformFileError error) {
callback.Run(error, filesystem_name, filesystem_root);
}
} // anonymous namespace
FileSystemContext::FileSystemContext(
scoped_refptr<base::MessageLoopProxy> file_message_loop,
scoped_refptr<base::MessageLoopProxy> io_message_loop,
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy,
quota::QuotaManagerProxy* quota_manager_proxy,
const FilePath& profile_path,
const FileSystemOptions& options)
: file_message_loop_(file_message_loop),
io_message_loop_(io_message_loop),
quota_manager_proxy_(quota_manager_proxy),
sandbox_provider_(
new SandboxMountPointProvider(
file_message_loop,
profile_path,
options)),
isolated_provider_(new IsolatedMountPointProvider) {
if (quota_manager_proxy) {
quota_manager_proxy->RegisterClient(CreateQuotaClient(
file_message_loop, this, options.is_incognito()));
}
#if defined(OS_CHROMEOS)
external_provider_.reset(
new chromeos::CrosMountPointProvider(special_storage_policy));
#endif
}
bool FileSystemContext::DeleteDataForOriginOnFileThread(
const GURL& origin_url) {
DCHECK(file_message_loop_->BelongsToCurrentThread());
DCHECK(sandbox_provider());
// Delete temporary and persistent data.
return
sandbox_provider()->DeleteOriginDataOnFileThread(
quota_manager_proxy(), origin_url, kFileSystemTypeTemporary) &&
sandbox_provider()->DeleteOriginDataOnFileThread(
quota_manager_proxy(), origin_url, kFileSystemTypePersistent);
}
bool FileSystemContext::DeleteDataForOriginAndTypeOnFileThread(
const GURL& origin_url, FileSystemType type) {
DCHECK(file_message_loop_->BelongsToCurrentThread());
if (type == fileapi::kFileSystemTypeTemporary ||
type == fileapi::kFileSystemTypePersistent) {
DCHECK(sandbox_provider());
return sandbox_provider()->DeleteOriginDataOnFileThread(
quota_manager_proxy(), origin_url, type);
}
return false;
}
FileSystemQuotaUtil*
FileSystemContext::GetQuotaUtil(FileSystemType type) const {
if (type == fileapi::kFileSystemTypeTemporary ||
type == fileapi::kFileSystemTypePersistent) {
DCHECK(sandbox_provider());
return sandbox_provider()->quota_util();
}
return NULL;
}
FileSystemFileUtil* FileSystemContext::GetFileUtil(
FileSystemType type) const {
FileSystemMountPointProvider* mount_point_provider =
GetMountPointProvider(type);
if (!mount_point_provider)
return NULL;
return mount_point_provider->GetFileUtil();
}
FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider(
FileSystemType type) const {
switch (type) {
case kFileSystemTypeTemporary:
case kFileSystemTypePersistent:
return sandbox_provider_.get();
case kFileSystemTypeExternal:
return external_provider_.get();
case kFileSystemTypeIsolated:
return isolated_provider_.get();
case kFileSystemTypeUnknown:
default:
NOTREACHED();
return NULL;
}
}
SandboxMountPointProvider*
FileSystemContext::sandbox_provider() const {
return sandbox_provider_.get();
}
ExternalFileSystemMountPointProvider*
FileSystemContext::external_provider() const {
return external_provider_.get();
}
void FileSystemContext::OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
bool create,
OpenFileSystemCallback callback) {
DCHECK(!callback.is_null());
FileSystemMountPointProvider* mount_point_provider =
GetMountPointProvider(type);
if (!mount_point_provider) {
callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL());
return;
}
GURL root_url = GetFileSystemRootURI(origin_url, type);
std::string name = GetFileSystemName(origin_url, type);
mount_point_provider->ValidateFileSystemRoot(
origin_url, type, create,
base::Bind(&DidOpenFileSystem, callback, root_url, name));
}
FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation(
const GURL& url,
base::MessageLoopProxy* file_proxy) {
GURL origin_url;
FileSystemType file_system_type = kFileSystemTypeUnknown;
FilePath file_path;
if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path))
return NULL;
FileSystemMountPointProvider* mount_point_provider =
GetMountPointProvider(file_system_type);
if (!mount_point_provider)
return NULL;
return mount_point_provider->CreateFileSystemOperation(
origin_url, file_system_type, file_path, file_proxy, this);
}
webkit_blob::FileReader* FileSystemContext::CreateFileReader(
const GURL& url,
int64 offset,
base::MessageLoopProxy* file_proxy) {
GURL origin_url;
FileSystemType file_system_type = kFileSystemTypeUnknown;
FilePath file_path;
if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path))
return NULL;
FileSystemMountPointProvider* mount_point_provider =
GetMountPointProvider(file_system_type);
if (!mount_point_provider)
return NULL;
return mount_point_provider->CreateFileReader(url, offset, file_proxy, this);
}
FileSystemContext::~FileSystemContext() {}
void FileSystemContext::DeleteOnCorrectThread() const {
if (!io_message_loop_->BelongsToCurrentThread() &&
io_message_loop_->DeleteSoon(FROM_HERE, this)) {
return;
}
delete this;
}
} // namespace fileapi
|