Chromium Code Reviews| Index: chrome/browser/chromeos/arc/arc_support_host.cc |
| diff --git a/chrome/browser/chromeos/arc/arc_support_host.cc b/chrome/browser/chromeos/arc/arc_support_host.cc |
| index b8fe3a4f5a787c724199c4caabbac948d8f9dde0..8d3bafff54bf8da80901a70d19aa2da945e3a947 100644 |
| --- a/chrome/browser/chromeos/arc/arc_support_host.cc |
| +++ b/chrome/browser/chromeos/arc/arc_support_host.cc |
| @@ -23,7 +23,9 @@ |
| #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| #include "chrome/browser/ui/extensions/app_launch_params.h" |
| #include "chrome/browser/ui/extensions/application_launch.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "components/prefs/pref_service.h" |
| #include "components/user_manager/known_user.h" |
| #include "extensions/browser/extension_registry.h" |
| #include "ui/base/l10n/l10n_util.h" |
| @@ -162,6 +164,11 @@ ArcSupportHost::ArcSupportHost(Profile* profile) |
| } |
| ArcSupportHost::~ArcSupportHost() { |
| + // Delegates should have been reset to nullptr at this point. |
| + DCHECK(!auth_delegate_); |
| + DCHECK(!tos_delegate_); |
| + DCHECK(!error_delegate_); |
| + |
| if (message_host_) |
| DisconnectMessageHost(); |
| } |
| @@ -178,6 +185,25 @@ bool ArcSupportHost::HasObserver(Observer* observer) { |
| return observer_list_.HasObserver(observer); |
| } |
| +void ArcSupportHost::SetAuthDelegate(AuthDelegate* delegate) { |
| + // Since AuthDelegate and TermsOfServiceDelegate should not have overlapping |
| + // life cycle, both delegates can't be non-null at the same time. |
| + DCHECK(!(delegate && tos_delegate_)); |
| + auth_delegate_ = delegate; |
| +} |
| + |
| +void ArcSupportHost::SetTermsOfServiceDelegate( |
| + TermsOfServiceDelegate* delegate) { |
| + // Since AuthDelegate and TermsOfServiceDelegate should not have overlapping |
| + // life cycle, both delegates can't be non-null at the same time. |
| + DCHECK(!(delegate && auth_delegate_)); |
| + tos_delegate_ = delegate; |
| +} |
| + |
| +void ArcSupportHost::SetErrorDelegate(ErrorDelegate* delegate) { |
| + error_delegate_ = delegate; |
| +} |
| + |
| void ArcSupportHost::SetArcManaged(bool is_arc_managed) { |
| DCHECK(!message_host_); |
| is_arc_managed_ = is_arc_managed; |
| @@ -518,20 +544,26 @@ void ArcSupportHost::OnMessage(const base::DictionaryValue& message) { |
| } |
| if (event == kEventOnWindowClosed) { |
| - for (auto& observer : observer_list_) |
| - observer.OnWindowClosed(); |
| + // If ToS negotiation is ongoing, call the specific function. |
| + if (tos_delegate_) { |
| + tos_delegate_->OnTermsRejected(); |
| + } else { |
| + DCHECK(error_delegate_); |
| + error_delegate_->OnWindowClosedTermsAccepted(); |
| + } |
| } else if (event == kEventOnAuthSucceeded) { |
| + DCHECK(auth_delegate_); |
| std::string code; |
| if (message.GetString(kCode, &code)) { |
|
Luis Héctor Chávez
2017/05/30 16:06:27
nit: maybe convert to guard clause pattern?
if (!
victorhsieh0
2017/05/30 19:52:42
Done.
|
| - for (auto& observer : observer_list_) |
| - observer.OnAuthSucceeded(code); |
| + auth_delegate_->OnAuthSucceeded(code); |
| } else { |
| NOTREACHED(); |
| } |
| } else if (event == kEventOnAuthFailed) { |
| - for (auto& observer : observer_list_) |
| - observer.OnAuthFailed(); |
| + DCHECK(auth_delegate_); |
| + auth_delegate_->OnAuthFailed(); |
| } else if (event == kEventOnAgreed) { |
| + DCHECK(tos_delegate_); |
| bool is_metrics_enabled; |
| bool is_backup_restore_enabled; |
| bool is_location_service_enabled; |
| @@ -540,19 +572,26 @@ void ArcSupportHost::OnMessage(const base::DictionaryValue& message) { |
| &is_backup_restore_enabled) && |
| message.GetBoolean(kIsLocationServiceEnabled, |
| &is_location_service_enabled)) { |
| - for (auto& observer : observer_list_) { |
| - observer.OnTermsAgreed(is_metrics_enabled, is_backup_restore_enabled, |
| - is_location_service_enabled); |
| - } |
| + tos_delegate_->OnTermsAgreed(is_metrics_enabled, |
| + is_backup_restore_enabled, |
| + is_location_service_enabled); |
| } else { |
| NOTREACHED(); |
| } |
| } else if (event == kEventOnRetryClicked) { |
| - for (auto& observer : observer_list_) |
| - observer.OnRetryClicked(); |
| + // If ToS negotiation or manual authentication is ongoing, call the |
| + // corresponding delegate. Otherwise, call the general retry function. |
| + if (tos_delegate_) { |
| + tos_delegate_->OnTermsRetryClicked(); |
| + } else if (auth_delegate_) { |
| + auth_delegate_->OnAuthRetryClicked(); |
| + } else { |
| + DCHECK(error_delegate_); |
| + error_delegate_->OnRetryClicked(); |
| + } |
| } else if (event == kEventOnSendFeedbackClicked) { |
| - for (auto& observer : observer_list_) |
| - observer.OnSendFeedbackClicked(); |
| + DCHECK(error_delegate_); |
| + error_delegate_->OnSendFeedbackClicked(); |
| } else { |
| LOG(ERROR) << "Unknown message: " << event; |
| NOTREACHED(); |