Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h> | |
| 6 | |
| 7 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/profiles/profile_manager.h" | |
| 10 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | |
| 11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | |
| 12 #include "chrome/common/pref_names.h" | |
| 13 #include "components/prefs/pref_service.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 ArcKioskAppService* ArcKioskAppService::Create(Profile* profile, | |
|
Luis Héctor Chávez
2016/11/16 16:37:12
nit: this needs a // static comment before. Same f
Sergey Poromov
2016/11/16 17:42:14
Done.
| |
| 18 ArcAppListPrefs* prefs) { | |
| 19 return new ArcKioskAppService(profile, prefs); | |
| 20 } | |
| 21 | |
| 22 ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) { | |
| 23 return ArcKioskAppServiceFactory::GetForBrowserContext(context); | |
| 24 } | |
| 25 | |
| 26 void ArcKioskAppService::OnAppRegistered( | |
| 27 const std::string& app_id, | |
| 28 const ArcAppListPrefs::AppInfo& app_info) { | |
| 29 if (app_id == app_id_) { | |
|
Luis Héctor Chávez
2016/11/16 16:37:12
nit: elide braces
Sergey Poromov
2016/11/16 17:42:14
Done.
| |
| 30 MaybeStartOrStopKioskApp(); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 void ArcKioskAppService::OnAppReadyChanged(const std::string& id, bool ready) { | |
| 35 if (id == app_id_) { | |
| 36 MaybeStartOrStopKioskApp(); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 void ArcKioskAppService::OnPackageListInitialRefreshed() { | |
| 41 // The app could already be registered. | |
| 42 app_id_ = GetAppId(); | |
| 43 MaybeStartOrStopKioskApp(); | |
| 44 } | |
| 45 | |
| 46 void ArcKioskAppService::OnArcKioskAppsChanged() { | |
| 47 app_id_ = GetAppId(); | |
| 48 MaybeStartOrStopKioskApp(); | |
| 49 } | |
| 50 | |
| 51 void ArcKioskAppService::OnTaskCreated(int32_t task_id, | |
| 52 const std::string& package_name, | |
| 53 const std::string& activity) { | |
| 54 // Store task id of the app to stop it later when needed. | |
| 55 if (app_info_ && package_name == app_info_->package_name && | |
| 56 activity == app_info_->activity) | |
|
Luis Héctor Chávez
2016/11/16 16:37:12
nit: you cannot elide braces if the condition span
Sergey Poromov
2016/11/16 17:42:14
Done.
| |
| 57 task_id_ = task_id; | |
| 58 } | |
| 59 | |
| 60 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) { | |
| 61 if (task_id == task_id_) { | |
| 62 app_launcher_.reset(); | |
| 63 task_id_ = -1; | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs) | |
| 68 : profile_(profile), prefs_(prefs) { | |
| 69 if (prefs_) | |
| 70 prefs_->AddObserver(this); | |
| 71 app_manager_ = ArcKioskAppManager::Get(); | |
| 72 if (app_manager_) { | |
| 73 app_manager_->AddObserver(this); | |
| 74 app_id_ = GetAppId(); | |
| 75 } | |
| 76 pref_change_registrar_.reset(new PrefChangeRegistrar()); | |
| 77 pref_change_registrar_->Init(profile_->GetPrefs()); | |
| 78 // Try to start/stop kiosk app on policy compliance state change. | |
| 79 pref_change_registrar_->Add( | |
| 80 prefs::kArcPolicyCompliant, | |
| 81 base::Bind(&ArcKioskAppService::MaybeStartOrStopKioskApp, | |
| 82 base::Unretained(this))); | |
| 83 MaybeStartOrStopKioskApp(); | |
| 84 } | |
| 85 | |
| 86 ArcKioskAppService::~ArcKioskAppService() { | |
| 87 if (prefs_) { | |
|
Luis Héctor Chávez
2016/11/16 16:37:12
nit: elide braces, since you've been doing it in t
Sergey Poromov
2016/11/16 17:42:14
Done.
| |
| 88 prefs_->RemoveObserver(this); | |
| 89 } | |
| 90 if (app_manager_) { | |
| 91 app_manager_->RemoveObserver(this); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 void ArcKioskAppService::MaybeStartOrStopKioskApp() { | |
| 96 app_info_ = std::move(prefs_->GetApp(app_id_)); | |
|
Luis Héctor Chávez
2016/11/16 16:37:12
pref_->GetApp(...) is an rvalue. std::move() shoul
Sergey Poromov
2016/11/16 17:42:14
Done.
| |
| 97 if (app_info_ && app_info_->ready && | |
| 98 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) { | |
| 99 if (!app_launcher_) { | |
| 100 app_launcher_.reset(new ArcKioskAppLauncher(profile_, app_id_)); | |
| 101 } | |
| 102 } else if (task_id_ != -1) { | |
| 103 arc::CloseTask(task_id_); | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 std::string ArcKioskAppService::GetAppId() { | |
| 108 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); | |
| 109 const ArcKioskAppManager::ArcKioskApp* app = | |
| 110 app_manager_->GetAppByAccountId(account_id); | |
| 111 if (app) { | |
|
Luis Héctor Chávez
2016/11/16 16:37:12
nit:
if (!app)
return std::string();
// Rest o
Sergey Poromov
2016/11/16 17:42:14
Done.
| |
| 112 std::unordered_set<std::string> app_ids = | |
| 113 prefs_->GetAppsForPackage(app->app_info().package_name()); | |
| 114 if (!app_ids.empty()) { | |
|
Luis Héctor Chávez
2016/11/16 16:37:12
nit:
if (app_ids.empty())
return std::string();
Sergey Poromov
2016/11/16 17:42:14
Done.
| |
| 115 // TODO(poromov@): Choose appropriate app id to launch. See | |
| 116 // http://crbug.com/665904 | |
| 117 return std::string(*app_ids.begin()); | |
| 118 } | |
| 119 } | |
| 120 return std::string(); | |
| 121 } | |
| 122 } // namespace chromeos | |
| OLD | NEW |