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