OLD | NEW |
---|---|
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/fileapi/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 const char kChromeScheme[] = "chrome"; | 36 const char kChromeScheme[] = "chrome"; |
37 const char kExtensionScheme[] = "chrome-extension"; | 37 const char kExtensionScheme[] = "chrome-extension"; |
38 | 38 |
39 const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = | 39 const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = |
40 FILE_PATH_LITERAL("chrome-"); | 40 FILE_PATH_LITERAL("chrome-"); |
41 const size_t kOldFileSystemUniqueLength = 16; | 41 const size_t kOldFileSystemUniqueLength = 16; |
42 const size_t kOldFileSystemUniqueDirectoryNameLength = | 42 const size_t kOldFileSystemUniqueDirectoryNameLength = |
43 kOldFileSystemUniqueLength + arraysize(kOldFileSystemUniqueNamePrefix) - 1; | 43 kOldFileSystemUniqueLength + arraysize(kOldFileSystemUniqueNamePrefix) - 1; |
44 | 44 |
45 const char kOpenFileSystemLabel[] = "FileSystem.OpenFileSystem"; | 45 const char kOpenFileSystemLabel[] = "FileSystem.OpenFileSystem"; |
46 const char kOpenFileSystemBreakLabel[] = "FileSystem.OpenFileSystemBreak"; | |
kinuko
2012/05/08 06:29:17
Break -> Detail?
Unique -> NonThrottled?
tzik
2012/05/08 06:39:24
Done.
| |
47 const char kOpenFileSystemUniqueBreakLabel[] = | |
48 "FileSystem.OpenFileSystemUnqueBreak"; | |
49 int64 kMinimumStatsCollectionIntervalHours = 1; | |
50 | |
46 enum FileSystemError { | 51 enum FileSystemError { |
47 kOK = 0, | 52 kOK = 0, |
48 kIncognito, | 53 kIncognito, |
49 kInvalidScheme, | 54 kInvalidSchemeError, |
50 kCreateDirectoryError, | 55 kCreateDirectoryError, |
56 kNotFound, | |
57 kUnknownError, | |
51 kFileSystemErrorMax, | 58 kFileSystemErrorMax, |
52 }; | 59 }; |
53 | 60 |
54 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; | 61 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; |
55 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; | 62 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; |
56 | 63 |
57 // Restricted names. | 64 // Restricted names. |
58 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions | 65 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions |
59 const FilePath::CharType* const kRestrictedNames[] = { | 66 const FilePath::CharType* const kRestrictedNames[] = { |
60 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), | 67 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 MigrateAllOldFileSystems(file_util, old_base_path); | 267 MigrateAllOldFileSystems(file_util, old_base_path); |
261 } | 268 } |
262 | 269 |
263 void PassPointerErrorByValue( | 270 void PassPointerErrorByValue( |
264 const base::Callback<void(PlatformFileError)>& callback, | 271 const base::Callback<void(PlatformFileError)>& callback, |
265 PlatformFileError* error_ptr) { | 272 PlatformFileError* error_ptr) { |
266 DCHECK(error_ptr); | 273 DCHECK(error_ptr); |
267 callback.Run(*error_ptr); | 274 callback.Run(*error_ptr); |
268 } | 275 } |
269 | 276 |
270 void ValidateRootOnFileThread(ObfuscatedFileUtil* file_util, | 277 void DidValidateFileSystemRoot( |
271 const GURL& origin_url, | 278 base::WeakPtr<SandboxMountPointProvider> mount_point_provider, |
272 FileSystemType type, | 279 const base::Callback<void(PlatformFileError)>& callback, |
273 const FilePath& old_base_path, | 280 base::PlatformFileError* error) { |
274 bool create, | 281 if (mount_point_provider.get()) |
275 base::PlatformFileError* error_ptr) { | 282 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); |
283 callback.Run(*error); | |
284 } | |
285 | |
286 void ValidateRootOnFileThread( | |
287 ObfuscatedFileUtil* file_util, | |
288 const GURL& origin_url, | |
289 FileSystemType type, | |
290 const FilePath& old_base_path, | |
291 bool create, | |
292 base::PlatformFileError* error_ptr) { | |
276 DCHECK(error_ptr); | 293 DCHECK(error_ptr); |
277 MigrateIfNeeded(file_util, old_base_path); | 294 MigrateIfNeeded(file_util, old_base_path); |
295 | |
278 FilePath root_path = | 296 FilePath root_path = |
279 file_util->GetDirectoryForOriginAndType(origin_url, type, create); | 297 file_util->GetDirectoryForOriginAndType( |
298 origin_url, type, create, error_ptr); | |
280 if (root_path.empty()) { | 299 if (root_path.empty()) { |
281 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, | 300 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, |
282 kCreateDirectoryError, | 301 kCreateDirectoryError, |
283 kFileSystemErrorMax); | 302 kFileSystemErrorMax); |
284 // TODO(kinuko): We should return appropriate error code. | |
285 *error_ptr = base::PLATFORM_FILE_ERROR_FAILED; | |
286 } else { | 303 } else { |
287 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax); | 304 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax); |
288 *error_ptr = base::PLATFORM_FILE_OK; | |
289 } | 305 } |
290 // The reference of file_util will be derefed on the FILE thread | 306 // The reference of file_util will be derefed on the FILE thread |
291 // when the storage of this callback gets deleted regardless of whether | 307 // when the storage of this callback gets deleted regardless of whether |
292 // this method is called or not. | 308 // this method is called or not. |
293 } | 309 } |
294 | 310 |
295 } // anonymous namespace | 311 } // anonymous namespace |
296 | 312 |
297 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = | 313 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = |
298 FILE_PATH_LITERAL("FileSystem"); | 314 FILE_PATH_LITERAL("FileSystem"); |
299 | 315 |
300 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = | 316 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = |
301 FILE_PATH_LITERAL("File System"); | 317 FILE_PATH_LITERAL("File System"); |
302 | 318 |
303 const FilePath::CharType | 319 const FilePath::CharType |
304 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = | 320 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = |
305 FILE_PATH_LITERAL("FS.old"); | 321 FILE_PATH_LITERAL("FS.old"); |
306 | 322 |
307 SandboxMountPointProvider::SandboxMountPointProvider( | 323 SandboxMountPointProvider::SandboxMountPointProvider( |
308 base::SequencedTaskRunner* file_task_runner, | 324 base::SequencedTaskRunner* file_task_runner, |
309 const FilePath& profile_path, | 325 const FilePath& profile_path, |
310 const FileSystemOptions& file_system_options) | 326 const FileSystemOptions& file_system_options) |
311 : FileSystemQuotaUtil(file_task_runner), | 327 : FileSystemQuotaUtil(file_task_runner), |
312 file_task_runner_(file_task_runner), | 328 file_task_runner_(file_task_runner), |
313 profile_path_(profile_path), | 329 profile_path_(profile_path), |
314 file_system_options_(file_system_options), | 330 file_system_options_(file_system_options), |
315 sandbox_file_util_( | 331 sandbox_file_util_( |
316 new ObfuscatedFileUtil( | 332 new ObfuscatedFileUtil( |
317 profile_path.Append(kNewFileSystemDirectory), | 333 profile_path.Append(kNewFileSystemDirectory), |
318 QuotaFileUtil::CreateDefault())) { | 334 QuotaFileUtil::CreateDefault())), |
335 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
319 } | 336 } |
320 | 337 |
321 SandboxMountPointProvider::~SandboxMountPointProvider() { | 338 SandboxMountPointProvider::~SandboxMountPointProvider() { |
322 if (!file_task_runner_->RunsTasksOnCurrentThread()) { | 339 if (!file_task_runner_->RunsTasksOnCurrentThread()) { |
323 ObfuscatedFileUtil* sandbox_file_util = sandbox_file_util_.release(); | 340 ObfuscatedFileUtil* sandbox_file_util = sandbox_file_util_.release(); |
324 if (!file_task_runner_->ReleaseSoon(FROM_HERE, sandbox_file_util)) | 341 if (!file_task_runner_->ReleaseSoon(FROM_HERE, sandbox_file_util)) |
325 sandbox_file_util->Release(); | 342 sandbox_file_util->Release(); |
326 } | 343 } |
327 } | 344 } |
328 | 345 |
329 void SandboxMountPointProvider::ValidateFileSystemRoot( | 346 void SandboxMountPointProvider::ValidateFileSystemRoot( |
330 const GURL& origin_url, fileapi::FileSystemType type, bool create, | 347 const GURL& origin_url, fileapi::FileSystemType type, bool create, |
331 const ValidateFileSystemCallback& callback) { | 348 const ValidateFileSystemCallback& callback) { |
332 if (file_system_options_.is_incognito()) { | 349 if (file_system_options_.is_incognito()) { |
333 // TODO(kinuko): return an isolated temporary directory. | 350 // TODO(kinuko): return an isolated temporary directory. |
334 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 351 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
335 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, | 352 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, |
336 kIncognito, | 353 kIncognito, |
337 kFileSystemErrorMax); | 354 kFileSystemErrorMax); |
338 return; | 355 return; |
339 } | 356 } |
340 | 357 |
341 if (!IsAllowedScheme(origin_url)) { | 358 if (!IsAllowedScheme(origin_url)) { |
342 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 359 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
343 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, | 360 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, |
344 kInvalidScheme, | 361 kInvalidSchemeError, |
345 kFileSystemErrorMax); | 362 kFileSystemErrorMax); |
346 return; | 363 return; |
347 } | 364 } |
348 | 365 |
349 base::PlatformFileError* error_ptr = new base::PlatformFileError; | 366 base::PlatformFileError* error_ptr = new base::PlatformFileError; |
350 file_task_runner_->PostTaskAndReply( | 367 file_task_runner_->PostTaskAndReply( |
351 FROM_HERE, | 368 FROM_HERE, |
352 base::Bind(&ValidateRootOnFileThread, | 369 base::Bind(&ValidateRootOnFileThread, |
353 sandbox_file_util_, | 370 sandbox_file_util_, |
354 origin_url, type, old_base_path(), create, | 371 origin_url, type, old_base_path(), create, |
355 base::Unretained(error_ptr)), | 372 base::Unretained(error_ptr)), |
356 base::Bind(base::Bind(&PassPointerErrorByValue, callback), | 373 base::Bind(&DidValidateFileSystemRoot, |
357 base::Owned(error_ptr))); | 374 weak_factory_.GetWeakPtr(), |
375 callback, base::Owned(error_ptr))); | |
358 }; | 376 }; |
359 | 377 |
360 FilePath | 378 FilePath |
361 SandboxMountPointProvider::GetFileSystemRootPathOnFileThread( | 379 SandboxMountPointProvider::GetFileSystemRootPathOnFileThread( |
362 const GURL& origin_url, FileSystemType type, const FilePath& unused, | 380 const GURL& origin_url, FileSystemType type, const FilePath& unused, |
363 bool create) { | 381 bool create) { |
364 if (file_system_options_.is_incognito()) | 382 if (file_system_options_.is_incognito()) |
365 // TODO(kinuko): return an isolated temporary directory. | 383 // TODO(kinuko): return an isolated temporary directory. |
366 return FilePath(); | 384 return FilePath(); |
367 | 385 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 for (size_t i = 0; | 684 for (size_t i = 0; |
667 i < file_system_options_.additional_allowed_schemes().size(); | 685 i < file_system_options_.additional_allowed_schemes().size(); |
668 ++i) { | 686 ++i) { |
669 if (url.SchemeIs( | 687 if (url.SchemeIs( |
670 file_system_options_.additional_allowed_schemes()[i].c_str())) | 688 file_system_options_.additional_allowed_schemes()[i].c_str())) |
671 return true; | 689 return true; |
672 } | 690 } |
673 return false; | 691 return false; |
674 } | 692 } |
675 | 693 |
694 void SandboxMountPointProvider::CollectOpenFileSystemMetrics( | |
695 base::PlatformFileError error_code) { | |
696 base::Time now = base::Time::Now(); | |
697 bool throttled = now < next_release_time_for_open_filesystem_stat_; | |
698 if (!throttled) { | |
699 next_release_time_for_open_filesystem_stat_ = | |
700 now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours); | |
701 } | |
702 | |
703 #define REPORT(report_value) \ | |
704 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemBreakLabel, \ | |
705 (report_value), \ | |
706 kFileSystemErrorMax); \ | |
707 if (!throttled) { \ | |
708 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemUniqueBreakLabel, \ | |
709 (report_value), \ | |
710 kFileSystemErrorMax); \ | |
711 } | |
712 | |
713 switch (error_code) { | |
714 case base::PLATFORM_FILE_OK: | |
715 REPORT(kOK); | |
716 break; | |
717 case base::PLATFORM_FILE_ERROR_INVALID_URL: | |
718 REPORT(kInvalidSchemeError); | |
719 break; | |
720 case base::PLATFORM_FILE_ERROR_NOT_FOUND: | |
721 REPORT(kNotFound); | |
722 break; | |
723 case base::PLATFORM_FILE_ERROR_FAILED: | |
724 default: | |
725 REPORT(kUnknownError); | |
726 break; | |
727 } | |
728 #undef REPORT | |
729 } | |
730 | |
676 } // namespace fileapi | 731 } // namespace fileapi |
OLD | NEW |