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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ASH_PUBLIC_INTERFACES_SHELF_STRUCT_TRAITS_H_ 5 #ifndef ASH_PUBLIC_CPP_SHELF_STRUCT_TRAITS_H_
6 #define ASH_PUBLIC_INTERFACES_SHELF_STRUCT_TRAITS_H_ 6 #define ASH_PUBLIC_CPP_SHELF_STRUCT_TRAITS_H_
7 7
8 #include "ash/public/cpp/ash_public_export.h"
9 #include "ash/public/cpp/shelf_item.h"
8 #include "ash/public/cpp/shelf_types.h" 10 #include "ash/public/cpp/shelf_types.h"
9 #include "ash/public/interfaces/shelf.mojom.h" 11 #include "ash/public/interfaces/shelf.mojom-shared.h"
10 12
11 namespace mojo { 13 namespace mojo {
12 14
13 template <> 15 template <>
14 struct EnumTraits<ash::mojom::ShelfAction, ash::ShelfAction> { 16 struct EnumTraits<ash::mojom::ShelfAction, ash::ShelfAction> {
15 static ash::mojom::ShelfAction ToMojom(ash::ShelfAction input) { 17 static ash::mojom::ShelfAction ToMojom(ash::ShelfAction input) {
16 switch (input) { 18 switch (input) {
17 case ash::SHELF_ACTION_NONE: 19 case ash::SHELF_ACTION_NONE:
18 return ash::mojom::ShelfAction::NONE; 20 return ash::mojom::ShelfAction::NONE;
19 case ash::SHELF_ACTION_NEW_WINDOW_CREATED: 21 case ash::SHELF_ACTION_NEW_WINDOW_CREATED:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 case ash::mojom::ShelfAutoHideBehavior::HIDDEN: 121 case ash::mojom::ShelfAutoHideBehavior::HIDDEN:
120 *out = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; 122 *out = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN;
121 return true; 123 return true;
122 } 124 }
123 NOTREACHED(); 125 NOTREACHED();
124 return false; 126 return false;
125 } 127 }
126 }; 128 };
127 129
128 template <> 130 template <>
131 struct EnumTraits<ash::mojom::ShelfItemStatus, ash::ShelfItemStatus> {
132 static ash::mojom::ShelfItemStatus ToMojom(ash::ShelfItemStatus input) {
133 switch (input) {
134 case ash::STATUS_CLOSED:
135 return ash::mojom::ShelfItemStatus::CLOSED;
136 case ash::STATUS_RUNNING:
137 return ash::mojom::ShelfItemStatus::RUNNING;
138 case ash::STATUS_ACTIVE:
139 return ash::mojom::ShelfItemStatus::ACTIVE;
140 case ash::STATUS_ATTENTION:
141 return ash::mojom::ShelfItemStatus::ATTENTION;
142 }
143 NOTREACHED();
144 return ash::mojom::ShelfItemStatus::CLOSED;
145 }
146
147 static bool FromMojom(ash::mojom::ShelfItemStatus input,
148 ash::ShelfItemStatus* out) {
149 switch (input) {
150 case ash::mojom::ShelfItemStatus::CLOSED:
151 *out = ash::STATUS_CLOSED;
152 return true;
153 case ash::mojom::ShelfItemStatus::RUNNING:
154 *out = ash::STATUS_RUNNING;
155 return true;
156 case ash::mojom::ShelfItemStatus::ACTIVE:
157 *out = ash::STATUS_ACTIVE;
158 return true;
159 case ash::mojom::ShelfItemStatus::ATTENTION:
160 *out = ash::STATUS_ATTENTION;
161 return true;
162 }
163 NOTREACHED();
164 return false;
165 }
166 };
167
168 template <>
169 struct EnumTraits<ash::mojom::ShelfItemType, ash::ShelfItemType> {
170 static ash::mojom::ShelfItemType ToMojom(ash::ShelfItemType input) {
171 switch (input) {
172 case ash::TYPE_APP_PANEL:
173 return ash::mojom::ShelfItemType::PANEL;
174 case ash::TYPE_PINNED_APP:
175 return ash::mojom::ShelfItemType::PINNED_APP;
176 case ash::TYPE_APP_LIST:
177 return ash::mojom::ShelfItemType::APP_LIST;
178 case ash::TYPE_BROWSER_SHORTCUT:
179 return ash::mojom::ShelfItemType::BROWSER;
180 case ash::TYPE_APP:
181 return ash::mojom::ShelfItemType::APP;
182 case ash::TYPE_DIALOG:
183 return ash::mojom::ShelfItemType::DIALOG;
184 case ash::TYPE_UNDEFINED:
185 return ash::mojom::ShelfItemType::UNDEFINED;
186 }
187 NOTREACHED();
188 return ash::mojom::ShelfItemType::UNDEFINED;
189 }
190
191 static bool FromMojom(ash::mojom::ShelfItemType input,
192 ash::ShelfItemType* out) {
193 switch (input) {
194 case ash::mojom::ShelfItemType::PANEL:
195 *out = ash::TYPE_APP_PANEL;
196 return true;
197 case ash::mojom::ShelfItemType::PINNED_APP:
198 *out = ash::TYPE_PINNED_APP;
199 return true;
200 case ash::mojom::ShelfItemType::APP_LIST:
201 *out = ash::TYPE_APP_LIST;
202 return true;
203 case ash::mojom::ShelfItemType::BROWSER:
204 *out = ash::TYPE_BROWSER_SHORTCUT;
205 return true;
206 case ash::mojom::ShelfItemType::APP:
207 *out = ash::TYPE_APP;
208 return true;
209 case ash::mojom::ShelfItemType::DIALOG:
210 *out = ash::TYPE_DIALOG;
211 return true;
212 case ash::mojom::ShelfItemType::UNDEFINED:
213 *out = ash::TYPE_UNDEFINED;
214 return true;
215 }
216 NOTREACHED();
217 return false;
218 }
219 };
220
221 template <>
129 struct EnumTraits<ash::mojom::ShelfLaunchSource, ash::ShelfLaunchSource> { 222 struct EnumTraits<ash::mojom::ShelfLaunchSource, ash::ShelfLaunchSource> {
130 static ash::mojom::ShelfLaunchSource ToMojom(ash::ShelfLaunchSource input) { 223 static ash::mojom::ShelfLaunchSource ToMojom(ash::ShelfLaunchSource input) {
131 switch (input) { 224 switch (input) {
132 case ash::LAUNCH_FROM_UNKNOWN: 225 case ash::LAUNCH_FROM_UNKNOWN:
133 return ash::mojom::ShelfLaunchSource::UNKNOWN; 226 return ash::mojom::ShelfLaunchSource::UNKNOWN;
134 case ash::LAUNCH_FROM_APP_LIST: 227 case ash::LAUNCH_FROM_APP_LIST:
135 return ash::mojom::ShelfLaunchSource::APP_LIST; 228 return ash::mojom::ShelfLaunchSource::APP_LIST;
136 case ash::LAUNCH_FROM_APP_LIST_SEARCH: 229 case ash::LAUNCH_FROM_APP_LIST_SEARCH:
137 return ash::mojom::ShelfLaunchSource::APP_LIST_SEARCH; 230 return ash::mojom::ShelfLaunchSource::APP_LIST_SEARCH;
138 } 231 }
(...skipping 12 matching lines...) Expand all
151 return true; 244 return true;
152 case ash::mojom::ShelfLaunchSource::APP_LIST_SEARCH: 245 case ash::mojom::ShelfLaunchSource::APP_LIST_SEARCH:
153 *out = ash::LAUNCH_FROM_APP_LIST_SEARCH; 246 *out = ash::LAUNCH_FROM_APP_LIST_SEARCH;
154 return true; 247 return true;
155 } 248 }
156 NOTREACHED(); 249 NOTREACHED();
157 return false; 250 return false;
158 } 251 }
159 }; 252 };
160 253
254 template <>
255 struct ASH_PUBLIC_EXPORT
256 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem> {
257 static ash::ShelfItemType type(const ash::ShelfItem& i) { return i.type; }
258 static const SkBitmap& image(const ash::ShelfItem& i);
259 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.
260 static ash::ShelfItemStatus status(const ash::ShelfItem& i) {
261 return i.status;
262 }
263 static const std::string& app_id(const ash::ShelfItem& i) { return i.app_id; }
264 static const base::string16& title(const ash::ShelfItem& i) {
265 return i.title;
266 }
267 static bool shows_tooltip(const ash::ShelfItem& i) { return i.shows_tooltip; }
268 static bool pinned_by_policy(const ash::ShelfItem& i) {
269 return i.pinned_by_policy;
270 }
271
272 static bool Read(ash::mojom::ShelfItemDataView data, ash::ShelfItem* out);
273 };
274
161 } // namespace mojo 275 } // namespace mojo
162 276
163 #endif // ASH_PUBLIC_INTERFACES_SHELF_STRUCT_TRAITS_H_ 277 #endif // ASH_PUBLIC_CPP_SHELF_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698