OLD | NEW |
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 void FakeArcBridgeService::SetReady() { | 27 void FakeArcBridgeService::SetReady() { |
62 SetState(State::READY); | 28 SetState(State::READY); |
63 } | 29 } |
64 | 30 |
65 void FakeArcBridgeService::SetStopped() { | 31 void FakeArcBridgeService::SetStopped() { |
66 SetState(State::STOPPED); | 32 SetState(State::STOPPED); |
67 } | 33 } |
68 | 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 |
69 bool FakeArcBridgeService::HasObserver(const Observer* observer) { | 62 bool FakeArcBridgeService::HasObserver(const Observer* observer) { |
70 return observer_list().HasObserver(observer); | 63 return observer_list().HasObserver(observer); |
71 } | 64 } |
72 | 65 |
73 bool FakeArcBridgeService::HasAppObserver(const AppObserver* observer) { | |
74 return app_observer_list().HasObserver(observer); | |
75 } | |
76 | |
77 void FakeArcBridgeService::SendRefreshAppList( | |
78 const std::vector<AppInfo>& apps) { | |
79 FOR_EACH_OBSERVER(AppObserver, app_observer_list(), OnAppListRefreshed(apps)); | |
80 } | |
81 | |
82 bool FakeArcBridgeService::GenerateAndSendIcon( | |
83 const AppInfo& app, | |
84 ScaleFactor scale_factor, | |
85 std::string* png_data_as_string) { | |
86 CHECK(png_data_as_string != nullptr); | |
87 std::string icon_file_name; | |
88 switch (scale_factor) { | |
89 case SCALE_FACTOR_SCALE_FACTOR_100P: | |
90 icon_file_name = "icon_100p.png"; | |
91 break; | |
92 case SCALE_FACTOR_SCALE_FACTOR_125P: | |
93 icon_file_name = "icon_125p.png"; | |
94 break; | |
95 case SCALE_FACTOR_SCALE_FACTOR_133P: | |
96 icon_file_name = "icon_133p.png"; | |
97 break; | |
98 case SCALE_FACTOR_SCALE_FACTOR_140P: | |
99 icon_file_name = "icon_140p.png"; | |
100 break; | |
101 case SCALE_FACTOR_SCALE_FACTOR_150P: | |
102 icon_file_name = "icon_150p.png"; | |
103 break; | |
104 case SCALE_FACTOR_SCALE_FACTOR_180P: | |
105 icon_file_name = "icon_180p.png"; | |
106 break; | |
107 case SCALE_FACTOR_SCALE_FACTOR_200P: | |
108 icon_file_name = "icon_200p.png"; | |
109 break; | |
110 case SCALE_FACTOR_SCALE_FACTOR_250P: | |
111 icon_file_name = "icon_250p.png"; | |
112 break; | |
113 case SCALE_FACTOR_SCALE_FACTOR_300P: | |
114 icon_file_name = "icon_300p.png"; | |
115 break; | |
116 default: | |
117 NOTREACHED(); | |
118 return false; | |
119 } | |
120 | |
121 base::FilePath base_path; | |
122 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &base_path)); | |
123 base::FilePath icon_file_path = base_path | |
124 .AppendASCII("components") | |
125 .AppendASCII("test") | |
126 .AppendASCII("data") | |
127 .AppendASCII("arc") | |
128 .AppendASCII(icon_file_name); | |
129 CHECK(base::PathExists(icon_file_path)); | |
130 CHECK(base::ReadFileToString(icon_file_path, png_data_as_string)); | |
131 | |
132 std::vector<uint8_t> png_data(png_data_as_string->begin(), | |
133 png_data_as_string->end()); | |
134 | |
135 FOR_EACH_OBSERVER(AppObserver, | |
136 app_observer_list(), | |
137 OnAppIcon(app.package, | |
138 app.activity, | |
139 scale_factor, | |
140 png_data)); | |
141 | |
142 return true; | |
143 } | |
144 | |
145 } // namespace arc | 66 } // namespace arc |
OLD | NEW |