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

Side by Side Diff: remoting/protocol/validating_authenticator.cc

Issue 2308133002: Addressing feedback from ValidatingAuthenticator CL (Closed)
Patch Set: Fixing a gt cl formatting issue Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 115
118 default: 116 // No default statement exists as we want the compiler to error out if a
Sergey Ulanov 2016/09/02 23:13:39 Don't really need this comment - we don't have sim
119 // Log an error and fail to prevent logging a misleading error value. 117 // new value is added to the enum but not added here.
120 CHECK(false) << "Unknown validation result value: "
121 << static_cast<unsigned int>(validation_result);
122 } 118 }
123 119
120 state_ = Authenticator::REJECTED;
124 resume_callback.Run(); 121 resume_callback.Run();
125 } 122 }
126 123
127 void ValidatingAuthenticator::UpdateState( 124 void ValidatingAuthenticator::UpdateState(
128 const base::Closure& resume_callback) { 125 const base::Closure& resume_callback) {
129 DCHECK_EQ(state_, PROCESSING_MESSAGE); 126 DCHECK_EQ(state_, PROCESSING_MESSAGE);
130 127
131 // Update our current state before running |resume_callback|. 128 // Update our current state before running |resume_callback|.
132 state_ = current_authenticator_->state(); 129 state_ = current_authenticator_->state();
133 if (state_ == REJECTED) { 130 if (state_ == REJECTED) {
134 rejection_reason_ = current_authenticator_->rejection_reason(); 131 rejection_reason_ = current_authenticator_->rejection_reason();
135 } 132 }
136 133
137 resume_callback.Run(); 134 resume_callback.Run();
138 } 135 }
139 136
140 } // namespace protocol 137 } // namespace protocol
141 } // namespace remoting 138 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698