Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_callback_factory.h" | 10 #include "base/memory/scoped_callback_factory.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/metrics/histogram.h" | |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 19 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/fileapi/file_system_path_manager.h" | 21 #include "webkit/fileapi/file_system_path_manager.h" |
| 21 #include "webkit/fileapi/file_system_types.h" | 22 #include "webkit/fileapi/file_system_types.h" |
| 22 #include "webkit/fileapi/file_system_usage_cache.h" | 23 #include "webkit/fileapi/file_system_usage_cache.h" |
| 23 #include "webkit/fileapi/file_system_util.h" | 24 #include "webkit/fileapi/file_system_util.h" |
| 24 #include "webkit/fileapi/obfuscated_file_util.h" | 25 #include "webkit/fileapi/obfuscated_file_util.h" |
| 25 #include "webkit/fileapi/quota_file_util.h" | 26 #include "webkit/fileapi/quota_file_util.h" |
| 26 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
| 27 #include "webkit/quota/quota_manager.h" | 28 #include "webkit/quota/quota_manager.h" |
| 28 | 29 |
| 29 using quota::QuotaManagerProxy; | 30 using quota::QuotaManagerProxy; |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 static const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = | 34 static const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = |
| 34 FILE_PATH_LITERAL("chrome-"); | 35 FILE_PATH_LITERAL("chrome-"); |
| 35 static const int kOldFileSystemUniqueLength = 16; | 36 static const int kOldFileSystemUniqueLength = 16; |
| 36 static const unsigned kOldFileSystemUniqueDirectoryNameLength = | 37 static const unsigned kOldFileSystemUniqueDirectoryNameLength = |
| 37 kOldFileSystemUniqueLength + arraysize(kOldFileSystemUniqueNamePrefix) - 1; | 38 kOldFileSystemUniqueLength + arraysize(kOldFileSystemUniqueNamePrefix) - 1; |
| 38 | 39 |
| 40 const char kOpenFileSystem[] = "FileSystem.OpenFileSystem"; | |
| 41 enum FileSystemError { | |
| 42 kOK = 0, | |
| 43 kIncognito, | |
| 44 kInvalidScheme, | |
| 45 kCreateDirectoryError, | |
| 46 kFileSystemErrorMax, | |
| 47 }; | |
| 48 | |
| 39 // Restricted names. | 49 // Restricted names. |
| 40 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions | 50 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions |
| 41 static const char* const kRestrictedNames[] = { | 51 static const char* const kRestrictedNames[] = { |
| 42 ".", "..", | 52 ".", "..", |
| 43 }; | 53 }; |
| 44 | 54 |
| 45 // Restricted chars. | 55 // Restricted chars. |
| 46 static const FilePath::CharType kRestrictedChars[] = { | 56 static const FilePath::CharType kRestrictedChars[] = { |
| 47 '/', '\\', | 57 '/', '\\', |
| 48 }; | 58 }; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 private: | 346 private: |
| 337 void GetFileSystemRootPathOnFileThread(bool create) { | 347 void GetFileSystemRootPathOnFileThread(bool create) { |
| 338 MigrateIfNeeded(file_util_, old_base_path_); | 348 MigrateIfNeeded(file_util_, old_base_path_); |
| 339 DispatchCallbackOnCallerThread( | 349 DispatchCallbackOnCallerThread( |
| 340 file_util_->GetDirectoryForOriginAndType(origin_url_, type_, create)); | 350 file_util_->GetDirectoryForOriginAndType(origin_url_, type_, create)); |
| 341 // We must clear the reference on the file thread. | 351 // We must clear the reference on the file thread. |
| 342 file_util_ = NULL; | 352 file_util_ = NULL; |
| 343 } | 353 } |
| 344 | 354 |
| 345 void DispatchCallbackOnCallerThread(const FilePath& root_path) { | 355 void DispatchCallbackOnCallerThread(const FilePath& root_path) { |
| 356 if (root_path.empty()) { | |
| 357 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, | |
| 358 kCreateDirectoryError, | |
| 359 kFileSystemErrorMax); | |
|
kinuko
2011/12/15 04:34:05
Tzik-san, I know this patch has been already lande
| |
| 360 } | |
| 346 origin_message_loop_proxy_->PostTask( | 361 origin_message_loop_proxy_->PostTask( |
| 347 FROM_HERE, | 362 FROM_HERE, |
| 348 base::Bind(&GetFileSystemRootPathTask::DispatchCallback, this, | 363 base::Bind(&GetFileSystemRootPathTask::DispatchCallback, this, |
| 349 root_path)); | 364 root_path)); |
| 350 } | 365 } |
| 351 | 366 |
| 352 void DispatchCallback(const FilePath& root_path) { | 367 void DispatchCallback(const FilePath& root_path) { |
| 353 std::string origin_identifier = GetOriginIdentifierFromURL(origin_url_); | 368 std::string origin_identifier = GetOriginIdentifierFromURL(origin_url_); |
| 354 std::string type_string = | 369 std::string type_string = |
| 355 FileSystemPathManager::GetFileSystemTypeString(type_); | 370 FileSystemPathManager::GetFileSystemTypeString(type_); |
| 356 DCHECK(!type_string.empty()); | 371 DCHECK(!type_string.empty()); |
| 357 std::string name = origin_identifier + ":" + type_string; | 372 std::string name = origin_identifier + ":" + type_string; |
| 373 | |
| 374 if (!root_path.empty()) | |
| 375 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, kOK, kFileSystemErrorMax); | |
| 376 | |
| 358 callback_.Run(!root_path.empty(), root_path, name); | 377 callback_.Run(!root_path.empty(), root_path, name); |
| 359 callback_.Reset(); | 378 callback_.Reset(); |
| 360 } | 379 } |
| 361 | 380 |
| 362 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | 381 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
| 363 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 382 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
| 364 GURL origin_url_; | 383 GURL origin_url_; |
| 365 FileSystemType type_; | 384 FileSystemType type_; |
| 366 scoped_refptr<ObfuscatedFileUtil> file_util_; | 385 scoped_refptr<ObfuscatedFileUtil> file_util_; |
| 367 FilePath old_base_path_; | 386 FilePath old_base_path_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 } | 437 } |
| 419 | 438 |
| 420 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( | 439 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
| 421 const GURL& origin_url, fileapi::FileSystemType type, bool create, | 440 const GURL& origin_url, fileapi::FileSystemType type, bool create, |
| 422 const FileSystemPathManager::GetRootPathCallback& callback) { | 441 const FileSystemPathManager::GetRootPathCallback& callback) { |
| 423 FilePath origin_base_path; | 442 FilePath origin_base_path; |
| 424 | 443 |
| 425 if (path_manager_->is_incognito()) { | 444 if (path_manager_->is_incognito()) { |
| 426 // TODO(kinuko): return an isolated temporary directory. | 445 // TODO(kinuko): return an isolated temporary directory. |
| 427 callback.Run(false, FilePath(), std::string()); | 446 callback.Run(false, FilePath(), std::string()); |
| 447 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, | |
| 448 kIncognito, | |
| 449 kFileSystemErrorMax); | |
| 428 return; | 450 return; |
| 429 } | 451 } |
| 430 | 452 |
| 431 if (!path_manager_->IsAllowedScheme(origin_url)) { | 453 if (!path_manager_->IsAllowedScheme(origin_url)) { |
| 432 callback.Run(false, FilePath(), std::string()); | 454 callback.Run(false, FilePath(), std::string()); |
| 455 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, | |
| 456 kInvalidScheme, | |
| 457 kFileSystemErrorMax); | |
| 433 return; | 458 return; |
| 434 } | 459 } |
| 435 | 460 |
| 436 scoped_refptr<GetFileSystemRootPathTask> task( | 461 scoped_refptr<GetFileSystemRootPathTask> task( |
| 437 new GetFileSystemRootPathTask( | 462 new GetFileSystemRootPathTask( |
| 438 file_message_loop_, origin_url, type, sandbox_file_util_.get(), | 463 file_message_loop_, origin_url, type, sandbox_file_util_.get(), |
| 439 old_base_path(), callback)); | 464 old_base_path(), callback)); |
| 440 task->Start(create); | 465 task->Start(create); |
| 441 }; | 466 }; |
| 442 | 467 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 | 672 |
| 648 // Creates the root directory. | 673 // Creates the root directory. |
| 649 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); | 674 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); |
| 650 if (!file_util::CreateDirectory(root)) | 675 if (!file_util::CreateDirectory(root)) |
| 651 return FilePath(); | 676 return FilePath(); |
| 652 | 677 |
| 653 return root; | 678 return root; |
| 654 } | 679 } |
| 655 | 680 |
| 656 } // namespace fileapi | 681 } // namespace fileapi |
| OLD | NEW |