Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc

Issue 23167002: FileAPI: Rename SandboxContext to SandboxFileSystemBackendDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/browser/fileapi/sandbox_context.h" 5 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/task_runner_util.h" 11 #include "base/task_runner_util.h"
12 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
13 #include "webkit/browser/fileapi/async_file_util_adapter.h" 13 #include "webkit/browser/fileapi/async_file_util_adapter.h"
14 #include "webkit/browser/fileapi/file_system_context.h" 14 #include "webkit/browser/fileapi/file_system_context.h"
15 #include "webkit/browser/fileapi/file_system_operation_context.h" 15 #include "webkit/browser/fileapi/file_system_operation_context.h"
(...skipping 30 matching lines...) Expand all
46 const base::FilePath::CharType* const kRestrictedNames[] = { 46 const base::FilePath::CharType* const kRestrictedNames[] = {
47 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), 47 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."),
48 }; 48 };
49 49
50 // Restricted chars. 50 // Restricted chars.
51 const base::FilePath::CharType kRestrictedChars[] = { 51 const base::FilePath::CharType kRestrictedChars[] = {
52 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'), 52 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'),
53 }; 53 };
54 54
55 class ObfuscatedOriginEnumerator 55 class ObfuscatedOriginEnumerator
56 : public SandboxContext::OriginEnumerator { 56 : public SandboxFileSystemBackendDelegate::OriginEnumerator {
57 public: 57 public:
58 explicit ObfuscatedOriginEnumerator(ObfuscatedFileUtil* file_util) { 58 explicit ObfuscatedOriginEnumerator(ObfuscatedFileUtil* file_util) {
59 enum_.reset(file_util->CreateOriginEnumerator()); 59 enum_.reset(file_util->CreateOriginEnumerator());
60 } 60 }
61 virtual ~ObfuscatedOriginEnumerator() {} 61 virtual ~ObfuscatedOriginEnumerator() {}
62 62
63 virtual GURL Next() OVERRIDE { 63 virtual GURL Next() OVERRIDE {
64 return enum_->Next(); 64 return enum_->Next();
65 } 65 }
66 66
(...skipping 20 matching lines...) Expand all
87 kFileSystemErrorMax); 87 kFileSystemErrorMax);
88 } else { 88 } else {
89 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax); 89 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax);
90 } 90 }
91 // The reference of file_util will be derefed on the FILE thread 91 // The reference of file_util will be derefed on the FILE thread
92 // when the storage of this callback gets deleted regardless of whether 92 // when the storage of this callback gets deleted regardless of whether
93 // this method is called or not. 93 // this method is called or not.
94 } 94 }
95 95
96 void DidOpenFileSystem( 96 void DidOpenFileSystem(
97 base::WeakPtr<SandboxContext> sandbox_context, 97 base::WeakPtr<SandboxFileSystemBackendDelegate> delegate,
98 const base::Callback<void(base::PlatformFileError error)>& callback, 98 const base::Callback<void(base::PlatformFileError error)>& callback,
99 base::PlatformFileError* error) { 99 base::PlatformFileError* error) {
100 if (sandbox_context.get()) 100 if (delegate.get())
101 sandbox_context.get()->CollectOpenFileSystemMetrics(*error); 101 delegate.get()->CollectOpenFileSystemMetrics(*error);
102 callback.Run(*error); 102 callback.Run(*error);
103 } 103 }
104 104
105 } // namespace 105 } // namespace
106 106
107 const base::FilePath::CharType 107 const base::FilePath::CharType
108 SandboxContext::kFileSystemDirectory[] = FILE_PATH_LITERAL("File System"); 108 SandboxFileSystemBackendDelegate::kFileSystemDirectory[] =
109 FILE_PATH_LITERAL("File System");
109 110
110 SandboxContext::SandboxContext( 111 SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate(
111 quota::QuotaManagerProxy* quota_manager_proxy, 112 quota::QuotaManagerProxy* quota_manager_proxy,
112 base::SequencedTaskRunner* file_task_runner, 113 base::SequencedTaskRunner* file_task_runner,
113 const base::FilePath& profile_path, 114 const base::FilePath& profile_path,
114 quota::SpecialStoragePolicy* special_storage_policy, 115 quota::SpecialStoragePolicy* special_storage_policy,
115 const FileSystemOptions& file_system_options) 116 const FileSystemOptions& file_system_options)
116 : file_task_runner_(file_task_runner), 117 : file_task_runner_(file_task_runner),
117 sandbox_file_util_(new AsyncFileUtilAdapter( 118 sandbox_file_util_(new AsyncFileUtilAdapter(
118 new ObfuscatedFileUtil( 119 new ObfuscatedFileUtil(
119 special_storage_policy, 120 special_storage_policy,
120 profile_path.Append(kFileSystemDirectory), 121 profile_path.Append(kFileSystemDirectory),
121 file_task_runner))), 122 file_task_runner))),
122 file_system_usage_cache_(new FileSystemUsageCache(file_task_runner)), 123 file_system_usage_cache_(new FileSystemUsageCache(file_task_runner)),
123 quota_observer_(new SandboxQuotaObserver( 124 quota_observer_(new SandboxQuotaObserver(
124 quota_manager_proxy, 125 quota_manager_proxy,
125 file_task_runner, 126 file_task_runner,
126 obfuscated_file_util(), 127 obfuscated_file_util(),
127 usage_cache())), 128 usage_cache())),
128 special_storage_policy_(special_storage_policy), 129 special_storage_policy_(special_storage_policy),
129 file_system_options_(file_system_options), 130 file_system_options_(file_system_options),
130 weak_factory_(this) { 131 weak_factory_(this) {
131 } 132 }
132 133
133 SandboxContext::~SandboxContext() { 134 SandboxFileSystemBackendDelegate::~SandboxFileSystemBackendDelegate() {
134 if (!file_task_runner_->RunsTasksOnCurrentThread()) { 135 if (!file_task_runner_->RunsTasksOnCurrentThread()) {
135 AsyncFileUtil* sandbox_file_util = sandbox_file_util_.release(); 136 AsyncFileUtil* sandbox_file_util = sandbox_file_util_.release();
136 SandboxQuotaObserver* quota_observer = quota_observer_.release(); 137 SandboxQuotaObserver* quota_observer = quota_observer_.release();
137 FileSystemUsageCache* file_system_usage_cache = 138 FileSystemUsageCache* file_system_usage_cache =
138 file_system_usage_cache_.release(); 139 file_system_usage_cache_.release();
139 if (!file_task_runner_->DeleteSoon(FROM_HERE, sandbox_file_util)) 140 if (!file_task_runner_->DeleteSoon(FROM_HERE, sandbox_file_util))
140 delete sandbox_file_util; 141 delete sandbox_file_util;
141 if (!file_task_runner_->DeleteSoon(FROM_HERE, quota_observer)) 142 if (!file_task_runner_->DeleteSoon(FROM_HERE, quota_observer))
142 delete quota_observer; 143 delete quota_observer;
143 if (!file_task_runner_->DeleteSoon(FROM_HERE, file_system_usage_cache)) 144 if (!file_task_runner_->DeleteSoon(FROM_HERE, file_system_usage_cache))
144 delete file_system_usage_cache; 145 delete file_system_usage_cache;
145 } 146 }
146 } 147 }
147 148
148 bool SandboxContext::IsAccessValid(const FileSystemURL& url) const { 149 bool SandboxFileSystemBackendDelegate::IsAccessValid(
150 const FileSystemURL& url) const {
149 if (!IsAllowedScheme(url.origin())) 151 if (!IsAllowedScheme(url.origin()))
150 return false; 152 return false;
151 153
152 if (url.path().ReferencesParent()) 154 if (url.path().ReferencesParent())
153 return false; 155 return false;
154 156
155 // Return earlier if the path is '/', because VirtualPath::BaseName() 157 // Return earlier if the path is '/', because VirtualPath::BaseName()
156 // returns '/' for '/' and we fail the "basename != '/'" check below. 158 // returns '/' for '/' and we fail the "basename != '/'" check below.
157 // (We exclude '.' because it's disallowed by spec.) 159 // (We exclude '.' because it's disallowed by spec.)
158 if (VirtualPath::IsRootPath(url.path()) && 160 if (VirtualPath::IsRootPath(url.path()) &&
(...skipping 10 matching lines...) Expand all
169 } 171 }
170 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { 172 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) {
171 if (filename.value().find(kRestrictedChars[i]) != 173 if (filename.value().find(kRestrictedChars[i]) !=
172 base::FilePath::StringType::npos) 174 base::FilePath::StringType::npos)
173 return false; 175 return false;
174 } 176 }
175 177
176 return true; 178 return true;
177 } 179 }
178 180
179 bool SandboxContext::IsAllowedScheme(const GURL& url) const { 181 bool SandboxFileSystemBackendDelegate::IsAllowedScheme(const GURL& url) const {
180 // Basically we only accept http or https. We allow file:// URLs 182 // Basically we only accept http or https. We allow file:// URLs
181 // only if --allow-file-access-from-files flag is given. 183 // only if --allow-file-access-from-files flag is given.
182 if (url.SchemeIs("http") || url.SchemeIs("https")) 184 if (url.SchemeIs("http") || url.SchemeIs("https"))
183 return true; 185 return true;
184 if (url.SchemeIsFileSystem()) 186 if (url.SchemeIsFileSystem())
185 return url.inner_url() && IsAllowedScheme(*url.inner_url()); 187 return url.inner_url() && IsAllowedScheme(*url.inner_url());
186 188
187 for (size_t i = 0; 189 for (size_t i = 0;
188 i < file_system_options_.additional_allowed_schemes().size(); 190 i < file_system_options_.additional_allowed_schemes().size();
189 ++i) { 191 ++i) {
190 if (url.SchemeIs( 192 if (url.SchemeIs(
191 file_system_options_.additional_allowed_schemes()[i].c_str())) 193 file_system_options_.additional_allowed_schemes()[i].c_str()))
192 return true; 194 return true;
193 } 195 }
194 return false; 196 return false;
195 } 197 }
196 198
197 SandboxContext::OriginEnumerator* SandboxContext::CreateOriginEnumerator() { 199 SandboxFileSystemBackendDelegate::OriginEnumerator*
200 SandboxFileSystemBackendDelegate::CreateOriginEnumerator() {
198 return new ObfuscatedOriginEnumerator(obfuscated_file_util()); 201 return new ObfuscatedOriginEnumerator(obfuscated_file_util());
199 } 202 }
200 203
201 base::FilePath SandboxContext::GetBaseDirectoryForOriginAndType( 204 base::FilePath
202 const GURL& origin_url, fileapi::FileSystemType type, bool create) { 205 SandboxFileSystemBackendDelegate::GetBaseDirectoryForOriginAndType(
206 const GURL& origin_url,
207 fileapi::FileSystemType type,
208 bool create) {
203 base::PlatformFileError error = base::PLATFORM_FILE_OK; 209 base::PlatformFileError error = base::PLATFORM_FILE_OK;
204 base::FilePath path = obfuscated_file_util()->GetDirectoryForOriginAndType( 210 base::FilePath path = obfuscated_file_util()->GetDirectoryForOriginAndType(
205 origin_url, type, create, &error); 211 origin_url, type, create, &error);
206 if (error != base::PLATFORM_FILE_OK) 212 if (error != base::PLATFORM_FILE_OK)
207 return base::FilePath(); 213 return base::FilePath();
208 return path; 214 return path;
209 } 215 }
210 216
211 void SandboxContext::OpenFileSystem( 217 void SandboxFileSystemBackendDelegate::OpenFileSystem(
212 const GURL& origin_url, 218 const GURL& origin_url,
213 fileapi::FileSystemType type, 219 fileapi::FileSystemType type,
214 OpenFileSystemMode mode, 220 OpenFileSystemMode mode,
215 const OpenFileSystemCallback& callback, 221 const OpenFileSystemCallback& callback,
216 const GURL& root_url) { 222 const GURL& root_url) {
217 if (!IsAllowedScheme(origin_url)) { 223 if (!IsAllowedScheme(origin_url)) {
218 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY); 224 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY);
219 return; 225 return;
220 } 226 }
221 227
222 std::string name = GetFileSystemName(origin_url, type); 228 std::string name = GetFileSystemName(origin_url, type);
223 229
224 base::PlatformFileError* error_ptr = new base::PlatformFileError; 230 base::PlatformFileError* error_ptr = new base::PlatformFileError;
225 file_task_runner_->PostTaskAndReply( 231 file_task_runner_->PostTaskAndReply(
226 FROM_HERE, 232 FROM_HERE,
227 base::Bind(&OpenFileSystemOnFileThread, 233 base::Bind(&OpenFileSystemOnFileThread,
228 obfuscated_file_util(), origin_url, type, mode, 234 obfuscated_file_util(), origin_url, type, mode,
229 base::Unretained(error_ptr)), 235 base::Unretained(error_ptr)),
230 base::Bind(&DidOpenFileSystem, 236 base::Bind(&DidOpenFileSystem,
231 weak_factory_.GetWeakPtr(), 237 weak_factory_.GetWeakPtr(),
232 base::Bind(callback, root_url, name), 238 base::Bind(callback, root_url, name),
233 base::Owned(error_ptr))); 239 base::Owned(error_ptr)));
234 } 240 }
235 241
236 base::PlatformFileError SandboxContext::DeleteOriginDataOnFileThread( 242 base::PlatformFileError
243 SandboxFileSystemBackendDelegate::DeleteOriginDataOnFileThread(
237 FileSystemContext* file_system_context, 244 FileSystemContext* file_system_context,
238 quota::QuotaManagerProxy* proxy, 245 quota::QuotaManagerProxy* proxy,
239 const GURL& origin_url, 246 const GURL& origin_url,
240 fileapi::FileSystemType type) { 247 fileapi::FileSystemType type) {
241 int64 usage = GetOriginUsageOnFileThread( 248 int64 usage = GetOriginUsageOnFileThread(
242 file_system_context, origin_url, type); 249 file_system_context, origin_url, type);
243 usage_cache()->CloseCacheFiles(); 250 usage_cache()->CloseCacheFiles();
244 bool result = obfuscated_file_util()->DeleteDirectoryForOriginAndType( 251 bool result = obfuscated_file_util()->DeleteDirectoryForOriginAndType(
245 origin_url, type); 252 origin_url, type);
246 if (result && proxy) { 253 if (result && proxy) {
247 proxy->NotifyStorageModified( 254 proxy->NotifyStorageModified(
248 quota::QuotaClient::kFileSystem, 255 quota::QuotaClient::kFileSystem,
249 origin_url, 256 origin_url,
250 FileSystemTypeToQuotaStorageType(type), 257 FileSystemTypeToQuotaStorageType(type),
251 -usage); 258 -usage);
252 } 259 }
253 260
254 if (result) 261 if (result)
255 return base::PLATFORM_FILE_OK; 262 return base::PLATFORM_FILE_OK;
256 return base::PLATFORM_FILE_ERROR_FAILED; 263 return base::PLATFORM_FILE_ERROR_FAILED;
257 } 264 }
258 265
259 void SandboxContext::GetOriginsForTypeOnFileThread( 266 void SandboxFileSystemBackendDelegate::GetOriginsForTypeOnFileThread(
260 fileapi::FileSystemType type, std::set<GURL>* origins) { 267 fileapi::FileSystemType type, std::set<GURL>* origins) {
261 DCHECK(origins); 268 DCHECK(origins);
262 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); 269 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
263 GURL origin; 270 GURL origin;
264 while (!(origin = enumerator->Next()).is_empty()) { 271 while (!(origin = enumerator->Next()).is_empty()) {
265 if (enumerator->HasFileSystemType(type)) 272 if (enumerator->HasFileSystemType(type))
266 origins->insert(origin); 273 origins->insert(origin);
267 } 274 }
268 } 275 }
269 276
270 void SandboxContext::GetOriginsForHostOnFileThread( 277 void SandboxFileSystemBackendDelegate::GetOriginsForHostOnFileThread(
271 fileapi::FileSystemType type, const std::string& host, 278 fileapi::FileSystemType type, const std::string& host,
272 std::set<GURL>* origins) { 279 std::set<GURL>* origins) {
273 DCHECK(origins); 280 DCHECK(origins);
274 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); 281 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
275 GURL origin; 282 GURL origin;
276 while (!(origin = enumerator->Next()).is_empty()) { 283 while (!(origin = enumerator->Next()).is_empty()) {
277 if (host == net::GetHostOrSpecFromURL(origin) && 284 if (host == net::GetHostOrSpecFromURL(origin) &&
278 enumerator->HasFileSystemType(type)) 285 enumerator->HasFileSystemType(type))
279 origins->insert(origin); 286 origins->insert(origin);
280 } 287 }
281 } 288 }
282 289
283 int64 SandboxContext::GetOriginUsageOnFileThread( 290 int64 SandboxFileSystemBackendDelegate::GetOriginUsageOnFileThread(
284 FileSystemContext* file_system_context, 291 FileSystemContext* file_system_context,
285 const GURL& origin_url, 292 const GURL& origin_url,
286 fileapi::FileSystemType type) { 293 fileapi::FileSystemType type) {
287 // Don't use usage cache and return recalculated usage for sticky invalidated 294 // Don't use usage cache and return recalculated usage for sticky invalidated
288 // origins. 295 // origins.
289 if (ContainsKey(sticky_dirty_origins_, std::make_pair(origin_url, type))) 296 if (ContainsKey(sticky_dirty_origins_, std::make_pair(origin_url, type)))
290 return RecalculateUsage(file_system_context, origin_url, type); 297 return RecalculateUsage(file_system_context, origin_url, type);
291 298
292 base::FilePath base_path = 299 base::FilePath base_path =
293 GetBaseDirectoryForOriginAndType(origin_url, type, false); 300 GetBaseDirectoryForOriginAndType(origin_url, type, false);
(...skipping 17 matching lines...) Expand all
311 // Get the directory size now and update the cache. 318 // Get the directory size now and update the cache.
312 usage_cache()->Delete(usage_file_path); 319 usage_cache()->Delete(usage_file_path);
313 320
314 int64 usage = RecalculateUsage(file_system_context, origin_url, type); 321 int64 usage = RecalculateUsage(file_system_context, origin_url, type);
315 322
316 // This clears the dirty flag too. 323 // This clears the dirty flag too.
317 usage_cache()->UpdateUsage(usage_file_path, usage); 324 usage_cache()->UpdateUsage(usage_file_path, usage);
318 return usage; 325 return usage;
319 } 326 }
320 327
321 void SandboxContext::InvalidateUsageCache( 328 void SandboxFileSystemBackendDelegate::InvalidateUsageCache(
322 const GURL& origin, 329 const GURL& origin,
323 fileapi::FileSystemType type) { 330 fileapi::FileSystemType type) {
324 base::PlatformFileError error = base::PLATFORM_FILE_OK; 331 base::PlatformFileError error = base::PLATFORM_FILE_OK;
325 base::FilePath usage_file_path = GetUsageCachePathForOriginAndType( 332 base::FilePath usage_file_path = GetUsageCachePathForOriginAndType(
326 obfuscated_file_util(), origin, type, &error); 333 obfuscated_file_util(), origin, type, &error);
327 if (error != base::PLATFORM_FILE_OK) 334 if (error != base::PLATFORM_FILE_OK)
328 return; 335 return;
329 usage_cache()->IncrementDirty(usage_file_path); 336 usage_cache()->IncrementDirty(usage_file_path);
330 } 337 }
331 338
332 void SandboxContext::StickyInvalidateUsageCache( 339 void SandboxFileSystemBackendDelegate::StickyInvalidateUsageCache(
333 const GURL& origin, 340 const GURL& origin,
334 fileapi::FileSystemType type) { 341 fileapi::FileSystemType type) {
335 sticky_dirty_origins_.insert(std::make_pair(origin, type)); 342 sticky_dirty_origins_.insert(std::make_pair(origin, type));
336 quota_observer()->SetUsageCacheEnabled(origin, type, false); 343 quota_observer()->SetUsageCacheEnabled(origin, type, false);
337 InvalidateUsageCache(origin, type); 344 InvalidateUsageCache(origin, type);
338 } 345 }
339 346
340 FileSystemFileUtil* SandboxContext::sync_file_util() { 347 FileSystemFileUtil* SandboxFileSystemBackendDelegate::sync_file_util() {
341 return static_cast<AsyncFileUtilAdapter*>(file_util())->sync_file_util(); 348 return static_cast<AsyncFileUtilAdapter*>(file_util())->sync_file_util();
342 } 349 }
343 350
344 base::FilePath SandboxContext::GetUsageCachePathForOriginAndType( 351 base::FilePath
352 SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType(
345 const GURL& origin_url, 353 const GURL& origin_url,
346 FileSystemType type) { 354 FileSystemType type) {
347 base::PlatformFileError error; 355 base::PlatformFileError error;
348 base::FilePath path = GetUsageCachePathForOriginAndType( 356 base::FilePath path = GetUsageCachePathForOriginAndType(
349 obfuscated_file_util(), origin_url, type, &error); 357 obfuscated_file_util(), origin_url, type, &error);
350 if (error != base::PLATFORM_FILE_OK) 358 if (error != base::PLATFORM_FILE_OK)
351 return base::FilePath(); 359 return base::FilePath();
352 return path; 360 return path;
353 } 361 }
354 362
355 // static 363 // static
356 base::FilePath SandboxContext::GetUsageCachePathForOriginAndType( 364 base::FilePath
365 SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType(
357 ObfuscatedFileUtil* sandbox_file_util, 366 ObfuscatedFileUtil* sandbox_file_util,
358 const GURL& origin_url, 367 const GURL& origin_url,
359 fileapi::FileSystemType type, 368 fileapi::FileSystemType type,
360 base::PlatformFileError* error_out) { 369 base::PlatformFileError* error_out) {
361 DCHECK(error_out); 370 DCHECK(error_out);
362 *error_out = base::PLATFORM_FILE_OK; 371 *error_out = base::PLATFORM_FILE_OK;
363 base::FilePath base_path = sandbox_file_util->GetDirectoryForOriginAndType( 372 base::FilePath base_path = sandbox_file_util->GetDirectoryForOriginAndType(
364 origin_url, type, false /* create */, error_out); 373 origin_url, type, false /* create */, error_out);
365 if (*error_out != base::PLATFORM_FILE_OK) 374 if (*error_out != base::PLATFORM_FILE_OK)
366 return base::FilePath(); 375 return base::FilePath();
367 return base_path.Append(FileSystemUsageCache::kUsageFileName); 376 return base_path.Append(FileSystemUsageCache::kUsageFileName);
368 } 377 }
369 378
370 int64 SandboxContext::RecalculateUsage(FileSystemContext* context, 379 int64 SandboxFileSystemBackendDelegate::RecalculateUsage(
371 const GURL& origin, 380 FileSystemContext* context,
372 FileSystemType type) { 381 const GURL& origin,
382 FileSystemType type) {
373 FileSystemOperationContext operation_context(context); 383 FileSystemOperationContext operation_context(context);
374 FileSystemURL url = context->CreateCrackedFileSystemURL( 384 FileSystemURL url = context->CreateCrackedFileSystemURL(
375 origin, type, base::FilePath()); 385 origin, type, base::FilePath());
376 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( 386 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator(
377 obfuscated_file_util()->CreateFileEnumerator( 387 obfuscated_file_util()->CreateFileEnumerator(
378 &operation_context, url, true)); 388 &operation_context, url, true));
379 389
380 base::FilePath file_path_each; 390 base::FilePath file_path_each;
381 int64 usage = 0; 391 int64 usage = 0;
382 392
383 while (!(file_path_each = enumerator->Next()).empty()) { 393 while (!(file_path_each = enumerator->Next()).empty()) {
384 usage += enumerator->Size(); 394 usage += enumerator->Size();
385 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); 395 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each);
386 } 396 }
387 397
388 return usage; 398 return usage;
389 } 399 }
390 400
391 void SandboxContext::CollectOpenFileSystemMetrics( 401 void SandboxFileSystemBackendDelegate::CollectOpenFileSystemMetrics(
392 base::PlatformFileError error_code) { 402 base::PlatformFileError error_code) {
393 base::Time now = base::Time::Now(); 403 base::Time now = base::Time::Now();
394 bool throttled = now < next_release_time_for_open_filesystem_stat_; 404 bool throttled = now < next_release_time_for_open_filesystem_stat_;
395 if (!throttled) { 405 if (!throttled) {
396 next_release_time_for_open_filesystem_stat_ = 406 next_release_time_for_open_filesystem_stat_ =
397 now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours); 407 now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours);
398 } 408 }
399 409
400 #define REPORT(report_value) \ 410 #define REPORT(report_value) \
401 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \ 411 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \
(...skipping 16 matching lines...) Expand all
418 REPORT(kNotFound); 428 REPORT(kNotFound);
419 break; 429 break;
420 case base::PLATFORM_FILE_ERROR_FAILED: 430 case base::PLATFORM_FILE_ERROR_FAILED:
421 default: 431 default:
422 REPORT(kUnknownError); 432 REPORT(kUnknownError);
423 break; 433 break;
424 } 434 }
425 #undef REPORT 435 #undef REPORT
426 } 436 }
427 437
428 ObfuscatedFileUtil* SandboxContext::obfuscated_file_util() { 438 ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() {
429 return static_cast<ObfuscatedFileUtil*>(sync_file_util()); 439 return static_cast<ObfuscatedFileUtil*>(sync_file_util());
430 } 440 }
431 441
432 } // namespace fileapi 442 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698