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

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

Issue 2524673003: arc: Stop/start ARC++ kiosk app when maintenance session started/finished. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ArcAppListPrefs* from ArcKioskAppService and nits. Created 4 years 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 "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h" 7 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/app_list/arc/arc_app_utils.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" 11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "components/prefs/pref_service.h" 13 #include "components/prefs/pref_service.h"
14 14
15 namespace chromeos { 15 namespace chromeos {
16 16
17 // static 17 // static
18 ArcKioskAppService* ArcKioskAppService::Create(Profile* profile, 18 ArcKioskAppService* ArcKioskAppService::Create(Profile* profile) {
19 ArcAppListPrefs* prefs) { 19 return new ArcKioskAppService(profile);
20 return new ArcKioskAppService(profile, prefs);
21 } 20 }
22 21
23 // static 22 // static
24 ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) { 23 ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) {
25 return ArcKioskAppServiceFactory::GetForBrowserContext(context); 24 return ArcKioskAppServiceFactory::GetForBrowserContext(context);
26 } 25 }
27 26
27 void ArcKioskAppService::Shutdown() {
28 ArcAppListPrefs::Get(profile_)->RemoveObserver(this);
29 if (app_manager_)
30 app_manager_->RemoveObserver(this);
31 }
32
28 void ArcKioskAppService::OnAppRegistered( 33 void ArcKioskAppService::OnAppRegistered(
29 const std::string& app_id, 34 const std::string& app_id,
30 const ArcAppListPrefs::AppInfo& app_info) { 35 const ArcAppListPrefs::AppInfo& app_info) {
31 if (app_id == app_id_) 36 if (app_id == app_id_)
32 PreconditionsChanged(); 37 PreconditionsChanged();
33 } 38 }
34 39
35 void ArcKioskAppService::OnAppReadyChanged(const std::string& id, bool ready) { 40 void ArcKioskAppService::OnAppReadyChanged(const std::string& id, bool ready) {
36 if (id == app_id_) 41 if (id == app_id_)
37 PreconditionsChanged(); 42 PreconditionsChanged();
(...skipping 21 matching lines...) Expand all
59 } 64 }
60 } 65 }
61 66
62 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) { 67 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) {
63 if (task_id == task_id_) { 68 if (task_id == task_id_) {
64 app_launcher_.reset(); 69 app_launcher_.reset();
65 task_id_ = -1; 70 task_id_ = -1;
66 } 71 }
67 } 72 }
68 73
69 ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs) 74 void ArcKioskAppService::OnMaintenanceSessionCreated() {
70 : profile_(profile), prefs_(prefs) { 75 maintenance_session_running_ = true;
71 if (prefs_) 76 PreconditionsChanged();
72 prefs_->AddObserver(this); 77 }
78
79 void ArcKioskAppService::OnMaintenanceSessionFinished() {
80 maintenance_session_running_ = false;
81 PreconditionsChanged();
82 }
83
84 ArcKioskAppService::ArcKioskAppService(Profile* profile)
85 : profile_(profile), maintenance_session_running_(false) {
Luis Héctor Chávez 2016/12/16 16:33:46 nit: you can initialize |maintentance_session_runn
Sergey Poromov 2016/12/16 17:00:30 Done.
86 ArcAppListPrefs::Get(profile_)->AddObserver(this);
73 app_manager_ = ArcKioskAppManager::Get(); 87 app_manager_ = ArcKioskAppManager::Get();
74 if (app_manager_) { 88 if (app_manager_) {
75 app_manager_->AddObserver(this); 89 app_manager_->AddObserver(this);
76 app_id_ = GetAppId(); 90 app_id_ = GetAppId();
77 } 91 }
78 pref_change_registrar_.reset(new PrefChangeRegistrar()); 92 pref_change_registrar_.reset(new PrefChangeRegistrar());
79 pref_change_registrar_->Init(profile_->GetPrefs()); 93 pref_change_registrar_->Init(profile_->GetPrefs());
80 // Try to start/stop kiosk app on policy compliance state change. 94 // Try to start/stop kiosk app on policy compliance state change.
81 pref_change_registrar_->Add( 95 pref_change_registrar_->Add(
82 prefs::kArcPolicyCompliant, 96 prefs::kArcPolicyCompliant,
83 base::Bind(&ArcKioskAppService::PreconditionsChanged, 97 base::Bind(&ArcKioskAppService::PreconditionsChanged,
84 base::Unretained(this))); 98 base::Unretained(this)));
85 PreconditionsChanged(); 99 PreconditionsChanged();
86 } 100 }
87 101
88 ArcKioskAppService::~ArcKioskAppService() { 102 ArcKioskAppService::~ArcKioskAppService() = default;
89 if (prefs_)
90 prefs_->RemoveObserver(this);
91 if (app_manager_)
92 app_manager_->RemoveObserver(this);
93 }
94 103
95 void ArcKioskAppService::PreconditionsChanged() { 104 void ArcKioskAppService::PreconditionsChanged() {
96 app_info_ = prefs_->GetApp(app_id_); 105 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_);
97 if (app_info_ && app_info_->ready && 106 if (app_info_ && app_info_->ready &&
98 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) { 107 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant) &&
108 !maintenance_session_running_) {
99 if (!app_launcher_) 109 if (!app_launcher_)
100 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_)); 110 app_launcher_.reset(new ArcKioskAppLauncher(
111 profile_, ArcAppListPrefs::Get(profile_), app_id_));
101 } else if (task_id_ != -1) { 112 } else if (task_id_ != -1) {
102 arc::CloseTask(task_id_); 113 arc::CloseTask(task_id_);
103 } 114 }
104 } 115 }
105 116
106 std::string ArcKioskAppService::GetAppId() { 117 std::string ArcKioskAppService::GetAppId() {
107 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); 118 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_);
108 const ArcKioskAppManager::ArcKioskApp* app = 119 const ArcKioskAppManager::ArcKioskApp* app =
109 app_manager_->GetAppByAccountId(account_id); 120 app_manager_->GetAppByAccountId(account_id);
110 if (!app) 121 if (!app)
111 return std::string(); 122 return std::string();
112 std::unordered_set<std::string> app_ids = 123 std::unordered_set<std::string> app_ids =
113 prefs_->GetAppsForPackage(app->app_info().package_name()); 124 ArcAppListPrefs::Get(profile_)->GetAppsForPackage(
125 app->app_info().package_name());
114 if (app_ids.empty()) 126 if (app_ids.empty())
115 return std::string(); 127 return std::string();
116 // TODO(poromov@): Choose appropriate app id to launch. See 128 // TODO(poromov@): Choose appropriate app id to launch. See
117 // http://crbug.com/665904 129 // http://crbug.com/665904
118 return std::string(*app_ids.begin()); 130 return std::string(*app_ids.begin());
119 } 131 }
120 132
121 } // namespace chromeos 133 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698