diff options
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/file_system_url.cc | 7 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url.h | 3 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url_unittest.cc | 52 | ||||
-rw-r--r-- | webkit/fileapi/syncable/local_file_sync_status.cc | 18 |
4 files changed, 64 insertions, 16 deletions
diff --git a/webkit/fileapi/file_system_url.cc b/webkit/fileapi/file_system_url.cc index 52dbce6..f3053a4 100644 --- a/webkit/fileapi/file_system_url.cc +++ b/webkit/fileapi/file_system_url.cc @@ -114,6 +114,13 @@ FileSystemURL FileSystemURL::WithPath(const FilePath& path) const { return url; } +bool FileSystemURL::IsParent(const FileSystemURL& child) const { + return origin() == child.origin() && + type() == child.type() && + filesystem_id() == child.filesystem_id() && + path().IsParent(child.path()); +} + bool FileSystemURL::operator==(const FileSystemURL& that) const { return origin_ == that.origin_ && type_ == that.type_ && diff --git a/webkit/fileapi/file_system_url.h b/webkit/fileapi/file_system_url.h index 12f465a..cabe79d 100644 --- a/webkit/fileapi/file_system_url.h +++ b/webkit/fileapi/file_system_url.h @@ -93,6 +93,9 @@ class FILEAPI_EXPORT FileSystemURL { // original filesystem: URL in the current implementation). FileSystemURL WithPath(const FilePath& path) const; + // Returns true if this URL is a strict parent of the |child|. + bool IsParent(const FileSystemURL& child) const; + bool operator==(const FileSystemURL& that) const; struct FILEAPI_EXPORT Comparator { diff --git a/webkit/fileapi/file_system_url_unittest.cc b/webkit/fileapi/file_system_url_unittest.cc index 3378919..46ae5b3 100644 --- a/webkit/fileapi/file_system_url_unittest.cc +++ b/webkit/fileapi/file_system_url_unittest.cc @@ -10,14 +10,18 @@ #include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/isolated_context.h" +#include "webkit/fileapi/syncable/syncable_file_system_util.h" #define FPL FILE_PATH_LITERAL namespace fileapi { + namespace { -FileSystemURL CreateFileSystemURL(const char* url) { - return FileSystemURL(GURL(url)); + +FileSystemURL CreateFileSystemURL(const std::string& url_string) { + return FileSystemURL(GURL(url_string)); } + } // namespace TEST(FileSystemURLTest, ParsePersistent) { @@ -157,4 +161,48 @@ TEST(FileSystemURLTest, WithPathForExternal) { } } +TEST(FileSystemURLTest, IsParent) { + ScopedExternalFileSystem scoped1("foo", kFileSystemTypeSyncable, FilePath()); + ScopedExternalFileSystem scoped2("bar", kFileSystemTypeSyncable, FilePath()); + + const std::string root1 = GetFileSystemRootURI( + GURL("http://example.com"), kFileSystemTypeTemporary).spec(); + const std::string root2 = GetSyncableFileSystemRootURI( + GURL("http://example.com"), "foo").spec(); + const std::string root3 = GetSyncableFileSystemRootURI( + GURL("http://example.com"), "bar").spec(); + const std::string root4 = GetFileSystemRootURI( + GURL("http://chromium.org"), kFileSystemTypeTemporary).spec(); + + const std::string parent("dir"); + const std::string child("dir/child"); + const std::string other("other"); + + // True cases. + EXPECT_TRUE(CreateFileSystemURL(root1 + parent).IsParent( + CreateFileSystemURL(root1 + child))); + EXPECT_TRUE(CreateFileSystemURL(root2 + parent).IsParent( + CreateFileSystemURL(root2 + child))); + + // False cases: the path is not a child. + EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( + CreateFileSystemURL(root1 + other))); + EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( + CreateFileSystemURL(root1 + parent))); + EXPECT_FALSE(CreateFileSystemURL(root1 + child).IsParent( + CreateFileSystemURL(root1 + parent))); + + // False case: different types. + EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( + CreateFileSystemURL(root2 + child))); + + // False case: different filesystem ID. + EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( + CreateFileSystemURL(root3 + child))); + + // False case: different origins. + EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( + CreateFileSystemURL(root4 + child))); +} + } // namespace fileapi diff --git a/webkit/fileapi/syncable/local_file_sync_status.cc b/webkit/fileapi/syncable/local_file_sync_status.cc index 5e153a4..0ef59f6 100644 --- a/webkit/fileapi/syncable/local_file_sync_status.cc +++ b/webkit/fileapi/syncable/local_file_sync_status.cc @@ -6,16 +6,6 @@ namespace fileapi { -namespace { - -bool IsParent(const FileSystemURL& a, const FileSystemURL& b) { - return a.origin() == b.origin() && - a.type() == b.type() && - a.path().IsParent(b.path()); -} - -} // namespace - LocalFileSyncStatus::LocalFileSyncStatus() {} LocalFileSyncStatus::~LocalFileSyncStatus() { @@ -71,10 +61,10 @@ bool LocalFileSyncStatus::IsChildOrParentWriting( lock_.AssertAcquired(); URLCountMap::const_iterator upper = writing_.upper_bound(url); URLCountMap::const_reverse_iterator rupper(upper); - if (upper != writing_.end() && IsParent(url, upper->first)) + if (upper != writing_.end() && url.IsParent(upper->first)) return true; if (rupper != writing_.rend() && - (rupper->first == url || IsParent(rupper->first, url))) + (rupper->first == url || rupper->first.IsParent(url))) return true; return false; } @@ -84,10 +74,10 @@ bool LocalFileSyncStatus::IsChildOrParentSyncing( lock_.AssertAcquired(); URLSet::const_iterator upper = syncing_.upper_bound(url); URLSet::const_reverse_iterator rupper(upper); - if (upper != syncing_.end() && IsParent(url, *upper)) + if (upper != syncing_.end() && url.IsParent(*upper)) return true; if (rupper != syncing_.rend() && - (*rupper == url || IsParent(*rupper, url))) + (*rupper == url || rupper->IsParent(url))) return true; return false; } |