| 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 "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 7 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 8 #include "components/arc/arc_bridge_service.h" | 8 #include "components/arc/arc_bridge_service.h" |
| 9 #include "mojo/public/cpp/bindings/string.h" |
| 9 | 10 |
| 10 namespace arc { | 11 namespace arc { |
| 11 | 12 |
| 12 void GetAndroidAppTargetRect(gfx::Rect& target_rect) { | 13 void GetAndroidAppTargetRect(gfx::Rect& target_rect) { |
| 13 // TODO: Figure out where to put the android window. | 14 // TODO: Figure out where to put the android window. |
| 14 target_rect.SetRect(0, 0, 0, 0); | 15 target_rect.SetRect(0, 0, 0, 0); |
| 15 } | 16 } |
| 16 | 17 |
| 17 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { | 18 bool LaunchApp(content::BrowserContext* context, const std::string& app_id) { |
| 18 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 19 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
| 19 CHECK(prefs); | 20 CHECK(prefs); |
| 20 | 21 |
| 21 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 22 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
| 22 if (!app_info) { | 23 if (!app_info) { |
| 23 VLOG(2) << "Cannot launch unavailable app:" << app_id << "."; | 24 VLOG(2) << "Cannot launch unavailable app: " << app_id << "."; |
| 24 return false; | 25 return false; |
| 25 } | 26 } |
| 26 | 27 |
| 27 if (!app_info->ready) { | 28 if (!app_info->ready) { |
| 28 VLOG(2) << "Cannot launch not-ready app:" << app_id << "."; | 29 VLOG(2) << "Cannot launch not-ready app: " << app_id << "."; |
| 29 return false; | 30 return false; |
| 30 } | 31 } |
| 31 | 32 |
| 32 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 33 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 33 if (!bridge_service) { | 34 if (!bridge_service) { |
| 34 VLOG(2) << "Request to launch app when bridge service is not ready: " | 35 VLOG(2) << "Request to launch app when bridge service is not ready: " |
| 35 << app_id << "."; | 36 << app_id << "."; |
| 36 return false; | 37 return false; |
| 37 } | 38 } |
| 38 arc::AppInstance* app_instance = bridge_service->app_instance(); | 39 arc::AppInstance* app_instance = bridge_service->app_instance(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 app_instance->LaunchApp(app_info->package_name, app_info->activity, | 55 app_instance->LaunchApp(app_info->package_name, app_info->activity, |
| 55 std::move(rect)); | 56 std::move(rect)); |
| 56 prefs->SetLastLaunchTime(app_id, base::Time::Now()); | 57 prefs->SetLastLaunchTime(app_id, base::Time::Now()); |
| 57 | 58 |
| 58 return true; | 59 return true; |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool CanHandleResolution(content::BrowserContext* context, | 62 bool CanHandleResolution(content::BrowserContext* context, |
| 62 const std::string& app_id, | 63 const std::string& app_id, |
| 63 const gfx::Rect& rect, | 64 const gfx::Rect& rect, |
| 64 const CanHandleResolutionCallback callback) { | 65 const CanHandleResolutionCallback& callback) { |
| 65 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); | 66 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context); |
| 66 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); | 67 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id); |
| 67 if (!app_info) { | 68 if (!app_info) { |
| 68 VLOG(2) << "Cannot test resolution capability of unavailable app:" << app_id | 69 VLOG(2) << "Cannot test resolution capability of unavailable app:" << app_id |
| 69 << "."; | 70 << "."; |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 | 73 |
| 73 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 74 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 74 arc::AppInstance* app_instance = | 75 arc::AppInstance* app_instance = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 91 screen_rect->right = rect.right(); | 92 screen_rect->right = rect.right(); |
| 92 screen_rect->top = rect.y(); | 93 screen_rect->top = rect.y(); |
| 93 screen_rect->bottom = rect.bottom(); | 94 screen_rect->bottom = rect.bottom(); |
| 94 | 95 |
| 95 app_instance->CanHandleResolution(app_info->package_name, app_info->activity, | 96 app_instance->CanHandleResolution(app_info->package_name, app_info->activity, |
| 96 std::move(screen_rect), | 97 std::move(screen_rect), |
| 97 callback); | 98 callback); |
| 98 return true; | 99 return true; |
| 99 } | 100 } |
| 100 | 101 |
| 102 void UninstallPackage(const std::string& package_name) { |
| 103 VLOG(2) << "Uninstalling " << package_name; |
| 104 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 105 if (!bridge_service) { |
| 106 VLOG(2) << "Request to uninstall package when bridge service is not ready: " |
| 107 << package_name << "."; |
| 108 return; |
| 109 } |
| 110 arc::AppInstance* app_instance = bridge_service->app_instance(); |
| 111 if (!app_instance) { |
| 112 VLOG(2) << "Request to uninstall package when bridge service is not ready: " |
| 113 << package_name << "."; |
| 114 return; |
| 115 } |
| 116 |
| 117 if (bridge_service->app_version() < 2) { |
| 118 LOG(ERROR) << "Request to uninstall package when version " |
| 119 << bridge_service->app_version() << " does not support it"; |
| 120 return; |
| 121 } |
| 122 app_instance->UninstallPackage(package_name); |
| 123 } |
| 124 |
| 101 } // namespace arc | 125 } // namespace arc |
| OLD | NEW |