summaryrefslogtreecommitdiffstats
path: root/extensions/common
diff options
context:
space:
mode:
authorlimasdf <limasdf@gmail.com>2015-12-19 04:04:49 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-19 12:06:04 +0000
commit21d67e679792a286c581f20ea8e4848b9c34061e (patch)
treedc6783b7a0229c79e3a8514293fc874eb0fa4789 /extensions/common
parent49f72db8dbff60fb22dfddf09dddeffe54f674db (diff)
downloadchromium_src-21d67e679792a286c581f20ea8e4848b9c34061e.zip
chromium_src-21d67e679792a286c581f20ea8e4848b9c34061e.tar.gz
chromium_src-21d67e679792a286c581f20ea8e4848b9c34061e.tar.bz2
Use rvalue reference instead of extensions::DictionaryBuilder::pass()
C++ 11 enables rvalue reference with std::move() so that removing DictionaryBuilder::Pass(). BUG=563649 TBR=thakis@chromium.org Review URL: https://codereview.chromium.org/1532193003 Cr-Commit-Position: refs/heads/master@{#366280}
Diffstat (limited to 'extensions/common')
-rw-r--r--extensions/common/extension_builder.h2
-rw-r--r--extensions/common/features/base_feature_provider_unittest.cc19
-rw-r--r--extensions/common/manifest_handler_unittest.cc44
-rw-r--r--extensions/common/test_util.cc24
-rw-r--r--extensions/common/value_builder.cc12
-rw-r--r--extensions/common/value_builder.h11
6 files changed, 61 insertions, 51 deletions
diff --git a/extensions/common/extension_builder.h b/extensions/common/extension_builder.h
index 96c81d2..3ceda07 100644
--- a/extensions/common/extension_builder.h
+++ b/extensions/common/extension_builder.h
@@ -39,7 +39,7 @@ class ExtensionBuilder {
ExtensionBuilder& SetLocation(Manifest::Location location);
ExtensionBuilder& SetManifest(scoped_ptr<base::DictionaryValue> manifest);
- ExtensionBuilder& SetManifest(DictionaryBuilder& manifest_builder) {
+ ExtensionBuilder& SetManifest(DictionaryBuilder manifest_builder) {
return SetManifest(manifest_builder.Build());
}
diff --git a/extensions/common/features/base_feature_provider_unittest.cc b/extensions/common/features/base_feature_provider_unittest.cc
index 30850a3..43e0ce2 100644
--- a/extensions/common/features/base_feature_provider_unittest.cc
+++ b/extensions/common/features/base_feature_provider_unittest.cc
@@ -46,10 +46,10 @@ TEST(BaseFeatureProviderTest, ManifestFeatureAvailability) {
scoped_refptr<const Extension> extension =
ExtensionBuilder()
- .SetManifest(DictionaryBuilder()
- .Set("name", "test extension")
- .Set("version", "1")
- .Set("description", "hello there"))
+ .SetManifest(std::move(DictionaryBuilder()
+ .Set("name", "test extension")
+ .Set("version", "1")
+ .Set("description", "hello there")))
.Build();
ASSERT_TRUE(extension.get());
@@ -100,16 +100,17 @@ TEST(BaseFeatureProviderTest, PermissionFeatureAvailability) {
scoped_refptr<const Extension> app =
ExtensionBuilder()
- .SetManifest(
+ .SetManifest(std::move(
DictionaryBuilder()
.Set("name", "test app")
.Set("version", "1")
- .Set("app", DictionaryBuilder().Set(
+ .Set("app", std::move(DictionaryBuilder().Set(
"background",
- DictionaryBuilder().Set(
+ std::move(DictionaryBuilder().Set(
"scripts", std::move(ListBuilder().Append(
- "background.js")))))
- .Set("permissions", std::move(ListBuilder().Append("power"))))
+ "background.js")))))))
+ .Set("permissions",
+ std::move(ListBuilder().Append("power")))))
.Build();
ASSERT_TRUE(app.get());
ASSERT_TRUE(app->is_platform_app());
diff --git a/extensions/common/manifest_handler_unittest.cc b/extensions/common/manifest_handler_unittest.cc
index 4c31c99..a014dae 100644
--- a/extensions/common/manifest_handler_unittest.cc
+++ b/extensions/common/manifest_handler_unittest.cc
@@ -182,19 +182,20 @@ TEST_F(ManifestHandlerTest, DependentHandlers) {
Register();
ManifestHandler::FinalizeRegistration();
- scoped_refptr<Extension> extension = ExtensionBuilder()
- .SetManifest(DictionaryBuilder()
- .Set("name", "no name")
- .Set("version", "0")
- .Set("manifest_version", 2)
- .Set("a", 1)
- .Set("b", 2)
- .Set("c", DictionaryBuilder()
- .Set("d", 3)
- .Set("e", 4)
- .Set("f", 5))
- .Set("g", 6))
- .Build();
+ scoped_refptr<Extension> extension =
+ ExtensionBuilder()
+ .SetManifest(std::move(
+ DictionaryBuilder()
+ .Set("name", "no name")
+ .Set("version", "0")
+ .Set("manifest_version", 2)
+ .Set("a", 1)
+ .Set("b", 2)
+ .Set("c", std::move(
+ DictionaryBuilder().Set("d", 3).Set("e", 4).Set(
+ "f", 5)))
+ .Set("g", 6)))
+ .Build();
// A, B, C.EZ, C.D, K
EXPECT_EQ(5u, watcher.parsed_names().size());
@@ -243,14 +244,15 @@ TEST_F(ManifestHandlerTest, FailingHandlers) {
TEST_F(ManifestHandlerTest, Validate) {
ScopedTestingManifestHandlerRegistry registry;
- scoped_refptr<Extension> extension = ExtensionBuilder()
- .SetManifest(DictionaryBuilder()
- .Set("name", "no name")
- .Set("version", "0")
- .Set("manifest_version", 2)
- .Set("a", 1)
- .Set("b", 2))
- .Build();
+ scoped_refptr<Extension> extension =
+ ExtensionBuilder()
+ .SetManifest(std::move(DictionaryBuilder()
+ .Set("name", "no name")
+ .Set("version", "0")
+ .Set("manifest_version", 2)
+ .Set("a", 1)
+ .Set("b", 2)))
+ .Build();
EXPECT_TRUE(extension.get());
std::string error;
diff --git a/extensions/common/test_util.cc b/extensions/common/test_util.cc
index eb857fd..e3775e5 100644
--- a/extensions/common/test_util.cc
+++ b/extensions/common/test_util.cc
@@ -14,39 +14,39 @@ namespace extensions {
namespace test_util {
ExtensionBuilder BuildExtension(ExtensionBuilder builder) {
- builder.SetManifest(DictionaryBuilder()
- .Set("name", "Test extension")
- .Set("version", "1.0")
- .Set("manifest_version", 2));
+ builder.SetManifest(std::move(DictionaryBuilder()
+ .Set("name", "Test extension")
+ .Set("version", "1.0")
+ .Set("manifest_version", 2)));
return builder;
}
ExtensionBuilder BuildApp(ExtensionBuilder builder) {
- builder.SetManifest(
+ builder.SetManifest(std::move(
DictionaryBuilder()
.Set("name", "Test extension")
.Set("version", "1.0")
.Set("manifest_version", 2)
.Set("app",
- extensions::DictionaryBuilder().Set(
+ std::move(extensions::DictionaryBuilder().Set(
"background",
- extensions::DictionaryBuilder().Set(
+ std::move(extensions::DictionaryBuilder().Set(
"scripts", std::move(extensions::ListBuilder().Append(
- "background.js"))))));
+ "background.js")))))))));
return builder;
}
scoped_refptr<Extension> CreateEmptyExtension() {
return ExtensionBuilder()
- .SetManifest(
- DictionaryBuilder().Set("name", "Test").Set("version", "1.0"))
+ .SetManifest(std::move(
+ DictionaryBuilder().Set("name", "Test").Set("version", "1.0")))
.Build();
}
scoped_refptr<Extension> CreateEmptyExtension(const std::string& id) {
return ExtensionBuilder()
- .SetManifest(
- DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
+ .SetManifest(std::move(
+ DictionaryBuilder().Set("name", "test").Set("version", "0.1")))
.SetID(id)
.Build();
}
diff --git a/extensions/common/value_builder.cc b/extensions/common/value_builder.cc
index 89c3ec3..987bbb4 100644
--- a/extensions/common/value_builder.cc
+++ b/extensions/common/value_builder.cc
@@ -20,6 +20,14 @@ DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue& init)
DictionaryBuilder::~DictionaryBuilder() {}
+DictionaryBuilder::DictionaryBuilder(DictionaryBuilder&& other)
+ : dict_(other.Build()) {}
+
+DictionaryBuilder& DictionaryBuilder::operator=(DictionaryBuilder&& other) {
+ dict_ = other.Build();
+ return *this;
+}
+
std::string DictionaryBuilder::ToJSON() const {
std::string json;
base::JSONWriter::WriteWithOptions(
@@ -52,7 +60,7 @@ DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
- DictionaryBuilder& in_value) {
+ DictionaryBuilder in_value) {
dict_->SetWithoutPathExpansion(path, in_value.Build());
return *this;
}
@@ -110,7 +118,7 @@ ListBuilder& ListBuilder::Append(const base::string16& in_value) {
return *this;
}
-ListBuilder& ListBuilder::Append(DictionaryBuilder& in_value) {
+ListBuilder& ListBuilder::Append(DictionaryBuilder in_value) {
list_->Append(in_value.Build());
return *this;
}
diff --git a/extensions/common/value_builder.h b/extensions/common/value_builder.h
index 17020a8..d746904 100644
--- a/extensions/common/value_builder.h
+++ b/extensions/common/value_builder.h
@@ -52,10 +52,9 @@ class DictionaryBuilder {
explicit DictionaryBuilder(const base::DictionaryValue& init);
~DictionaryBuilder();
- // Workaround to allow you to pass rvalue ExtensionBuilders by reference to
- // other functions.
- // TODO(limasdf): Remove. Write move constructor instead.
- DictionaryBuilder& Pass() { return *this; }
+ // Move constructor and operator=.
+ DictionaryBuilder(DictionaryBuilder&& other);
+ DictionaryBuilder& operator=(DictionaryBuilder&& other);
// Can only be called once, after which it's invalid to use the builder.
scoped_ptr<base::DictionaryValue> Build() { return std::move(dict_); }
@@ -69,7 +68,7 @@ class DictionaryBuilder {
DictionaryBuilder& Set(const std::string& path, const std::string& in_value);
DictionaryBuilder& Set(const std::string& path,
const base::string16& in_value);
- DictionaryBuilder& Set(const std::string& path, DictionaryBuilder& in_value);
+ DictionaryBuilder& Set(const std::string& path, DictionaryBuilder in_value);
DictionaryBuilder& Set(const std::string& path, ListBuilder in_value);
DictionaryBuilder& Set(const std::string& path,
scoped_ptr<base::Value> in_value);
@@ -99,7 +98,7 @@ class ListBuilder {
ListBuilder& Append(double in_value);
ListBuilder& Append(const std::string& in_value);
ListBuilder& Append(const base::string16& in_value);
- ListBuilder& Append(DictionaryBuilder& in_value);
+ ListBuilder& Append(DictionaryBuilder in_value);
ListBuilder& Append(ListBuilder in_value);
// Named differently because overload resolution is too eager to