diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-16 07:24:48 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-16 07:24:48 +0000 |
commit | b4bbe9ad1ec0320b73e0914a6fc24ac514b30844 (patch) | |
tree | 44fe4361486ef35c5e538228a4762a2cf764a602 /webkit/fileapi/file_system_path_manager.cc | |
parent | cf1d3ee8cef29833d62a149b721dd31ff7cd17f2 (diff) | |
download | chromium_src-b4bbe9ad1ec0320b73e0914a6fc24ac514b30844.zip chromium_src-b4bbe9ad1ec0320b73e0914a6fc24ac514b30844.tar.gz chromium_src-b4bbe9ad1ec0320b73e0914a6fc24ac514b30844.tar.bz2 |
Make more methods of FileSystemPathManager static and portable.
Changes:
- Renamed StorageIdentifier to OriginIdentifier to better reflect its meaning.
- Changed a few methods to take string origin identifier but not origin URL as its parameter, since in some cases it seems to be more convenient just to use the identifier string (which can be easily extracted from the path) than to call WebKit method to convert back the identifier to GURL.
BUG=none
TEST=FileSystemPathManagerTest.*
Review URL: http://codereview.chromium.org/6483017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_path_manager.cc')
-rw-r--r-- | webkit/fileapi/file_system_path_manager.cc | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/webkit/fileapi/file_system_path_manager.cc b/webkit/fileapi/file_system_path_manager.cc index 3e0cd5e..8aee5d5 100644 --- a/webkit/fileapi/file_system_path_manager.cc +++ b/webkit/fileapi/file_system_path_manager.cc @@ -19,7 +19,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" #include "webkit/glue/webkit_glue.h" -// We use some of WebKit types for conversions between storage identifiers +// We use some of WebKit types for conversions between origin identifiers // and origin URLs. using WebKit::WebFileSystem; using WebKit::WebSecurityOrigin; @@ -77,14 +77,6 @@ FilePath::StringType CreateUniqueDirectoryName(const GURL& origin_url) { static const char kExtensionScheme[] = "chrome-extension"; -inline std::string GetFileSystemTypeString(fileapi::FileSystemType type) { - if (type == fileapi::kFileSystemTypeTemporary) - return fileapi::FileSystemPathManager::kTemporaryName; - else if (type == fileapi::kFileSystemTypePersistent) - return fileapi::FileSystemPathManager::kPersistentName; - return std::string(); -} - } // anonymous namespace class FileSystemPathManager::GetFileSystemRootPathTask @@ -206,16 +198,20 @@ void FileSystemPathManager::GetFileSystemRootPath( return; } + std::string origin_identifier = GetOriginIdentifierFromURL(origin_url); FilePath origin_base_path = GetFileSystemBaseDirectoryForOriginAndType( - base_path(), origin_url, type); + base_path(), origin_identifier, type); if (origin_base_path.empty()) { callback->Run(false, FilePath(), std::string()); return; } + std::string type_string = GetFileSystemTypeString(type); + DCHECK(!type_string.empty()); + scoped_refptr<GetFileSystemRootPathTask> task( new GetFileSystemRootPathTask(file_message_loop_, - GetFileSystemName(origin_url, type), + origin_identifier + ":" + type_string, callback.release())); task->Start(origin_url, origin_base_path, create); } @@ -284,8 +280,16 @@ bool FileSystemPathManager::CrackFileSystemPath( return true; } -bool FileSystemPathManager::IsRestrictedFileName( - const FilePath& filename) const { +bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { + // Basically we only accept http or https. We allow file:// URLs + // only if --allow-file-access-from-files flag is given. + return url.SchemeIs("http") || url.SchemeIs("https") || + url.SchemeIs(kExtensionScheme) || + (url.SchemeIsFile() && allow_file_access_from_files_); +} + +// static +bool FileSystemPathManager::IsRestrictedFileName(const FilePath& filename) { if (filename.value().size() == 0) return false; @@ -314,23 +318,18 @@ bool FileSystemPathManager::IsRestrictedFileName( return false; } -bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { - // Basically we only accept http or https. We allow file:// URLs - // only if --allow-file-access-from-files flag is given. - return url.SchemeIs("http") || url.SchemeIs("https") || - url.SchemeIs(kExtensionScheme) || - (url.SchemeIsFile() && allow_file_access_from_files_); -} - // static -std::string FileSystemPathManager::GetFileSystemName( - const GURL& origin_url, fileapi::FileSystemType type) { - return GetStorageIdentifierFromURL(origin_url) - .append(":").append(GetFileSystemTypeString(type)); +std::string FileSystemPathManager::GetFileSystemTypeString( + fileapi::FileSystemType type) { + if (type == fileapi::kFileSystemTypeTemporary) + return fileapi::FileSystemPathManager::kTemporaryName; + else if (type == fileapi::kFileSystemTypePersistent) + return fileapi::FileSystemPathManager::kPersistentName; + return std::string(); } // static -std::string FileSystemPathManager::GetStorageIdentifierFromURL( +std::string FileSystemPathManager::GetOriginIdentifierFromURL( const GURL& url) { WebKit::WebSecurityOrigin web_security_origin = WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); @@ -339,16 +338,16 @@ std::string FileSystemPathManager::GetStorageIdentifierFromURL( // static FilePath FileSystemPathManager::GetFileSystemBaseDirectoryForOriginAndType( - const FilePath& base_path, const GURL& origin_url, + const FilePath& base_path, const std::string& origin_identifier, fileapi::FileSystemType type) { - if (!origin_url.is_valid()) + if (origin_identifier.empty()) return FilePath(); std::string type_string = GetFileSystemTypeString(type); if (type_string.empty()) { LOG(WARNING) << "Unknown filesystem type is requested:" << type; return FilePath(); } - return base_path.AppendASCII(GetStorageIdentifierFromURL(origin_url)) + return base_path.AppendASCII(origin_identifier) .AppendASCII(type_string); } |