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

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

Issue 1523643002: arc-bridge: Move most methods to Mojo interfaces (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Fixed GN build Created 5 years 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 2015 The Chromium Authors. All rights reserved. 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 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 "components/arc/test/fake_arc_bridge_service.h" 5 #include "components/arc/test/fake_arc_bridge_service.h"
6 6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/path_service.h"
10
11 namespace arc { 7 namespace arc {
12 8
13 FakeArcBridgeService::FakeArcBridgeService() { 9 FakeArcBridgeService::FakeArcBridgeService() {
14 } 10 }
15 11
16 FakeArcBridgeService::~FakeArcBridgeService() { 12 FakeArcBridgeService::~FakeArcBridgeService() {
17 if (state() != State::STOPPED) { 13 if (state() != State::STOPPED) {
18 SetState(State::STOPPED); 14 SetState(State::STOPPED);
19 } 15 }
20 } 16 }
21 17
22 void FakeArcBridgeService::DetectAvailability() { 18 void FakeArcBridgeService::DetectAvailability() {
23 } 19 }
24 20
25 void FakeArcBridgeService::HandleStartup() { 21 void FakeArcBridgeService::HandleStartup() {
26 } 22 }
27 23
28 void FakeArcBridgeService::Shutdown() { 24 void FakeArcBridgeService::Shutdown() {
29 } 25 }
30 26
31 bool FakeArcBridgeService::RegisterInputDevice(const std::string& name,
32 const std::string& device_type,
33 base::ScopedFD fd) {
34 return true;
35 }
36
37 bool FakeArcBridgeService::SendNotificationEventToAndroid(
38 const std::string& key,
39 ArcNotificationEvent event) {
40 return true;
41 }
42
43 bool FakeArcBridgeService::RefreshAppList() {
44 ++refresh_app_list_count_;
45 return true;
46 }
47
48 bool FakeArcBridgeService::LaunchApp(const std::string& package,
49 const std::string& activity) {
50 launch_requests_.push_back(new Request(package, activity));
51 return true;
52 }
53
54 bool FakeArcBridgeService::RequestAppIcon(const std::string& package,
55 const std::string& activity,
56 ScaleFactor scale_factor) {
57 icon_requests_.push_back(new IconRequest(package, activity, scale_factor));
58 return true;
59 }
60
61 bool FakeArcBridgeService::RequestProcessList() {
62 return true;
63 }
64
65 void FakeArcBridgeService::SetReady() { 27 void FakeArcBridgeService::SetReady() {
66 SetState(State::READY); 28 SetState(State::READY);
67 } 29 }
68 30
69 void FakeArcBridgeService::SetStopped() { 31 void FakeArcBridgeService::SetStopped() {
70 SetState(State::STOPPED); 32 SetState(State::STOPPED);
71 } 33 }
72 34
35 void FakeArcBridgeService::SetAppInstance(AppInstancePtr app_ptr) {
36 app_ptr_ = std::move(app_ptr);
37 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceReady());
38 }
39
40 void FakeArcBridgeService::SetInputInstance(InputInstancePtr input_ptr) {
41 input_ptr_ = std::move(input_ptr);
42 FOR_EACH_OBSERVER(Observer, observer_list(), OnInputInstanceReady());
43 }
44
45 void FakeArcBridgeService::SetNotificationsInstance(
46 NotificationsInstancePtr notifications_ptr) {
47 notifications_ptr_ = std::move(notifications_ptr);
48 FOR_EACH_OBSERVER(Observer, observer_list(), OnNotificationsInstanceReady());
49 }
50
51 void FakeArcBridgeService::SetPowerInstance(PowerInstancePtr power_ptr) {
52 power_ptr_ = std::move(power_ptr);
53 FOR_EACH_OBSERVER(Observer, observer_list(), OnPowerInstanceReady());
54 }
55
56 void FakeArcBridgeService::SetProcessListInstance(
57 ProcessListInstancePtr process_list_ptr) {
58 process_list_ptr_ = std::move(process_list_ptr);
59 FOR_EACH_OBSERVER(Observer, observer_list(), OnProcessListInstanceReady());
60 }
61
73 bool FakeArcBridgeService::HasObserver(const Observer* observer) { 62 bool FakeArcBridgeService::HasObserver(const Observer* observer) {
74 return observer_list().HasObserver(observer); 63 return observer_list().HasObserver(observer);
75 } 64 }
76 65
77 bool FakeArcBridgeService::HasAppObserver(const AppObserver* observer) {
78 return app_observer_list().HasObserver(observer);
79 }
80
81 void FakeArcBridgeService::SendRefreshAppList(
82 const std::vector<AppInfo>& apps) {
83 FOR_EACH_OBSERVER(AppObserver, app_observer_list(), OnAppListRefreshed(apps));
84 }
85
86 bool FakeArcBridgeService::GenerateAndSendIcon(
87 const AppInfo& app,
88 ScaleFactor scale_factor,
89 std::string* png_data_as_string) {
90 CHECK(png_data_as_string != nullptr);
91 std::string icon_file_name;
92 switch (scale_factor) {
93 case SCALE_FACTOR_SCALE_FACTOR_100P:
94 icon_file_name = "icon_100p.png";
95 break;
96 case SCALE_FACTOR_SCALE_FACTOR_125P:
97 icon_file_name = "icon_125p.png";
98 break;
99 case SCALE_FACTOR_SCALE_FACTOR_133P:
100 icon_file_name = "icon_133p.png";
101 break;
102 case SCALE_FACTOR_SCALE_FACTOR_140P:
103 icon_file_name = "icon_140p.png";
104 break;
105 case SCALE_FACTOR_SCALE_FACTOR_150P:
106 icon_file_name = "icon_150p.png";
107 break;
108 case SCALE_FACTOR_SCALE_FACTOR_180P:
109 icon_file_name = "icon_180p.png";
110 break;
111 case SCALE_FACTOR_SCALE_FACTOR_200P:
112 icon_file_name = "icon_200p.png";
113 break;
114 case SCALE_FACTOR_SCALE_FACTOR_250P:
115 icon_file_name = "icon_250p.png";
116 break;
117 case SCALE_FACTOR_SCALE_FACTOR_300P:
118 icon_file_name = "icon_300p.png";
119 break;
120 default:
121 NOTREACHED();
122 return false;
123 }
124
125 base::FilePath base_path;
126 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &base_path));
127 base::FilePath icon_file_path = base_path
128 .AppendASCII("components")
129 .AppendASCII("test")
130 .AppendASCII("data")
131 .AppendASCII("arc")
132 .AppendASCII(icon_file_name);
133 CHECK(base::PathExists(icon_file_path));
134 CHECK(base::ReadFileToString(icon_file_path, png_data_as_string));
135
136 std::vector<uint8_t> png_data(png_data_as_string->begin(),
137 png_data_as_string->end());
138
139 FOR_EACH_OBSERVER(AppObserver,
140 app_observer_list(),
141 OnAppIcon(app.package,
142 app.activity,
143 scale_factor,
144 png_data));
145
146 return true;
147 }
148
149 } // namespace arc 66 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698