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

Side by Side Diff: ash/public/cpp/shelf_struct_traits.cc

Issue 2860503002: mash: Replace int ShelfIDs with AppLaunchID strings. (Closed)
Patch Set: Fix struct traits typo. Created 3 years, 7 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
« no previous file with comments | « ash/public/cpp/shelf_struct_traits.h ('k') | ash/public/cpp/shelf_struct_traits_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "ash/public/cpp/shelf_struct_traits.h" 5 #include "ash/public/cpp/shelf_struct_traits.h"
6 6
7 #include "mojo/common/common_custom_types_struct_traits.h" 7 #include "mojo/common/common_custom_types_struct_traits.h"
8 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" 8 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h"
9 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 using ShelfItemStructTraits = 13 using ShelfItemStructTraits =
14 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>; 14 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>;
15 15
16 // static 16 // static
17 bool StructTraits<ash::mojom::ShelfIDDataView, ash::ShelfID>::Read(
18 ash::mojom::ShelfIDDataView data,
19 ash::ShelfID* out) {
20 if (!data.ReadAppId(&out->app_id) ||!data.ReadLaunchId(&out->launch_id))
21 return false;
22 // A non-empty launch id requires a non-empty app id.
23 return out->launch_id.empty() || !out->app_id.empty();
24 }
25
26 // static
17 const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) { 27 const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) {
18 // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom. 28 // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom.
19 static const SkBitmap kNullSkBitmap; 29 static const SkBitmap kNullSkBitmap;
20 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap(); 30 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap();
21 } 31 }
22 32
23 // static 33 // static
24 bool ShelfItemStructTraits::Read(ash::mojom::ShelfItemDataView data, 34 bool ShelfItemStructTraits::Read(ash::mojom::ShelfItemDataView data,
25 ash::ShelfItem* out) { 35 ash::ShelfItem* out) {
26 SkBitmap image; 36 SkBitmap image;
27 std::string app_id;
28 std::string launch_id;
29 if (!data.ReadType(&out->type) || !data.ReadImage(&image) || 37 if (!data.ReadType(&out->type) || !data.ReadImage(&image) ||
30 !data.ReadStatus(&out->status) || !data.ReadAppId(&app_id) || 38 !data.ReadStatus(&out->status) || !data.ReadShelfId(&out->id) ||
31 !data.ReadLaunchId(&launch_id) || !data.ReadTitle(&out->title)) { 39 !data.ReadTitle(&out->title)) {
32 return false; 40 return false;
33 } 41 }
34 out->id = data.shelf_id();
35 out->app_launch_id = ash::AppLaunchId(app_id, launch_id);
36 // TODO(crbug.com/655874): Support high-dpi images via gfx::Image[Skia] mojom. 42 // TODO(crbug.com/655874): Support high-dpi images via gfx::Image[Skia] mojom.
37 out->image = gfx::ImageSkia::CreateFrom1xBitmap(image); 43 out->image = gfx::ImageSkia::CreateFrom1xBitmap(image);
38 out->shows_tooltip = data.shows_tooltip(); 44 out->shows_tooltip = data.shows_tooltip();
39 out->pinned_by_policy = data.pinned_by_policy(); 45 out->pinned_by_policy = data.pinned_by_policy();
40 return true; 46 return true;
41 } 47 }
42 48
43 } // namespace mojo 49 } // namespace mojo
OLDNEW
« no previous file with comments | « ash/public/cpp/shelf_struct_traits.h ('k') | ash/public/cpp/shelf_struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698