Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_utils.cc

Issue 1756193008: Support uninstalling ARC app from Chrome launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 bool UninstallApp(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
128 void OnUninstallAppResponse(const mojo::String& error_message) {
129 if (!error_message.is_null()) {
130 // TODO(victorhsieh): Notify user about the error.
131 LOG(ERROR) << "Failed to uninstall package: " << error_message.get();
132 }
133 }
134
101 } // namespace arc 135 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698