OLD | NEW |
---|---|
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 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 // happens. | 46 // happens. |
47 arc::mojom::AppInstance* GetAppInstance(int required_version, | 47 arc::mojom::AppInstance* GetAppInstance(int required_version, |
48 const std::string& service_name) { | 48 const std::string& service_name) { |
49 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 49 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
50 if (!bridge_service) { | 50 if (!bridge_service) { |
51 VLOG(2) << "Request to " << service_name | 51 VLOG(2) << "Request to " << service_name |
52 << " when bridge service is not ready."; | 52 << " when bridge service is not ready."; |
53 return nullptr; | 53 return nullptr; |
54 } | 54 } |
55 | 55 |
56 arc::mojom::AppInstance* app_instance = bridge_service->app_instance(); | 56 arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
57 if (!app_instance) { | 57 if (!app_instance) { |
58 VLOG(2) << "Request to " << service_name | 58 VLOG(2) << "Request to " << service_name |
59 << " when mojom::app_instance is not ready."; | 59 << " when mojom::app_instance is not ready."; |
60 return nullptr; | 60 return nullptr; |
61 } | 61 } |
62 | 62 |
63 int bridge_version = bridge_service->app_version(); | 63 int bridge_version = bridge_service->app()->version(); |
64 if (bridge_version < required_version) { | 64 if (bridge_version < required_version) { |
65 VLOG(2) << "Request to " << service_name << " when Arc version " | 65 VLOG(2) << "Request to " << service_name << " when Arc version " |
66 << bridge_version << " does not support it."; | 66 << bridge_version << " does not support it."; |
67 return nullptr; | 67 return nullptr; |
68 } | 68 } |
69 | 69 |
70 return app_instance; | 70 return app_instance; |
71 } | 71 } |
72 | 72 |
73 // Find a proper size and position for a given rectangle on the screen. | 73 // Find a proper size and position for a given rectangle on the screen. |
(...skipping 28 matching lines...) Expand all Loading... | |
102 } | 102 } |
103 | 103 |
104 // A class which handles the asynchronous ARC runtime callback to figure out if | 104 // A class which handles the asynchronous ARC runtime callback to figure out if |
105 // an app can handle a certain resolution or not. | 105 // an app can handle a certain resolution or not. |
106 // After LaunchAndRelease() got called, the object will destroy itself once | 106 // After LaunchAndRelease() got called, the object will destroy itself once |
107 // done. | 107 // done. |
108 class LaunchAppWithoutSize { | 108 class LaunchAppWithoutSize { |
109 public: | 109 public: |
110 LaunchAppWithoutSize(content::BrowserContext* context, | 110 LaunchAppWithoutSize(content::BrowserContext* context, |
111 const std::string& app_id, | 111 const std::string& app_id, |
112 bool landscape_mode) : | 112 bool landscape_mode) |
113 context_(context), | 113 : context_(context), app_id_(app_id), landscape_mode_(landscape_mode) {} |
114 app_id_(app_id), | |
115 landscape_mode_(landscape_mode) {} | |
116 | 114 |
117 // This will launch the request and after the return the creator does not | 115 // This will launch the request and after the return the creator does not |
118 // need to delete the object anymore. | 116 // need to delete the object anymore. |
119 bool LaunchAndRelease() { | 117 bool LaunchAndRelease() { |
120 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) | 118 landscape_ = landscape_mode_ ? gfx::Rect(0, 0, kNexus7Width, kNexus7Height) |
121 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); | 119 : gfx::Rect(0, 0, kNexus5Width, kNexus5Height); |
122 if (!ash::Shell::HasInstance()) { | 120 if (!ash::Shell::HasInstance()) { |
123 // Skip this if there is no Ash shell. | 121 // Skip this if there is no Ash shell. |
124 LaunchAppWithRect(context_, app_id_, landscape_); | 122 LaunchAppWithRect(context_, app_id_, landscape_); |
125 delete this; | 123 delete this; |
126 return true; | 124 return true; |
127 } | 125 } |
128 | 126 |
129 // TODO(skuhne): Change CanHandleResolution into a call which returns | 127 // TODO(skuhne): Change CanHandleResolution into a call which returns |
130 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which | 128 // capability flags like [PHONE/TABLET]_[LANDSCAPE/PORTRAIT] and which |
131 // might also return the used DP->PIX conversion constant to do better | 129 // might also return the used DP->PIX conversion constant to do better |
132 // size calculations. | 130 // size calculations. |
133 bool result = CanHandleResolution(context_, app_id_, landscape_, | 131 bool result = CanHandleResolution( |
132 context_, app_id_, landscape_, | |
134 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); | 133 base::Bind(&LaunchAppWithoutSize::Callback, base::Unretained(this))); |
135 if (!result) | 134 if (!result) |
136 delete this; | 135 delete this; |
137 | 136 |
138 return result; | 137 return result; |
139 } | 138 } |
140 | 139 |
141 private: | 140 private: |
142 content::BrowserContext* context_; | 141 content::BrowserContext* context_; |
143 const std::string app_id_; | 142 const std::string app_id_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 } else { | 192 } else { |
194 app_instance->LaunchApp(app_info->package_name, app_info->activity, | 193 app_instance->LaunchApp(app_info->package_name, app_info->activity, |
195 target_rect); | 194 target_rect); |
196 } | 195 } |
197 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 196 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
198 | 197 |
199 return true; | 198 return true; |
200 } | 199 } |
201 | 200 |
202 bool LaunchAndroidSettingsApp(content::BrowserContext* context) { | 201 bool LaunchAndroidSettingsApp(content::BrowserContext* context) { |
203 return arc::LaunchApp(context, | 202 return arc::LaunchApp(context, kSettingsAppId, true); // landscape_layout |
hidehiko
2016/07/11 05:24:53
nit: "// landscape_layout" looks to comment for th
Luis Héctor Chávez
2016/07/11 17:13:33
The latter looks nicer.
| |
204 kSettingsAppId, | |
205 true); // landscape_layout | |
206 } | 203 } |
207 | 204 |
208 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { | 205 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { |
209 return LaunchApp(context, app_id, true); | 206 return LaunchApp(context, app_id, true); |
210 } | 207 } |
211 | 208 |
212 bool LaunchApp(content::BrowserContext* context, | 209 bool LaunchApp(content::BrowserContext* context, |
213 const std::string& app_id, | 210 const std::string& app_id, |
214 bool landscape_layout) { | 211 bool landscape_layout) { |
215 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 212 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
216 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 213 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
217 if (app_info && !app_info->ready) { | 214 if (app_info && !app_info->ready) { |
218 if (!ash::Shell::HasInstance()) | 215 if (!ash::Shell::HasInstance()) |
219 return false; | 216 return false; |
220 | 217 |
221 ChromeLauncherController* chrome_controller = | 218 ChromeLauncherController* chrome_controller = |
222 ChromeLauncherController::instance(); | 219 ChromeLauncherController::instance(); |
223 DCHECK(chrome_controller); | 220 DCHECK(chrome_controller); |
224 chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch(app_id); | 221 chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch(app_id); |
225 return true; | 222 return true; |
226 } | 223 } |
227 | 224 |
228 return (new LaunchAppWithoutSize(context, | 225 return (new LaunchAppWithoutSize(context, app_id, landscape_layout)) |
hidehiko
2016/07/11 05:24:53
nit: unnecessary parent?
Luis Héctor Chávez
2016/07/11 17:13:33
it's necessary, unfortunately.
| |
229 app_id, | 226 ->LaunchAndRelease(); |
230 landscape_layout))->LaunchAndRelease(); | |
231 } | 227 } |
232 | 228 |
233 bool CanHandleResolution(content::BrowserContext* context, | 229 bool CanHandleResolution(content::BrowserContext* context, |
234 const std::string& app_id, | 230 const std::string& app_id, |
235 const gfx::Rect& rect, | 231 const gfx::Rect& rect, |
236 const CanHandleResolutionCallback& callback) { | 232 const CanHandleResolutionCallback& callback) { |
237 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 233 const ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
238 DCHECK(prefs); | 234 DCHECK(prefs); |
239 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 235 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
240 if (!app_info) { | 236 if (!app_info) { |
241 VLOG(2) << "Cannot test resolution capability of unavailable app:" << app_id | 237 VLOG(2) << "Cannot test resolution capability of unavailable app:" << app_id |
242 << "."; | 238 << "."; |
243 return false; | 239 return false; |
244 } | 240 } |
245 | 241 |
246 arc::mojom::AppInstance* app_instance = | 242 arc::mojom::AppInstance* app_instance = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 if (!app_instance) | 294 if (!app_instance) |
299 return false; | 295 return false; |
300 | 296 |
301 app_instance->ShowPackageInfoOnPage( | 297 app_instance->ShowPackageInfoOnPage( |
302 package_name, page, | 298 package_name, page, |
303 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); | 299 GetTargetRect(gfx::Size(kNexus7Width, kNexus7Height))); |
304 return true; | 300 return true; |
305 } | 301 } |
306 | 302 |
307 } // namespace arc | 303 } // namespace arc |
OLD | NEW |