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

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

Issue 18344013: fileapi: Rename FileSystemMountProvider to FileSystemBackend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_mount_point_provider.h" 5 #include "webkit/browser/fileapi/sandbox_file_system_backend.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const base::FilePath::CharType* const kRestrictedNames[] = { 68 const base::FilePath::CharType* const kRestrictedNames[] = {
69 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), 69 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."),
70 }; 70 };
71 71
72 // Restricted chars. 72 // Restricted chars.
73 const base::FilePath::CharType kRestrictedChars[] = { 73 const base::FilePath::CharType kRestrictedChars[] = {
74 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'), 74 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'),
75 }; 75 };
76 76
77 class ObfuscatedOriginEnumerator 77 class ObfuscatedOriginEnumerator
78 : public SandboxMountPointProvider::OriginEnumerator { 78 : public SandboxFileSystemBackend::OriginEnumerator {
79 public: 79 public:
80 explicit ObfuscatedOriginEnumerator(ObfuscatedFileUtil* file_util) { 80 explicit ObfuscatedOriginEnumerator(ObfuscatedFileUtil* file_util) {
81 enum_.reset(file_util->CreateOriginEnumerator()); 81 enum_.reset(file_util->CreateOriginEnumerator());
82 } 82 }
83 virtual ~ObfuscatedOriginEnumerator() {} 83 virtual ~ObfuscatedOriginEnumerator() {}
84 84
85 virtual GURL Next() OVERRIDE { 85 virtual GURL Next() OVERRIDE {
86 return enum_->Next(); 86 return enum_->Next();
87 } 87 }
88 88
89 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { 89 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE {
90 return enum_->HasFileSystemType(type); 90 return enum_->HasFileSystemType(type);
91 } 91 }
92 92
93 private: 93 private:
94 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_; 94 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_;
95 }; 95 };
96 96
97 void DidOpenFileSystem( 97 void DidOpenFileSystem(
98 base::WeakPtr<SandboxMountPointProvider> mount_point_provider, 98 base::WeakPtr<SandboxFileSystemBackend> mount_point_provider,
99 const FileSystemMountPointProvider::OpenFileSystemCallback& callback, 99 const FileSystemBackend::OpenFileSystemCallback& callback,
100 base::PlatformFileError* error) { 100 base::PlatformFileError* error) {
101 if (mount_point_provider.get()) 101 if (mount_point_provider.get())
102 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); 102 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error);
103 callback.Run(*error); 103 callback.Run(*error);
104 } 104 }
105 105
106 void OpenFileSystemOnFileThread( 106 void OpenFileSystemOnFileThread(
107 ObfuscatedFileUtil* file_util, 107 ObfuscatedFileUtil* file_util,
108 const GURL& origin_url, 108 const GURL& origin_url,
109 FileSystemType type, 109 FileSystemType type,
(...skipping 13 matching lines...) Expand all
123 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax); 123 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax);
124 } 124 }
125 // The reference of file_util will be derefed on the FILE thread 125 // The reference of file_util will be derefed on the FILE thread
126 // when the storage of this callback gets deleted regardless of whether 126 // when the storage of this callback gets deleted regardless of whether
127 // this method is called or not. 127 // this method is called or not.
128 } 128 }
129 129
130 } // anonymous namespace 130 } // anonymous namespace
131 131
132 const base::FilePath::CharType 132 const base::FilePath::CharType
133 SandboxMountPointProvider::kFileSystemDirectory[] = 133 SandboxFileSystemBackend::kFileSystemDirectory[] =
134 FILE_PATH_LITERAL("File System"); 134 FILE_PATH_LITERAL("File System");
135 135
136 SandboxMountPointProvider::SandboxMountPointProvider( 136 SandboxFileSystemBackend::SandboxFileSystemBackend(
137 quota::QuotaManagerProxy* quota_manager_proxy, 137 quota::QuotaManagerProxy* quota_manager_proxy,
138 base::SequencedTaskRunner* file_task_runner, 138 base::SequencedTaskRunner* file_task_runner,
139 const base::FilePath& profile_path, 139 const base::FilePath& profile_path,
140 const FileSystemOptions& file_system_options, 140 const FileSystemOptions& file_system_options,
141 quota::SpecialStoragePolicy* special_storage_policy) 141 quota::SpecialStoragePolicy* special_storage_policy)
142 : file_task_runner_(file_task_runner), 142 : file_task_runner_(file_task_runner),
143 profile_path_(profile_path), 143 profile_path_(profile_path),
144 file_system_options_(file_system_options), 144 file_system_options_(file_system_options),
145 enable_temporary_file_system_in_incognito_(false), 145 enable_temporary_file_system_in_incognito_(false),
146 sandbox_file_util_( 146 sandbox_file_util_(
(...skipping 30 matching lines...) Expand all
177 if (!file_task_runner_->RunsTasksOnCurrentThread()) { 177 if (!file_task_runner_->RunsTasksOnCurrentThread()) {
178 // Post prepopulate task only if it's not already running on 178 // Post prepopulate task only if it's not already running on
179 // file_task_runner (which implies running in tests). 179 // file_task_runner (which implies running in tests).
180 file_task_runner_->PostTask( 180 file_task_runner_->PostTask(
181 FROM_HERE, 181 FROM_HERE,
182 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, 182 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase,
183 base::Unretained(sandbox_sync_file_util()))); 183 base::Unretained(sandbox_sync_file_util())));
184 } 184 }
185 } 185 }
186 186
187 SandboxMountPointProvider::~SandboxMountPointProvider() { 187 SandboxFileSystemBackend::~SandboxFileSystemBackend() {
188 if (!file_task_runner_->RunsTasksOnCurrentThread()) { 188 if (!file_task_runner_->RunsTasksOnCurrentThread()) {
189 AsyncFileUtilAdapter* sandbox_file_util = sandbox_file_util_.release(); 189 AsyncFileUtilAdapter* sandbox_file_util = sandbox_file_util_.release();
190 SandboxQuotaObserver* quota_observer = quota_observer_.release(); 190 SandboxQuotaObserver* quota_observer = quota_observer_.release();
191 FileSystemUsageCache* file_system_usage_cache = 191 FileSystemUsageCache* file_system_usage_cache =
192 file_system_usage_cache_.release(); 192 file_system_usage_cache_.release();
193 if (!file_task_runner_->DeleteSoon(FROM_HERE, sandbox_file_util)) 193 if (!file_task_runner_->DeleteSoon(FROM_HERE, sandbox_file_util))
194 delete sandbox_file_util; 194 delete sandbox_file_util;
195 if (!file_task_runner_->DeleteSoon(FROM_HERE, quota_observer)) 195 if (!file_task_runner_->DeleteSoon(FROM_HERE, quota_observer))
196 delete quota_observer; 196 delete quota_observer;
197 if (!file_task_runner_->DeleteSoon(FROM_HERE, file_system_usage_cache)) 197 if (!file_task_runner_->DeleteSoon(FROM_HERE, file_system_usage_cache))
198 delete file_system_usage_cache; 198 delete file_system_usage_cache;
199 } 199 }
200 } 200 }
201 201
202 bool SandboxMountPointProvider::CanHandleType(FileSystemType type) const { 202 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const {
203 return type == kFileSystemTypeTemporary || 203 return type == kFileSystemTypeTemporary ||
204 type == kFileSystemTypePersistent || 204 type == kFileSystemTypePersistent ||
205 type == kFileSystemTypeSyncable || 205 type == kFileSystemTypeSyncable ||
206 type == kFileSystemTypeSyncableForInternalSync; 206 type == kFileSystemTypeSyncableForInternalSync;
207 } 207 }
208 208
209 void SandboxMountPointProvider::OpenFileSystem( 209 void SandboxFileSystemBackend::OpenFileSystem(
210 const GURL& origin_url, fileapi::FileSystemType type, 210 const GURL& origin_url, fileapi::FileSystemType type,
211 OpenFileSystemMode mode, 211 OpenFileSystemMode mode,
212 const OpenFileSystemCallback& callback) { 212 const OpenFileSystemCallback& callback) {
213 if (file_system_options_.is_incognito() && 213 if (file_system_options_.is_incognito() &&
214 !(type == kFileSystemTypeTemporary && 214 !(type == kFileSystemTypeTemporary &&
215 enable_temporary_file_system_in_incognito_)) { 215 enable_temporary_file_system_in_incognito_)) {
216 // TODO(kinuko): return an isolated temporary directory. 216 // TODO(kinuko): return an isolated temporary directory.
217 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 217 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY);
218 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, 218 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel,
219 kIncognito, 219 kIncognito,
(...skipping 20 matching lines...) Expand all
240 weak_factory_.GetWeakPtr(), 240 weak_factory_.GetWeakPtr(),
241 callback, base::Owned(error_ptr))); 241 callback, base::Owned(error_ptr)));
242 242
243 if (enable_usage_tracking_) 243 if (enable_usage_tracking_)
244 return; 244 return;
245 245
246 // Schedule full usage recalculation on the next launch without 246 // Schedule full usage recalculation on the next launch without
247 // --disable-file-system-usage-tracking. 247 // --disable-file-system-usage-tracking.
248 file_task_runner_->PostTask( 248 file_task_runner_->PostTask(
249 FROM_HERE, 249 FROM_HERE,
250 base::Bind(&SandboxMountPointProvider::InvalidateUsageCacheOnFileThread, 250 base::Bind(&SandboxFileSystemBackend::InvalidateUsageCacheOnFileThread,
251 sandbox_sync_file_util(), origin_url, type, 251 sandbox_sync_file_util(), origin_url, type,
252 file_system_usage_cache_.get())); 252 file_system_usage_cache_.get()));
253 }; 253 };
254 254
255 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil( 255 FileSystemFileUtil* SandboxFileSystemBackend::GetFileUtil(
256 FileSystemType type) { 256 FileSystemType type) {
257 DCHECK(sandbox_file_util_.get()); 257 DCHECK(sandbox_file_util_.get());
258 return sandbox_file_util_->sync_file_util(); 258 return sandbox_file_util_->sync_file_util();
259 } 259 }
260 260
261 AsyncFileUtil* SandboxMountPointProvider::GetAsyncFileUtil( 261 AsyncFileUtil* SandboxFileSystemBackend::GetAsyncFileUtil(
262 FileSystemType type) { 262 FileSystemType type) {
263 return sandbox_file_util_.get(); 263 return sandbox_file_util_.get();
264 } 264 }
265 265
266 CopyOrMoveFileValidatorFactory* 266 CopyOrMoveFileValidatorFactory*
267 SandboxMountPointProvider::GetCopyOrMoveFileValidatorFactory( 267 SandboxFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
268 FileSystemType type, 268 FileSystemType type,
269 base::PlatformFileError* error_code) { 269 base::PlatformFileError* error_code) {
270 DCHECK(error_code); 270 DCHECK(error_code);
271 *error_code = base::PLATFORM_FILE_OK; 271 *error_code = base::PLATFORM_FILE_OK;
272 return NULL; 272 return NULL;
273 } 273 }
274 274
275 FileSystemOperation* SandboxMountPointProvider::CreateFileSystemOperation( 275 FileSystemOperation* SandboxFileSystemBackend::CreateFileSystemOperation(
276 const FileSystemURL& url, 276 const FileSystemURL& url,
277 FileSystemContext* context, 277 FileSystemContext* context,
278 base::PlatformFileError* error_code) const { 278 base::PlatformFileError* error_code) const {
279 if (!IsAccessValid(url)) { 279 if (!IsAccessValid(url)) {
280 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; 280 *error_code = base::PLATFORM_FILE_ERROR_SECURITY;
281 return NULL; 281 return NULL;
282 } 282 }
283 283
284 scoped_ptr<FileSystemOperationContext> operation_context( 284 scoped_ptr<FileSystemOperationContext> operation_context(
285 new FileSystemOperationContext(context)); 285 new FileSystemOperationContext(context));
(...skipping 14 matching lines...) Expand all
300 special_storage_policy_->IsStorageUnlimited(url.origin())) { 300 special_storage_policy_->IsStorageUnlimited(url.origin())) {
301 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); 301 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited);
302 } else { 302 } else {
303 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); 303 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited);
304 } 304 }
305 305
306 return new LocalFileSystemOperation(url, context, operation_context.Pass()); 306 return new LocalFileSystemOperation(url, context, operation_context.Pass());
307 } 307 }
308 308
309 scoped_ptr<webkit_blob::FileStreamReader> 309 scoped_ptr<webkit_blob::FileStreamReader>
310 SandboxMountPointProvider::CreateFileStreamReader( 310 SandboxFileSystemBackend::CreateFileStreamReader(
311 const FileSystemURL& url, 311 const FileSystemURL& url,
312 int64 offset, 312 int64 offset,
313 const base::Time& expected_modification_time, 313 const base::Time& expected_modification_time,
314 FileSystemContext* context) const { 314 FileSystemContext* context) const {
315 if (!IsAccessValid(url)) 315 if (!IsAccessValid(url))
316 return scoped_ptr<webkit_blob::FileStreamReader>(); 316 return scoped_ptr<webkit_blob::FileStreamReader>();
317 return scoped_ptr<webkit_blob::FileStreamReader>( 317 return scoped_ptr<webkit_blob::FileStreamReader>(
318 new FileSystemFileStreamReader( 318 new FileSystemFileStreamReader(
319 context, url, offset, expected_modification_time)); 319 context, url, offset, expected_modification_time));
320 } 320 }
321 321
322 scoped_ptr<fileapi::FileStreamWriter> 322 scoped_ptr<fileapi::FileStreamWriter>
323 SandboxMountPointProvider::CreateFileStreamWriter( 323 SandboxFileSystemBackend::CreateFileStreamWriter(
324 const FileSystemURL& url, 324 const FileSystemURL& url,
325 int64 offset, 325 int64 offset,
326 FileSystemContext* context) const { 326 FileSystemContext* context) const {
327 if (!IsAccessValid(url)) 327 if (!IsAccessValid(url))
328 return scoped_ptr<fileapi::FileStreamWriter>(); 328 return scoped_ptr<fileapi::FileStreamWriter>();
329 return scoped_ptr<fileapi::FileStreamWriter>( 329 return scoped_ptr<fileapi::FileStreamWriter>(
330 new SandboxFileStreamWriter(context, url, offset, update_observers_)); 330 new SandboxFileStreamWriter(context, url, offset, update_observers_));
331 } 331 }
332 332
333 FileSystemQuotaUtil* SandboxMountPointProvider::GetQuotaUtil() { 333 FileSystemQuotaUtil* SandboxFileSystemBackend::GetQuotaUtil() {
334 return this; 334 return this;
335 } 335 }
336 336
337 void SandboxMountPointProvider::DeleteFileSystem( 337 void SandboxFileSystemBackend::DeleteFileSystem(
338 const GURL& origin_url, 338 const GURL& origin_url,
339 FileSystemType type, 339 FileSystemType type,
340 FileSystemContext* context, 340 FileSystemContext* context,
341 const DeleteFileSystemCallback& callback) { 341 const DeleteFileSystemCallback& callback) {
342 base::PostTaskAndReplyWithResult( 342 base::PostTaskAndReplyWithResult(
343 context->task_runners()->file_task_runner(), 343 context->task_runners()->file_task_runner(),
344 FROM_HERE, 344 FROM_HERE,
345 // It is safe to pass Unretained(this) since context owns it. 345 // It is safe to pass Unretained(this) since context owns it.
346 base::Bind(&SandboxMountPointProvider::DeleteOriginDataOnFileThread, 346 base::Bind(&SandboxFileSystemBackend::DeleteOriginDataOnFileThread,
347 base::Unretained(this), 347 base::Unretained(this),
348 make_scoped_refptr(context), 348 make_scoped_refptr(context),
349 base::Unretained(context->quota_manager_proxy()), 349 base::Unretained(context->quota_manager_proxy()),
350 origin_url, 350 origin_url,
351 type), 351 type),
352 callback); 352 callback);
353 } 353 }
354 354
355 SandboxMountPointProvider::OriginEnumerator* 355 SandboxFileSystemBackend::OriginEnumerator*
356 SandboxMountPointProvider::CreateOriginEnumerator() { 356 SandboxFileSystemBackend::CreateOriginEnumerator() {
357 return new ObfuscatedOriginEnumerator(sandbox_sync_file_util()); 357 return new ObfuscatedOriginEnumerator(sandbox_sync_file_util());
358 } 358 }
359 359
360 base::FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( 360 base::FilePath SandboxFileSystemBackend::GetBaseDirectoryForOriginAndType(
361 const GURL& origin_url, fileapi::FileSystemType type, bool create) { 361 const GURL& origin_url, fileapi::FileSystemType type, bool create) {
362 362
363 base::PlatformFileError error = base::PLATFORM_FILE_OK; 363 base::PlatformFileError error = base::PLATFORM_FILE_OK;
364 base::FilePath path = sandbox_sync_file_util()->GetDirectoryForOriginAndType( 364 base::FilePath path = sandbox_sync_file_util()->GetDirectoryForOriginAndType(
365 origin_url, type, create, &error); 365 origin_url, type, create, &error);
366 if (error != base::PLATFORM_FILE_OK) 366 if (error != base::PLATFORM_FILE_OK)
367 return base::FilePath(); 367 return base::FilePath();
368 return path; 368 return path;
369 } 369 }
370 370
371 base::PlatformFileError 371 base::PlatformFileError
372 SandboxMountPointProvider::DeleteOriginDataOnFileThread( 372 SandboxFileSystemBackend::DeleteOriginDataOnFileThread(
373 FileSystemContext* file_system_context, 373 FileSystemContext* file_system_context,
374 QuotaManagerProxy* proxy, 374 QuotaManagerProxy* proxy,
375 const GURL& origin_url, 375 const GURL& origin_url,
376 fileapi::FileSystemType type) { 376 fileapi::FileSystemType type) {
377 377
378 int64 usage = GetOriginUsageOnFileThread(file_system_context, 378 int64 usage = GetOriginUsageOnFileThread(file_system_context,
379 origin_url, type); 379 origin_url, type);
380 380
381 file_system_usage_cache_->CloseCacheFiles(); 381 file_system_usage_cache_->CloseCacheFiles();
382 bool result = sandbox_sync_file_util()->DeleteDirectoryForOriginAndType( 382 bool result = sandbox_sync_file_util()->DeleteDirectoryForOriginAndType(
383 origin_url, type); 383 origin_url, type);
384 if (result && proxy) { 384 if (result && proxy) {
385 proxy->NotifyStorageModified( 385 proxy->NotifyStorageModified(
386 quota::QuotaClient::kFileSystem, 386 quota::QuotaClient::kFileSystem,
387 origin_url, 387 origin_url,
388 FileSystemTypeToQuotaStorageType(type), 388 FileSystemTypeToQuotaStorageType(type),
389 -usage); 389 -usage);
390 } 390 }
391 391
392 if (result) 392 if (result)
393 return base::PLATFORM_FILE_OK; 393 return base::PLATFORM_FILE_OK;
394 return base::PLATFORM_FILE_ERROR_FAILED; 394 return base::PLATFORM_FILE_ERROR_FAILED;
395 } 395 }
396 396
397 void SandboxMountPointProvider::GetOriginsForTypeOnFileThread( 397 void SandboxFileSystemBackend::GetOriginsForTypeOnFileThread(
398 fileapi::FileSystemType type, std::set<GURL>* origins) { 398 fileapi::FileSystemType type, std::set<GURL>* origins) {
399 DCHECK(CanHandleType(type)); 399 DCHECK(CanHandleType(type));
400 DCHECK(origins); 400 DCHECK(origins);
401 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); 401 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
402 GURL origin; 402 GURL origin;
403 while (!(origin = enumerator->Next()).is_empty()) { 403 while (!(origin = enumerator->Next()).is_empty()) {
404 if (enumerator->HasFileSystemType(type)) 404 if (enumerator->HasFileSystemType(type))
405 origins->insert(origin); 405 origins->insert(origin);
406 } 406 }
407 switch (type) { 407 switch (type) {
408 case kFileSystemTypeTemporary: 408 case kFileSystemTypeTemporary:
409 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size()); 409 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size());
410 break; 410 break;
411 case kFileSystemTypePersistent: 411 case kFileSystemTypePersistent:
412 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size()); 412 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size());
413 break; 413 break;
414 case kFileSystemTypeSyncable: 414 case kFileSystemTypeSyncable:
415 UMA_HISTOGRAM_COUNTS(kSyncableOriginsCountLabel, origins->size()); 415 UMA_HISTOGRAM_COUNTS(kSyncableOriginsCountLabel, origins->size());
416 break; 416 break;
417 default: 417 default:
418 break; 418 break;
419 } 419 }
420 } 420 }
421 421
422 void SandboxMountPointProvider::GetOriginsForHostOnFileThread( 422 void SandboxFileSystemBackend::GetOriginsForHostOnFileThread(
423 fileapi::FileSystemType type, const std::string& host, 423 fileapi::FileSystemType type, const std::string& host,
424 std::set<GURL>* origins) { 424 std::set<GURL>* origins) {
425 DCHECK(CanHandleType(type)); 425 DCHECK(CanHandleType(type));
426 DCHECK(origins); 426 DCHECK(origins);
427 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); 427 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
428 GURL origin; 428 GURL origin;
429 while (!(origin = enumerator->Next()).is_empty()) { 429 while (!(origin = enumerator->Next()).is_empty()) {
430 if (host == net::GetHostOrSpecFromURL(origin) && 430 if (host == net::GetHostOrSpecFromURL(origin) &&
431 enumerator->HasFileSystemType(type)) 431 enumerator->HasFileSystemType(type))
432 origins->insert(origin); 432 origins->insert(origin);
433 } 433 }
434 } 434 }
435 435
436 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( 436 int64 SandboxFileSystemBackend::GetOriginUsageOnFileThread(
437 FileSystemContext* file_system_context, 437 FileSystemContext* file_system_context,
438 const GURL& origin_url, 438 const GURL& origin_url,
439 fileapi::FileSystemType type) { 439 fileapi::FileSystemType type) {
440 DCHECK(CanHandleType(type)); 440 DCHECK(CanHandleType(type));
441 if (!enable_usage_tracking_) 441 if (!enable_usage_tracking_)
442 return 0; 442 return 0;
443 443
444 // Don't use usage cache and return recalculated usage for sticky invalidated 444 // Don't use usage cache and return recalculated usage for sticky invalidated
445 // origins. 445 // origins.
446 if (ContainsKey(sticky_dirty_origins_, std::make_pair(origin_url, type))) 446 if (ContainsKey(sticky_dirty_origins_, std::make_pair(origin_url, type)))
(...skipping 22 matching lines...) Expand all
469 // Get the directory size now and update the cache. 469 // Get the directory size now and update the cache.
470 file_system_usage_cache_->Delete(usage_file_path); 470 file_system_usage_cache_->Delete(usage_file_path);
471 471
472 int64 usage = RecalculateUsage(file_system_context, origin_url, type); 472 int64 usage = RecalculateUsage(file_system_context, origin_url, type);
473 473
474 // This clears the dirty flag too. 474 // This clears the dirty flag too.
475 file_system_usage_cache_->UpdateUsage(usage_file_path, usage); 475 file_system_usage_cache_->UpdateUsage(usage_file_path, usage);
476 return usage; 476 return usage;
477 } 477 }
478 478
479 void SandboxMountPointProvider::InvalidateUsageCache( 479 void SandboxFileSystemBackend::InvalidateUsageCache(
480 const GURL& origin, 480 const GURL& origin,
481 fileapi::FileSystemType type) { 481 fileapi::FileSystemType type) {
482 DCHECK(CanHandleType(type)); 482 DCHECK(CanHandleType(type));
483 base::PlatformFileError error = base::PLATFORM_FILE_OK; 483 base::PlatformFileError error = base::PLATFORM_FILE_OK;
484 base::FilePath usage_file_path = GetUsageCachePathForOriginAndType( 484 base::FilePath usage_file_path = GetUsageCachePathForOriginAndType(
485 sandbox_sync_file_util(), origin, type, &error); 485 sandbox_sync_file_util(), origin, type, &error);
486 if (error != base::PLATFORM_FILE_OK) 486 if (error != base::PLATFORM_FILE_OK)
487 return; 487 return;
488 file_system_usage_cache_->IncrementDirty(usage_file_path); 488 file_system_usage_cache_->IncrementDirty(usage_file_path);
489 } 489 }
490 490
491 void SandboxMountPointProvider::StickyInvalidateUsageCache( 491 void SandboxFileSystemBackend::StickyInvalidateUsageCache(
492 const GURL& origin, 492 const GURL& origin,
493 fileapi::FileSystemType type) { 493 fileapi::FileSystemType type) {
494 DCHECK(CanHandleType(type)); 494 DCHECK(CanHandleType(type));
495 sticky_dirty_origins_.insert(std::make_pair(origin, type)); 495 sticky_dirty_origins_.insert(std::make_pair(origin, type));
496 quota_observer_->SetUsageCacheEnabled(origin, type, false); 496 quota_observer_->SetUsageCacheEnabled(origin, type, false);
497 InvalidateUsageCache(origin, type); 497 InvalidateUsageCache(origin, type);
498 } 498 }
499 499
500 void SandboxMountPointProvider::CollectOpenFileSystemMetrics( 500 void SandboxFileSystemBackend::CollectOpenFileSystemMetrics(
501 base::PlatformFileError error_code) { 501 base::PlatformFileError error_code) {
502 base::Time now = base::Time::Now(); 502 base::Time now = base::Time::Now();
503 bool throttled = now < next_release_time_for_open_filesystem_stat_; 503 bool throttled = now < next_release_time_for_open_filesystem_stat_;
504 if (!throttled) { 504 if (!throttled) {
505 next_release_time_for_open_filesystem_stat_ = 505 next_release_time_for_open_filesystem_stat_ =
506 now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours); 506 now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours);
507 } 507 }
508 508
509 #define REPORT(report_value) \ 509 #define REPORT(report_value) \
510 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \ 510 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \
(...skipping 16 matching lines...) Expand all
527 REPORT(kNotFound); 527 REPORT(kNotFound);
528 break; 528 break;
529 case base::PLATFORM_FILE_ERROR_FAILED: 529 case base::PLATFORM_FILE_ERROR_FAILED:
530 default: 530 default:
531 REPORT(kUnknownError); 531 REPORT(kUnknownError);
532 break; 532 break;
533 } 533 }
534 #undef REPORT 534 #undef REPORT
535 } 535 }
536 536
537 const UpdateObserverList* SandboxMountPointProvider::GetUpdateObservers( 537 const UpdateObserverList* SandboxFileSystemBackend::GetUpdateObservers(
538 FileSystemType type) const { 538 FileSystemType type) const {
539 DCHECK(CanHandleType(type)); 539 DCHECK(CanHandleType(type));
540 if (type == kFileSystemTypeSyncable) 540 if (type == kFileSystemTypeSyncable)
541 return &syncable_update_observers_; 541 return &syncable_update_observers_;
542 return &update_observers_; 542 return &update_observers_;
543 } 543 }
544 544
545 const AccessObserverList* SandboxMountPointProvider::GetAccessObservers( 545 const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers(
546 FileSystemType type) const { 546 FileSystemType type) const {
547 DCHECK(CanHandleType(type)); 547 DCHECK(CanHandleType(type));
548 return &access_observers_; 548 return &access_observers_;
549 } 549 }
550 550
551 void SandboxMountPointProvider::AddFileUpdateObserver( 551 void SandboxFileSystemBackend::AddFileUpdateObserver(
552 FileSystemType type, 552 FileSystemType type,
553 FileUpdateObserver* observer, 553 FileUpdateObserver* observer,
554 base::SequencedTaskRunner* task_runner) { 554 base::SequencedTaskRunner* task_runner) {
555 DCHECK(CanHandleType(type)); 555 DCHECK(CanHandleType(type));
556 UpdateObserverList* list = &update_observers_; 556 UpdateObserverList* list = &update_observers_;
557 if (type == kFileSystemTypeSyncable) 557 if (type == kFileSystemTypeSyncable)
558 list = &syncable_update_observers_; 558 list = &syncable_update_observers_;
559 UpdateObserverList::Source observer_source = list->source(); 559 UpdateObserverList::Source observer_source = list->source();
560 observer_source.AddObserver(observer, task_runner); 560 observer_source.AddObserver(observer, task_runner);
561 *list = UpdateObserverList(observer_source); 561 *list = UpdateObserverList(observer_source);
562 } 562 }
563 563
564 void SandboxMountPointProvider::AddFileChangeObserver( 564 void SandboxFileSystemBackend::AddFileChangeObserver(
565 FileSystemType type, 565 FileSystemType type,
566 FileChangeObserver* observer, 566 FileChangeObserver* observer,
567 base::SequencedTaskRunner* task_runner) { 567 base::SequencedTaskRunner* task_runner) {
568 ChangeObserverList* list = &change_observers_; 568 ChangeObserverList* list = &change_observers_;
569 if (type == kFileSystemTypeSyncable) 569 if (type == kFileSystemTypeSyncable)
570 list = &syncable_change_observers_; 570 list = &syncable_change_observers_;
571 ChangeObserverList::Source observer_source = list->source(); 571 ChangeObserverList::Source observer_source = list->source();
572 observer_source.AddObserver(observer, task_runner); 572 observer_source.AddObserver(observer, task_runner);
573 *list = ChangeObserverList(observer_source); 573 *list = ChangeObserverList(observer_source);
574 } 574 }
575 575
576 bool SandboxMountPointProvider::IsAccessValid( 576 bool SandboxFileSystemBackend::IsAccessValid(
577 const FileSystemURL& url) const { 577 const FileSystemURL& url) const {
578 if (!IsAllowedScheme(url.origin())) 578 if (!IsAllowedScheme(url.origin()))
579 return false; 579 return false;
580 580
581 if (!CanHandleType(url.type())) 581 if (!CanHandleType(url.type()))
582 return false; 582 return false;
583 583
584 if (url.path().ReferencesParent()) 584 if (url.path().ReferencesParent())
585 return false; 585 return false;
586 586
(...skipping 14 matching lines...) Expand all
601 } 601 }
602 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { 602 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) {
603 if (filename.value().find(kRestrictedChars[i]) != 603 if (filename.value().find(kRestrictedChars[i]) !=
604 base::FilePath::StringType::npos) 604 base::FilePath::StringType::npos)
605 return false; 605 return false;
606 } 606 }
607 607
608 return true; 608 return true;
609 } 609 }
610 610
611 base::FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( 611 base::FilePath SandboxFileSystemBackend::GetUsageCachePathForOriginAndType(
612 const GURL& origin_url, 612 const GURL& origin_url,
613 FileSystemType type) { 613 FileSystemType type) {
614 base::PlatformFileError error; 614 base::PlatformFileError error;
615 base::FilePath path = GetUsageCachePathForOriginAndType( 615 base::FilePath path = GetUsageCachePathForOriginAndType(
616 sandbox_sync_file_util(), origin_url, type, &error); 616 sandbox_sync_file_util(), origin_url, type, &error);
617 if (error != base::PLATFORM_FILE_OK) 617 if (error != base::PLATFORM_FILE_OK)
618 return base::FilePath(); 618 return base::FilePath();
619 return path; 619 return path;
620 } 620 }
621 621
622 // static 622 // static
623 base::FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( 623 base::FilePath SandboxFileSystemBackend::GetUsageCachePathForOriginAndType(
624 ObfuscatedFileUtil* sandbox_file_util, 624 ObfuscatedFileUtil* sandbox_file_util,
625 const GURL& origin_url, 625 const GURL& origin_url,
626 fileapi::FileSystemType type, 626 fileapi::FileSystemType type,
627 base::PlatformFileError* error_out) { 627 base::PlatformFileError* error_out) {
628 DCHECK(error_out); 628 DCHECK(error_out);
629 *error_out = base::PLATFORM_FILE_OK; 629 *error_out = base::PLATFORM_FILE_OK;
630 base::FilePath base_path = sandbox_file_util->GetDirectoryForOriginAndType( 630 base::FilePath base_path = sandbox_file_util->GetDirectoryForOriginAndType(
631 origin_url, type, false /* create */, error_out); 631 origin_url, type, false /* create */, error_out);
632 if (*error_out != base::PLATFORM_FILE_OK) 632 if (*error_out != base::PLATFORM_FILE_OK)
633 return base::FilePath(); 633 return base::FilePath();
634 return base_path.Append(FileSystemUsageCache::kUsageFileName); 634 return base_path.Append(FileSystemUsageCache::kUsageFileName);
635 } 635 }
636 636
637 bool SandboxMountPointProvider::IsAllowedScheme(const GURL& url) const { 637 bool SandboxFileSystemBackend::IsAllowedScheme(const GURL& url) const {
638 // Basically we only accept http or https. We allow file:// URLs 638 // Basically we only accept http or https. We allow file:// URLs
639 // only if --allow-file-access-from-files flag is given. 639 // only if --allow-file-access-from-files flag is given.
640 if (url.SchemeIs("http") || url.SchemeIs("https")) 640 if (url.SchemeIs("http") || url.SchemeIs("https"))
641 return true; 641 return true;
642 if (url.SchemeIsFileSystem()) 642 if (url.SchemeIsFileSystem())
643 return url.inner_url() && IsAllowedScheme(*url.inner_url()); 643 return url.inner_url() && IsAllowedScheme(*url.inner_url());
644 644
645 for (size_t i = 0; 645 for (size_t i = 0;
646 i < file_system_options_.additional_allowed_schemes().size(); 646 i < file_system_options_.additional_allowed_schemes().size();
647 ++i) { 647 ++i) {
648 if (url.SchemeIs( 648 if (url.SchemeIs(
649 file_system_options_.additional_allowed_schemes()[i].c_str())) 649 file_system_options_.additional_allowed_schemes()[i].c_str()))
650 return true; 650 return true;
651 } 651 }
652 return false; 652 return false;
653 } 653 }
654 654
655 ObfuscatedFileUtil* SandboxMountPointProvider::sandbox_sync_file_util() { 655 ObfuscatedFileUtil* SandboxFileSystemBackend::sandbox_sync_file_util() {
656 DCHECK(sandbox_file_util_.get()); 656 DCHECK(sandbox_file_util_.get());
657 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util()); 657 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util());
658 } 658 }
659 659
660 // static 660 // static
661 void SandboxMountPointProvider::InvalidateUsageCacheOnFileThread( 661 void SandboxFileSystemBackend::InvalidateUsageCacheOnFileThread(
662 ObfuscatedFileUtil* file_util, 662 ObfuscatedFileUtil* file_util,
663 const GURL& origin, 663 const GURL& origin,
664 FileSystemType type, 664 FileSystemType type,
665 FileSystemUsageCache* usage_cache) { 665 FileSystemUsageCache* usage_cache) {
666 base::PlatformFileError error = base::PLATFORM_FILE_OK; 666 base::PlatformFileError error = base::PLATFORM_FILE_OK;
667 base::FilePath usage_cache_path = GetUsageCachePathForOriginAndType( 667 base::FilePath usage_cache_path = GetUsageCachePathForOriginAndType(
668 file_util, origin, type, &error); 668 file_util, origin, type, &error);
669 if (error == base::PLATFORM_FILE_OK) 669 if (error == base::PLATFORM_FILE_OK)
670 usage_cache->IncrementDirty(usage_cache_path); 670 usage_cache->IncrementDirty(usage_cache_path);
671 } 671 }
672 672
673 int64 SandboxMountPointProvider::RecalculateUsage(FileSystemContext* context, 673 int64 SandboxFileSystemBackend::RecalculateUsage(FileSystemContext* context,
674 const GURL& origin, 674 const GURL& origin,
675 FileSystemType type) { 675 FileSystemType type) {
676 FileSystemOperationContext operation_context(context); 676 FileSystemOperationContext operation_context(context);
677 FileSystemURL url = context->CreateCrackedFileSystemURL( 677 FileSystemURL url = context->CreateCrackedFileSystemURL(
678 origin, type, base::FilePath()); 678 origin, type, base::FilePath());
679 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( 679 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator(
680 sandbox_sync_file_util()->CreateFileEnumerator( 680 sandbox_sync_file_util()->CreateFileEnumerator(
681 &operation_context, url, true)); 681 &operation_context, url, true));
682 682
683 base::FilePath file_path_each; 683 base::FilePath file_path_each;
684 int64 usage = 0; 684 int64 usage = 0;
685 685
686 while (!(file_path_each = enumerator->Next()).empty()) { 686 while (!(file_path_each = enumerator->Next()).empty()) {
687 usage += enumerator->Size(); 687 usage += enumerator->Size();
688 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); 688 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each);
689 } 689 }
690 690
691 return usage; 691 return usage;
692 } 692 }
693 693
694 } // namespace fileapi 694 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698