Commit e6975c78 authored by msw's avatar msw Committed by Commit bot

mash: Add type names to PropertyConverter::Register*Property.

Came up in https://codereview.chromium.org/2878133002/
(calling the wrong function ate up 1hr+ debugging)
(this cl also depends on that one)

BUG=NONE
TEST=NONE
R=sky@chromium.org
NOTRY=true

Review-Url: https://codereview.chromium.org/2889443002
Cr-Commit-Position: refs/heads/master@{#472239}
parent 9b38f0b5
......@@ -82,25 +82,25 @@ WindowManager::WindowManager(service_manager::Connector* connector,
show_primary_host_on_connect_(show_primary_host_on_connect),
wm_state_(base::MakeUnique<::wm::WMState>()),
property_converter_(base::MakeUnique<aura::PropertyConverter>()) {
property_converter_->RegisterProperty(
property_converter_->RegisterPrimitiveProperty(
kPanelAttachedKey, ui::mojom::WindowManager::kPanelAttached_Property,
aura::PropertyConverter::CreateAcceptAnyValueCallback());
property_converter_->RegisterProperty(
property_converter_->RegisterPrimitiveProperty(
kRenderTitleAreaProperty,
ui::mojom::WindowManager::kRenderParentTitleArea_Property,
aura::PropertyConverter::CreateAcceptAnyValueCallback());
property_converter_->RegisterProperty(
kShelfIDKey, ui::mojom::WindowManager::kShelfID_Property);
property_converter_->RegisterProperty(
property_converter_->RegisterPrimitiveProperty(
kShelfItemTypeKey, ui::mojom::WindowManager::kShelfItemType_Property,
base::Bind(&IsValidShelfItemType));
property_converter_->RegisterProperty(
property_converter_->RegisterPrimitiveProperty(
::wm::kShadowElevationKey,
ui::mojom::WindowManager::kShadowElevation_Property,
base::Bind(&::wm::IsValidShadowElevation));
property_converter_->RegisterProperty(kWindowPinTypeKey,
ash::mojom::kWindowPinType_Property,
property_converter_->RegisterPrimitiveProperty(
kWindowPinTypeKey, ash::mojom::kWindowPinType_Property,
base::Bind(&ash::IsValidWindowPinType));
property_converter_->RegisterStringProperty(
kShelfIDKey, ui::mojom::WindowManager::kShelfID_Property);
}
WindowManager::~WindowManager() {
......
......@@ -49,19 +49,19 @@ void ChromeBrowserMainExtraPartsAsh::ServiceManagerConnectionStarted(
aura::WindowTreeClientDelegate* delegate = mus_client;
aura::PropertyConverter* converter = delegate->GetPropertyConverter();
converter->RegisterProperty(
converter->RegisterPrimitiveProperty(
ash::kPanelAttachedKey,
ui::mojom::WindowManager::kPanelAttached_Property,
aura::PropertyConverter::CreateAcceptAnyValueCallback());
converter->RegisterProperty(ash::kShelfIDKey,
ui::mojom::WindowManager::kShelfID_Property);
converter->RegisterProperty(
converter->RegisterPrimitiveProperty(
ash::kShelfItemTypeKey,
ui::mojom::WindowManager::kShelfItemType_Property,
base::Bind(&ash::IsValidShelfItemType));
converter->RegisterProperty(ash::kWindowPinTypeKey,
ash::mojom::kWindowPinType_Property,
converter->RegisterPrimitiveProperty(
ash::kWindowPinTypeKey, ash::mojom::kWindowPinType_Property,
base::Bind(&ash::IsValidWindowPinType));
converter->RegisterStringProperty(
ash::kShelfIDKey, ui::mojom::WindowManager::kShelfID_Property);
mus_client->SetMusPropertyMirror(
base::MakeUnique<ash::MusPropertyMirrorAsh>());
......
......@@ -66,28 +66,30 @@ PropertyConverter::CreateAcceptAnyValueCallback() {
PropertyConverter::PropertyConverter() {
// Add known aura properties with associated mus properties.
RegisterProperty(client::kAlwaysOnTopKey,
RegisterImageSkiaProperty(client::kAppIconKey,
ui::mojom::WindowManager::kAppIcon_Property);
RegisterImageSkiaProperty(client::kWindowIconKey,
ui::mojom::WindowManager::kWindowIcon_Property);
RegisterPrimitiveProperty(client::kAlwaysOnTopKey,
ui::mojom::WindowManager::kAlwaysOnTop_Property,
CreateAcceptAnyValueCallback());
RegisterProperty(client::kAppIconKey,
ui::mojom::WindowManager::kAppIcon_Property);
RegisterProperty(client::kImmersiveFullscreenKey,
RegisterPrimitiveProperty(
client::kImmersiveFullscreenKey,
ui::mojom::WindowManager::kImmersiveFullscreen_Property,
CreateAcceptAnyValueCallback());
RegisterProperty(client::kNameKey, ui::mojom::WindowManager::kName_Property);
RegisterProperty(client::kPreferredSize,
ui::mojom::WindowManager::kPreferredSize_Property);
RegisterProperty(client::kResizeBehaviorKey,
RegisterPrimitiveProperty(client::kResizeBehaviorKey,
ui::mojom::WindowManager::kResizeBehavior_Property,
base::Bind(&ValidateResizeBehaviour));
RegisterProperty(client::kRestoreBoundsKey,
ui::mojom::WindowManager::kRestoreBounds_Property);
RegisterProperty(client::kShowStateKey,
RegisterPrimitiveProperty(client::kShowStateKey,
ui::mojom::WindowManager::kShowState_Property,
base::Bind(&ValidateShowState));
RegisterProperty(client::kWindowIconKey,
ui::mojom::WindowManager::kWindowIcon_Property);
RegisterProperty(client::kTitleKey,
RegisterRectProperty(client::kRestoreBoundsKey,
ui::mojom::WindowManager::kRestoreBounds_Property);
RegisterSizeProperty(client::kPreferredSize,
ui::mojom::WindowManager::kPreferredSize_Property);
RegisterStringProperty(client::kNameKey,
ui::mojom::WindowManager::kName_Property);
RegisterString16Property(client::kTitleKey,
ui::mojom::WindowManager::kWindowTitle_Property);
}
......@@ -288,35 +290,35 @@ bool PropertyConverter::GetPropertyValueFromTransportValue(
return false;
}
void PropertyConverter::RegisterProperty(
void PropertyConverter::RegisterImageSkiaProperty(
const WindowProperty<gfx::ImageSkia*>* property,
const char* transport_name) {
image_properties_[property] = transport_name;
transport_names_.insert(transport_name);
}
void PropertyConverter::RegisterProperty(
void PropertyConverter::RegisterRectProperty(
const WindowProperty<gfx::Rect*>* property,
const char* transport_name) {
rect_properties_[property] = transport_name;
transport_names_.insert(transport_name);
}
void PropertyConverter::RegisterProperty(
void PropertyConverter::RegisterSizeProperty(
const WindowProperty<gfx::Size*>* property,
const char* transport_name) {
size_properties_[property] = transport_name;
transport_names_.insert(transport_name);
}
void PropertyConverter::RegisterProperty(
void PropertyConverter::RegisterStringProperty(
const WindowProperty<std::string*>* property,
const char* transport_name) {
string_properties_[property] = transport_name;
transport_names_.insert(transport_name);
}
void PropertyConverter::RegisterProperty(
void PropertyConverter::RegisterString16Property(
const WindowProperty<base::string16*>* property,
const char* transport_name) {
string16_properties_[property] = transport_name;
......
......@@ -78,9 +78,8 @@ class AURA_EXPORT PropertyConverter {
// Register a property to support conversion between mus and aura.
// |validator| is a callback used to validate incoming values from
// transport_data; if it returns false, the value is rejected.
// TODO(msw): Include type names in RegisterProperty function names.
template <typename T>
void RegisterProperty(
void RegisterPrimitiveProperty(
const WindowProperty<T>* property,
const char* transport_name,
const base::RepeatingCallback<bool(int64_t)>& validator) {
......@@ -95,16 +94,16 @@ class AURA_EXPORT PropertyConverter {
}
// Register owned properties to support conversion between mus and aura.
// TODO(msw): Include type names in RegisterProperty function names.
void RegisterProperty(const WindowProperty<gfx::ImageSkia*>* property,
void RegisterImageSkiaProperty(
const WindowProperty<gfx::ImageSkia*>* property,
const char* transport_name);
void RegisterProperty(const WindowProperty<gfx::Rect*>* property,
void RegisterRectProperty(const WindowProperty<gfx::Rect*>* property,
const char* transport_name);
void RegisterProperty(const WindowProperty<gfx::Size*>* property,
void RegisterSizeProperty(const WindowProperty<gfx::Size*>* property,
const char* transport_name);
void RegisterProperty(const WindowProperty<std::string*>* property,
void RegisterStringProperty(const WindowProperty<std::string*>* property,
const char* transport_name);
void RegisterProperty(const WindowProperty<base::string16*>* property,
void RegisterString16Property(const WindowProperty<base::string16*>* property,
const char* transport_name);
private:
......
......@@ -43,7 +43,8 @@ DEFINE_UI_CLASS_PROPERTY_KEY(int16_t, kTestPropertyKey7, 1);
DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kTestPropertyKey8, -1);
DEFINE_UI_CLASS_PROPERTY_KEY(int64_t, kTestPropertyKey9, 777);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia, kTestImagePropertyKey,
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia,
kTestImageSkiaPropertyKey,
nullptr);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Size, kTestSizePropertyKey, nullptr);
......@@ -63,7 +64,7 @@ const char kTestPropertyServerKey7[] = "test-property-server7";
const char kTestPropertyServerKey8[] = "test-property-server8";
const char kTestPropertyServerKey9[] = "test-property-server9";
const char kTestImagePropertyServerKey[] = "test-image-property-server";
const char kTestImageSkiaPropertyServerKey[] = "test-imageskia-property-server";
const char kTestRectPropertyServerKey[] = "test-rect-property-server";
const char kTestSizePropertyServerKey[] = "test-size-property-server";
const char kTestStringPropertyServerKey[] = "test-string-property-server";
......@@ -77,7 +78,7 @@ void TestPrimitiveProperty(PropertyConverter* property_converter,
const char* transport_name,
T value_1,
T value_2) {
property_converter->RegisterProperty(
property_converter->RegisterPrimitiveProperty(
key, transport_name, PropertyConverter::CreateAcceptAnyValueCallback());
EXPECT_EQ(transport_name,
property_converter->GetTransportNameForPropertyKey(key));
......@@ -174,8 +175,8 @@ TEST_F(PropertyConverterTest, TestPrimitiveVerifier) {
std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
PropertyConverter property_converter;
property_converter.RegisterProperty(kTestPropertyKey8,
kTestPropertyServerKey8,
property_converter.RegisterPrimitiveProperty(
kTestPropertyKey8, kTestPropertyServerKey8,
base::Bind(&OnlyAllowNegativeNumbers));
// Test that we reject invalid TransportValues during
......@@ -197,29 +198,29 @@ TEST_F(PropertyConverterTest, TestPrimitiveVerifier) {
// Verifies property setting behavior for a gfx::ImageSkia* property.
TEST_F(PropertyConverterTest, ImageSkiaProperty) {
PropertyConverter property_converter;
property_converter.RegisterProperty(kTestImagePropertyKey,
kTestImagePropertyServerKey);
EXPECT_EQ(
kTestImagePropertyServerKey,
property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey));
property_converter.RegisterImageSkiaProperty(kTestImageSkiaPropertyKey,
kTestImageSkiaPropertyServerKey);
EXPECT_EQ(kTestImageSkiaPropertyServerKey,
property_converter.GetTransportNameForPropertyKey(
kTestImageSkiaPropertyKey));
EXPECT_TRUE(property_converter.IsTransportNameRegistered(
kTestImagePropertyServerKey));
kTestImageSkiaPropertyServerKey));
SkBitmap bitmap_1;
bitmap_1.allocN32Pixels(16, 32);
bitmap_1.eraseARGB(255, 11, 22, 33);
gfx::ImageSkia value_1 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_1);
std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
window->SetProperty(kTestImagePropertyKey, new gfx::ImageSkia(value_1));
gfx::ImageSkia* image_out_1 = window->GetProperty(kTestImagePropertyKey);
window->SetProperty(kTestImageSkiaPropertyKey, new gfx::ImageSkia(value_1));
gfx::ImageSkia* image_out_1 = window->GetProperty(kTestImageSkiaPropertyKey);
EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_1, *image_out_1->bitmap()));
std::string transport_name_out;
std::unique_ptr<std::vector<uint8_t>> transport_value_out;
EXPECT_TRUE(property_converter.ConvertPropertyForTransport(
window.get(), kTestImagePropertyKey, &transport_name_out,
window.get(), kTestImageSkiaPropertyKey, &transport_name_out,
&transport_value_out));
EXPECT_EQ(kTestImagePropertyServerKey, transport_name_out);
EXPECT_EQ(kTestImageSkiaPropertyServerKey, transport_name_out);
EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(bitmap_1),
*transport_value_out.get());
......@@ -231,15 +232,15 @@ TEST_F(PropertyConverterTest, ImageSkiaProperty) {
std::vector<uint8_t> transport_value =
mojo::ConvertTo<std::vector<uint8_t>>(bitmap_2);
property_converter.SetPropertyFromTransportValue(
window.get(), kTestImagePropertyServerKey, &transport_value);
gfx::ImageSkia* image_out_2 = window->GetProperty(kTestImagePropertyKey);
window.get(), kTestImageSkiaPropertyServerKey, &transport_value);
gfx::ImageSkia* image_out_2 = window->GetProperty(kTestImageSkiaPropertyKey);
EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_2, *image_out_2->bitmap()));
}
// Verifies property setting behavior for a gfx::Rect* property.
TEST_F(PropertyConverterTest, RectProperty) {
PropertyConverter property_converter;
property_converter.RegisterProperty(kTestRectPropertyKey,
property_converter.RegisterRectProperty(kTestRectPropertyKey,
kTestRectPropertyServerKey);
EXPECT_EQ(
kTestRectPropertyServerKey,
......@@ -272,7 +273,7 @@ TEST_F(PropertyConverterTest, RectProperty) {
// Verifies property setting behavior for a gfx::Size* property.
TEST_F(PropertyConverterTest, SizeProperty) {
PropertyConverter property_converter;
property_converter.RegisterProperty(kTestSizePropertyKey,
property_converter.RegisterSizeProperty(kTestSizePropertyKey,
kTestSizePropertyServerKey);
EXPECT_EQ(
kTestSizePropertyServerKey,
......@@ -305,7 +306,7 @@ TEST_F(PropertyConverterTest, SizeProperty) {
// Verifies property setting behavior for a std::string* property.
TEST_F(PropertyConverterTest, StringProperty) {
PropertyConverter property_converter;
property_converter.RegisterProperty(kTestStringPropertyKey,
property_converter.RegisterStringProperty(kTestStringPropertyKey,
kTestStringPropertyServerKey);
EXPECT_EQ(kTestStringPropertyServerKey,
property_converter.GetTransportNameForPropertyKey(
......@@ -338,7 +339,7 @@ TEST_F(PropertyConverterTest, StringProperty) {
// Verifies property setting behavior for a base::string16* property.
TEST_F(PropertyConverterTest, String16Property) {
PropertyConverter property_converter;
property_converter.RegisterProperty(kTestString16PropertyKey,
property_converter.RegisterString16Property(kTestString16PropertyKey,
kTestString16PropertyServerKey);
EXPECT_EQ(kTestString16PropertyServerKey,
property_converter.GetTransportNameForPropertyKey(
......
......@@ -82,13 +82,13 @@ bool IsWindowHostVisible(Window* window) {
// Register some test window properties for aura/mus conversion.
void RegisterTestProperties(PropertyConverter* converter) {
converter->RegisterProperty(
converter->RegisterPrimitiveProperty(
kTestPropertyKey1, kTestPropertyServerKey1,
PropertyConverter::CreateAcceptAnyValueCallback());
converter->RegisterProperty(
converter->RegisterPrimitiveProperty(
kTestPropertyKey2, kTestPropertyServerKey2,
PropertyConverter::CreateAcceptAnyValueCallback());
converter->RegisterProperty(
converter->RegisterPrimitiveProperty(
kTestPropertyKey3, kTestPropertyServerKey3,
PropertyConverter::CreateAcceptAnyValueCallback());
}
......
......@@ -94,7 +94,7 @@ MusClient::MusClient(service_manager::Connector* connector,
// TODO(msw): Avoid this... use some default value? Allow clients to extend?
property_converter_ = base::MakeUnique<aura::PropertyConverter>();
property_converter_->RegisterProperty(
property_converter_->RegisterPrimitiveProperty(
wm::kShadowElevationKey,
ui::mojom::WindowManager::kShadowElevation_Property,
base::Bind(&wm::IsValidShadowElevation));
......
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