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(Profile* context) { |
Luis Héctor Chávez
2016/12/01 20:13:33
This doesn't need to change. Profile is-a content:
Sergey Poromov
2016/12/16 16:12:05
Done.
| |
25 return ArcKioskAppServiceFactory::GetForBrowserContext(context); | 24 return ArcKioskAppServiceFactory::GetForBrowserContext(context); |
26 } | 25 } |
27 | 26 |
28 void ArcKioskAppService::OnAppRegistered( | 27 void ArcKioskAppService::OnAppRegistered( |
29 const std::string& app_id, | 28 const std::string& app_id, |
30 const ArcAppListPrefs::AppInfo& app_info) { | 29 const ArcAppListPrefs::AppInfo& app_info) { |
31 if (app_id == app_id_) | 30 if (app_id == app_id_) |
32 PreconditionsChanged(); | 31 PreconditionsChanged(); |
33 } | 32 } |
34 | 33 |
(...skipping 23 matching lines...) Expand all Loading... | |
58 } | 57 } |
59 } | 58 } |
60 | 59 |
61 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) { | 60 void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) { |
62 if (task_id == task_id_) { | 61 if (task_id == task_id_) { |
63 app_launcher_.reset(); | 62 app_launcher_.reset(); |
64 task_id_ = -1; | 63 task_id_ = -1; |
65 } | 64 } |
66 } | 65 } |
67 | 66 |
68 ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs) | 67 void ArcKioskAppService::OnMaintenanceSessionCreated() { |
69 : profile_(profile), prefs_(prefs) { | 68 maintenance_session_running_ = true; |
69 PreconditionsChanged(); | |
70 } | |
71 | |
72 void ArcKioskAppService::OnMaintenanceSessionFinished() { | |
73 maintenance_session_running_ = false; | |
74 PreconditionsChanged(); | |
75 } | |
76 | |
77 ArcKioskAppService::ArcKioskAppService(Profile* profile) | |
78 : profile_(profile), | |
79 prefs_(ArcAppListPrefs::Get(profile)), | |
Luis Héctor Chávez
2016/12/01 20:13:33
Remove this line and then s/prefs_/ArcAppListPrefs
Sergey Poromov
2016/12/16 16:12:05
Done.
| |
80 maintenance_session_running_(false) { | |
70 if (prefs_) | 81 if (prefs_) |
71 prefs_->AddObserver(this); | 82 prefs_->AddObserver(this); |
72 app_manager_ = ArcKioskAppManager::Get(); | 83 app_manager_ = ArcKioskAppManager::Get(); |
73 if (app_manager_) { | 84 if (app_manager_) { |
74 app_manager_->AddObserver(this); | 85 app_manager_->AddObserver(this); |
75 app_id_ = GetAppId(); | 86 app_id_ = GetAppId(); |
76 } | 87 } |
77 pref_change_registrar_.reset(new PrefChangeRegistrar()); | 88 pref_change_registrar_.reset(new PrefChangeRegistrar()); |
78 pref_change_registrar_->Init(profile_->GetPrefs()); | 89 pref_change_registrar_->Init(profile_->GetPrefs()); |
79 // Try to start/stop kiosk app on policy compliance state change. | 90 // Try to start/stop kiosk app on policy compliance state change. |
80 pref_change_registrar_->Add( | 91 pref_change_registrar_->Add( |
81 prefs::kArcPolicyCompliant, | 92 prefs::kArcPolicyCompliant, |
82 base::Bind(&ArcKioskAppService::PreconditionsChanged, | 93 base::Bind(&ArcKioskAppService::PreconditionsChanged, |
83 base::Unretained(this))); | 94 base::Unretained(this))); |
84 PreconditionsChanged(); | 95 PreconditionsChanged(); |
85 } | 96 } |
86 | 97 |
87 ArcKioskAppService::~ArcKioskAppService() { | 98 ArcKioskAppService::~ArcKioskAppService() { |
88 if (prefs_) | 99 if (prefs_) |
89 prefs_->RemoveObserver(this); | 100 prefs_->RemoveObserver(this); |
Luis Héctor Chávez
2016/12/01 20:13:33
It's probably better if you override KeyedService:
Sergey Poromov
2016/12/16 16:12:05
Done.
| |
90 if (app_manager_) | 101 if (app_manager_) |
91 app_manager_->RemoveObserver(this); | 102 app_manager_->RemoveObserver(this); |
92 } | 103 } |
93 | 104 |
94 void ArcKioskAppService::PreconditionsChanged() { | 105 void ArcKioskAppService::PreconditionsChanged() { |
95 app_info_ = prefs_->GetApp(app_id_); | 106 app_info_ = prefs_->GetApp(app_id_); |
96 if (app_info_ && app_info_->ready && | 107 if (app_info_ && app_info_->ready && |
97 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) { | 108 profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant) && |
109 !maintenance_session_running_) { | |
98 if (!app_launcher_) | 110 if (!app_launcher_) |
99 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_)); | 111 app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_)); |
100 } else if (task_id_ != -1) { | 112 } else if (task_id_ != -1) { |
101 arc::CloseTask(task_id_); | 113 arc::CloseTask(task_id_); |
102 } | 114 } |
103 } | 115 } |
104 | 116 |
105 std::string ArcKioskAppService::GetAppId() { | 117 std::string ArcKioskAppService::GetAppId() { |
106 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); | 118 AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); |
107 const ArcKioskAppManager::ArcKioskApp* app = | 119 const ArcKioskAppManager::ArcKioskApp* app = |
108 app_manager_->GetAppByAccountId(account_id); | 120 app_manager_->GetAppByAccountId(account_id); |
109 if (!app) | 121 if (!app) |
110 return std::string(); | 122 return std::string(); |
111 std::unordered_set<std::string> app_ids = | 123 std::unordered_set<std::string> app_ids = |
112 prefs_->GetAppsForPackage(app->app_info().package_name()); | 124 prefs_->GetAppsForPackage(app->app_info().package_name()); |
113 if (app_ids.empty()) | 125 if (app_ids.empty()) |
114 return std::string(); | 126 return std::string(); |
115 // TODO(poromov@): Choose appropriate app id to launch. See | 127 // TODO(poromov@): Choose appropriate app id to launch. See |
116 // http://crbug.com/665904 | 128 // http://crbug.com/665904 |
117 return std::string(*app_ids.begin()); | 129 return std::string(*app_ids.begin()); |
118 } | 130 } |
119 | 131 |
120 } // namespace chromeos | 132 } // namespace chromeos |
OLD | NEW |