Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Unified Diff: chrome/browser/chromeos/arc/arc_support_host.cc

Issue 2844383006: Turn ArcSupportHost from Observer model to Delegate (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..47b16db185892b5b86256f8a45eefae41683355c 100644
--- a/chrome/browser/chromeos/arc/arc_support_host.cc
+++ b/chrome/browser/chromeos/arc/arc_support_host.cc
@@ -162,6 +162,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 +183,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,41 +542,53 @@ 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_->OnWindowClosed();
+ }
} else if (event == kEventOnAuthSucceeded) {
+ DCHECK(auth_delegate_);
std::string code;
- if (message.GetString(kCode, &code)) {
- for (auto& observer : observer_list_)
- observer.OnAuthSucceeded(code);
- } else {
+ if (!message.GetString(kCode, &code)) {
NOTREACHED();
+ return;
}
+ auth_delegate_->OnAuthSucceeded(code);
} 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;
- if (message.GetBoolean(kIsMetricsEnabled, &is_metrics_enabled) &&
- message.GetBoolean(kIsBackupRestoreEnabled,
- &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);
- }
- } else {
+ if (!message.GetBoolean(kIsMetricsEnabled, &is_metrics_enabled) ||
+ !message.GetBoolean(kIsBackupRestoreEnabled,
+ &is_backup_restore_enabled) ||
+ !message.GetBoolean(kIsLocationServiceEnabled,
+ &is_location_service_enabled)) {
NOTREACHED();
+ return;
}
+ tos_delegate_->OnTermsAgreed(is_metrics_enabled, is_backup_restore_enabled,
+ is_location_service_enabled);
} 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();
« no previous file with comments | « chrome/browser/chromeos/arc/arc_support_host.h ('k') | chrome/browser/chromeos/arc/arc_support_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698