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

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: some nits Created 3 years, 8 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/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
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 app_id_ = GetAppId(); 178 app_id_ = GetAppId();
154 if (app_id_.empty()) 179 if (app_id_.empty())
155 return; 180 return;
156 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_); 181 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_);
157 if (app_info_ && app_info_->ready && !maintenance_session_running_) { 182 if (app_info_ && app_info_->ready && !maintenance_session_running_) {
158 if (!app_launcher_) 183 if (!app_launcher_)
159 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>( 184 app_launcher_ = base::MakeUnique<ArcKioskAppLauncher>(
160 profile_, ArcAppListPrefs::Get(profile_), app_id_, this); 185 profile_, ArcAppListPrefs::Get(profile_), app_id_, this);
161 } else if (task_id_ != -1) { 186 } else if (task_id_ != -1) {
162 arc::CloseTask(task_id_); 187 arc::CloseTask(task_id_);
163 } 188 }
189 RequestNameAndIconUpdate();
164 } 190 }
165 191
166 std::string ArcKioskAppService::GetAppId() { 192 std::string ArcKioskAppService::GetAppId() {
167 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); 193 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_);
168 const ArcKioskAppManager::ArcKioskApp* app = 194 const ArcKioskAppData* app = app_manager_->GetAppByAccountId(account_id);
169 app_manager_->GetAppByAccountId(account_id);
170 if (!app) 195 if (!app)
171 return std::string(); 196 return std::string();
172 std::unordered_set<std::string> app_ids = 197 std::unordered_set<std::string> app_ids =
173 ArcAppListPrefs::Get(profile_)->GetAppsForPackage( 198 ArcAppListPrefs::Get(profile_)->GetAppsForPackage(app->app_id());
174 app->app_info().package_name());
175 if (app_ids.empty()) 199 if (app_ids.empty())
176 return std::string(); 200 return std::string();
177 // TODO(poromov@): Choose appropriate app id to launch. See 201 // TODO(poromov@): Choose appropriate app id to launch. See
178 // http://crbug.com/665904 202 // http://crbug.com/665904
179 return std::string(*app_ids.begin()); 203 return std::string(*app_ids.begin());
180 } 204 }
181 205
182 } // namespace chromeos 206 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698