| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"}; | 65 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"}; |
| 66 | 66 |
| 67 // static | 67 // static |
| 68 std::unique_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { | 68 std::unique_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { |
| 69 return std::unique_ptr<NativeMessageHost>(new ArcSupportHost()); | 69 return std::unique_ptr<NativeMessageHost>(new ArcSupportHost()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ArcSupportHost::ArcSupportHost() { | 72 ArcSupportHost::ArcSupportHost() { |
| 73 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 73 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 74 DCHECK(arc_auth_service); | 74 DCHECK(arc_auth_service); |
| 75 |
| 76 if (!arc_auth_service->IsAllowed()) |
| 77 return; |
| 78 |
| 75 arc_auth_service->AddObserver(this); | 79 arc_auth_service->AddObserver(this); |
| 76 | 80 |
| 77 pref_change_registrar_.Init(g_browser_process->local_state()); | 81 pref_change_registrar_.Init(g_browser_process->local_state()); |
| 78 pref_change_registrar_.Add( | 82 pref_change_registrar_.Add( |
| 79 metrics::prefs::kMetricsReportingEnabled, | 83 metrics::prefs::kMetricsReportingEnabled, |
| 80 base::Bind(&ArcSupportHost::OnMetricsPreferenceChanged, | 84 base::Bind(&ArcSupportHost::OnMetricsPreferenceChanged, |
| 81 base::Unretained(this))); | 85 base::Unretained(this))); |
| 82 } | 86 } |
| 83 | 87 |
| 84 ArcSupportHost::~ArcSupportHost() { | 88 ArcSupportHost::~ArcSupportHost() { |
| 85 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 89 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 86 if (arc_auth_service) | 90 if (arc_auth_service) |
| 87 arc_auth_service->RemoveObserver(this); | 91 arc_auth_service->RemoveObserver(this); |
| 88 } | 92 } |
| 89 | 93 |
| 90 void ArcSupportHost::Start(Client* client) { | 94 void ArcSupportHost::Start(Client* client) { |
| 91 DCHECK(!client_); | 95 DCHECK(!client_); |
| 92 client_ = client; | 96 client_ = client; |
| 93 | 97 |
| 94 Initialize(); | 98 if (!Initialize()) { |
| 99 OnOptInUIClose(); |
| 100 return; |
| 101 } |
| 102 |
| 95 SendMetricsMode(); | 103 SendMetricsMode(); |
| 96 | 104 |
| 97 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 105 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 98 DCHECK(arc_auth_service); | 106 DCHECK(arc_auth_service); |
| 99 OnOptInUIShowPage(arc_auth_service->ui_page(), | 107 OnOptInUIShowPage(arc_auth_service->ui_page(), |
| 100 arc_auth_service->ui_page_status()); | 108 arc_auth_service->ui_page_status()); |
| 101 } | 109 } |
| 102 | 110 |
| 103 void ArcSupportHost::Initialize() { | 111 bool ArcSupportHost::Initialize() { |
| 104 DCHECK(client_); | 112 DCHECK(client_); |
| 113 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 114 if (!arc_auth_service->IsAllowed()) |
| 115 return false; |
| 116 |
| 105 std::unique_ptr<base::DictionaryValue> loadtime_data( | 117 std::unique_ptr<base::DictionaryValue> loadtime_data( |
| 106 new base::DictionaryValue()); | 118 new base::DictionaryValue()); |
| 107 base::string16 device_name = ash::GetChromeOSDeviceName(); | 119 base::string16 device_name = ash::GetChromeOSDeviceName(); |
| 108 loadtime_data->SetString( | 120 loadtime_data->SetString( |
| 109 "greetingHeader", | 121 "greetingHeader", |
| 110 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); | 122 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); |
| 111 loadtime_data->SetString("greetingDescription", | 123 loadtime_data->SetString("greetingDescription", |
| 112 l10n_util::GetStringFUTF16( | 124 l10n_util::GetStringFUTF16( |
| 113 IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, device_name)); | 125 IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, device_name)); |
| 114 loadtime_data->SetString( | 126 loadtime_data->SetString( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 136 "termsOfService", | 148 "termsOfService", |
| 137 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_TERMS_OF_SERVICE)); | 149 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_TERMS_OF_SERVICE)); |
| 138 loadtime_data->SetString( | 150 loadtime_data->SetString( |
| 139 "textBackupRestore", | 151 "textBackupRestore", |
| 140 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE)); | 152 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE)); |
| 141 | 153 |
| 142 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 154 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 143 const std::string& country_code = base::CountryCodeForCurrentTimezone(); | 155 const std::string& country_code = base::CountryCodeForCurrentTimezone(); |
| 144 loadtime_data->SetString("countryCode", country_code); | 156 loadtime_data->SetString("countryCode", country_code); |
| 145 | 157 |
| 146 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | |
| 147 | |
| 148 loadtime_data->SetBoolean(kBackupRestoreEnabled, | 158 loadtime_data->SetBoolean(kBackupRestoreEnabled, |
| 149 arc_auth_service->profile()->GetPrefs()->GetBoolean( | 159 arc_auth_service->profile()->GetPrefs()->GetBoolean( |
| 150 prefs::kArcBackupRestoreEnabled)); | 160 prefs::kArcBackupRestoreEnabled)); |
| 151 | 161 |
| 152 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); | 162 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); |
| 153 DCHECK(arc_auth_service); | 163 DCHECK(arc_auth_service); |
| 154 const std::string device_id = user_manager::known_user::GetDeviceId( | 164 const std::string device_id = user_manager::known_user::GetDeviceId( |
| 155 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); | 165 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); |
| 156 DCHECK(!device_id.empty()); | 166 DCHECK(!device_id.empty()); |
| 157 | 167 |
| 158 base::DictionaryValue request; | 168 base::DictionaryValue request; |
| 159 std::string request_string; | 169 std::string request_string; |
| 160 request.SetString(kAction, kActionInitialize); | 170 request.SetString(kAction, kActionInitialize); |
| 161 request.Set(kData, std::move(loadtime_data)); | 171 request.Set(kData, std::move(loadtime_data)); |
| 162 request.SetString(kDeviceId, device_id); | 172 request.SetString(kDeviceId, device_id); |
| 163 base::JSONWriter::Write(request, &request_string); | 173 base::JSONWriter::Write(request, &request_string); |
| 164 client_->PostMessageFromNativeHost(request_string); | 174 client_->PostMessageFromNativeHost(request_string); |
| 175 |
| 176 return true; |
| 165 } | 177 } |
| 166 | 178 |
| 167 void ArcSupportHost::OnMetricsPreferenceChanged() { | 179 void ArcSupportHost::OnMetricsPreferenceChanged() { |
| 168 SendMetricsMode(); | 180 SendMetricsMode(); |
| 169 } | 181 } |
| 170 | 182 |
| 171 void ArcSupportHost::SendMetricsMode() { | 183 void ArcSupportHost::SendMetricsMode() { |
| 172 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 184 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 173 DCHECK(arc_auth_service); | 185 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); |
| 174 const Profile* profile = arc_auth_service->profile(); | 186 const Profile* profile = arc_auth_service->profile(); |
| 175 | 187 |
| 176 const bool metrics_managed = IsMetricsReportingPolicyManaged(); | 188 const bool metrics_managed = IsMetricsReportingPolicyManaged(); |
| 177 const bool owner_profile = | 189 const bool owner_profile = |
| 178 profile && chromeos::ProfileHelper::IsOwnerProfile(profile); | 190 profile && chromeos::ProfileHelper::IsOwnerProfile(profile); |
| 179 const bool metrics_on = | 191 const bool metrics_on = |
| 180 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 192 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
| 181 | 193 |
| 182 int message_id; | 194 int message_id; |
| 183 if (metrics_managed || !owner_profile) { | 195 if (metrics_managed || !owner_profile) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 std::string response_string; | 234 std::string response_string; |
| 223 base::JSONWriter::Write(response, &response_string); | 235 base::JSONWriter::Write(response, &response_string); |
| 224 client_->PostMessageFromNativeHost(response_string); | 236 client_->PostMessageFromNativeHost(response_string); |
| 225 } | 237 } |
| 226 | 238 |
| 227 void ArcSupportHost::EnableMetrics(bool is_enabled) { | 239 void ArcSupportHost::EnableMetrics(bool is_enabled) { |
| 228 InitiateMetricsReportingChange(is_enabled, OnMetricsReportingCallbackType()); | 240 InitiateMetricsReportingChange(is_enabled, OnMetricsReportingCallbackType()); |
| 229 } | 241 } |
| 230 | 242 |
| 231 void ArcSupportHost::EnableBackupRestore(bool is_enabled) { | 243 void ArcSupportHost::EnableBackupRestore(bool is_enabled) { |
| 232 PrefService* pref_service = arc::ArcAuthService::Get()->profile()->GetPrefs(); | 244 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 245 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); |
| 246 PrefService* pref_service = arc_auth_service->profile()->GetPrefs(); |
| 233 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled); | 247 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled); |
| 234 } | 248 } |
| 235 | 249 |
| 236 void ArcSupportHost::OnMessage(const std::string& request_string) { | 250 void ArcSupportHost::OnMessage(const std::string& request_string) { |
| 237 std::unique_ptr<base::Value> request_value = | 251 std::unique_ptr<base::Value> request_value = |
| 238 base::JSONReader::Read(request_string); | 252 base::JSONReader::Read(request_string); |
| 239 base::DictionaryValue* request; | 253 base::DictionaryValue* request; |
| 240 if (!request_value || !request_value->GetAsDictionary(&request)) { | 254 if (!request_value || !request_value->GetAsDictionary(&request)) { |
| 241 NOTREACHED(); | 255 NOTREACHED(); |
| 242 return; | 256 return; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 EnableBackupRestore(is_enabled); | 294 EnableBackupRestore(is_enabled); |
| 281 } else { | 295 } else { |
| 282 NOTREACHED(); | 296 NOTREACHED(); |
| 283 } | 297 } |
| 284 } | 298 } |
| 285 | 299 |
| 286 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() | 300 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() |
| 287 const { | 301 const { |
| 288 return base::ThreadTaskRunnerHandle::Get(); | 302 return base::ThreadTaskRunnerHandle::Get(); |
| 289 } | 303 } |
| OLD | NEW |