| 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 "remoting/protocol/validating_authenticator.h" | 5 #include "remoting/protocol/validating_authenticator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 state_ = current_authenticator_->state(); | 84 state_ = current_authenticator_->state(); |
| 85 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE); | 85 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE); |
| 86 | 86 |
| 87 return result; | 87 return result; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void ValidatingAuthenticator::OnValidateComplete( | 90 void ValidatingAuthenticator::OnValidateComplete( |
| 91 const buzz::XmlElement* message, | 91 const buzz::XmlElement* message, |
| 92 const base::Closure& resume_callback, | 92 const base::Closure& resume_callback, |
| 93 Result validation_result) { | 93 Result validation_result) { |
| 94 if (validation_result == Result::SUCCESS) { | 94 // Process the original message in the success case, otherwise map |
| 95 current_authenticator_->ProcessMessage( | 95 // |rejection_reason_| to a known reason, set |state_| to REJECTED and notify |
| 96 message, base::Bind(&ValidatingAuthenticator::UpdateState, | 96 // the listener of the connection error via the callback. |
| 97 weak_factory_.GetWeakPtr(), resume_callback)); | 97 switch (validation_result) { |
| 98 return; | 98 case Result::SUCCESS: |
| 99 } | 99 current_authenticator_->ProcessMessage( |
| 100 message, base::Bind(&ValidatingAuthenticator::UpdateState, |
| 101 weak_factory_.GetWeakPtr(), resume_callback)); |
| 102 return; |
| 100 | 103 |
| 101 // |validation_result| represents a rejected state so map the result to a | |
| 102 // rejection reason and call the callback to let the caller know the result. | |
| 103 state_ = Authenticator::REJECTED; | |
| 104 | |
| 105 switch (validation_result) { | |
| 106 case Result::ERROR_INVALID_CREDENTIALS: | 104 case Result::ERROR_INVALID_CREDENTIALS: |
| 107 rejection_reason_ = Authenticator::INVALID_CREDENTIALS; | 105 rejection_reason_ = Authenticator::INVALID_CREDENTIALS; |
| 108 break; | 106 break; |
| 109 | 107 |
| 110 case Result::ERROR_INVALID_ACCOUNT: | 108 case Result::ERROR_INVALID_ACCOUNT: |
| 111 rejection_reason_ = Authenticator::INVALID_ACCOUNT; | 109 rejection_reason_ = Authenticator::INVALID_ACCOUNT; |
| 112 break; | 110 break; |
| 113 | 111 |
| 114 case Result::ERROR_REJECTED_BY_USER: | 112 case Result::ERROR_REJECTED_BY_USER: |
| 115 rejection_reason_ = Authenticator::REJECTED_BY_USER; | 113 rejection_reason_ = Authenticator::REJECTED_BY_USER; |
| 116 break; | 114 break; |
| 117 | |
| 118 default: | |
| 119 // Log an error and fail to prevent logging a misleading error value. | |
| 120 CHECK(false) << "Unknown validation result value: " | |
| 121 << static_cast<unsigned int>(validation_result); | |
| 122 } | 115 } |
| 123 | 116 |
| 117 state_ = Authenticator::REJECTED; |
| 124 resume_callback.Run(); | 118 resume_callback.Run(); |
| 125 } | 119 } |
| 126 | 120 |
| 127 void ValidatingAuthenticator::UpdateState( | 121 void ValidatingAuthenticator::UpdateState( |
| 128 const base::Closure& resume_callback) { | 122 const base::Closure& resume_callback) { |
| 129 DCHECK_EQ(state_, PROCESSING_MESSAGE); | 123 DCHECK_EQ(state_, PROCESSING_MESSAGE); |
| 130 | 124 |
| 131 // Update our current state before running |resume_callback|. | 125 // Update our current state before running |resume_callback|. |
| 132 state_ = current_authenticator_->state(); | 126 state_ = current_authenticator_->state(); |
| 133 if (state_ == REJECTED) { | 127 if (state_ == REJECTED) { |
| 134 rejection_reason_ = current_authenticator_->rejection_reason(); | 128 rejection_reason_ = current_authenticator_->rejection_reason(); |
| 135 } | 129 } |
| 136 | 130 |
| 137 resume_callback.Run(); | 131 resume_callback.Run(); |
| 138 } | 132 } |
| 139 | 133 |
| 140 } // namespace protocol | 134 } // namespace protocol |
| 141 } // namespace remoting | 135 } // namespace remoting |
| OLD | NEW |