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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/chromeos/arc/arc_util.h" | 15 #include "chrome/browser/chromeos/arc/arc_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 17 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
18 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" | 18 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
19 #include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h" | 19 #include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h" |
20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
21 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
22 #include "chromeos/dbus/session_manager_client.h" | 22 #include "chromeos/dbus/session_manager_client.h" |
23 #include "components/arc/arc_bridge_service.h" | 23 #include "components/arc/arc_bridge_service.h" |
24 #include "components/arc/arc_service_manager.h" | 24 #include "components/arc/arc_service_manager.h" |
25 #include "components/arc/arc_util.h" | |
25 #include "components/arc/common/intent_helper.mojom.h" | 26 #include "components/arc/common/intent_helper.mojom.h" |
26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
27 #include "ui/display/display.h" | 28 #include "ui/display/display.h" |
28 #include "ui/display/screen.h" | 29 #include "ui/display/screen.h" |
29 #include "ui/events/event_constants.h" | 30 #include "ui/events/event_constants.h" |
30 | 31 |
31 // Helper macro which returns the AppInstance. | 32 // Helper macro which returns the AppInstance. |
32 #define GET_APP_INSTANCE(method_name) \ | 33 #define GET_APP_INSTANCE(method_name) \ |
33 (arc::ArcServiceManager::Get() \ | 34 (arc::ArcServiceManager::Get() \ |
34 ? ARC_GET_INSTANCE_FOR_METHOD( \ | 35 ? ARC_GET_INSTANCE_FOR_METHOD( \ |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 } | 261 } |
261 | 262 |
262 bool LaunchApp(content::BrowserContext* context, | 263 bool LaunchApp(content::BrowserContext* context, |
263 const std::string& app_id, | 264 const std::string& app_id, |
264 bool landscape_layout, | 265 bool landscape_layout, |
265 int event_flags) { | 266 int event_flags) { |
266 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 267 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
267 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 268 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
268 if (app_info && !app_info->ready) { | 269 if (app_info && !app_info->ready) { |
269 Profile* profile = Profile::FromBrowserContext(context); | 270 Profile* profile = Profile::FromBrowserContext(context); |
270 bool play_store_activated = false; | 271 |
hidehiko
2017/03/02 15:57:51
Dropping this changes the behavior in case Google
victorhsieh
2017/03/02 18:49:52
Yury and I had an offline discussion, then realize
| |
271 if (!IsArcPlayStoreEnabledForProfile(profile)) { | 272 if (!IsArcPlayStoreEnabledForProfile(profile)) { |
272 if (!prefs->IsDefault(app_id)) { | 273 if (prefs->IsDefault(app_id)) { |
273 NOTREACHED(); | 274 SetArcPlayStoreEnabledForProfile(profile, true); |
274 return false; | 275 if (!IsArcPlayStoreEnabledForProfile(profile)) { |
276 NOTREACHED(); | |
277 return false; | |
278 } | |
279 | |
280 // PlayStore item has special handling for shelf controllers. In order | |
281 // to avoid unwanted initial animation for PlayStore item do not create | |
282 // deferred launch request when PlayStore item enables Google Play | |
283 // Store. | |
284 if (app_id == kPlayStoreAppId) { | |
285 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | |
286 return true; | |
287 } | |
288 } else { | |
289 if (!arc::ShouldArcAlwaysStart()) { | |
290 NOTREACHED(); | |
291 return false; | |
292 } | |
275 } | 293 } |
276 | |
277 SetArcPlayStoreEnabledForProfile(profile, true); | |
278 if (!IsArcPlayStoreEnabledForProfile(profile)) { | |
279 NOTREACHED(); | |
280 return false; | |
281 } | |
282 play_store_activated = true; | |
283 } | 294 } |
284 | 295 |
285 // PlayStore item has special handling for shelf controllers. In order to | 296 ChromeLauncherController* chrome_controller = |
286 // avoid unwanted initial animation for PlayStore item do not create | 297 ChromeLauncherController::instance(); |
287 // deferred launch request when PlayStore item enables Google Play Store. | 298 DCHECK(chrome_controller || !ash::Shell::HasInstance()); |
288 if (!play_store_activated || app_id != kPlayStoreAppId) { | 299 if (chrome_controller) { |
289 ChromeLauncherController* chrome_controller = | 300 chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch( |
290 ChromeLauncherController::instance(); | 301 app_id, event_flags); |
291 DCHECK(chrome_controller || !ash::Shell::HasInstance()); | |
292 if (chrome_controller) { | |
293 chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch( | |
294 app_id, event_flags); | |
295 | 302 |
296 // On some boards, ARC is booted with a restricted set of resources by | 303 // On some boards, ARC is booted with a restricted set of resources by |
297 // default to avoid slowing down Chrome's user session restoration. | 304 // default to avoid slowing down Chrome's user session restoration. |
298 // However, the restriction should be lifted once the user explicitly | 305 // However, the restriction should be lifted once the user explicitly |
299 // tries to launch an ARC app. | 306 // tries to launch an ARC app. |
300 VLOG(2) << "Prioritizing the instance"; | 307 VLOG(2) << "Prioritizing the instance"; |
301 chromeos::SessionManagerClient* session_manager_client = | 308 chromeos::SessionManagerClient* session_manager_client = |
302 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 309 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
303 session_manager_client->SetArcCpuRestriction( | 310 session_manager_client->SetArcCpuRestriction( |
304 login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND, | 311 login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND, |
305 base::Bind(SetArcCpuRestrictionCallback)); | 312 base::Bind(SetArcCpuRestrictionCallback)); |
306 } | |
307 } | 313 } |
308 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 314 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
309 return true; | 315 return true; |
310 } | 316 } |
311 | |
312 return (new LaunchAppWithoutSize(context, app_id, landscape_layout, | 317 return (new LaunchAppWithoutSize(context, app_id, landscape_layout, |
313 event_flags)) | 318 event_flags)) |
314 ->LaunchAndRelease(); | 319 ->LaunchAndRelease(); |
315 } | 320 } |
316 | 321 |
317 void SetTaskActive(int task_id) { | 322 void SetTaskActive(int task_id) { |
318 arc::mojom::AppInstance* app_instance = GET_APP_INSTANCE(SetTaskActive); | 323 arc::mojom::AppInstance* app_instance = GET_APP_INSTANCE(SetTaskActive); |
319 if (!app_instance) | 324 if (!app_instance) |
320 return; | 325 return; |
321 app_instance->SetTaskActive(task_id); | 326 app_instance->SetTaskActive(task_id); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 return false; | 439 return false; |
435 | 440 |
436 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(context); | 441 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(context); |
437 if (!arc_prefs) | 442 if (!arc_prefs) |
438 return false; | 443 return false; |
439 | 444 |
440 return arc_prefs->IsRegistered(ArcAppShelfId::FromString(id).app_id()); | 445 return arc_prefs->IsRegistered(ArcAppShelfId::FromString(id).app_id()); |
441 } | 446 } |
442 | 447 |
443 } // namespace arc | 448 } // namespace arc |
OLD | NEW |