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

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: Created 4 years, 1 month 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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 } 59 }
60 60
61 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) { 61 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) {
62 if (task_id == task_id_) { 62 if (task_id == task_id_) {
63 app_launcher_.reset(); 63 app_launcher_.reset();
64 task_id_ = -1; 64 task_id_ = -1;
65 } 65 }
66 } 66 }
67 67
68 void ArcKioskAppService::MaintenanceSessionCreated() {
69 maintenance_session_running_ = true;
70 PreconditionsChanged();
71 }
72
73 void ArcKioskAppService::MaintenanceSessionFinished() {
74 maintenance_session_running_ = false;
75 PreconditionsChanged();
76 }
77
68 ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs) 78 ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs)
69 : profile_(profile), prefs_(prefs) { 79 : profile_(profile), prefs_(prefs), maintenance_session_running_(false) {
70 if (prefs_) 80 if (prefs_)
71 prefs_->AddObserver(this); 81 prefs_->AddObserver(this);
72 app_manager_ = ArcKioskAppManager::Get(); 82 app_manager_ = ArcKioskAppManager::Get();
73 if (app_manager_) { 83 if (app_manager_) {
74 app_manager_->AddObserver(this); 84 app_manager_->AddObserver(this);
75 app_id_ = GetAppId(); 85 app_id_ = GetAppId();
76 } 86 }
77 pref_change_registrar_.reset(new PrefChangeRegistrar()); 87 pref_change_registrar_.reset(new PrefChangeRegistrar());
78 pref_change_registrar_->Init(profile_->GetPrefs()); 88 pref_change_registrar_->Init(profile_->GetPrefs());
79 // Try to start/stop kiosk app on policy compliance state change. 89 // Try to start/stop kiosk app on policy compliance state change.
80 pref_change_registrar_->Add( 90 pref_change_registrar_->Add(
81 prefs::kArcPolicyCompliant, 91 prefs::kArcPolicyCompliant,
82 base::Bind(&ArcKioskAppService::PreconditionsChanged, 92 base::Bind(&ArcKioskAppService::PreconditionsChanged,
83 base::Unretained(this))); 93 base::Unretained(this)));
84 PreconditionsChanged(); 94 PreconditionsChanged();
85 } 95 }
86 96
87 ArcKioskAppService::~ArcKioskAppService() { 97 ArcKioskAppService::~ArcKioskAppService() {
88 if (prefs_) 98 if (prefs_)
89 prefs_->RemoveObserver(this); 99 prefs_->RemoveObserver(this);
90 if (app_manager_) 100 if (app_manager_)
91 app_manager_->RemoveObserver(this); 101 app_manager_->RemoveObserver(this);
92 } 102 }
93 103
94 void ArcKioskAppService::PreconditionsChanged() { 104 void ArcKioskAppService::PreconditionsChanged() {
95 app_info_ = prefs_->GetApp(app_id_); 105 app_info_ = prefs_->GetApp(app_id_);
96 if (app_info_ && app_info_->ready && 106 if (app_info_ && app_info_->ready &&
97 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) { 107 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant) &&
108 !maintenance_session_running_) {
98 if (!app_launcher_) 109 if (!app_launcher_)
99 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_)); 110 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_));
100 } else if (task_id_ != -1) { 111 } else if (task_id_ != -1) {
101 arc::CloseTask(task_id_); 112 arc::CloseTask(task_id_);
102 } 113 }
103 } 114 }
104 115
105 std::string ArcKioskAppService::GetAppId() { 116 std::string ArcKioskAppService::GetAppId() {
106 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); 117 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_);
107 const ArcKioskAppManager::ArcKioskApp* app = 118 const ArcKioskAppManager::ArcKioskApp* app =
108 app_manager_->GetAppByAccountId(account_id); 119 app_manager_->GetAppByAccountId(account_id);
109 if (!app) 120 if (!app)
110 return std::string(); 121 return std::string();
111 std::unordered_set<std::string> app_ids = 122 std::unordered_set<std::string> app_ids =
112 prefs_->GetAppsForPackage(app->app_info().package_name()); 123 prefs_->GetAppsForPackage(app->app_info().package_name());
113 if (app_ids.empty()) 124 if (app_ids.empty())
114 return std::string(); 125 return std::string();
115 // TODO(poromov@): Choose appropriate app id to launch. See 126 // TODO(poromov@): Choose appropriate app id to launch. See
116 // http://crbug.com/665904 127 // http://crbug.com/665904
117 return std::string(*app_ids.begin()); 128 return std::string(*app_ids.begin());
118 } 129 }
119 130
120 } // namespace chromeos 131 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698