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

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 SandboxMountPointProvider::OriginEnumerator* 337 SandboxFileSystemBackend::OriginEnumerator*
338 SandboxMountPointProvider::CreateOriginEnumerator() { 338 SandboxFileSystemBackend::CreateOriginEnumerator() {
339 return new ObfuscatedOriginEnumerator(sandbox_sync_file_util()); 339 return new ObfuscatedOriginEnumerator(sandbox_sync_file_util());
340 } 340 }
341 341
342 base::FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( 342 base::FilePath SandboxFileSystemBackend::GetBaseDirectoryForOriginAndType(
343 const GURL& origin_url, fileapi::FileSystemType type, bool create) { 343 const GURL& origin_url, fileapi::FileSystemType type, bool create) {
344 344
345 base::PlatformFileError error = base::PLATFORM_FILE_OK; 345 base::PlatformFileError error = base::PLATFORM_FILE_OK;
346 base::FilePath path = sandbox_sync_file_util()->GetDirectoryForOriginAndType( 346 base::FilePath path = sandbox_sync_file_util()->GetDirectoryForOriginAndType(
347 origin_url, type, create, &error); 347 origin_url, type, create, &error);
348 if (error != base::PLATFORM_FILE_OK) 348 if (error != base::PLATFORM_FILE_OK)
349 return base::FilePath(); 349 return base::FilePath();
350 return path; 350 return path;
351 } 351 }
352 352
353 base::PlatformFileError 353 base::PlatformFileError
354 SandboxMountPointProvider::DeleteOriginDataOnFileThread( 354 SandboxFileSystemBackend::DeleteOriginDataOnFileThread(
355 FileSystemContext* file_system_context, 355 FileSystemContext* file_system_context,
356 QuotaManagerProxy* proxy, 356 QuotaManagerProxy* proxy,
357 const GURL& origin_url, 357 const GURL& origin_url,
358 fileapi::FileSystemType type) { 358 fileapi::FileSystemType type) {
359 359
360 int64 usage = GetOriginUsageOnFileThread(file_system_context, 360 int64 usage = GetOriginUsageOnFileThread(file_system_context,
361 origin_url, type); 361 origin_url, type);
362 362
363 file_system_usage_cache_->CloseCacheFiles(); 363 file_system_usage_cache_->CloseCacheFiles();
364 bool result = sandbox_sync_file_util()->DeleteDirectoryForOriginAndType( 364 bool result = sandbox_sync_file_util()->DeleteDirectoryForOriginAndType(
365 origin_url, type); 365 origin_url, type);
366 if (result && proxy) { 366 if (result && proxy) {
367 proxy->NotifyStorageModified( 367 proxy->NotifyStorageModified(
368 quota::QuotaClient::kFileSystem, 368 quota::QuotaClient::kFileSystem,
369 origin_url, 369 origin_url,
370 FileSystemTypeToQuotaStorageType(type), 370 FileSystemTypeToQuotaStorageType(type),
371 -usage); 371 -usage);
372 } 372 }
373 373
374 if (result) 374 if (result)
375 return base::PLATFORM_FILE_OK; 375 return base::PLATFORM_FILE_OK;
376 return base::PLATFORM_FILE_ERROR_FAILED; 376 return base::PLATFORM_FILE_ERROR_FAILED;
377 } 377 }
378 378
379 void SandboxMountPointProvider::GetOriginsForTypeOnFileThread( 379 void SandboxFileSystemBackend::GetOriginsForTypeOnFileThread(
380 fileapi::FileSystemType type, std::set<GURL>* origins) { 380 fileapi::FileSystemType type, std::set<GURL>* origins) {
381 DCHECK(CanHandleType(type)); 381 DCHECK(CanHandleType(type));
382 DCHECK(origins); 382 DCHECK(origins);
383 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); 383 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
384 GURL origin; 384 GURL origin;
385 while (!(origin = enumerator->Next()).is_empty()) { 385 while (!(origin = enumerator->Next()).is_empty()) {
386 if (enumerator->HasFileSystemType(type)) 386 if (enumerator->HasFileSystemType(type))
387 origins->insert(origin); 387 origins->insert(origin);
388 } 388 }
389 switch (type) { 389 switch (type) {
390 case kFileSystemTypeTemporary: 390 case kFileSystemTypeTemporary:
391 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size()); 391 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size());
392 break; 392 break;
393 case kFileSystemTypePersistent: 393 case kFileSystemTypePersistent:
394 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size()); 394 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size());
395 break; 395 break;
396 case kFileSystemTypeSyncable: 396 case kFileSystemTypeSyncable:
397 UMA_HISTOGRAM_COUNTS(kSyncableOriginsCountLabel, origins->size()); 397 UMA_HISTOGRAM_COUNTS(kSyncableOriginsCountLabel, origins->size());
398 break; 398 break;
399 default: 399 default:
400 break; 400 break;
401 } 401 }
402 } 402 }
403 403
404 void SandboxMountPointProvider::GetOriginsForHostOnFileThread( 404 void SandboxFileSystemBackend::GetOriginsForHostOnFileThread(
405 fileapi::FileSystemType type, const std::string& host, 405 fileapi::FileSystemType type, const std::string& host,
406 std::set<GURL>* origins) { 406 std::set<GURL>* origins) {
407 DCHECK(CanHandleType(type)); 407 DCHECK(CanHandleType(type));
408 DCHECK(origins); 408 DCHECK(origins);
409 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); 409 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
410 GURL origin; 410 GURL origin;
411 while (!(origin = enumerator->Next()).is_empty()) { 411 while (!(origin = enumerator->Next()).is_empty()) {
412 if (host == net::GetHostOrSpecFromURL(origin) && 412 if (host == net::GetHostOrSpecFromURL(origin) &&
413 enumerator->HasFileSystemType(type)) 413 enumerator->HasFileSystemType(type))
414 origins->insert(origin); 414 origins->insert(origin);
415 } 415 }
416 } 416 }
417 417
418 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( 418 int64 SandboxFileSystemBackend::GetOriginUsageOnFileThread(
419 FileSystemContext* file_system_context, 419 FileSystemContext* file_system_context,
420 const GURL& origin_url, 420 const GURL& origin_url,
421 fileapi::FileSystemType type) { 421 fileapi::FileSystemType type) {
422 DCHECK(CanHandleType(type)); 422 DCHECK(CanHandleType(type));
423 if (!enable_usage_tracking_) 423 if (!enable_usage_tracking_)
424 return 0; 424 return 0;
425 425
426 // Don't use usage cache and return recalculated usage for sticky invalidated 426 // Don't use usage cache and return recalculated usage for sticky invalidated
427 // origins. 427 // origins.
428 if (ContainsKey(sticky_dirty_origins_, std::make_pair(origin_url, type))) 428 if (ContainsKey(sticky_dirty_origins_, std::make_pair(origin_url, type)))
(...skipping 22 matching lines...) Expand all
451 // Get the directory size now and update the cache. 451 // Get the directory size now and update the cache.
452 file_system_usage_cache_->Delete(usage_file_path); 452 file_system_usage_cache_->Delete(usage_file_path);
453 453
454 int64 usage = RecalculateUsage(file_system_context, origin_url, type); 454 int64 usage = RecalculateUsage(file_system_context, origin_url, type);
455 455
456 // This clears the dirty flag too. 456 // This clears the dirty flag too.
457 file_system_usage_cache_->UpdateUsage(usage_file_path, usage); 457 file_system_usage_cache_->UpdateUsage(usage_file_path, usage);
458 return usage; 458 return usage;
459 } 459 }
460 460
461 void SandboxMountPointProvider::InvalidateUsageCache( 461 void SandboxFileSystemBackend::InvalidateUsageCache(
462 const GURL& origin, 462 const GURL& origin,
463 fileapi::FileSystemType type) { 463 fileapi::FileSystemType type) {
464 DCHECK(CanHandleType(type)); 464 DCHECK(CanHandleType(type));
465 base::PlatformFileError error = base::PLATFORM_FILE_OK; 465 base::PlatformFileError error = base::PLATFORM_FILE_OK;
466 base::FilePath usage_file_path = GetUsageCachePathForOriginAndType( 466 base::FilePath usage_file_path = GetUsageCachePathForOriginAndType(
467 sandbox_sync_file_util(), origin, type, &error); 467 sandbox_sync_file_util(), origin, type, &error);
468 if (error != base::PLATFORM_FILE_OK) 468 if (error != base::PLATFORM_FILE_OK)
469 return; 469 return;
470 file_system_usage_cache_->IncrementDirty(usage_file_path); 470 file_system_usage_cache_->IncrementDirty(usage_file_path);
471 } 471 }
472 472
473 void SandboxMountPointProvider::StickyInvalidateUsageCache( 473 void SandboxFileSystemBackend::StickyInvalidateUsageCache(
474 const GURL& origin, 474 const GURL& origin,
475 fileapi::FileSystemType type) { 475 fileapi::FileSystemType type) {
476 DCHECK(CanHandleType(type)); 476 DCHECK(CanHandleType(type));
477 sticky_dirty_origins_.insert(std::make_pair(origin, type)); 477 sticky_dirty_origins_.insert(std::make_pair(origin, type));
478 quota_observer_->SetUsageCacheEnabled(origin, type, false); 478 quota_observer_->SetUsageCacheEnabled(origin, type, false);
479 InvalidateUsageCache(origin, type); 479 InvalidateUsageCache(origin, type);
480 } 480 }
481 481
482 void SandboxMountPointProvider::CollectOpenFileSystemMetrics( 482 void SandboxFileSystemBackend::CollectOpenFileSystemMetrics(
483 base::PlatformFileError error_code) { 483 base::PlatformFileError error_code) {
484 base::Time now = base::Time::Now(); 484 base::Time now = base::Time::Now();
485 bool throttled = now < next_release_time_for_open_filesystem_stat_; 485 bool throttled = now < next_release_time_for_open_filesystem_stat_;
486 if (!throttled) { 486 if (!throttled) {
487 next_release_time_for_open_filesystem_stat_ = 487 next_release_time_for_open_filesystem_stat_ =
488 now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours); 488 now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours);
489 } 489 }
490 490
491 #define REPORT(report_value) \ 491 #define REPORT(report_value) \
492 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \ 492 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \
(...skipping 16 matching lines...) Expand all
509 REPORT(kNotFound); 509 REPORT(kNotFound);
510 break; 510 break;
511 case base::PLATFORM_FILE_ERROR_FAILED: 511 case base::PLATFORM_FILE_ERROR_FAILED:
512 default: 512 default:
513 REPORT(kUnknownError); 513 REPORT(kUnknownError);
514 break; 514 break;
515 } 515 }
516 #undef REPORT 516 #undef REPORT
517 } 517 }
518 518
519 const UpdateObserverList* SandboxMountPointProvider::GetUpdateObservers( 519 const UpdateObserverList* SandboxFileSystemBackend::GetUpdateObservers(
520 FileSystemType type) const { 520 FileSystemType type) const {
521 DCHECK(CanHandleType(type)); 521 DCHECK(CanHandleType(type));
522 if (type == kFileSystemTypeSyncable) 522 if (type == kFileSystemTypeSyncable)
523 return &syncable_update_observers_; 523 return &syncable_update_observers_;
524 return &update_observers_; 524 return &update_observers_;
525 } 525 }
526 526
527 const AccessObserverList* SandboxMountPointProvider::GetAccessObservers( 527 const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers(
528 FileSystemType type) const { 528 FileSystemType type) const {
529 DCHECK(CanHandleType(type)); 529 DCHECK(CanHandleType(type));
530 return &access_observers_; 530 return &access_observers_;
531 } 531 }
532 532
533 void SandboxMountPointProvider::AddFileUpdateObserver( 533 void SandboxFileSystemBackend::AddFileUpdateObserver(
534 FileSystemType type, 534 FileSystemType type,
535 FileUpdateObserver* observer, 535 FileUpdateObserver* observer,
536 base::SequencedTaskRunner* task_runner) { 536 base::SequencedTaskRunner* task_runner) {
537 DCHECK(CanHandleType(type)); 537 DCHECK(CanHandleType(type));
538 UpdateObserverList* list = &update_observers_; 538 UpdateObserverList* list = &update_observers_;
539 if (type == kFileSystemTypeSyncable) 539 if (type == kFileSystemTypeSyncable)
540 list = &syncable_update_observers_; 540 list = &syncable_update_observers_;
541 UpdateObserverList::Source observer_source = list->source(); 541 UpdateObserverList::Source observer_source = list->source();
542 observer_source.AddObserver(observer, task_runner); 542 observer_source.AddObserver(observer, task_runner);
543 *list = UpdateObserverList(observer_source); 543 *list = UpdateObserverList(observer_source);
544 } 544 }
545 545
546 void SandboxMountPointProvider::AddFileChangeObserver( 546 void SandboxFileSystemBackend::AddFileChangeObserver(
547 FileSystemType type, 547 FileSystemType type,
548 FileChangeObserver* observer, 548 FileChangeObserver* observer,
549 base::SequencedTaskRunner* task_runner) { 549 base::SequencedTaskRunner* task_runner) {
550 ChangeObserverList* list = &change_observers_; 550 ChangeObserverList* list = &change_observers_;
551 if (type == kFileSystemTypeSyncable) 551 if (type == kFileSystemTypeSyncable)
552 list = &syncable_change_observers_; 552 list = &syncable_change_observers_;
553 ChangeObserverList::Source observer_source = list->source(); 553 ChangeObserverList::Source observer_source = list->source();
554 observer_source.AddObserver(observer, task_runner); 554 observer_source.AddObserver(observer, task_runner);
555 *list = ChangeObserverList(observer_source); 555 *list = ChangeObserverList(observer_source);
556 } 556 }
557 557
558 bool SandboxMountPointProvider::IsAccessValid( 558 bool SandboxFileSystemBackend::IsAccessValid(
559 const FileSystemURL& url) const { 559 const FileSystemURL& url) const {
560 if (!IsAllowedScheme(url.origin())) 560 if (!IsAllowedScheme(url.origin()))
561 return false; 561 return false;
562 562
563 if (!CanHandleType(url.type())) 563 if (!CanHandleType(url.type()))
564 return false; 564 return false;
565 565
566 if (url.path().ReferencesParent()) 566 if (url.path().ReferencesParent())
567 return false; 567 return false;
568 568
(...skipping 14 matching lines...) Expand all
583 } 583 }
584 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { 584 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) {
585 if (filename.value().find(kRestrictedChars[i]) != 585 if (filename.value().find(kRestrictedChars[i]) !=
586 base::FilePath::StringType::npos) 586 base::FilePath::StringType::npos)
587 return false; 587 return false;
588 } 588 }
589 589
590 return true; 590 return true;
591 } 591 }
592 592
593 base::FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( 593 base::FilePath SandboxFileSystemBackend::GetUsageCachePathForOriginAndType(
594 const GURL& origin_url, 594 const GURL& origin_url,
595 FileSystemType type) { 595 FileSystemType type) {
596 base::PlatformFileError error; 596 base::PlatformFileError error;
597 base::FilePath path = GetUsageCachePathForOriginAndType( 597 base::FilePath path = GetUsageCachePathForOriginAndType(
598 sandbox_sync_file_util(), origin_url, type, &error); 598 sandbox_sync_file_util(), origin_url, type, &error);
599 if (error != base::PLATFORM_FILE_OK) 599 if (error != base::PLATFORM_FILE_OK)
600 return base::FilePath(); 600 return base::FilePath();
601 return path; 601 return path;
602 } 602 }
603 603
604 // static 604 // static
605 base::FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( 605 base::FilePath SandboxFileSystemBackend::GetUsageCachePathForOriginAndType(
606 ObfuscatedFileUtil* sandbox_file_util, 606 ObfuscatedFileUtil* sandbox_file_util,
607 const GURL& origin_url, 607 const GURL& origin_url,
608 fileapi::FileSystemType type, 608 fileapi::FileSystemType type,
609 base::PlatformFileError* error_out) { 609 base::PlatformFileError* error_out) {
610 DCHECK(error_out); 610 DCHECK(error_out);
611 *error_out = base::PLATFORM_FILE_OK; 611 *error_out = base::PLATFORM_FILE_OK;
612 base::FilePath base_path = sandbox_file_util->GetDirectoryForOriginAndType( 612 base::FilePath base_path = sandbox_file_util->GetDirectoryForOriginAndType(
613 origin_url, type, false /* create */, error_out); 613 origin_url, type, false /* create */, error_out);
614 if (*error_out != base::PLATFORM_FILE_OK) 614 if (*error_out != base::PLATFORM_FILE_OK)
615 return base::FilePath(); 615 return base::FilePath();
616 return base_path.Append(FileSystemUsageCache::kUsageFileName); 616 return base_path.Append(FileSystemUsageCache::kUsageFileName);
617 } 617 }
618 618
619 bool SandboxMountPointProvider::IsAllowedScheme(const GURL& url) const { 619 bool SandboxFileSystemBackend::IsAllowedScheme(const GURL& url) const {
620 // Basically we only accept http or https. We allow file:// URLs 620 // Basically we only accept http or https. We allow file:// URLs
621 // only if --allow-file-access-from-files flag is given. 621 // only if --allow-file-access-from-files flag is given.
622 if (url.SchemeIs("http") || url.SchemeIs("https")) 622 if (url.SchemeIs("http") || url.SchemeIs("https"))
623 return true; 623 return true;
624 if (url.SchemeIsFileSystem()) 624 if (url.SchemeIsFileSystem())
625 return url.inner_url() && IsAllowedScheme(*url.inner_url()); 625 return url.inner_url() && IsAllowedScheme(*url.inner_url());
626 626
627 for (size_t i = 0; 627 for (size_t i = 0;
628 i < file_system_options_.additional_allowed_schemes().size(); 628 i < file_system_options_.additional_allowed_schemes().size();
629 ++i) { 629 ++i) {
630 if (url.SchemeIs( 630 if (url.SchemeIs(
631 file_system_options_.additional_allowed_schemes()[i].c_str())) 631 file_system_options_.additional_allowed_schemes()[i].c_str()))
632 return true; 632 return true;
633 } 633 }
634 return false; 634 return false;
635 } 635 }
636 636
637 ObfuscatedFileUtil* SandboxMountPointProvider::sandbox_sync_file_util() { 637 ObfuscatedFileUtil* SandboxFileSystemBackend::sandbox_sync_file_util() {
638 DCHECK(sandbox_file_util_.get()); 638 DCHECK(sandbox_file_util_.get());
639 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util()); 639 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util());
640 } 640 }
641 641
642 // static 642 // static
643 void SandboxMountPointProvider::InvalidateUsageCacheOnFileThread( 643 void SandboxFileSystemBackend::InvalidateUsageCacheOnFileThread(
644 ObfuscatedFileUtil* file_util, 644 ObfuscatedFileUtil* file_util,
645 const GURL& origin, 645 const GURL& origin,
646 FileSystemType type, 646 FileSystemType type,
647 FileSystemUsageCache* usage_cache) { 647 FileSystemUsageCache* usage_cache) {
648 base::PlatformFileError error = base::PLATFORM_FILE_OK; 648 base::PlatformFileError error = base::PLATFORM_FILE_OK;
649 base::FilePath usage_cache_path = GetUsageCachePathForOriginAndType( 649 base::FilePath usage_cache_path = GetUsageCachePathForOriginAndType(
650 file_util, origin, type, &error); 650 file_util, origin, type, &error);
651 if (error == base::PLATFORM_FILE_OK) 651 if (error == base::PLATFORM_FILE_OK)
652 usage_cache->IncrementDirty(usage_cache_path); 652 usage_cache->IncrementDirty(usage_cache_path);
653 } 653 }
654 654
655 int64 SandboxMountPointProvider::RecalculateUsage(FileSystemContext* context, 655 int64 SandboxFileSystemBackend::RecalculateUsage(FileSystemContext* context,
656 const GURL& origin, 656 const GURL& origin,
657 FileSystemType type) { 657 FileSystemType type) {
658 FileSystemOperationContext operation_context(context); 658 FileSystemOperationContext operation_context(context);
659 FileSystemURL url = context->CreateCrackedFileSystemURL( 659 FileSystemURL url = context->CreateCrackedFileSystemURL(
660 origin, type, base::FilePath()); 660 origin, type, base::FilePath());
661 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( 661 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator(
662 sandbox_sync_file_util()->CreateFileEnumerator( 662 sandbox_sync_file_util()->CreateFileEnumerator(
663 &operation_context, url, true)); 663 &operation_context, url, true));
664 664
665 base::FilePath file_path_each; 665 base::FilePath file_path_each;
666 int64 usage = 0; 666 int64 usage = 0;
667 667
668 while (!(file_path_each = enumerator->Next()).empty()) { 668 while (!(file_path_each = enumerator->Next()).empty()) {
669 usage += enumerator->Size(); 669 usage += enumerator->Size();
670 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); 670 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each);
671 } 671 }
672 672
673 return usage; 673 return usage;
674 } 674 }
675 675
676 } // namespace fileapi 676 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698