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" | |
19 #include "ui/message_center/message_center.h" | 15 #include "ui/message_center/message_center.h" |
20 #include "ui/message_center/notification_blocker.h" | 16 #include "ui/message_center/notification_blocker.h" |
21 | 17 |
22 namespace chromeos { | 18 namespace chromeos { |
23 | 19 |
24 // Timeout maintenance session after 30 minutes. | 20 // Timeout maintenance session after 30 minutes. |
25 constexpr base::TimeDelta kArcKioskMaintenanceSessionTimeout = | 21 constexpr base::TimeDelta kArcKioskMaintenanceSessionTimeout = |
26 base::TimeDelta::FromMinutes(30); | 22 base::TimeDelta::FromMinutes(30); |
27 | 23 |
28 // Blocks all notifications for ARC Kiosk | 24 // Blocks all notifications for ARC Kiosk |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 maintenance_timeout_timer_.Stop(); | 127 maintenance_timeout_timer_.Stop(); |
132 maintenance_session_running_ = false; | 128 maintenance_session_running_ = false; |
133 PreconditionsChanged(); | 129 PreconditionsChanged(); |
134 } | 130 } |
135 | 131 |
136 void ArcKioskAppService::OnAppWindowLaunched() { | 132 void ArcKioskAppService::OnAppWindowLaunched() { |
137 if (delegate_) | 133 if (delegate_) |
138 delegate_->OnAppWindowLaunched(); | 134 delegate_->OnAppWindowLaunched(); |
139 } | 135 } |
140 | 136 |
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 | |
151 ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) { | 137 ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) { |
152 ArcAppListPrefs::Get(profile_)->AddObserver(this); | 138 ArcAppListPrefs::Get(profile_)->AddObserver(this); |
153 app_manager_ = ArcKioskAppManager::Get(); | 139 app_manager_ = ArcKioskAppManager::Get(); |
154 DCHECK(app_manager_); | 140 DCHECK(app_manager_); |
155 app_manager_->AddObserver(this); | 141 app_manager_->AddObserver(this); |
156 pref_change_registrar_.reset(new PrefChangeRegistrar()); | 142 pref_change_registrar_.reset(new PrefChangeRegistrar()); |
157 pref_change_registrar_->Init(profile_->GetPrefs()); | 143 pref_change_registrar_->Init(profile_->GetPrefs()); |
158 notification_blocker_.reset(new ArcKioskNotificationBlocker()); | 144 notification_blocker_.reset(new ArcKioskNotificationBlocker()); |
159 PreconditionsChanged(); | 145 PreconditionsChanged(); |
160 } | 146 } |
161 | 147 |
162 ArcKioskAppService::~ArcKioskAppService() { | 148 ArcKioskAppService::~ArcKioskAppService() { |
163 maintenance_timeout_timer_.Stop(); | 149 maintenance_timeout_timer_.Stop(); |
164 } | 150 } |
165 | 151 |
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 | |
177 void ArcKioskAppService::PreconditionsChanged() { | 152 void ArcKioskAppService::PreconditionsChanged() { |
178 app_id_ = GetAppId(); | 153 app_id_ = GetAppId(); |
179 if (app_id_.empty()) | 154 if (app_id_.empty()) |
180 return; | 155 return; |
181 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_); | 156 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_); |
182 if (app_info_ && app_info_->ready && !maintenance_session_running_) { | 157 if (app_info_ && app_info_->ready && !maintenance_session_running_) { |
183 if (!app_launcher_) | 158 if (!app_launcher_) |
184 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>( | 159 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>( |
185 profile_, ArcAppListPrefs::Get(profile_), app_id_, this); | 160 profile_, ArcAppListPrefs::Get(profile_), app_id_, this); |
186 } else if (task_id_ != -1) { | 161 } else if (task_id_ != -1) { |
187 arc::CloseTask(task_id_); | 162 arc::CloseTask(task_id_); |
188 } | 163 } |
189 RequestNameAndIconUpdate(); | |
190 } | 164 } |
191 | 165 |
192 std::string ArcKioskAppService::GetAppId() { | 166 std::string ArcKioskAppService::GetAppId() { |
193 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); | 167 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); |
194 const ArcKioskAppData* app = app_manager_->GetAppByAccountId(account_id); | 168 const ArcKioskAppManager::ArcKioskApp* app = |
| 169 app_manager_->GetAppByAccountId(account_id); |
195 if (!app) | 170 if (!app) |
196 return std::string(); | 171 return std::string(); |
197 std::unordered_set<std::string> app_ids = | 172 std::unordered_set<std::string> app_ids = |
198 ArcAppListPrefs::Get(profile_)->GetAppsForPackage(app->app_id()); | 173 ArcAppListPrefs::Get(profile_)->GetAppsForPackage( |
| 174 app->app_info().package_name()); |
199 if (app_ids.empty()) | 175 if (app_ids.empty()) |
200 return std::string(); | 176 return std::string(); |
201 // TODO(poromov@): Choose appropriate app id to launch. See | 177 // TODO(poromov@): Choose appropriate app id to launch. See |
202 // http://crbug.com/665904 | 178 // http://crbug.com/665904 |
203 return std::string(*app_ids.begin()); | 179 return std::string(*app_ids.begin()); |
204 } | 180 } |
205 | 181 |
206 } // namespace chromeos | 182 } // namespace chromeos |
OLD | NEW |