diff options
author | jamescook <jamescook@chromium.org> | 2016-03-25 14:28:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-25 21:29:57 +0000 |
commit | da88c32858fdbc6040b07d51019d9f564e37416e (patch) | |
tree | 8f9aa64cb05eea75406425170c4b02ca171d9eca /components | |
parent | 0e07a14f1d8515fb5802c03e7c30dfe0bae4a87d (diff) | |
download | chromium_src-da88c32858fdbc6040b07d51019d9f564e37416e.zip chromium_src-da88c32858fdbc6040b07d51019d9f564e37416e.tar.gz chromium_src-da88c32858fdbc6040b07d51019d9f564e37416e.tar.bz2 |
mus: Remove unnecessary const from property TypeConverter templates
This allows them to be used with the idiomatic mojo::ConvertTo<Foo>() template.
(In particular, ConvertTo<Foo>(my_vector) matches my_vector to "const U&" to
determine which TypeConverter to call. If my_vector is either a "std::vector"
or a "const std::vector" it ends up looking for TypeConverter<Foo, std::vector>.
Since the second TypeConverter template parameter isn't const, the compiler
can't find our existing TypeConverter<Foo, const std::vector> functions. These
functions don't need their template parameter to be const std::vector, as they
use "const std::vector&" for their inputs regardless.)
BUG=none
TEST=compiles
Review URL: https://codereview.chromium.org/1832133002
Cr-Commit-Position: refs/heads/master@{#383366}
Diffstat (limited to 'components')
6 files changed, 44 insertions, 57 deletions
diff --git a/components/mus/public/cpp/lib/property_type_converters.cc b/components/mus/public/cpp/lib/property_type_converters.cc index 01c74a2..9503b9b 100644 --- a/components/mus/public/cpp/lib/property_type_converters.cc +++ b/components/mus/public/cpp/lib/property_type_converters.cc @@ -23,8 +23,7 @@ const int kMaxBitmapSize = 4096; namespace mojo { // static -const std::vector<uint8_t> -TypeConverter<const std::vector<uint8_t>, gfx::Rect>::Convert( +std::vector<uint8_t> TypeConverter<std::vector<uint8_t>, gfx::Rect>::Convert( const gfx::Rect& input) { std::vector<uint8_t> vec(16); vec[0] = (input.x() >> 24) & 0xFF; @@ -47,7 +46,7 @@ TypeConverter<const std::vector<uint8_t>, gfx::Rect>::Convert( } // static -gfx::Rect TypeConverter<gfx::Rect, const std::vector<uint8_t>>::Convert( +gfx::Rect TypeConverter<gfx::Rect, std::vector<uint8_t>>::Convert( const std::vector<uint8_t>& input) { return gfx::Rect( input[0] << 24 | input[1] << 16 | input[2] << 8 | input[3], @@ -57,8 +56,7 @@ gfx::Rect TypeConverter<gfx::Rect, const std::vector<uint8_t>>::Convert( } // static -const std::vector<uint8_t> -TypeConverter<const std::vector<uint8_t>, gfx::Size>::Convert( +std::vector<uint8_t> TypeConverter<std::vector<uint8_t>, gfx::Size>::Convert( const gfx::Size& input) { std::vector<uint8_t> vec(8); vec[0] = (input.width() >> 24) & 0xFF; @@ -73,16 +71,15 @@ TypeConverter<const std::vector<uint8_t>, gfx::Size>::Convert( } // static -gfx::Size TypeConverter<gfx::Size, const std::vector<uint8_t>>::Convert( +gfx::Size TypeConverter<gfx::Size, std::vector<uint8_t>>::Convert( const std::vector<uint8_t>& input) { return gfx::Size(input[0] << 24 | input[1] << 16 | input[2] << 8 | input[3], input[4] << 24 | input[5] << 16 | input[6] << 8 | input[7]); } // static -const std::vector<uint8_t> - TypeConverter<const std::vector<uint8_t>, int32_t>::Convert( - const int32_t& input) { +std::vector<uint8_t> TypeConverter<std::vector<uint8_t>, int32_t>::Convert( + const int32_t& input) { std::vector<uint8_t> vec(4); vec[0] = (input >> 24) & 0xFF; vec[1] = (input >> 16) & 0xFF; @@ -92,45 +89,38 @@ const std::vector<uint8_t> } // static -int32_t TypeConverter<int32_t, const std::vector<uint8_t>>::Convert( +int32_t TypeConverter<int32_t, std::vector<uint8_t>>::Convert( const std::vector<uint8_t>& input) { return input[0] << 24 | input[1] << 16 | input[2] << 8 | input[3]; } // static -const std::vector<uint8_t> -TypeConverter<const std::vector<uint8_t>, base::string16>::Convert( +std::vector<uint8_t> +TypeConverter<std::vector<uint8_t>, base::string16>::Convert( const base::string16& input) { - return TypeConverter<const std::vector<uint8_t>, std::string>::Convert( - base::UTF16ToUTF8(input)); + return ConvertTo<std::vector<uint8_t>>(base::UTF16ToUTF8(input)); } // static -base::string16 -TypeConverter<base::string16, const std::vector<uint8_t>>::Convert( +base::string16 TypeConverter<base::string16, std::vector<uint8_t>>::Convert( const std::vector<uint8_t>& input) { - return base::UTF8ToUTF16( - TypeConverter<std::string, const std::vector<uint8_t>>::Convert( - input)); + return base::UTF8ToUTF16(ConvertTo<std::string>(input)); } // static -const std::vector<uint8_t> -TypeConverter<const std::vector<uint8_t>, std::string>::Convert( +std::vector<uint8_t> TypeConverter<std::vector<uint8_t>, std::string>::Convert( const std::string& input) { return std::vector<uint8_t>(input.begin(), input.end()); } // static -std::string -TypeConverter<std::string, const std::vector<uint8_t>>::Convert( +std::string TypeConverter<std::string, std::vector<uint8_t>>::Convert( const std::vector<uint8_t>& input) { return std::string(input.begin(), input.end()); } // static -const std::vector<uint8_t> -TypeConverter<const std::vector<uint8_t>, SkBitmap>::Convert( +std::vector<uint8_t> TypeConverter<std::vector<uint8_t>, SkBitmap>::Convert( const SkBitmap& input) { // Empty images are valid to serialize and are represented by an empty vector. if (input.isNull()) @@ -165,7 +155,7 @@ TypeConverter<const std::vector<uint8_t>, SkBitmap>::Convert( } // static -SkBitmap TypeConverter<SkBitmap, const std::vector<uint8_t>>::Convert( +SkBitmap TypeConverter<SkBitmap, std::vector<uint8_t>>::Convert( const std::vector<uint8_t>& input) { // Empty images are represented by empty vectors. if (input.empty()) diff --git a/components/mus/public/cpp/property_type_converters.h b/components/mus/public/cpp/property_type_converters.h index cec17d6..20c0768 100644 --- a/components/mus/public/cpp/property_type_converters.h +++ b/components/mus/public/cpp/property_type_converters.h @@ -27,58 +27,58 @@ namespace mojo { // replaced with the skia.Bitmap mojom struct serialization. template <> -struct TypeConverter<const std::vector<uint8_t>, gfx::Rect> { - static const std::vector<uint8_t> Convert(const gfx::Rect& input); +struct TypeConverter<std::vector<uint8_t>, gfx::Rect> { + static std::vector<uint8_t> Convert(const gfx::Rect& input); }; template <> -struct TypeConverter<gfx::Rect, const std::vector<uint8_t>> { +struct TypeConverter<gfx::Rect, std::vector<uint8_t>> { static gfx::Rect Convert(const std::vector<uint8_t>& input); }; template <> -struct TypeConverter<const std::vector<uint8_t>, gfx::Size> { - static const std::vector<uint8_t> Convert(const gfx::Size& input); +struct TypeConverter<std::vector<uint8_t>, gfx::Size> { + static std::vector<uint8_t> Convert(const gfx::Size& input); }; template <> -struct TypeConverter<gfx::Size, const std::vector<uint8_t>> { +struct TypeConverter<gfx::Size, std::vector<uint8_t>> { static gfx::Size Convert(const std::vector<uint8_t>& input); }; template <> -struct TypeConverter<const std::vector<uint8_t>, int32_t> { - static const std::vector<uint8_t> Convert(const int32_t& input); +struct TypeConverter<std::vector<uint8_t>, int32_t> { + static std::vector<uint8_t> Convert(const int32_t& input); }; template <> -struct TypeConverter<int32_t, const std::vector<uint8_t>> { +struct TypeConverter<int32_t, std::vector<uint8_t>> { static int32_t Convert(const std::vector<uint8_t>& input); }; template <> -struct TypeConverter<const std::vector<uint8_t>, base::string16> { - static const std::vector<uint8_t> Convert(const base::string16& input); +struct TypeConverter<std::vector<uint8_t>, base::string16> { + static std::vector<uint8_t> Convert(const base::string16& input); }; template <> -struct TypeConverter<base::string16, const std::vector<uint8_t>> { +struct TypeConverter<base::string16, std::vector<uint8_t>> { static base::string16 Convert(const std::vector<uint8_t>& input); }; template <> -struct TypeConverter<const std::vector<uint8_t>, std::string> { - static const std::vector<uint8_t> Convert(const std::string& input); +struct TypeConverter<std::vector<uint8_t>, std::string> { + static std::vector<uint8_t> Convert(const std::string& input); }; template <> -struct TypeConverter<std::string, const std::vector<uint8_t>> { +struct TypeConverter<std::string, std::vector<uint8_t>> { static std::string Convert(const std::vector<uint8_t>& input); }; // NOTE: These methods only serialize and deserialize the common case of RGBA // 8888 bitmaps with premultiplied alpha. template <> -struct TypeConverter<const std::vector<uint8_t>, SkBitmap> { - static const std::vector<uint8_t> Convert(const SkBitmap& input); +struct TypeConverter<std::vector<uint8_t>, SkBitmap> { + static std::vector<uint8_t> Convert(const SkBitmap& input); }; template <> -struct TypeConverter<SkBitmap, const std::vector<uint8_t>> { +struct TypeConverter<SkBitmap, std::vector<uint8_t>> { static SkBitmap Convert(const std::vector<uint8_t>& input); }; diff --git a/components/mus/public/cpp/tests/property_type_converters_unittest.cc b/components/mus/public/cpp/tests/property_type_converters_unittest.cc index 7726172..f1a4b89 100644 --- a/components/mus/public/cpp/tests/property_type_converters_unittest.cc +++ b/components/mus/public/cpp/tests/property_type_converters_unittest.cc @@ -31,7 +31,7 @@ SkBitmap MakeBitmap() { TEST(PropertyTypeConvertersTest, SkBitmapSerialize) { SkBitmap bitmap = MakeBitmap(); std::vector<uint8_t> bytes = - TypeConverter<const std::vector<uint8_t>, SkBitmap>::Convert(bitmap); + TypeConverter<std::vector<uint8_t>, SkBitmap>::Convert(bitmap); // Size should be 4 bytes of header plus size of RGBA pixels. ASSERT_EQ(4 + bitmap.getSize(), bytes.size()); @@ -51,7 +51,7 @@ TEST(PropertyTypeConvertersTest, SkBitmapDeserialize) { // Make a 1x2 pixel bitmap. std::vector<uint8_t> bytes = {0, 1, 0, 2, 11, 22, 33, 44, 55, 66, 77, 88}; SkBitmap bitmap = - TypeConverter<SkBitmap, const std::vector<uint8_t>>::Convert(bytes); + TypeConverter<SkBitmap, std::vector<uint8_t>>::Convert(bytes); EXPECT_EQ(1, bitmap.width()); EXPECT_EQ(2, bitmap.height()); // The image pixels match the vector bytes. @@ -63,9 +63,9 @@ TEST(PropertyTypeConvertersTest, SkBitmapDeserialize) { TEST(PropertyTypeConvertersTest, SkBitmapRoundTrip) { SkBitmap bitmap1 = MakeBitmap(); std::vector<uint8_t> bytes = - TypeConverter<const std::vector<uint8_t>, SkBitmap>::Convert(bitmap1); + TypeConverter<std::vector<uint8_t>, SkBitmap>::Convert(bitmap1); SkBitmap bitmap2 = - TypeConverter<SkBitmap, const std::vector<uint8_t>>::Convert(bytes); + TypeConverter<SkBitmap, std::vector<uint8_t>>::Convert(bytes); EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap1, bitmap2)); } @@ -73,7 +73,7 @@ TEST(PropertyTypeConvertersTest, SkBitmapRoundTrip) { TEST(PropertyTypeConvertersTest, SkBitmapSerializeEmpty) { SkBitmap bitmap; std::vector<uint8_t> bytes = - TypeConverter<const std::vector<uint8_t>, SkBitmap>::Convert(bitmap); + TypeConverter<std::vector<uint8_t>, SkBitmap>::Convert(bitmap); EXPECT_TRUE(bytes.empty()); } @@ -81,7 +81,7 @@ TEST(PropertyTypeConvertersTest, SkBitmapSerializeEmpty) { TEST(PropertyTypeConvertersTest, SkBitmapDeserializeEmpty) { std::vector<uint8_t> bytes; SkBitmap bitmap = - TypeConverter<SkBitmap, const std::vector<uint8_t>>::Convert(bytes); + TypeConverter<SkBitmap, std::vector<uint8_t>>::Convert(bytes); EXPECT_TRUE(bitmap.isNull()); } diff --git a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc index 909c873..822354a 100644 --- a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc +++ b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc @@ -37,7 +37,7 @@ namespace mus { mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { const std::vector<uint8_t> bytes = - mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(value); + mojo::ConvertTo<std::vector<uint8_t>>(value); mojo::Array<uint8_t> transport_value; transport_value.resize(bytes.size()); memcpy(&transport_value.front(), &(bytes.front()), bytes.size()); diff --git a/components/mus/public/cpp/tests/window_unittest.cc b/components/mus/public/cpp/tests/window_unittest.cc index 005bc57..dc51663 100644 --- a/components/mus/public/cpp/tests/window_unittest.cc +++ b/components/mus/public/cpp/tests/window_unittest.cc @@ -791,9 +791,7 @@ class SharedPropertyChangeObserver : public WindowObserver { std::string VectorToString(const std::vector<uint8_t>* data) { if (!data) return "NULL"; - gfx::Size size = - mojo::TypeConverter<gfx::Size, const std::vector<uint8_t>>::Convert( - *data); + gfx::Size size = mojo::ConvertTo<gfx::Size>(*data); return base::StringPrintf("%d,%d", size.width(), size.height()); } diff --git a/components/mus/public/cpp/window_property.h b/components/mus/public/cpp/window_property.h index d89a7b7..fafe416 100644 --- a/components/mus/public/cpp/window_property.h +++ b/components/mus/public/cpp/window_property.h @@ -47,7 +47,7 @@ namespace mus { template <typename T> void Window::SetSharedProperty(const std::string& name, const T& data) { const std::vector<uint8_t> bytes = - mojo::TypeConverter<const std::vector<uint8_t>, T>::Convert(data); + mojo::TypeConverter<std::vector<uint8_t>, T>::Convert(data); SetSharedPropertyInternal(name, &bytes); } @@ -55,8 +55,7 @@ template <typename T> T Window::GetSharedProperty(const std::string& name) const { DCHECK(HasSharedProperty(name)); auto it = properties_.find(name); - return mojo::TypeConverter<T, const std::vector<uint8_t>>::Convert( - it->second); + return mojo::TypeConverter<T, std::vector<uint8_t>>::Convert(it->second); } namespace { |