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