| 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::StartNegotiation( |
| 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()); |
| 44 DCHECK(preference_handler_); |
| 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(&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(!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(&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 } |
| 97 |
| 98 } // namespace arc |
| OLD | NEW |