Commit ef8a99cb authored by Chris Mumford's avatar Chris Mumford Committed by Commit Bot

FileSystem: Add move constructor/operator for FileSystemURL.

This is not strictly required for issue 797292 (filesystem:
support with network service), but it should make that implementation
slightly more efficient and better to land in its own CL.

Bug: 797292
Change-Id: Ia6a20ded0f0c414d632530805bc3ae3eb3053328
Reviewed-on: https://chromium-review.googlesource.com/960922Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Chris Mumford <cmumford@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543380}
parent ee1319b3
......@@ -26,6 +26,12 @@ FileSystemURL::FileSystemURL()
FileSystemURL::FileSystemURL(const FileSystemURL& other) = default;
FileSystemURL::FileSystemURL(FileSystemURL&& other) noexcept = default;
FileSystemURL& FileSystemURL::operator=(FileSystemURL&& rhs) = default;
FileSystemURL& FileSystemURL::operator=(const FileSystemURL& rhs) = default;
// static
FileSystemURL FileSystemURL::CreateForTest(const GURL& url) {
return FileSystemURL(url);
......
......@@ -79,8 +79,17 @@ class STORAGE_EXPORT FileSystemURL {
public:
FileSystemURL();
FileSystemURL(const FileSystemURL& other);
// Constructs FileSystemURL with the contents of |other|, which is left in
// valid but unspecified state.
FileSystemURL(FileSystemURL&& other) noexcept;
~FileSystemURL();
// Replaces the contents with those of |rhs|, which is left in valid but
// unspecified state.
FileSystemURL& operator=(FileSystemURL&& rhs);
FileSystemURL& operator=(const FileSystemURL& rhs);
// Methods for creating FileSystemURL without attempting to crack them.
// Should be used only in tests.
static FileSystemURL CreateForTest(const GURL& url);
......
......@@ -6,6 +6,8 @@
#include <stddef.h>
#include <utility>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "storage/common/fileapi/file_system_types.h"
......@@ -221,4 +223,29 @@ TEST(FileSystemURLTest, IsInSameFileSystem) {
EXPECT_FALSE(url_foo_temp_a.IsInSameFileSystem(url_bar_perm_a));
}
TEST(FileSystemURLTest, ValidAfterMoves) {
// Move constructor.
{
FileSystemURL original = FileSystemURL::CreateForTest(
GURL("http://foo"), kFileSystemTypeTemporary,
base::FilePath::FromUTF8Unsafe("a"));
EXPECT_TRUE(original.is_valid());
FileSystemURL new_url(std::move(original));
EXPECT_TRUE(new_url.is_valid());
EXPECT_TRUE(original.is_valid());
}
// Move operator.
{
FileSystemURL original = FileSystemURL::CreateForTest(
GURL("http://foo"), kFileSystemTypeTemporary,
base::FilePath::FromUTF8Unsafe("a"));
EXPECT_TRUE(original.is_valid());
FileSystemURL new_url;
new_url = std::move(std::move(original));
EXPECT_TRUE(new_url.is_valid());
EXPECT_TRUE(original.is_valid());
}
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment