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