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