Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_negotiator.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/callback_helpers.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ptr_util.h" | |
| 12 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler.h" | |
| 13 | |
| 14 namespace arc { | |
| 15 | |
| 16 ArcTermsOfServiceNegotiator::ArcTermsOfServiceNegotiator( | |
| 17 PrefService* pref_service, | |
| 18 ArcSupportHost* support_host) | |
| 19 : pref_service_(pref_service), support_host_(support_host) { | |
| 20 DCHECK(pref_service_); | |
| 21 DCHECK(support_host_); | |
| 22 } | |
| 23 | |
| 24 ArcTermsOfServiceNegotiator::~ArcTermsOfServiceNegotiator() { | |
| 25 support_host_->RemoveObserver(this); | |
| 26 } | |
| 27 | |
| 28 void ArcTermsOfServiceNegotiator::StartNegotiate( | |
| 29 const AgreementCallback& callback) { | |
| 30 DCHECK(callback_.is_null()); | |
| 31 DCHECK(!preference_handler_); | |
| 32 callback_ = callback; | |
| 33 preference_handler_ = | |
| 34 base::MakeUnique<ArcOptInPreferenceHandler>(this, pref_service_); | |
| 35 // This automatically updates all preferences. | |
| 36 preference_handler_->Start(); | |
| 37 | |
| 38 support_host_->AddObserver(this); | |
| 39 support_host_->ShowTermsOfService(); | |
| 40 } | |
| 41 | |
| 42 void ArcTermsOfServiceNegotiator::OnWindowClosed() { | |
| 43 DCHECK(!callback_.is_null()); | |
|
Luis Héctor Chávez
2016/11/29 00:15:28
nit: for consistency with OnTermsAgreed:
DCHECK(p
hidehiko
2016/11/29 17:43:28
Done.
| |
| 44 preference_handler_.reset(); | |
| 45 support_host_->RemoveObserver(this); | |
| 46 | |
| 47 // User cancels terms-of-service agreement UI by clicking "Cancel" button | |
| 48 // or closing the window directly. | |
| 49 base::ResetAndReturn(&callback_).Run(false); | |
| 50 } | |
| 51 | |
| 52 void ArcTermsOfServiceNegotiator::OnTermsAgreed( | |
| 53 bool is_metrics_enabled, | |
| 54 bool is_backup_and_restore_enabled, | |
| 55 bool is_location_service_enabled) { | |
| 56 DCHECK(!callback_.is_null()); | |
| 57 DCHECK(preference_handler_); | |
| 58 support_host_->RemoveObserver(this); | |
| 59 | |
| 60 // Update the preferences with the value passed from UI. | |
| 61 preference_handler_->EnableMetrics(is_metrics_enabled); | |
| 62 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); | |
| 63 preference_handler_->EnableLocationService(is_location_service_enabled); | |
| 64 preference_handler_.reset(); | |
| 65 | |
| 66 base::ResetAndReturn(&callback_).Run(true); | |
| 67 } | |
| 68 | |
| 69 void ArcTermsOfServiceNegotiator::OnAuthSucceeded( | |
| 70 const std::string& auth_code) { | |
| 71 NOTREACHED(); | |
| 72 } | |
| 73 | |
| 74 void ArcTermsOfServiceNegotiator::OnRetryClicked() { | |
| 75 support_host_->ShowTermsOfService(); | |
| 76 } | |
| 77 | |
| 78 void ArcTermsOfServiceNegotiator::OnSendFeedbackClicked() { | |
| 79 NOTREACHED(); | |
| 80 } | |
| 81 | |
| 82 void ArcTermsOfServiceNegotiator::OnMetricsModeChanged(bool enabled, | |
| 83 bool managed) { | |
| 84 support_host_->SetMetricsPreferenceCheckbox(enabled, managed); | |
| 85 } | |
| 86 | |
| 87 void ArcTermsOfServiceNegotiator::OnBackupAndRestoreModeChanged(bool enabled, | |
| 88 bool managed) { | |
| 89 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed); | |
| 90 } | |
| 91 | |
| 92 void ArcTermsOfServiceNegotiator::OnLocationServicesModeChanged(bool enabled, | |
| 93 bool managed) { | |
| 94 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed); | |
| 95 } | |
| 96 | |
| 97 } // namespace arc | |
| OLD | NEW |