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

Side by Side 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 unified diff | Download patch
OLDNEW
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/arc_support_host.h" 5 #include "chrome/browser/chromeos/arc/arc_support_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/system/devicetype_utils.h" 10 #include "ash/system/devicetype_utils.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // static 156 // static
157 const char ArcSupportHost::kStorageId[] = "arc_support"; 157 const char ArcSupportHost::kStorageId[] = "arc_support";
158 158
159 ArcSupportHost::ArcSupportHost(Profile* profile) 159 ArcSupportHost::ArcSupportHost(Profile* profile)
160 : profile_(profile), 160 : profile_(profile),
161 request_open_app_callback_(base::Bind(&RequestOpenApp)) { 161 request_open_app_callback_(base::Bind(&RequestOpenApp)) {
162 DCHECK(profile_); 162 DCHECK(profile_);
163 } 163 }
164 164
165 ArcSupportHost::~ArcSupportHost() { 165 ArcSupportHost::~ArcSupportHost() {
166 // Delegates should have been reset to nullptr at this point.
167 DCHECK(!auth_delegate_);
168 DCHECK(!tos_delegate_);
169 DCHECK(!error_delegate_);
170
166 if (message_host_) 171 if (message_host_)
167 DisconnectMessageHost(); 172 DisconnectMessageHost();
168 } 173 }
169 174
170 void ArcSupportHost::AddObserver(Observer* observer) { 175 void ArcSupportHost::AddObserver(Observer* observer) {
171 observer_list_.AddObserver(observer); 176 observer_list_.AddObserver(observer);
172 } 177 }
173 178
174 void ArcSupportHost::RemoveObserver(Observer* observer) { 179 void ArcSupportHost::RemoveObserver(Observer* observer) {
175 observer_list_.RemoveObserver(observer); 180 observer_list_.RemoveObserver(observer);
176 } 181 }
177 182
178 bool ArcSupportHost::HasObserver(Observer* observer) { 183 bool ArcSupportHost::HasObserver(Observer* observer) {
179 return observer_list_.HasObserver(observer); 184 return observer_list_.HasObserver(observer);
180 } 185 }
181 186
187 void ArcSupportHost::SetAuthDelegate(AuthDelegate* delegate) {
188 // Since AuthDelegate and TermsOfServiceDelegate should not have overlapping
189 // life cycle, both delegates can't be non-null at the same time.
190 DCHECK(!(delegate && tos_delegate_));
191 auth_delegate_ = delegate;
192 }
193
194 void ArcSupportHost::SetTermsOfServiceDelegate(
195 TermsOfServiceDelegate* delegate) {
196 // Since AuthDelegate and TermsOfServiceDelegate should not have overlapping
197 // life cycle, both delegates can't be non-null at the same time.
198 DCHECK(!(delegate && auth_delegate_));
199 tos_delegate_ = delegate;
200 }
201
202 void ArcSupportHost::SetErrorDelegate(ErrorDelegate* delegate) {
203 error_delegate_ = delegate;
204 }
205
182 void ArcSupportHost::SetArcManaged(bool is_arc_managed) { 206 void ArcSupportHost::SetArcManaged(bool is_arc_managed) {
183 DCHECK(!message_host_); 207 DCHECK(!message_host_);
184 is_arc_managed_ = is_arc_managed; 208 is_arc_managed_ = is_arc_managed;
185 } 209 }
186 210
187 void ArcSupportHost::Close() { 211 void ArcSupportHost::Close() {
188 ui_page_ = UIPage::NO_PAGE; 212 ui_page_ = UIPage::NO_PAGE;
189 if (!message_host_) { 213 if (!message_host_) {
190 VLOG(2) << "ArcSupportHost::Close() is called " 214 VLOG(2) << "ArcSupportHost::Close() is called "
191 << "but message_host_ is not available."; 215 << "but message_host_ is not available.";
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 536 }
513 537
514 void ArcSupportHost::OnMessage(const base::DictionaryValue& message) { 538 void ArcSupportHost::OnMessage(const base::DictionaryValue& message) {
515 std::string event; 539 std::string event;
516 if (!message.GetString(kEvent, &event)) { 540 if (!message.GetString(kEvent, &event)) {
517 NOTREACHED(); 541 NOTREACHED();
518 return; 542 return;
519 } 543 }
520 544
521 if (event == kEventOnWindowClosed) { 545 if (event == kEventOnWindowClosed) {
522 for (auto& observer : observer_list_) 546 // If ToS negotiation is ongoing, call the specific function.
523 observer.OnWindowClosed(); 547 if (tos_delegate_) {
548 tos_delegate_->OnTermsRejected();
549 } else {
550 DCHECK(error_delegate_);
551 error_delegate_->OnWindowClosed();
552 }
524 } else if (event == kEventOnAuthSucceeded) { 553 } else if (event == kEventOnAuthSucceeded) {
554 DCHECK(auth_delegate_);
525 std::string code; 555 std::string code;
526 if (message.GetString(kCode, &code)) { 556 if (!message.GetString(kCode, &code)) {
527 for (auto& observer : observer_list_)
528 observer.OnAuthSucceeded(code);
529 } else {
530 NOTREACHED(); 557 NOTREACHED();
558 return;
531 } 559 }
560 auth_delegate_->OnAuthSucceeded(code);
532 } else if (event == kEventOnAuthFailed) { 561 } else if (event == kEventOnAuthFailed) {
533 for (auto& observer : observer_list_) 562 DCHECK(auth_delegate_);
534 observer.OnAuthFailed(); 563 auth_delegate_->OnAuthFailed();
535 } else if (event == kEventOnAgreed) { 564 } else if (event == kEventOnAgreed) {
565 DCHECK(tos_delegate_);
536 bool is_metrics_enabled; 566 bool is_metrics_enabled;
537 bool is_backup_restore_enabled; 567 bool is_backup_restore_enabled;
538 bool is_location_service_enabled; 568 bool is_location_service_enabled;
539 if (message.GetBoolean(kIsMetricsEnabled, &is_metrics_enabled) && 569 if (!message.GetBoolean(kIsMetricsEnabled, &is_metrics_enabled) ||
540 message.GetBoolean(kIsBackupRestoreEnabled, 570 !message.GetBoolean(kIsBackupRestoreEnabled,
541 &is_backup_restore_enabled) && 571 &is_backup_restore_enabled) ||
542 message.GetBoolean(kIsLocationServiceEnabled, 572 !message.GetBoolean(kIsLocationServiceEnabled,
543 &is_location_service_enabled)) { 573 &is_location_service_enabled)) {
544 for (auto& observer : observer_list_) { 574 NOTREACHED();
545 observer.OnTermsAgreed(is_metrics_enabled, is_backup_restore_enabled, 575 return;
546 is_location_service_enabled); 576 }
547 } 577 tos_delegate_->OnTermsAgreed(is_metrics_enabled, is_backup_restore_enabled,
578 is_location_service_enabled);
579 } else if (event == kEventOnRetryClicked) {
580 // If ToS negotiation or manual authentication is ongoing, call the
581 // corresponding delegate. Otherwise, call the general retry function.
582 if (tos_delegate_) {
583 tos_delegate_->OnTermsRetryClicked();
584 } else if (auth_delegate_) {
585 auth_delegate_->OnAuthRetryClicked();
548 } else { 586 } else {
549 NOTREACHED(); 587 DCHECK(error_delegate_);
588 error_delegate_->OnRetryClicked();
550 } 589 }
551 } else if (event == kEventOnRetryClicked) {
552 for (auto& observer : observer_list_)
553 observer.OnRetryClicked();
554 } else if (event == kEventOnSendFeedbackClicked) { 590 } else if (event == kEventOnSendFeedbackClicked) {
555 for (auto& observer : observer_list_) 591 DCHECK(error_delegate_);
556 observer.OnSendFeedbackClicked(); 592 error_delegate_->OnSendFeedbackClicked();
557 } else { 593 } else {
558 LOG(ERROR) << "Unknown message: " << event; 594 LOG(ERROR) << "Unknown message: " << event;
559 NOTREACHED(); 595 NOTREACHED();
560 } 596 }
561 } 597 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698