Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1715)

Unified Diff: ash/public/cpp/shelf_struct_traits.h

Issue 2750463009: mash: Fix ShelfItem mojo struct; add enums and traits. (Closed)
Patch Set: Address comments; try adding a unit test. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/public/cpp/shelf_struct_traits.h
diff --git a/ash/public/interfaces/shelf_struct_traits.h b/ash/public/cpp/shelf_struct_traits.h
similarity index 56%
rename from ash/public/interfaces/shelf_struct_traits.h
rename to ash/public/cpp/shelf_struct_traits.h
index 74c0a7cdcfa6246b8c96aaaebf3a7cb55fa47753..6109ed5c45c3e41ee984217b2834c0109e5cbcdc 100644
--- a/ash/public/interfaces/shelf_struct_traits.h
+++ b/ash/public/cpp/shelf_struct_traits.h
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef ASH_PUBLIC_INTERFACES_SHELF_STRUCT_TRAITS_H_
-#define ASH_PUBLIC_INTERFACES_SHELF_STRUCT_TRAITS_H_
+#ifndef ASH_PUBLIC_CPP_SHELF_STRUCT_TRAITS_H_
+#define ASH_PUBLIC_CPP_SHELF_STRUCT_TRAITS_H_
+#include "ash/public/cpp/ash_public_export.h"
+#include "ash/public/cpp/shelf_item.h"
#include "ash/public/cpp/shelf_types.h"
-#include "ash/public/interfaces/shelf.mojom.h"
+#include "ash/public/interfaces/shelf.mojom-shared.h"
namespace mojo {
@@ -126,6 +128,97 @@ struct EnumTraits<ash::mojom::ShelfAutoHideBehavior,
};
template <>
+struct EnumTraits<ash::mojom::ShelfItemStatus, ash::ShelfItemStatus> {
+ static ash::mojom::ShelfItemStatus ToMojom(ash::ShelfItemStatus input) {
+ switch (input) {
+ case ash::STATUS_CLOSED:
+ return ash::mojom::ShelfItemStatus::CLOSED;
+ case ash::STATUS_RUNNING:
+ return ash::mojom::ShelfItemStatus::RUNNING;
+ case ash::STATUS_ACTIVE:
+ return ash::mojom::ShelfItemStatus::ACTIVE;
+ case ash::STATUS_ATTENTION:
+ return ash::mojom::ShelfItemStatus::ATTENTION;
+ }
+ NOTREACHED();
+ return ash::mojom::ShelfItemStatus::CLOSED;
+ }
+
+ static bool FromMojom(ash::mojom::ShelfItemStatus input,
+ ash::ShelfItemStatus* out) {
+ switch (input) {
+ case ash::mojom::ShelfItemStatus::CLOSED:
+ *out = ash::STATUS_CLOSED;
+ return true;
+ case ash::mojom::ShelfItemStatus::RUNNING:
+ *out = ash::STATUS_RUNNING;
+ return true;
+ case ash::mojom::ShelfItemStatus::ACTIVE:
+ *out = ash::STATUS_ACTIVE;
+ return true;
+ case ash::mojom::ShelfItemStatus::ATTENTION:
+ *out = ash::STATUS_ATTENTION;
+ return true;
+ }
+ NOTREACHED();
+ return false;
+ }
+};
+
+template <>
+struct EnumTraits<ash::mojom::ShelfItemType, ash::ShelfItemType> {
+ static ash::mojom::ShelfItemType ToMojom(ash::ShelfItemType input) {
+ switch (input) {
+ case ash::TYPE_APP_PANEL:
+ return ash::mojom::ShelfItemType::PANEL;
+ case ash::TYPE_PINNED_APP:
+ return ash::mojom::ShelfItemType::PINNED_APP;
+ case ash::TYPE_APP_LIST:
+ return ash::mojom::ShelfItemType::APP_LIST;
+ case ash::TYPE_BROWSER_SHORTCUT:
+ return ash::mojom::ShelfItemType::BROWSER;
+ case ash::TYPE_APP:
+ return ash::mojom::ShelfItemType::APP;
+ case ash::TYPE_DIALOG:
+ return ash::mojom::ShelfItemType::DIALOG;
+ case ash::TYPE_UNDEFINED:
+ return ash::mojom::ShelfItemType::UNDEFINED;
+ }
+ NOTREACHED();
+ return ash::mojom::ShelfItemType::UNDEFINED;
+ }
+
+ static bool FromMojom(ash::mojom::ShelfItemType input,
+ ash::ShelfItemType* out) {
+ switch (input) {
+ case ash::mojom::ShelfItemType::PANEL:
+ *out = ash::TYPE_APP_PANEL;
+ return true;
+ case ash::mojom::ShelfItemType::PINNED_APP:
+ *out = ash::TYPE_PINNED_APP;
+ return true;
+ case ash::mojom::ShelfItemType::APP_LIST:
+ *out = ash::TYPE_APP_LIST;
+ return true;
+ case ash::mojom::ShelfItemType::BROWSER:
+ *out = ash::TYPE_BROWSER_SHORTCUT;
+ return true;
+ case ash::mojom::ShelfItemType::APP:
+ *out = ash::TYPE_APP;
+ return true;
+ case ash::mojom::ShelfItemType::DIALOG:
+ *out = ash::TYPE_DIALOG;
+ return true;
+ case ash::mojom::ShelfItemType::UNDEFINED:
+ *out = ash::TYPE_UNDEFINED;
+ return true;
+ }
+ NOTREACHED();
+ return false;
+ }
+};
+
+template <>
struct EnumTraits<ash::mojom::ShelfLaunchSource, ash::ShelfLaunchSource> {
static ash::mojom::ShelfLaunchSource ToMojom(ash::ShelfLaunchSource input) {
switch (input) {
@@ -158,6 +251,27 @@ struct EnumTraits<ash::mojom::ShelfLaunchSource, ash::ShelfLaunchSource> {
}
};
+template <>
+struct ASH_PUBLIC_EXPORT
+ StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem> {
+ static ash::ShelfItemType type(const ash::ShelfItem& i) { return i.type; }
+ static const SkBitmap& image(const ash::ShelfItem& i);
+ static int64_t shelf_id(const ash::ShelfItem& i) { return i.id; }
James Cook 2017/03/17 02:32:29 Wait, should this be uint32_t ? Or ShelfID?
msw 2017/03/17 05:35:19 Good catch! Changed to ShelfID.
+ static ash::ShelfItemStatus status(const ash::ShelfItem& i) {
+ return i.status;
+ }
+ static const std::string& app_id(const ash::ShelfItem& i) { return i.app_id; }
+ static const base::string16& title(const ash::ShelfItem& i) {
+ return i.title;
+ }
+ static bool shows_tooltip(const ash::ShelfItem& i) { return i.shows_tooltip; }
+ static bool pinned_by_policy(const ash::ShelfItem& i) {
+ return i.pinned_by_policy;
+ }
+
+ static bool Read(ash::mojom::ShelfItemDataView data, ash::ShelfItem* out);
+};
+
} // namespace mojo
-#endif // ASH_PUBLIC_INTERFACES_SHELF_STRUCT_TRAITS_H_
+#endif // ASH_PUBLIC_CPP_SHELF_STRUCT_TRAITS_H_

Powered by Google App Engine
This is Rietveld 408576698