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/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/app_list/app_list_constants.h" |
| 16 #include "ui/base/layout.h" |
| 17 #include "ui/display/display.h" |
| 18 #include "ui/display/screen.h" |
15 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
16 #include "ui/message_center/notification_blocker.h" | 20 #include "ui/message_center/notification_blocker.h" |
17 | 21 |
18 namespace chromeos { | 22 namespace chromeos { |
19 | 23 |
20 // Timeout maintenance session after 30 minutes. | 24 // Timeout maintenance session after 30 minutes. |
21 constexpr base::TimeDelta kArcKioskMaintenanceSessionTimeout = | 25 constexpr base::TimeDelta kArcKioskMaintenanceSessionTimeout = |
22 base::TimeDelta::FromMinutes(30); | 26 base::TimeDelta::FromMinutes(30); |
23 | 27 |
24 // Blocks all notifications for ARC Kiosk | 28 // Blocks all notifications for ARC Kiosk |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 maintenance_timeout_timer_.Stop(); | 131 maintenance_timeout_timer_.Stop(); |
128 maintenance_session_running_ = false; | 132 maintenance_session_running_ = false; |
129 PreconditionsChanged(); | 133 PreconditionsChanged(); |
130 } | 134 } |
131 | 135 |
132 void ArcKioskAppService::OnAppWindowLaunched() { | 136 void ArcKioskAppService::OnAppWindowLaunched() { |
133 if (delegate_) | 137 if (delegate_) |
134 delegate_->OnAppWindowLaunched(); | 138 delegate_->OnAppWindowLaunched(); |
135 } | 139 } |
136 | 140 |
| 141 void ArcKioskAppService::OnIconUpdated(ArcAppIcon* icon) { |
| 142 DCHECK_EQ(icon, app_icon_.get()); |
| 143 if (icon->image_skia().isNull()) { |
| 144 app_icon_.release(); |
| 145 return; |
| 146 } |
| 147 app_manager_->UpdateNameAndIcon(app_info_->package_name, app_info_->name, |
| 148 app_icon_->image_skia()); |
| 149 } |
| 150 |
137 ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) { | 151 ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) { |
138 ArcAppListPrefs::Get(profile_)->AddObserver(this); | 152 ArcAppListPrefs::Get(profile_)->AddObserver(this); |
139 app_manager_ = ArcKioskAppManager::Get(); | 153 app_manager_ = ArcKioskAppManager::Get(); |
140 DCHECK(app_manager_); | 154 DCHECK(app_manager_); |
141 app_manager_->AddObserver(this); | 155 app_manager_->AddObserver(this); |
142 pref_change_registrar_.reset(new PrefChangeRegistrar()); | 156 pref_change_registrar_.reset(new PrefChangeRegistrar()); |
143 pref_change_registrar_->Init(profile_->GetPrefs()); | 157 pref_change_registrar_->Init(profile_->GetPrefs()); |
144 notification_blocker_.reset(new ArcKioskNotificationBlocker()); | 158 notification_blocker_.reset(new ArcKioskNotificationBlocker()); |
145 PreconditionsChanged(); | 159 PreconditionsChanged(); |
146 } | 160 } |
147 | 161 |
148 ArcKioskAppService::~ArcKioskAppService() { | 162 ArcKioskAppService::~ArcKioskAppService() { |
149 maintenance_timeout_timer_.Stop(); | 163 maintenance_timeout_timer_.Stop(); |
150 } | 164 } |
151 | 165 |
| 166 void ArcKioskAppService::RequestNameAndIconUpdate() { |
| 167 // Request only once when app_icon_ is not initialized. |
| 168 if (!app_info_ || !app_info_->ready || app_icon_) |
| 169 return; |
| 170 app_icon_ = base::MakeUnique<ArcAppIcon>(profile_, app_id_, |
| 171 app_list::kGridIconDimension, this); |
| 172 app_icon_->LoadForScaleFactor(ui::GetSupportedScaleFactor( |
| 173 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor())); |
| 174 // Name and icon are updated when icon is loaded in OnIconUpdated() |
| 175 } |
| 176 |
152 void ArcKioskAppService::PreconditionsChanged() { | 177 void ArcKioskAppService::PreconditionsChanged() { |
153 VLOG(2) << "Preconditions for kiosk app changed"; | 178 VLOG(2) << "Preconditions for kiosk app changed"; |
154 app_id_ = GetAppId(); | 179 app_id_ = GetAppId(); |
155 if (app_id_.empty()) { | 180 if (app_id_.empty()) { |
156 VLOG(2) << "Kiosk app is not available"; | 181 VLOG(2) << "Kiosk app is not available"; |
157 return; | 182 return; |
158 } | 183 } |
159 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_); | 184 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_); |
160 VLOG_IF(2, app_info_ && app_info_->ready) << "Kiosk app is ready"; | 185 VLOG_IF(2, app_info_ && app_info_->ready) << "Kiosk app is ready"; |
161 VLOG(2) << "Maintenance session is " | 186 VLOG(2) << "Maintenance session is " |
162 << (maintenance_session_running_ ? "running" : "not running"); | 187 << (maintenance_session_running_ ? "running" : "not running"); |
163 VLOG(2) << "Kiosk app with id: " << app_id_ << " is " | 188 VLOG(2) << "Kiosk app with id: " << app_id_ << " is " |
164 << (app_launcher_ ? "already launched" : "not yet launched"); | 189 << (app_launcher_ ? "already launched" : "not yet launched"); |
165 if (app_info_ && app_info_->ready && !maintenance_session_running_) { | 190 if (app_info_ && app_info_->ready && !maintenance_session_running_) { |
166 if (!app_launcher_) { | 191 if (!app_launcher_) { |
167 VLOG(2) << "Starting kiosk app"; | 192 VLOG(2) << "Starting kiosk app"; |
168 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>( | 193 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>( |
169 profile_, ArcAppListPrefs::Get(profile_), app_id_, this); | 194 profile_, ArcAppListPrefs::Get(profile_), app_id_, this); |
170 } | 195 } |
171 } else if (task_id_ != -1) { | 196 } else if (task_id_ != -1) { |
172 VLOG(2) << "Kiosk app should be closed"; | 197 VLOG(2) << "Kiosk app should be closed"; |
173 arc::CloseTask(task_id_); | 198 arc::CloseTask(task_id_); |
174 } | 199 } |
| 200 RequestNameAndIconUpdate(); |
175 } | 201 } |
176 | 202 |
177 std::string ArcKioskAppService::GetAppId() { | 203 std::string ArcKioskAppService::GetAppId() { |
178 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); | 204 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); |
179 const ArcKioskAppManager::ArcKioskApp* app = | 205 const ArcKioskAppData* app = app_manager_->GetAppByAccountId(account_id); |
180 app_manager_->GetAppByAccountId(account_id); | |
181 if (!app) | 206 if (!app) |
182 return std::string(); | 207 return std::string(); |
183 std::unordered_set<std::string> app_ids = | 208 std::unordered_set<std::string> app_ids = |
184 ArcAppListPrefs::Get(profile_)->GetAppsForPackage( | 209 ArcAppListPrefs::Get(profile_)->GetAppsForPackage(app->app_id()); |
185 app->app_info().package_name()); | |
186 if (app_ids.empty()) | 210 if (app_ids.empty()) |
187 return std::string(); | 211 return std::string(); |
188 // TODO(poromov@): Choose appropriate app id to launch. See | 212 // TODO(poromov@): Choose appropriate app id to launch. See |
189 // http://crbug.com/665904 | 213 // http://crbug.com/665904 |
190 return std::string(*app_ids.begin()); | 214 return std::string(*app_ids.begin()); |
191 } | 215 } |
192 | 216 |
193 } // namespace chromeos | 217 } // namespace chromeos |
OLD | NEW |