OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_auth_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
10 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 13 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
12 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 14 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
14 #include "chrome/browser/extensions/extension_util.h" | 16 #include "chrome/browser/extensions/extension_util.h" |
15 #include "chrome/browser/policy/profile_policy_connector.h" | 17 #include "chrome/browser/policy/profile_policy_connector.h" |
16 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 18 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
17 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 19 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // Reuse storage used in ARC OptIn platform app. | 219 // Reuse storage used in ARC OptIn platform app. |
218 const std::string site_url = | 220 const std::string site_url = |
219 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, | 221 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, |
220 kArcSupportExtensionId, kArcSupportStorageId); | 222 kArcSupportExtensionId, kArcSupportStorageId); |
221 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( | 223 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( |
222 profile_, GURL(site_url)); | 224 profile_, GURL(site_url)); |
223 CHECK(storage_partition_); | 225 CHECK(storage_partition_); |
224 | 226 |
225 // In case UI is disabled we assume that ARC is opted-in. | 227 // In case UI is disabled we assume that ARC is opted-in. |
226 if (!IsOptInVerificationDisabled()) { | 228 if (!IsOptInVerificationDisabled()) { |
| 229 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 230 pref_change_registrar_.Add( |
| 231 prefs::kArcEnabled, |
| 232 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, |
| 233 base::Unretained(this))); |
227 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 234 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
228 OnOptInPreferenceChanged(); | 235 OnOptInPreferenceChanged(); |
229 } else { | 236 } else { |
230 UpdateEnabledStateUMA(false); | 237 UpdateEnabledStateUMA(false); |
231 if (!disable_ui_for_testing && profile_->IsNewProfile()) { | 238 if (!disable_ui_for_testing && profile_->IsNewProfile()) { |
232 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 239 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
233 OnIsSyncingChanged(); | 240 OnIsSyncingChanged(); |
234 } | 241 } |
235 } | 242 } |
236 } else { | 243 } else { |
(...skipping 14 matching lines...) Expand all Loading... |
251 } | 258 } |
252 | 259 |
253 void ArcAuthService::Shutdown() { | 260 void ArcAuthService::Shutdown() { |
254 ShutdownBridgeAndCloseUI(); | 261 ShutdownBridgeAndCloseUI(); |
255 if (profile_) { | 262 if (profile_) { |
256 syncable_prefs::PrefServiceSyncable* pref_service_syncable = | 263 syncable_prefs::PrefServiceSyncable* pref_service_syncable = |
257 PrefServiceSyncableFromProfile(profile_); | 264 PrefServiceSyncableFromProfile(profile_); |
258 pref_service_syncable->RemoveObserver(this); | 265 pref_service_syncable->RemoveObserver(this); |
259 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); | 266 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); |
260 } | 267 } |
| 268 pref_change_registrar_.RemoveAll(); |
261 profile_ = nullptr; | 269 profile_ = nullptr; |
262 } | 270 } |
263 | 271 |
264 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { | 272 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { |
265 if (disable_ui_for_testing || IsOptInVerificationDisabled()) | 273 if (disable_ui_for_testing || IsOptInVerificationDisabled()) |
266 return; | 274 return; |
267 | 275 |
268 SetUIPage(page, status); | 276 SetUIPage(page, status); |
269 const extensions::AppWindowRegistry* const app_window_registry = | 277 const extensions::AppWindowRegistry* const app_window_registry = |
270 extensions::AppWindowRegistry::Get(profile_); | 278 extensions::AppWindowRegistry::Get(profile_); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, | 322 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, |
315 bool from_sync) { | 323 bool from_sync) { |
316 DCHECK(thread_checker_.CalledOnValidThread()); | 324 DCHECK(thread_checker_.CalledOnValidThread()); |
317 | 325 |
318 // Update UMA only for local changes | 326 // Update UMA only for local changes |
319 if (!from_sync) { | 327 if (!from_sync) { |
320 UpdateOptInActionUMA(profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled) | 328 UpdateOptInActionUMA(profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled) |
321 ? OptInActionType::OPTED_IN | 329 ? OptInActionType::OPTED_IN |
322 : OptInActionType::OPTED_OUT); | 330 : OptInActionType::OPTED_OUT); |
323 } | 331 } |
324 | |
325 OnOptInPreferenceChanged(); | |
326 } | 332 } |
327 | 333 |
328 void ArcAuthService::OnOptInPreferenceChanged() { | 334 void ArcAuthService::OnOptInPreferenceChanged() { |
329 DCHECK(thread_checker_.CalledOnValidThread()); | 335 DCHECK(thread_checker_.CalledOnValidThread()); |
330 DCHECK(profile_); | 336 DCHECK(profile_); |
331 | 337 |
332 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 338 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
333 if (state_ != State::ACTIVE) { | 339 if (state_ != State::ACTIVE) { |
334 CloseUI(); | 340 CloseUI(); |
335 auth_code_.clear(); | 341 auth_code_.clear(); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 return os << kStateFetchingCode; | 532 return os << kStateFetchingCode; |
527 case ArcAuthService::State::ACTIVE: | 533 case ArcAuthService::State::ACTIVE: |
528 return os << kStateActive; | 534 return os << kStateActive; |
529 default: | 535 default: |
530 NOTREACHED(); | 536 NOTREACHED(); |
531 return os; | 537 return os; |
532 } | 538 } |
533 } | 539 } |
534 | 540 |
535 } // namespace arc | 541 } // namespace arc |
OLD | NEW |