summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamescook <jamescook@chromium.org>2016-03-25 14:28:59 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-25 21:29:57 +0000
commitda88c32858fdbc6040b07d51019d9f564e37416e (patch)
tree8f9aa64cb05eea75406425170c4b02ca171d9eca
parent0e07a14f1d8515fb5802c03e7c30dfe0bae4a87d (diff)
downloadchromium_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}
-rw-r--r--ash/mus/shelf_delegate_mus.cc3
-rw-r--r--ash/mus/sysui_application.cc5
-rw-r--r--components/mus/public/cpp/lib/property_type_converters.cc42
-rw-r--r--components/mus/public/cpp/property_type_converters.h36
-rw-r--r--components/mus/public/cpp/tests/property_type_converters_unittest.cc12
-rw-r--r--components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc2
-rw-r--r--components/mus/public/cpp/tests/window_unittest.cc4
-rw-r--r--components/mus/public/cpp/window_property.h5
-rw-r--r--mash/login/login.cc2
-rw-r--r--mash/screenlock/screenlock.cc2
-rw-r--r--mash/wm/property_util.cc3
-rw-r--r--mash/wm/user_window_controller_impl.cc2
-rw-r--r--ui/views/mus/native_widget_mus.cc13
13 files changed, 56 insertions, 75 deletions
diff --git a/ash/mus/shelf_delegate_mus.cc b/ash/mus/shelf_delegate_mus.cc
index 5b06eda..7dbff29 100644
--- a/ash/mus/shelf_delegate_mus.cc
+++ b/ash/mus/shelf_delegate_mus.cc
@@ -85,8 +85,7 @@ class ShelfItemDelegateMus : public ShelfItemDelegate {
gfx::ImageSkia GetShelfIconFromBitmap(
const mojo::Array<uint8_t>& serialized_bitmap) {
// Convert the data to an ImageSkia.
- SkBitmap bitmap = mojo::ConvertTo<SkBitmap, const std::vector<uint8_t>>(
- serialized_bitmap.storage());
+ SkBitmap bitmap = mojo::ConvertTo<SkBitmap>(serialized_bitmap.storage());
gfx::ImageSkia icon_image;
if (!bitmap.isNull()) {
icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
diff --git a/ash/mus/sysui_application.cc b/ash/mus/sysui_application.cc
index 5fd5aac..9230248 100644
--- a/ash/mus/sysui_application.cc
+++ b/ash/mus/sysui_application.cc
@@ -131,14 +131,13 @@ class NativeWidgetFactory {
mash::wm::mojom::Container container = GetContainerId(params);
if (container != mash::wm::mojom::Container::COUNT) {
properties[mash::wm::mojom::kWindowContainer_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
+ mojo::ConvertTo<std::vector<uint8_t>>(
static_cast<int32_t>(container));
}
mash::wm::mojom::AshWindowType type = GetAshWindowType(params.parent);
if (type != mash::wm::mojom::AshWindowType::COUNT) {
properties[mash::wm::mojom::kAshWindowType_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
- static_cast<int32_t>(type));
+ mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(type));
}
}
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 {
diff --git a/mash/login/login.cc b/mash/login/login.cc
index 92dec1d..78cddd9 100644
--- a/mash/login/login.cc
+++ b/mash/login/login.cc
@@ -48,7 +48,7 @@ class UI : public views::WidgetDelegateView,
std::map<std::string, std::vector<uint8_t>> properties;
properties[mash::wm::mojom::kWindowContainer_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
+ mojo::ConvertTo<std::vector<uint8_t>>(
static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS));
mus::Window* window =
views::WindowManagerConnection::Get()->NewWindow(properties);
diff --git a/mash/screenlock/screenlock.cc b/mash/screenlock/screenlock.cc
index 310164d..10f3263 100644
--- a/mash/screenlock/screenlock.cc
+++ b/mash/screenlock/screenlock.cc
@@ -95,7 +95,7 @@ void Screenlock::Initialize(mojo::Connector* connector,
std::map<std::string, std::vector<uint8_t>> properties;
properties[mash::wm::mojom::kWindowContainer_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
+ mojo::ConvertTo<std::vector<uint8_t>>(
static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS));
mus::Window* window =
views::WindowManagerConnection::Get()->NewWindow(properties);
diff --git a/mash/wm/property_util.cc b/mash/wm/property_util.cc
index 5fa4931..a7d2797 100644
--- a/mash/wm/property_util.cc
+++ b/mash/wm/property_util.cc
@@ -112,8 +112,7 @@ mus::mojom::WindowType GetWindowType(
properties.find(mus::mojom::WindowManager::kWindowType_Property);
if (iter != properties.end()) {
return static_cast<mus::mojom::WindowType>(
- mojo::TypeConverter<int32_t, const std::vector<uint8_t>>::Convert(
- iter->second));
+ mojo::ConvertTo<int32_t>(iter->second));
}
return mus::mojom::WindowType::POPUP;
}
diff --git a/mash/wm/user_window_controller_impl.cc b/mash/wm/user_window_controller_impl.cc
index 3e81da94..30d347a 100644
--- a/mash/wm/user_window_controller_impl.cc
+++ b/mash/wm/user_window_controller_impl.cc
@@ -32,7 +32,7 @@ mojo::Array<uint8_t> GetWindowAppIcon(mus::Window* window) {
if (window->HasSharedProperty(
mus::mojom::WindowManager::kWindowAppIcon_Property)) {
return mojo::Array<uint8_t>::From(
- window->GetSharedProperty<const std::vector<uint8_t>>(
+ window->GetSharedProperty<std::vector<uint8_t>>(
mus::mojom::WindowManager::kWindowAppIcon_Property));
}
return mojo::Array<uint8_t>();
diff --git a/ui/views/mus/native_widget_mus.cc b/ui/views/mus/native_widget_mus.cc
index 9b99d6b..48eb6d0 100644
--- a/ui/views/mus/native_widget_mus.cc
+++ b/ui/views/mus/native_widget_mus.cc
@@ -349,25 +349,22 @@ void NativeWidgetMus::ConfigurePropertiesForNewWindow(
std::map<std::string, std::vector<uint8_t>>* properties) {
if (!init_params.bounds.IsEmpty()) {
(*properties)[mus::mojom::WindowManager::kUserSetBounds_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, gfx::Rect>::Convert(
- init_params.bounds);
+ mojo::ConvertTo<std::vector<uint8_t>>(init_params.bounds);
}
if (!Widget::RequiresNonClientView(init_params.type))
return;
(*properties)[mus::mojom::WindowManager::kWindowType_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
- static_cast<int32_t>(
- mojo::ConvertTo<mus::mojom::WindowType>(init_params.type)));
+ mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(
+ mojo::ConvertTo<mus::mojom::WindowType>(init_params.type)));
(*properties)[mus::mojom::WindowManager::kResizeBehavior_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
+ mojo::ConvertTo<std::vector<uint8_t>>(
ResizeBehaviorFromDelegate(init_params.delegate));
SkBitmap app_icon = AppIconFromDelegate(init_params.delegate);
if (!app_icon.isNull()) {
(*properties)[mus::mojom::WindowManager::kWindowAppIcon_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, SkBitmap>::Convert(
- app_icon);
+ mojo::ConvertTo<std::vector<uint8_t>>(app_icon);
}
}