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