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

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: nits and includes 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) : profile_(profile) {
85 ArcAppListPrefs::Get(profile_)->AddObserver(this);
73 app_manager_ = ArcKioskAppManager::Get(); 86 app_manager_ = ArcKioskAppManager::Get();
74 if (app_manager_) { 87 if (app_manager_) {
75 app_manager_->AddObserver(this); 88 app_manager_->AddObserver(this);
76 app_id_ = GetAppId(); 89 app_id_ = GetAppId();
77 } 90 }
78 pref_change_registrar_.reset(new PrefChangeRegistrar()); 91 pref_change_registrar_.reset(new PrefChangeRegistrar());
79 pref_change_registrar_->Init(profile_->GetPrefs()); 92 pref_change_registrar_->Init(profile_->GetPrefs());
80 // Try to start/stop kiosk app on policy compliance state change. 93 // Try to start/stop kiosk app on policy compliance state change.
81 pref_change_registrar_->Add( 94 pref_change_registrar_->Add(
82 prefs::kArcPolicyCompliant, 95 prefs::kArcPolicyCompliant,
83 base::Bind(&ArcKioskAppService::PreconditionsChanged, 96 base::Bind(&ArcKioskAppService::PreconditionsChanged,
84 base::Unretained(this))); 97 base::Unretained(this)));
85 PreconditionsChanged(); 98 PreconditionsChanged();
86 } 99 }
87 100
88 ArcKioskAppService::~ArcKioskAppService() { 101 ArcKioskAppService::~ArcKioskAppService() = default;
89 if (prefs_)
90 prefs_->RemoveObserver(this);
91 if (app_manager_)
92 app_manager_->RemoveObserver(this);
93 }
94 102
95 void ArcKioskAppService::PreconditionsChanged() { 103 void ArcKioskAppService::PreconditionsChanged() {
96 app_info_ = prefs_->GetApp(app_id_); 104 app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_);
97 if (app_info_ && app_info_->ready && 105 if (app_info_ && app_info_->ready &&
98 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) { 106 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant) &&
107 !maintenance_session_running_) {
99 if (!app_launcher_) 108 if (!app_launcher_)
100 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_)); 109 app_launcher_.reset(new ArcKioskAppLauncher(
110 profile_, ArcAppListPrefs::Get(profile_), app_id_));
101 } else if (task_id_ != -1) { 111 } else if (task_id_ != -1) {
102 arc::CloseTask(task_id_); 112 arc::CloseTask(task_id_);
103 } 113 }
104 } 114 }
105 115
106 std::string ArcKioskAppService::GetAppId() { 116 std::string ArcKioskAppService::GetAppId() {
107 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); 117 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_);
108 const ArcKioskAppManager::ArcKioskApp* app = 118 const ArcKioskAppManager::ArcKioskApp* app =
109 app_manager_->GetAppByAccountId(account_id); 119 app_manager_->GetAppByAccountId(account_id);
hidehiko 2016/12/19 13:53:33 (maybe off topic): app_manager_ looks to be able t
Sergey Poromov 2016/12/19 17:28:38 Actually it couldn't be nullptr as it's unconditio
110 if (!app) 120 if (!app)
111 return std::string(); 121 return std::string();
112 std::unordered_set<std::string> app_ids = 122 std::unordered_set<std::string> app_ids =
113 prefs_->GetAppsForPackage(app->app_info().package_name()); 123 ArcAppListPrefs::Get(profile_)->GetAppsForPackage(
124 app->app_info().package_name());
114 if (app_ids.empty()) 125 if (app_ids.empty())
115 return std::string(); 126 return std::string();
116 // TODO(poromov@): Choose appropriate app id to launch. See 127 // TODO(poromov@): Choose appropriate app id to launch. See
117 // http://crbug.com/665904 128 // http://crbug.com/665904
118 return std::string(*app_ids.begin()); 129 return std::string(*app_ids.begin());
119 } 130 }
120 131
121 } // namespace chromeos 132 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698