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

Side by Side Diff: components/arc/test/fake_arc_bridge_service.cc

Issue 1413153007: arc-app-launcher: Minimal support for ARC app launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit comment addressed Created 5 years, 1 month 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/arc/test/fake_arc_bridge_service.h"
6
7 #include "chrome/browser/ui/app_list/arc_app_list_prefs.h"
8 #include "ui/app_list/app_list_constants.h"
9 #include "ui/gfx/codec/png_codec.h"
10
11 FakeArcBridgeService::FakeArcBridgeService()
12 : refresh_apps_count_(0) {
13 }
14
15 FakeArcBridgeService::~FakeArcBridgeService() {
16 if (state() != State::STOPPED) {
17 SetState(State::STOPPED);
18 }
19 }
20
21 void FakeArcBridgeService::HandleStartup() {
22 }
23
24 void FakeArcBridgeService::Shutdown() {
25 }
26
27 bool FakeArcBridgeService::RegisterInputDevice(const std::string& name,
28 const std::string& device_type,
29 base::ScopedFD fd) {
30 return true;
31 }
32
33 bool FakeArcBridgeService::RefreshApps() {
34 ++refresh_apps_count_;
35 return true;
36 }
37
38 bool FakeArcBridgeService::LaunchApp(const std::string& package,
39 const std::string& activity) {
40 launch_requests_.push_back(ArcAppListPrefs::GetAppId(package, activity));
41 return true;
42 }
43
44 bool FakeArcBridgeService::RequestIcon(const std::string& package,
45 const std::string& activity,
46 int scale_factor) {
47 IconRequest request;
48 request.package = package;
49 request.activity = activity;
50 request.scale_factor = scale_factor;
51 icon_requests_.push_back(request);
52 return true;
53 }
54
55 void FakeArcBridgeService::SetReady() {
56 SetState(State::READY);
57 }
58
59 void FakeArcBridgeService::SetStopped() {
60 SetState(State::STOPPED);
61 }
62
63 bool FakeArcBridgeService::HasObserver(const Observer* observer) const {
64 return observer_list_.HasObserver(observer);
65 }
66
67 void FakeArcBridgeService::SendRefreshApps(size_t size, const AppInfo* apps) {
68 std::vector<std::string> names(size);
69 std::vector<std::string> packages(size);
70 std::vector<std::string> activities(size);
71 for (size_t i = 0; i < size; ++i) {
72 names[i] = apps[i].name;
73 packages[i] = apps[i].package;
74 activities[i] = apps[i].activity;
75 }
76
77 FOR_EACH_OBSERVER(Observer,
78 observer_list_,
79 OnAppsRefreshed(names, packages, activities));
80 }
81
82 bool FakeArcBridgeService::GenerateAndSendIcon(
83 const AppInfo& app,
84 ui::ScaleFactor scale_factor,
85 std::vector<unsigned char>* png_data) {
86 const float scale = ui::GetScaleForScaleFactor(scale_factor);
87 const int icon_size = static_cast<int>(
88 app_list::kGridIconDimension * scale + 0.5f);
89
90 const int row_width = icon_size * 4;
91 const int data_size = icon_size * row_width;
92
93 // Generate random content.
94 std::vector<unsigned char> pixels(data_size);
95 for (int i = 0; i < icon_size; ++i) {
96 memset(&pixels[i * row_width], rand(), row_width);
97 }
98
99 if (!gfx::PNGCodec::Encode(&pixels[0],
100 gfx::PNGCodec::FORMAT_RGBA,
101 gfx::Size(icon_size, icon_size),
102 row_width,
103 false,
104 std::vector<gfx::PNGCodec::Comment>(),
105 png_data)) {
106 return false;
107 }
108
109 FOR_EACH_OBSERVER(Observer,
110 observer_list_,
111 OnAppIcon(app.package,
112 app.activity,
113 scale_factor,
114 *png_data));
115 return true;
116 }
117
118 std::string FakeArcBridgeService::AppInfo::id() const {
119 return ArcAppListPrefs::GetAppId(package, activity);
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698