Chromium Code Reviews| 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 |
| 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 // When managed, writting to the preference may be blocked. In reality, |
| 276 // other logics prevent us from reaching here in that case. | |
|
stevenjb
2017/03/03 18:59:06
I'm not sure I follow. Isn't managed part of 'real
victorhsieh
2017/03/03 19:04:18
IIUC, this code is never called because other code
stevenjb
2017/03/03 20:00:10
If that is true, great, it just wasn't entirely cl
victorhsieh
2017/03/03 20:42:46
Re-worded. Hopefully it's more clear.
| |
| 277 DCHECK(IsArcPlayStoreEnabledForProfile(profile)); | |
| 278 | |
| 279 // PlayStore item has special handling for shelf controllers. In order | |
| 280 // to avoid unwanted initial animation for PlayStore item do not create | |
| 281 // deferred launch request when PlayStore item enables Google Play | |
| 282 // Store. | |
| 283 if (app_id == kPlayStoreAppId) { | |
| 284 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | |
| 285 return true; | |
| 286 } | |
| 287 } else { | |
| 288 // Only reachable when ARC always starts. | |
| 289 DCHECK(arc::ShouldArcAlwaysStart()); | |
| 275 } | 290 } |
| 276 | |
| 277 SetArcPlayStoreEnabledForProfile(profile, true); | |
| 278 if (!IsArcPlayStoreEnabledForProfile(profile)) { | |
| 279 NOTREACHED(); | |
| 280 return false; | |
| 281 } | |
| 282 play_store_activated = true; | |
| 283 } | 291 } |
| 284 | 292 |
| 285 // PlayStore item has special handling for shelf controllers. In order to | 293 ChromeLauncherController* chrome_controller = |
| 286 // avoid unwanted initial animation for PlayStore item do not create | 294 ChromeLauncherController::instance(); |
| 287 // deferred launch request when PlayStore item enables Google Play Store. | 295 DCHECK(chrome_controller || !ash::Shell::HasInstance()); |
| 288 if (!play_store_activated || app_id != kPlayStoreAppId) { | 296 if (chrome_controller) { |
| 289 ChromeLauncherController* chrome_controller = | 297 chrome_controller->GetArcDeferredLauncher()->RegisterDeferredLaunch( |
| 290 ChromeLauncherController::instance(); | 298 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 | 299 |
| 296 // On some boards, ARC is booted with a restricted set of resources by | 300 // On some boards, ARC is booted with a restricted set of resources by |
| 297 // default to avoid slowing down Chrome's user session restoration. | 301 // default to avoid slowing down Chrome's user session restoration. |
| 298 // However, the restriction should be lifted once the user explicitly | 302 // However, the restriction should be lifted once the user explicitly |
| 299 // tries to launch an ARC app. | 303 // tries to launch an ARC app. |
| 300 VLOG(2) << "Prioritizing the instance"; | 304 VLOG(2) << "Prioritizing the instance"; |
| 301 chromeos::SessionManagerClient* session_manager_client = | 305 chromeos::SessionManagerClient* session_manager_client = |
| 302 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 306 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| 303 session_manager_client->SetArcCpuRestriction( | 307 session_manager_client->SetArcCpuRestriction( |
| 304 login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND, | 308 login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND, |
| 305 base::Bind(SetArcCpuRestrictionCallback)); | 309 base::Bind(SetArcCpuRestrictionCallback)); |
| 306 } | |
| 307 } | 310 } |
| 308 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 311 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
| 309 return true; | 312 return true; |
| 310 } | 313 } |
| 311 | |
| 312 return (new LaunchAppWithoutSize(context, app_id, landscape_layout, | 314 return (new LaunchAppWithoutSize(context, app_id, landscape_layout, |
| 313 event_flags)) | 315 event_flags)) |
| 314 ->LaunchAndRelease(); | 316 ->LaunchAndRelease(); |
| 315 } | 317 } |
| 316 | 318 |
| 317 void SetTaskActive(int task_id) { | 319 void SetTaskActive(int task_id) { |
| 318 arc::mojom::AppInstance* app_instance = GET_APP_INSTANCE(SetTaskActive); | 320 arc::mojom::AppInstance* app_instance = GET_APP_INSTANCE(SetTaskActive); |
| 319 if (!app_instance) | 321 if (!app_instance) |
| 320 return; | 322 return; |
| 321 app_instance->SetTaskActive(task_id); | 323 app_instance->SetTaskActive(task_id); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 return false; | 436 return false; |
| 435 | 437 |
| 436 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(context); | 438 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(context); |
| 437 if (!arc_prefs) | 439 if (!arc_prefs) |
| 438 return false; | 440 return false; |
| 439 | 441 |
| 440 return arc_prefs->IsRegistered(ArcAppShelfId::FromString(id).app_id()); | 442 return arc_prefs->IsRegistered(ArcAppShelfId::FromString(id).app_id()); |
| 441 } | 443 } |
| 442 | 444 |
| 443 } // namespace arc | 445 } // namespace arc |
| OLD | NEW |