| 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/optin/arc_terms_of_service_negotiator.h" | 5 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_negotiator.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/callback_helpers.h" | 7 #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 | 8 |
| 14 namespace arc { | 9 namespace arc { |
| 15 | 10 |
| 16 ArcTermsOfServiceNegotiator::ArcTermsOfServiceNegotiator( | 11 ArcTermsOfServiceNegotiator::ArcTermsOfServiceNegotiator() = default; |
| 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 | 12 |
| 24 ArcTermsOfServiceNegotiator::~ArcTermsOfServiceNegotiator() { | 13 ArcTermsOfServiceNegotiator::~ArcTermsOfServiceNegotiator() = default; |
| 25 support_host_->RemoveObserver(this); | |
| 26 } | |
| 27 | 14 |
| 28 void ArcTermsOfServiceNegotiator::StartNegotiation( | 15 void ArcTermsOfServiceNegotiator::StartNegotiation( |
| 29 const NegotiationCallback& callback) { | 16 const NegotiationCallback& callback) { |
| 30 DCHECK(pending_callback_.is_null()); | 17 DCHECK(pending_callback_.is_null()); |
| 31 DCHECK(!preference_handler_); | |
| 32 pending_callback_ = callback; | 18 pending_callback_ = callback; |
| 33 preference_handler_ = | 19 StartNegotiationImpl(); |
| 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 } | 20 } |
| 41 | 21 |
| 42 void ArcTermsOfServiceNegotiator::OnWindowClosed() { | 22 void ArcTermsOfServiceNegotiator::ReportResult(bool accepted) { |
| 43 DCHECK(!pending_callback_.is_null()); | 23 DCHECK(!pending_callback_.is_null()); |
| 44 DCHECK(preference_handler_); | 24 base::ResetAndReturn(&pending_callback_).Run(accepted); |
| 45 support_host_->RemoveObserver(this); | |
| 46 preference_handler_.reset(); | |
| 47 | |
| 48 // User cancels terms-of-service agreement UI by clicking "Cancel" button | |
| 49 // or closing the window directly. | |
| 50 base::ResetAndReturn(&pending_callback_).Run(false); | |
| 51 } | |
| 52 | |
| 53 void ArcTermsOfServiceNegotiator::OnTermsAgreed( | |
| 54 bool is_metrics_enabled, | |
| 55 bool is_backup_and_restore_enabled, | |
| 56 bool is_location_service_enabled) { | |
| 57 DCHECK(!pending_callback_.is_null()); | |
| 58 DCHECK(preference_handler_); | |
| 59 support_host_->RemoveObserver(this); | |
| 60 | |
| 61 // Update the preferences with the value passed from UI. | |
| 62 preference_handler_->EnableMetrics(is_metrics_enabled); | |
| 63 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); | |
| 64 preference_handler_->EnableLocationService(is_location_service_enabled); | |
| 65 preference_handler_.reset(); | |
| 66 | |
| 67 base::ResetAndReturn(&pending_callback_).Run(true); | |
| 68 } | |
| 69 | |
| 70 void ArcTermsOfServiceNegotiator::OnAuthSucceeded( | |
| 71 const std::string& auth_code) { | |
| 72 NOTREACHED(); | |
| 73 } | |
| 74 | |
| 75 void ArcTermsOfServiceNegotiator::OnRetryClicked() { | |
| 76 support_host_->ShowTermsOfService(); | |
| 77 } | |
| 78 | |
| 79 void ArcTermsOfServiceNegotiator::OnSendFeedbackClicked() { | |
| 80 NOTREACHED(); | |
| 81 } | |
| 82 | |
| 83 void ArcTermsOfServiceNegotiator::OnMetricsModeChanged(bool enabled, | |
| 84 bool managed) { | |
| 85 support_host_->SetMetricsPreferenceCheckbox(enabled, managed); | |
| 86 } | |
| 87 | |
| 88 void ArcTermsOfServiceNegotiator::OnBackupAndRestoreModeChanged(bool enabled, | |
| 89 bool managed) { | |
| 90 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed); | |
| 91 } | |
| 92 | |
| 93 void ArcTermsOfServiceNegotiator::OnLocationServicesModeChanged(bool enabled, | |
| 94 bool managed) { | |
| 95 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed); | |
| 96 } | 25 } |
| 97 | 26 |
| 98 } // namespace arc | 27 } // namespace arc |
| OLD | NEW |