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}
This commit is contained in:
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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>();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user