| 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/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 13 matching lines...) Expand all Loading... |
| 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 constexpr char kAction[] = "action"; | 32 constexpr char kAction[] = "action"; |
| 33 constexpr char kArcManaged[] = "arcManaged"; | 33 constexpr char kArcManaged[] = "arcManaged"; |
| 34 constexpr char kCanEnable[] = "canEnable"; | |
| 35 constexpr char kData[] = "data"; | 34 constexpr char kData[] = "data"; |
| 36 constexpr char kDeviceId[] = "deviceId"; | 35 constexpr char kDeviceId[] = "deviceId"; |
| 37 constexpr char kEnabled[] = "enabled"; | |
| 38 constexpr char kManaged[] = "managed"; | |
| 39 constexpr char kOn[] = "on"; | |
| 40 constexpr char kPage[] = "page"; | 36 constexpr char kPage[] = "page"; |
| 41 constexpr char kStatus[] = "status"; | 37 constexpr char kStatus[] = "status"; |
| 42 constexpr char kText[] = "text"; | |
| 43 constexpr char kActionInitialize[] = "initialize"; | 38 constexpr char kActionInitialize[] = "initialize"; |
| 44 constexpr char kActionSetMetricsMode[] = "setMetricsMode"; | 39 constexpr char kActionSetMetricsMode[] = "setMetricsMode"; |
| 45 constexpr char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode"; | 40 constexpr char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode"; |
| 46 constexpr char kActionLocationServiceMode[] = "setLocationServiceMode"; | 41 constexpr char kActionLocationServiceMode[] = "setLocationServiceMode"; |
| 47 constexpr char kActionSetWindowBounds[] = "setWindowBounds"; | 42 constexpr char kActionSetWindowBounds[] = "setWindowBounds"; |
| 48 constexpr char kActionCloseWindow[] = "closeWindow"; | 43 constexpr char kActionCloseWindow[] = "closeWindow"; |
| 49 constexpr char kActionShowPage[] = "showPage"; | 44 constexpr char kActionShowPage[] = "showPage"; |
| 50 | 45 |
| 46 // The preference update should have those two fields. |
| 47 constexpr char kEnabled[] = "enabled"; |
| 48 constexpr char kManaged[] = "managed"; |
| 49 |
| 51 // The JSON data sent from the extension should have at least "event" field. | 50 // The JSON data sent from the extension should have at least "event" field. |
| 52 // Each event data is defined below. | 51 // Each event data is defined below. |
| 53 // The key of the event type. | 52 // The key of the event type. |
| 54 constexpr char kEvent[] = "event"; | 53 constexpr char kEvent[] = "event"; |
| 55 | 54 |
| 56 // "onWindowClosed" is fired when the extension window is closed. | 55 // "onWindowClosed" is fired when the extension window is closed. |
| 57 // No data will be provided. | 56 // No data will be provided. |
| 58 constexpr char kEventOnWindowClosed[] = "onWindowClosed"; | 57 constexpr char kEventOnWindowClosed[] = "onWindowClosed"; |
| 59 | 58 |
| 60 // "onAuthSucceeded" is fired when successfully done to LSO authorization in | 59 // "onAuthSucceeded" is fired when successfully done to LSO authorization in |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 loadtime_data->SetString( | 193 loadtime_data->SetString( |
| 195 "progressAndroidLoading", | 194 "progressAndroidLoading", |
| 196 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_ANDROID)); | 195 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_ANDROID)); |
| 197 loadtime_data->SetString( | 196 loadtime_data->SetString( |
| 198 "authorizationFailed", | 197 "authorizationFailed", |
| 199 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_AUTHORIZATION_FAILED)); | 198 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_AUTHORIZATION_FAILED)); |
| 200 loadtime_data->SetString( | 199 loadtime_data->SetString( |
| 201 "termsOfService", | 200 "termsOfService", |
| 202 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_TERMS_OF_SERVICE)); | 201 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_TERMS_OF_SERVICE)); |
| 203 loadtime_data->SetString( | 202 loadtime_data->SetString( |
| 203 "textMetricsEnabled", |
| 204 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_METRICS_ENABLED)); |
| 205 loadtime_data->SetString( |
| 206 "textMetricsDisabled", |
| 207 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_METRICS_DISABLED)); |
| 208 loadtime_data->SetString( |
| 209 "textMetricsManagedEnabled", |
| 210 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_METRICS_MANAGED_ENABLED)); |
| 211 loadtime_data->SetString("textMetricsManagedDisabled", |
| 212 l10n_util::GetStringUTF16( |
| 213 IDS_ARC_OPT_IN_DIALOG_METRICS_MANAGED_DISABLED)); |
| 214 loadtime_data->SetString( |
| 204 "textBackupRestore", | 215 "textBackupRestore", |
| 205 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE)); | 216 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE)); |
| 206 loadtime_data->SetString( | 217 loadtime_data->SetString( |
| 207 "textLocationService", | 218 "textLocationService", |
| 208 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_LOCATION_SETTING)); | 219 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_LOCATION_SETTING)); |
| 209 loadtime_data->SetString( | 220 loadtime_data->SetString( |
| 210 "serverError", | 221 "serverError", |
| 211 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 222 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 212 loadtime_data->SetString( | 223 loadtime_data->SetString( |
| 213 "controlledByPolicy", | 224 "controlledByPolicy", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 228 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 239 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 229 const std::string& country_code = base::CountryCodeForCurrentTimezone(); | 240 const std::string& country_code = base::CountryCodeForCurrentTimezone(); |
| 230 loadtime_data->SetString("countryCode", country_code); | 241 loadtime_data->SetString("countryCode", country_code); |
| 231 loadtime_data->SetBoolean(kArcManaged, arc_auth_service->IsArcManaged()); | 242 loadtime_data->SetBoolean(kArcManaged, arc_auth_service->IsArcManaged()); |
| 232 | 243 |
| 233 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); | 244 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); |
| 234 DCHECK(arc_auth_service); | 245 DCHECK(arc_auth_service); |
| 235 const std::string device_id = user_manager::known_user::GetDeviceId( | 246 const std::string device_id = user_manager::known_user::GetDeviceId( |
| 236 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); | 247 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); |
| 237 DCHECK(!device_id.empty()); | 248 DCHECK(!device_id.empty()); |
| 249 loadtime_data->SetBoolean( |
| 250 "isOwnerProfile", |
| 251 chromeos::ProfileHelper::IsOwnerProfile(arc_auth_service->profile())); |
| 238 | 252 |
| 239 base::DictionaryValue request; | 253 base::DictionaryValue request; |
| 240 std::string request_string; | 254 std::string request_string; |
| 241 request.SetString(kAction, kActionInitialize); | 255 request.SetString(kAction, kActionInitialize); |
| 242 request.Set(kData, std::move(loadtime_data)); | 256 request.Set(kData, std::move(loadtime_data)); |
| 243 request.SetString(kDeviceId, device_id); | 257 request.SetString(kDeviceId, device_id); |
| 244 base::JSONWriter::Write(request, &request_string); | 258 base::JSONWriter::Write(request, &request_string); |
| 245 client_->PostMessageFromNativeHost(request_string); | 259 client_->PostMessageFromNativeHost(request_string); |
| 246 | 260 |
| 247 return true; | 261 return true; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 266 | 280 |
| 267 void ArcSupportHost::OnBackupAndRestorePreferenceChanged() { | 281 void ArcSupportHost::OnBackupAndRestorePreferenceChanged() { |
| 268 SendBackupAndRestoreMode(); | 282 SendBackupAndRestoreMode(); |
| 269 } | 283 } |
| 270 | 284 |
| 271 void ArcSupportHost::OnLocationServicePreferenceChanged() { | 285 void ArcSupportHost::OnLocationServicePreferenceChanged() { |
| 272 SendLocationServicesMode(); | 286 SendLocationServicesMode(); |
| 273 } | 287 } |
| 274 | 288 |
| 275 void ArcSupportHost::SendMetricsMode() { | 289 void ArcSupportHost::SendMetricsMode() { |
| 276 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 290 SendPreferenceUpdate( |
| 277 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); | 291 kActionSetMetricsMode, |
| 278 const Profile* profile = arc_auth_service->profile(); | 292 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(), |
| 279 | 293 IsMetricsReportingPolicyManaged()); |
| 280 const bool metrics_managed = IsMetricsReportingPolicyManaged(); | |
| 281 const bool owner_profile = | |
| 282 profile && chromeos::ProfileHelper::IsOwnerProfile(profile); | |
| 283 const bool metrics_on = | |
| 284 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | |
| 285 | |
| 286 int message_id; | |
| 287 if (metrics_managed || !owner_profile) { | |
| 288 message_id = metrics_on ? IDS_ARC_OPT_IN_DIALOG_METRICS_MANAGED_ENABLED | |
| 289 : IDS_ARC_OPT_IN_DIALOG_METRICS_MANAGED_DISABLED; | |
| 290 } else { | |
| 291 message_id = metrics_on ? IDS_ARC_OPT_IN_DIALOG_METRICS_ENABLED | |
| 292 : IDS_ARC_OPT_IN_DIALOG_METRICS_DISABLED; | |
| 293 } | |
| 294 | |
| 295 base::DictionaryValue request; | |
| 296 std::string request_string; | |
| 297 request.SetString(kAction, kActionSetMetricsMode); | |
| 298 request.SetString(kText, l10n_util::GetStringUTF16(message_id)); | |
| 299 request.SetBoolean(kCanEnable, | |
| 300 !metrics_on && !metrics_managed && owner_profile); | |
| 301 request.SetBoolean(kOn, metrics_on); | |
| 302 base::JSONWriter::Write(request, &request_string); | |
| 303 client_->PostMessageFromNativeHost(request_string); | |
| 304 } | |
| 305 | |
| 306 void ArcSupportHost::SendOptionMode(const std::string& action_name, | |
| 307 const std::string& pref_name) { | |
| 308 const arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | |
| 309 DCHECK(arc_auth_service); | |
| 310 const bool enabled = | |
| 311 arc_auth_service->profile()->GetPrefs()->GetBoolean(pref_name); | |
| 312 const bool managed = | |
| 313 arc_auth_service->profile()->GetPrefs()->IsManagedPreference(pref_name); | |
| 314 | |
| 315 base::DictionaryValue request; | |
| 316 std::string request_string; | |
| 317 request.SetString(kAction, action_name); | |
| 318 request.SetBoolean(kEnabled, enabled); | |
| 319 request.SetBoolean(kManaged, managed); | |
| 320 base::JSONWriter::Write(request, &request_string); | |
| 321 client_->PostMessageFromNativeHost(request_string); | |
| 322 } | 294 } |
| 323 | 295 |
| 324 void ArcSupportHost::SendBackupAndRestoreMode() { | 296 void ArcSupportHost::SendBackupAndRestoreMode() { |
| 325 SendOptionMode(kActionBackupAndRestoreMode, prefs::kArcBackupRestoreEnabled); | 297 SendOptionMode(kActionBackupAndRestoreMode, prefs::kArcBackupRestoreEnabled); |
| 326 } | 298 } |
| 327 | 299 |
| 328 void ArcSupportHost::SendLocationServicesMode() { | 300 void ArcSupportHost::SendLocationServicesMode() { |
| 329 SendOptionMode(kActionLocationServiceMode, prefs::kArcLocationServiceEnabled); | 301 SendOptionMode(kActionLocationServiceMode, prefs::kArcLocationServiceEnabled); |
| 330 } | 302 } |
| 331 | 303 |
| 304 void ArcSupportHost::SendOptionMode(const std::string& action_name, |
| 305 const std::string& pref_name) { |
| 306 const arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 307 DCHECK(arc_auth_service); |
| 308 SendPreferenceUpdate( |
| 309 action_name, |
| 310 arc_auth_service->profile()->GetPrefs()->GetBoolean(pref_name), |
| 311 arc_auth_service->profile()->GetPrefs()->IsManagedPreference(pref_name)); |
| 312 } |
| 313 |
| 314 void ArcSupportHost::SendPreferenceUpdate(const std::string& action_name, |
| 315 bool is_enabled, |
| 316 bool is_managed) { |
| 317 base::DictionaryValue request; |
| 318 std::string request_string; |
| 319 request.SetString(kAction, action_name); |
| 320 request.SetBoolean(kEnabled, is_enabled); |
| 321 request.SetBoolean(kManaged, is_managed); |
| 322 base::JSONWriter::Write(request, &request_string); |
| 323 client_->PostMessageFromNativeHost(request_string); |
| 324 } |
| 325 |
| 332 void ArcSupportHost::OnOptInUIClose() { | 326 void ArcSupportHost::OnOptInUIClose() { |
| 333 Close(); | 327 Close(); |
| 334 } | 328 } |
| 335 | 329 |
| 336 void ArcSupportHost::OnOptInUIShowPage(arc::ArcAuthService::UIPage page, | 330 void ArcSupportHost::OnOptInUIShowPage(arc::ArcAuthService::UIPage page, |
| 337 const base::string16& status) { | 331 const base::string16& status) { |
| 338 if (!client_) | 332 if (!client_) |
| 339 return; | 333 return; |
| 340 | 334 |
| 341 base::DictionaryValue response; | 335 base::DictionaryValue response; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } else { | 409 } else { |
| 416 LOG(ERROR) << "Unknown message: " << message_string; | 410 LOG(ERROR) << "Unknown message: " << message_string; |
| 417 NOTREACHED(); | 411 NOTREACHED(); |
| 418 } | 412 } |
| 419 } | 413 } |
| 420 | 414 |
| 421 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() | 415 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() |
| 422 const { | 416 const { |
| 423 return base::ThreadTaskRunnerHandle::Get(); | 417 return base::ThreadTaskRunnerHandle::Get(); |
| 424 } | 418 } |
| OLD | NEW |