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

Unified Diff: remoting/host/token_validator_base.cc

Issue 2267643002: Adjust callers and networking delegates in remoting/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/token_validator_base.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/token_validator_base.cc
diff --git a/remoting/host/token_validator_base.cc b/remoting/host/token_validator_base.cc
index 99796421204d05850e3235f41b4f47a8f743a949..561fb00373e4775fa5d2f6995dbcc65369acc364 100644
--- a/remoting/host/token_validator_base.cc
+++ b/remoting/host/token_validator_base.cc
@@ -85,33 +85,36 @@ const std::string& TokenValidatorBase::token_scope() const {
}
// URLFetcherDelegate interface.
-void TokenValidatorBase::OnResponseStarted(net::URLRequest* source) {
+void TokenValidatorBase::OnResponseStarted(net::URLRequest* source,
+ int net_result) {
+ DCHECK_NE(net_result, net::ERR_IO_PENDING);
DCHECK_EQ(request_.get(), source);
- int bytes_read = 0;
- request_->Read(buffer_.get(), kBufferSize, &bytes_read);
- OnReadCompleted(request_.get(), bytes_read);
+ if (net_result != net::OK)
+ return;
+
+ int bytes_read = request_->Read(buffer_.get(), kBufferSize);
+ if (bytes_read > 0)
+ OnReadCompleted(request_.get(), bytes_read);
}
void TokenValidatorBase::OnReadCompleted(net::URLRequest* source,
- int bytes_read) {
+ int net_result) {
+ DCHECK_NE(net_result, net::ERR_IO_PENDING);
DCHECK_EQ(request_.get(), source);
- do {
- if (!request_->status().is_success() || bytes_read <= 0)
- break;
-
- data_.append(buffer_->data(), bytes_read);
- } while (request_->Read(buffer_.get(), kBufferSize, &bytes_read));
+ while (net_result > 0) {
+ data_.append(buffer_->data(), net_result);
+ net_result = request_->Read(buffer_.get(), kBufferSize);
+ }
- const net::URLRequestStatus status = request_->status();
+ if (net_result == net::ERR_IO_PENDING)
+ return;
- if (!status.is_io_pending()) {
- retrying_request_ = false;
- std::string shared_token = ProcessResponse();
- request_.reset();
- on_token_validated_.Run(shared_token);
- }
+ retrying_request_ = false;
+ std::string shared_token = ProcessResponse(net_result);
+ request_.reset();
+ on_token_validated_.Run(shared_token);
}
void TokenValidatorBase::OnReceivedRedirect(
@@ -190,36 +193,33 @@ bool TokenValidatorBase::IsValidScope(const std::string& token_scope) {
return token_scope == token_scope_;
}
-std::string TokenValidatorBase::ProcessResponse() {
+std::string TokenValidatorBase::ProcessResponse(int net_result) {
// Verify that we got a successful response.
- net::URLRequestStatus status = request_->status();
- if (!status.is_success()) {
- LOG(ERROR) << "Error validating token, status=" << status.status()
- << " err=" << status.error();
- return std::string();
+ if (net_result != net::OK) {
+ LOG(ERROR) << "Error validating token, err=" << net_result;
Sergey Ulanov 2016/09/21 07:13:51 incorrect indentation
+ return std::string();
}
int response = request_->GetResponseCode();
if (response != 200) {
- LOG(ERROR)
- << "Error " << response << " validating token: '" << data_ << "'";
- return std::string();
+ LOG(ERROR) << "Error " << response << " validating token: '" << data_ << "'";
Sergey Ulanov 2016/09/21 07:13:51 incorrect indentation. Revert this change and the
maksims (do not use this acc) 2016/09/21 07:31:14 Oops, is "git cl format" OK to you?
+ return std::string();
}
// Decode the JSON data from the response.
std::unique_ptr<base::Value> value = base::JSONReader::Read(data_);
base::DictionaryValue* dict;
if (!value || !value->GetAsDictionary(&dict)) {
- LOG(ERROR) << "Invalid token validation response: '" << data_ << "'";
- return std::string();
+ LOG(ERROR) << "Invalid token validation response: '" << data_ << "'";
+ return std::string();
}
std::string token_scope;
dict->GetStringWithoutPathExpansion("scope", &token_scope);
if (!IsValidScope(token_scope)) {
- LOG(ERROR) << "Invalid scope: '" << token_scope
- << "', expected: '" << token_scope_ <<"'.";
- return std::string();
+ LOG(ERROR) << "Invalid scope: '" << token_scope << "', expected: '"
+ << token_scope_ << "'.";
+ return std::string();
}
std::string shared_secret;
« no previous file with comments | « remoting/host/token_validator_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698