diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-26 04:42:47 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-26 04:42:47 +0000 |
commit | d6d5d90f250ba12b79c9af2cbbdcf5431812cf38 (patch) | |
tree | f6208007bb576ed10e897d3e2155dfabd67481fa /webkit/fileapi | |
parent | 4c8f730b286880c832a30201efa7a7c4eecc6af5 (diff) | |
download | chromium_src-d6d5d90f250ba12b79c9af2cbbdcf5431812cf38.zip chromium_src-d6d5d90f250ba12b79c9af2cbbdcf5431812cf38.tar.gz chromium_src-d6d5d90f250ba12b79c9af2cbbdcf5431812cf38.tar.bz2 |
Cleanup: Add fileapi::AreSameFileSystem(url1, url2) utility function
BUG=none
TEST=FileSystemUtilTest.AreSameFileSystem
Review URL: https://codereview.chromium.org/12340049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184582 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/cross_operation_delegate.cc | 5 | ||||
-rw-r--r-- | webkit/fileapi/file_system_util.cc | 6 | ||||
-rw-r--r-- | webkit/fileapi/file_system_util.h | 8 | ||||
-rw-r--r-- | webkit/fileapi/file_system_util_unittest.cc | 26 | ||||
-rw-r--r-- | webkit/fileapi/local_file_system_operation.cc | 6 |
5 files changed, 42 insertions, 9 deletions
diff --git a/webkit/fileapi/cross_operation_delegate.cc b/webkit/fileapi/cross_operation_delegate.cc index 08e7865..d4d217b 100644 --- a/webkit/fileapi/cross_operation_delegate.cc +++ b/webkit/fileapi/cross_operation_delegate.cc @@ -8,6 +8,7 @@ #include "webkit/blob/shareable_file_reference.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_operation_context.h" +#include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/local_file_system_operation.h" namespace fileapi { @@ -24,9 +25,7 @@ CrossOperationDelegate::CrossOperationDelegate( operation_type_(operation_type), callback_(callback), src_root_operation_(NULL) { - same_file_system_ = - src_root_.origin() == dest_root_.origin() && - src_root_.type() == dest_root_.type(); + same_file_system_ = AreSameFileSystem(src_root_, dest_root_); } CrossOperationDelegate::~CrossOperationDelegate() { diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index 63b0b1b..5b3f4f5 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -15,7 +15,7 @@ #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" -#include "webkit/fileapi/file_system_types.h" +#include "webkit/fileapi/file_system_url.h" namespace fileapi { @@ -366,4 +366,8 @@ std::string GetIsolatedFileSystemRootURIString( return root; } +bool AreSameFileSystem(const FileSystemURL& url1, const FileSystemURL& url2) { + return url1.origin() == url2.origin() && url1.type() == url2.type(); +} + } // namespace fileapi diff --git a/webkit/fileapi/file_system_util.h b/webkit/fileapi/file_system_util.h index 0381383..6ccb701 100644 --- a/webkit/fileapi/file_system_util.h +++ b/webkit/fileapi/file_system_util.h @@ -19,6 +19,8 @@ class GURL; namespace fileapi { +class FileSystemURL; + extern const char kPersistentDir[]; extern const char kTemporaryDir[]; extern const char kExternalDir[]; @@ -154,6 +156,12 @@ WEBKIT_STORAGE_EXPORT std::string GetIsolatedFileSystemRootURIString( const std::string& filesystem_id, const std::string& optional_root_name); +// Returns true if |url1| and |url2| belong to the same filesystem +// (i.e. url1.origin() == url2.origin() && url1.type() == url2.type()) +WEBKIT_STORAGE_EXPORT bool AreSameFileSystem( + const FileSystemURL& url1, + const FileSystemURL& url2); + } // namespace fileapi #endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_ diff --git a/webkit/fileapi/file_system_util_unittest.cc b/webkit/fileapi/file_system_util_unittest.cc index d1ea9cc..7c946cc 100644 --- a/webkit/fileapi/file_system_util_unittest.cc +++ b/webkit/fileapi/file_system_util_unittest.cc @@ -7,7 +7,7 @@ #include "base/files/file_path.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/fileapi/file_system_types.h" +#include "webkit/fileapi/file_system_url.h" namespace fileapi { namespace { @@ -196,5 +196,29 @@ TEST_F(FileSystemUtilTest, RejectBadIsolatedFileSystemName) { EXPECT_FALSE(CrackIsolatedFileSystemName("foo:Isolated_", &fsid)); } +TEST_F(FileSystemUtilTest, AreSameFileSystem) { + FileSystemURL url_foo_temp_a = FileSystemURL::CreateForTest( + GURL("http://foo"), kFileSystemTypeTemporary, + base::FilePath::FromUTF8Unsafe("a")); + FileSystemURL url_foo_temp_b = FileSystemURL::CreateForTest( + GURL("http://foo"), kFileSystemTypeTemporary, + base::FilePath::FromUTF8Unsafe("b")); + FileSystemURL url_foo_perm_a = FileSystemURL::CreateForTest( + GURL("http://foo"), kFileSystemTypePersistent, + base::FilePath::FromUTF8Unsafe("a")); + FileSystemURL url_bar_temp_a = FileSystemURL::CreateForTest( + GURL("http://bar"), kFileSystemTypeTemporary, + base::FilePath::FromUTF8Unsafe("a")); + FileSystemURL url_bar_perm_a = FileSystemURL::CreateForTest( + GURL("http://bar"), kFileSystemTypePersistent, + base::FilePath::FromUTF8Unsafe("a")); + + EXPECT_TRUE(AreSameFileSystem(url_foo_temp_a, url_foo_temp_a)); + EXPECT_TRUE(AreSameFileSystem(url_foo_temp_a, url_foo_temp_b)); + EXPECT_FALSE(AreSameFileSystem(url_foo_temp_a, url_foo_perm_a)); + EXPECT_FALSE(AreSameFileSystem(url_foo_temp_a, url_bar_temp_a)); + EXPECT_FALSE(AreSameFileSystem(url_foo_temp_a, url_bar_perm_a)); +} + } // namespace (anonymous) } // namespace fileapi diff --git a/webkit/fileapi/local_file_system_operation.cc b/webkit/fileapi/local_file_system_operation.cc index 99a19b9..c5f4e1a 100644 --- a/webkit/fileapi/local_file_system_operation.cc +++ b/webkit/fileapi/local_file_system_operation.cc @@ -475,8 +475,7 @@ void LocalFileSystemOperation::CopyFileLocal( const FileSystemURL& dest_url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationCopy)); - DCHECK_EQ(src_url.origin(), dest_url.origin()); - DCHECK_EQ(src_url.type(), dest_url.type()); + DCHECK(AreSameFileSystem(src_url, dest_url)); base::PlatformFileError result = SetUp(src_url, SETUP_FOR_READ); if (result == base::PLATFORM_FILE_OK) @@ -506,8 +505,7 @@ void LocalFileSystemOperation::MoveFileLocal( const FileSystemURL& dest_url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationMove)); - DCHECK_EQ(src_url.origin(), dest_url.origin()); - DCHECK_EQ(src_url.type(), dest_url.type()); + DCHECK(AreSameFileSystem(src_url, dest_url)); base::PlatformFileError result = SetUp(src_url, SETUP_FOR_WRITE); if (result == base::PLATFORM_FILE_OK) |