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

Side by Side Diff: chrome/browser/chromeos/arc/arc_support_host.cc

Issue 2235293002: arc: Support managed Arc and managed Location Service and B&R consents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2225933002_managed_BR_LOC
Patch Set: don't load ToS for managed arc, add policy indicators Created 4 years, 4 months 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/arc/arc_support_host.h" 5 #include "chrome/browser/chromeos/arc/arc_support_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/common/system/chromeos/devicetype_utils.h" 9 #include "ash/common/system/chromeos/devicetype_utils.h"
10 #include "base/i18n/timezone.h" 10 #include "base/i18n/timezone.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "components/metrics/metrics_pref_names.h" 24 #include "components/metrics/metrics_pref_names.h"
25 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
26 #include "components/user_manager/known_user.h" 26 #include "components/user_manager/known_user.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/webui/web_ui_util.h" 28 #include "ui/base/webui/web_ui_util.h"
29 #include "ui/display/screen.h" 29 #include "ui/display/screen.h"
30 30
31 namespace { 31 namespace {
32 const char kAction[] = "action"; 32 const char kAction[] = "action";
33 const char kBackupRestoreEnabled[] = "backupRestoreEnabled"; 33 const char kArcManaged[] = "arcManaged";
34 const char kLocationServiceEnabled[] = "locationServiceEnabled";
35 const char kCanEnable[] = "canEnable"; 34 const char kCanEnable[] = "canEnable";
36 const char kCode[] = "code"; 35 const char kCode[] = "code";
37 const char kData[] = "data"; 36 const char kData[] = "data";
38 const char kDeviceId[] = "deviceId"; 37 const char kDeviceId[] = "deviceId";
39 const char kEnabled[] = "enabled"; 38 const char kEnabled[] = "enabled";
39 const char kManaged[] = "managed";
40 const char kOn[] = "on"; 40 const char kOn[] = "on";
41 const char kPage[] = "page"; 41 const char kPage[] = "page";
42 const char kStatus[] = "status"; 42 const char kStatus[] = "status";
43 const char kText[] = "text"; 43 const char kText[] = "text";
44 const char kActionInitialize[] = "initialize"; 44 const char kActionInitialize[] = "initialize";
45 const char kActionSetMetricsMode[] = "setMetricsMode"; 45 const char kActionSetMetricsMode[] = "setMetricsMode";
46 const char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode";
47 const char kActionLocationServiceMode[] = "setLocationServiceMode";
46 const char kActionSetWindowBounds[] = "setWindowBounds"; 48 const char kActionSetWindowBounds[] = "setWindowBounds";
47 const char kActionStartLso[] = "startLso"; 49 const char kActionStartLso[] = "startLso";
48 const char kActionCancelAuthCode[] = "cancelAuthCode"; 50 const char kActionCancelAuthCode[] = "cancelAuthCode";
49 const char kActionSetAuthCode[] = "setAuthCode"; 51 const char kActionSetAuthCode[] = "setAuthCode";
50 const char kActionEnableMetrics[] = "enableMetrics"; 52 const char kActionEnableMetrics[] = "enableMetrics";
51 const char kActionSendFeedback[] = "sendFeedback"; 53 const char kActionSendFeedback[] = "sendFeedback";
52 const char kActionSetBackupRestore[] = "setBackupRestore"; 54 const char kActionSetBackupRestore[] = "setBackupRestore";
53 const char kActionSetLocationService[] = "setLocationService"; 55 const char kActionSetLocationService[] = "setLocationService";
54 const char kActionCloseUI[] = "closeUI"; 56 const char kActionCloseUI[] = "closeUI";
55 const char kActionShowPage[] = "showPage"; 57 const char kActionShowPage[] = "showPage";
(...skipping 20 matching lines...) Expand all
76 ArcSupportHost::ArcSupportHost() { 78 ArcSupportHost::ArcSupportHost() {
77 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 79 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
78 DCHECK(arc_auth_service); 80 DCHECK(arc_auth_service);
79 81
80 if (!arc_auth_service->IsAllowed()) 82 if (!arc_auth_service->IsAllowed())
81 return; 83 return;
82 84
83 arc_auth_service->AddObserver(this); 85 arc_auth_service->AddObserver(this);
84 display::Screen::GetScreen()->AddObserver(this); 86 display::Screen::GetScreen()->AddObserver(this);
85 87
86 pref_change_registrar_.Init(g_browser_process->local_state()); 88 pref_local_change_registrar_.Init(g_browser_process->local_state());
87 pref_change_registrar_.Add( 89 pref_local_change_registrar_.Add(
88 metrics::prefs::kMetricsReportingEnabled, 90 metrics::prefs::kMetricsReportingEnabled,
89 base::Bind(&ArcSupportHost::OnMetricsPreferenceChanged, 91 base::Bind(&ArcSupportHost::OnMetricsPreferenceChanged,
90 base::Unretained(this))); 92 base::Unretained(this)));
93
94 pref_change_registrar_.Init(arc_auth_service->profile()->GetPrefs());
95 pref_change_registrar_.Add(
96 prefs::kArcBackupRestoreEnabled,
97 base::Bind(&ArcSupportHost::OnBackupAndRestorePreferenceChanged,
98 base::Unretained(this)));
99 pref_change_registrar_.Add(
100 prefs::kArcLocationServiceEnabled,
101 base::Bind(&ArcSupportHost::OnLocationServicePreferenceChanged,
102 base::Unretained(this)));
91 } 103 }
92 104
93 ArcSupportHost::~ArcSupportHost() { 105 ArcSupportHost::~ArcSupportHost() {
94 display::Screen::GetScreen()->RemoveObserver(this); 106 display::Screen::GetScreen()->RemoveObserver(this);
95 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 107 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
96 if (arc_auth_service) 108 if (arc_auth_service)
97 arc_auth_service->RemoveObserver(this); 109 arc_auth_service->RemoveObserver(this);
98 } 110 }
99 111
100 void ArcSupportHost::Start(Client* client) { 112 void ArcSupportHost::Start(Client* client) {
101 DCHECK(!client_); 113 DCHECK(!client_);
102 client_ = client; 114 client_ = client;
103 115
104 if (!Initialize()) { 116 if (!Initialize()) {
105 OnOptInUIClose(); 117 OnOptInUIClose();
106 return; 118 return;
107 } 119 }
108 120
109 SendMetricsMode(); 121 SendMetricsMode();
122 SendBackupAndRestoreMode();
123 SendLocationServicesMode();
110 124
111 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 125 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
112 DCHECK(arc_auth_service); 126 DCHECK(arc_auth_service);
113 OnOptInUIShowPage(arc_auth_service->ui_page(), 127 OnOptInUIShowPage(arc_auth_service->ui_page(),
114 arc_auth_service->ui_page_status()); 128 arc_auth_service->ui_page_status());
115 } 129 }
116 130
117 bool ArcSupportHost::Initialize() { 131 bool ArcSupportHost::Initialize() {
118 DCHECK(client_); 132 DCHECK(client_);
119 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 133 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_TERMS_OF_SERVICE)); 169 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_TERMS_OF_SERVICE));
156 loadtime_data->SetString( 170 loadtime_data->SetString(
157 "textBackupRestore", 171 "textBackupRestore",
158 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE)); 172 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE));
159 loadtime_data->SetString( 173 loadtime_data->SetString(
160 "textLocationService", 174 "textLocationService",
161 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_LOCATION_SETTING)); 175 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_LOCATION_SETTING));
162 loadtime_data->SetString( 176 loadtime_data->SetString(
163 "serverError", 177 "serverError",
164 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 178 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
179 loadtime_data->SetString(
180 "controlledByPolicy",
181 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY));
165 182
166 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 183 const std::string& app_locale = g_browser_process->GetApplicationLocale();
167 const std::string& country_code = base::CountryCodeForCurrentTimezone(); 184 const std::string& country_code = base::CountryCodeForCurrentTimezone();
168 loadtime_data->SetString("countryCode", country_code); 185 loadtime_data->SetString("countryCode", country_code);
169 186 loadtime_data->SetBoolean(kArcManaged, arc_auth_service->IsArcManaged());
170 loadtime_data->SetBoolean(kBackupRestoreEnabled,
171 arc_auth_service->profile()->GetPrefs()->GetBoolean(
172 prefs::kArcBackupRestoreEnabled));
173 loadtime_data->SetBoolean(kLocationServiceEnabled,
174 arc_auth_service->profile()->GetPrefs()->GetBoolean(
175 prefs::kArcLocationServiceEnabled));
176 187
177 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); 188 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get());
178 DCHECK(arc_auth_service); 189 DCHECK(arc_auth_service);
179 const std::string device_id = user_manager::known_user::GetDeviceId( 190 const std::string device_id = user_manager::known_user::GetDeviceId(
180 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); 191 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile()));
181 DCHECK(!device_id.empty()); 192 DCHECK(!device_id.empty());
182 193
183 base::DictionaryValue request; 194 base::DictionaryValue request;
184 std::string request_string; 195 std::string request_string;
185 request.SetString(kAction, kActionInitialize); 196 request.SetString(kAction, kActionInitialize);
(...skipping 15 matching lines...) Expand all
201 std::string request_string; 212 std::string request_string;
202 request.SetString(kAction, kActionSetWindowBounds); 213 request.SetString(kAction, kActionSetWindowBounds);
203 base::JSONWriter::Write(request, &request_string); 214 base::JSONWriter::Write(request, &request_string);
204 client_->PostMessageFromNativeHost(request_string); 215 client_->PostMessageFromNativeHost(request_string);
205 } 216 }
206 217
207 void ArcSupportHost::OnMetricsPreferenceChanged() { 218 void ArcSupportHost::OnMetricsPreferenceChanged() {
208 SendMetricsMode(); 219 SendMetricsMode();
209 } 220 }
210 221
222 void ArcSupportHost::OnBackupAndRestorePreferenceChanged() {
223 SendBackupAndRestoreMode();
224 }
225
226 void ArcSupportHost::OnLocationServicePreferenceChanged() {
227 SendLocationServicesMode();
228 }
229
211 void ArcSupportHost::SendMetricsMode() { 230 void ArcSupportHost::SendMetricsMode() {
212 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 231 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
213 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); 232 DCHECK(arc_auth_service && arc_auth_service->IsAllowed());
214 const Profile* profile = arc_auth_service->profile(); 233 const Profile* profile = arc_auth_service->profile();
215 234
216 const bool metrics_managed = IsMetricsReportingPolicyManaged(); 235 const bool metrics_managed = IsMetricsReportingPolicyManaged();
217 const bool owner_profile = 236 const bool owner_profile =
218 profile && chromeos::ProfileHelper::IsOwnerProfile(profile); 237 profile && chromeos::ProfileHelper::IsOwnerProfile(profile);
219 const bool metrics_on = 238 const bool metrics_on =
220 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); 239 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
(...skipping 11 matching lines...) Expand all
232 std::string request_string; 251 std::string request_string;
233 request.SetString(kAction, kActionSetMetricsMode); 252 request.SetString(kAction, kActionSetMetricsMode);
234 request.SetString(kText, l10n_util::GetStringUTF16(message_id)); 253 request.SetString(kText, l10n_util::GetStringUTF16(message_id));
235 request.SetBoolean(kCanEnable, 254 request.SetBoolean(kCanEnable,
236 !metrics_on && !metrics_managed && owner_profile); 255 !metrics_on && !metrics_managed && owner_profile);
237 request.SetBoolean(kOn, metrics_on); 256 request.SetBoolean(kOn, metrics_on);
238 base::JSONWriter::Write(request, &request_string); 257 base::JSONWriter::Write(request, &request_string);
239 client_->PostMessageFromNativeHost(request_string); 258 client_->PostMessageFromNativeHost(request_string);
240 } 259 }
241 260
261 void ArcSupportHost::SendOptionMode(const std::string& action_name,
262 const std::string& pref_name) {
263 const arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
264 DCHECK(arc_auth_service);
265 const bool enabled =
266 arc_auth_service->profile()->GetPrefs()->GetBoolean(pref_name);
267 const bool managed =
268 arc_auth_service->profile()->GetPrefs()->IsManagedPreference(pref_name);
269
270 base::DictionaryValue request;
271 std::string request_string;
272 request.SetString(kAction, action_name);
273 request.SetBoolean(kEnabled, enabled);
274 request.SetBoolean(kManaged, managed);
275 base::JSONWriter::Write(request, &request_string);
276 client_->PostMessageFromNativeHost(request_string);
277 }
278
279 void ArcSupportHost::SendBackupAndRestoreMode() {
280 SendOptionMode(kActionBackupAndRestoreMode, prefs::kArcBackupRestoreEnabled);
281 }
282
283 void ArcSupportHost::SendLocationServicesMode() {
284 SendOptionMode(kActionLocationServiceMode, prefs::kArcLocationServiceEnabled);
285 }
286
242 void ArcSupportHost::OnOptInUIClose() { 287 void ArcSupportHost::OnOptInUIClose() {
243 if (!client_) 288 if (!client_)
244 return; 289 return;
245 290
246 base::DictionaryValue response; 291 base::DictionaryValue response;
247 response.SetString(kAction, kActionCloseUI); 292 response.SetString(kAction, kActionCloseUI);
248 std::string response_string; 293 std::string response_string;
249 base::JSONWriter::Write(response, &response_string); 294 base::JSONWriter::Write(response, &response_string);
250 client_->PostMessageFromNativeHost(response_string); 295 client_->PostMessageFromNativeHost(response_string);
251 } 296 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 EnableLocationService(is_enabled); 381 EnableLocationService(is_enabled);
337 } else { 382 } else {
338 NOTREACHED(); 383 NOTREACHED();
339 } 384 }
340 } 385 }
341 386
342 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() 387 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner()
343 const { 388 const {
344 return base::ThreadTaskRunnerHandle::Get(); 389 return base::ThreadTaskRunnerHandle::Get();
345 } 390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698