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

Side by Side Diff: chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc

Issue 2778053002: Fetch ARC Kiosk app name and icon from Android side. (Closed)
Patch Set: Created 3 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/chromeos/app_mode/arc/arc_kiosk_app_service.h> 5 #include <chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h>
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h" 8 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 11 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 12 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "components/prefs/pref_service.h" 14 #include "components/prefs/pref_service.h"
15 #include "ui/base/layout.h"
16 #include "ui/display/display.h"
17 #include "ui/display/screen.h"
15 #include "ui/message_center/message_center.h" 18 #include "ui/message_center/message_center.h"
16 #include "ui/message_center/notification_blocker.h" 19 #include "ui/message_center/notification_blocker.h"
17 20
18 namespace chromeos { 21 namespace chromeos {
19 22
23 namespace {
24
20 // Timeout maintenance session after 30 minutes. 25 // Timeout maintenance session after 30 minutes.
21 constexpr base::TimeDelta kArcKioskMaintenanceSessionTimeout = 26 constexpr base::TimeDelta kArcKioskMaintenanceSessionTimeout =
22 base::TimeDelta::FromMinutes(30); 27 base::TimeDelta::FromMinutes(30);
23 28
29 // ARC icon is available only for 48x48 dips.
30 constexpr int kArcAppIconSizeInDp = 48;
khmel 2017/03/27 22:56:32 nit: Probably it is better to use kGridIconDimensi
Sergey Poromov 2017/03/28 15:25:55 Done.
31
32 } // namespace
33
24 // Blocks all notifications for ARC Kiosk 34 // Blocks all notifications for ARC Kiosk
25 class ArcKioskNotificationBlocker : public message_center::NotificationBlocker { 35 class ArcKioskNotificationBlocker : public message_center::NotificationBlocker {
26 public: 36 public:
27 ArcKioskNotificationBlocker() 37 ArcKioskNotificationBlocker()
28 : message_center::NotificationBlocker( 38 : message_center::NotificationBlocker(
29 message_center::MessageCenter::Get()) { 39 message_center::MessageCenter::Get()) {
30 NotifyBlockingStateChanged(); 40 NotifyBlockingStateChanged();
31 } 41 }
32 42
33 ~ArcKioskNotificationBlocker() override {} 43 ~ArcKioskNotificationBlocker() override {}
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 maintenance_timeout_timer_.Stop(); 137 maintenance_timeout_timer_.Stop();
128 maintenance_session_running_ = false; 138 maintenance_session_running_ = false;
129 PreconditionsChanged(); 139 PreconditionsChanged();
130 } 140 }
131 141
132 void ArcKioskAppService::OnAppWindowLaunched() { 142 void ArcKioskAppService::OnAppWindowLaunched() {
133 if (delegate_) 143 if (delegate_)
134 delegate_->OnAppWindowLaunched(); 144 delegate_->OnAppWindowLaunched();
135 } 145 }
136 146
147 void ArcKioskAppService::OnIconUpdated(ArcAppIcon* icon) {
148 if (icon == app_icon_.get()) {
khmel 2017/03/27 22:56:32 nit: Do you expect OnIconUpdated is called for not
Sergey Poromov 2017/03/28 15:25:55 Yes, now it's requested mostly once at any time. I
149 if (icon->image_skia().isNull()) {
150 app_icon_.release();
151 return;
152 }
153 app_manager_->UpdateNameAndIcon(app_info_->package_name, app_info_->name,
154 app_icon_->image_skia());
155 }
156 }
157
137 ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) { 158 ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) {
138 ArcAppListPrefs::Get(profile_)->AddObserver(this); 159 ArcAppListPrefs::Get(profile_)->AddObserver(this);
139 app_manager_ = ArcKioskAppManager::Get(); 160 app_manager_ = ArcKioskAppManager::Get();
140 DCHECK(app_manager_); 161 DCHECK(app_manager_);
141 app_manager_->AddObserver(this); 162 app_manager_->AddObserver(this);
142 pref_change_registrar_.reset(new PrefChangeRegistrar()); 163 pref_change_registrar_.reset(new PrefChangeRegistrar());
143 pref_change_registrar_->Init(profile_->GetPrefs()); 164 pref_change_registrar_->Init(profile_->GetPrefs());
144 notification_blocker_.reset(new ArcKioskNotificationBlocker()); 165 notification_blocker_.reset(new ArcKioskNotificationBlocker());
145 PreconditionsChanged(); 166 PreconditionsChanged();
146 } 167 }
147 168
148 ArcKioskAppService::~ArcKioskAppService() { 169 ArcKioskAppService::~ArcKioskAppService() {
149 maintenance_timeout_timer_.Stop(); 170 maintenance_timeout_timer_.Stop();
150 } 171 }
151 172
173 void ArcKioskAppService::RequestNameAndIconUpdate() {
174 // Request only once when app_icon_ is not initialized.
175 if (!app_info_ || !app_info_->ready || app_icon_)
176 return;
177 app_icon_.reset(new ArcAppIcon(profile_, app_id_, kArcAppIconSizeInDp, this));
178 app_icon_->LoadForScaleFactor(ui::GetSupportedScaleFactor(
179 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor()));
180 // Name and icon are updated when icon is loaded in OnIconUpdated()
181 }
182
152 void ArcKioskAppService::PreconditionsChanged() { 183 void ArcKioskAppService::PreconditionsChanged() {
153 app_id_ = GetAppId(); 184 app_id_ = GetAppId();
154 if (app_id_.empty()) 185 if (app_id_.empty())
155 return; 186 return;
156 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_); 187 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_);
157 if (app_info_ && app_info_->ready && !maintenance_session_running_) { 188 if (app_info_ && app_info_->ready && !maintenance_session_running_) {
158 if (!app_launcher_) 189 if (!app_launcher_)
159 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>( 190 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>(
160 profile_, ArcAppListPrefs::Get(profile_), app_id_, this); 191 profile_, ArcAppListPrefs::Get(profile_), app_id_, this);
161 } else if (task_id_ != -1) { 192 } else if (task_id_ != -1) {
162 arc::CloseTask(task_id_); 193 arc::CloseTask(task_id_);
163 } 194 }
195 RequestNameAndIconUpdate();
164 } 196 }
165 197
166 std::string ArcKioskAppService::GetAppId() { 198 std::string ArcKioskAppService::GetAppId() {
167 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); 199 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_);
168 const ArcKioskAppManager::ArcKioskApp* app = 200 const ArcKioskAppData* app = app_manager_->GetAppByAccountId(account_id);
169 app_manager_->GetAppByAccountId(account_id);
170 if (!app) 201 if (!app)
171 return std::string(); 202 return std::string();
172 std::unordered_set<std::string> app_ids = 203 std::unordered_set<std::string> app_ids =
173 ArcAppListPrefs::Get(profile_)->GetAppsForPackage( 204 ArcAppListPrefs::Get(profile_)->GetAppsForPackage(app->app_id());
174 app->app_info().package_name());
175 if (app_ids.empty()) 205 if (app_ids.empty())
176 return std::string(); 206 return std::string();
177 // TODO(poromov@): Choose appropriate app id to launch. See 207 // TODO(poromov@): Choose appropriate app id to launch. See
178 // http://crbug.com/665904 208 // http://crbug.com/665904
179 return std::string(*app_ids.begin()); 209 return std::string(*app_ids.begin());
180 } 210 }
181 211
182 } // namespace chromeos 212 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698