Chromium Code Reviews| 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..62ba99d14475c90553e51ecf068aed76fadf87f2 100644 |
| --- a/remoting/host/token_validator_base.cc |
| +++ b/remoting/host/token_validator_base.cc |
| @@ -85,11 +85,12 @@ const std::string& TokenValidatorBase::token_scope() const { |
| } |
| // URLFetcherDelegate interface. |
| -void TokenValidatorBase::OnResponseStarted(net::URLRequest* source) { |
| +void TokenValidatorBase::OnResponseStarted(net::URLRequest* source, |
| + int net_error) { |
|
Sergey Ulanov
2016/09/06 17:43:23
nit: maybe call this parameter net_result - it's n
|
| + DCHECK_NE(net::ERR_IO_PENDING, net_error); |
|
Sergey Ulanov
2016/09/06 17:43:23
nit: please swap these two parameters to make code
maksims (do not use this acc)
2016/09/21 05:17:07
Well, I've always thought it should have been othe
Sergey Ulanov
2016/09/21 07:13:50
It matters for EXPECT_EQ/EXPECT_NE from gtest, whe
|
| DCHECK_EQ(request_.get(), source); |
| - int bytes_read = 0; |
| - request_->Read(buffer_.get(), kBufferSize, &bytes_read); |
| + int bytes_read = request_->Read(buffer_.get(), kBufferSize); |
|
Sergey Ulanov
2016/09/06 17:43:23
Should we even try reading the response when net_e
maksims (do not use this acc)
2016/09/21 05:17:07
Done.
|
| OnReadCompleted(request_.get(), bytes_read); |
| } |
| @@ -97,21 +98,19 @@ void TokenValidatorBase::OnReadCompleted(net::URLRequest* source, |
| int bytes_read) { |
|
Sergey Ulanov
2016/09/06 17:43:23
rename this parameter to result or net_result and
maksims (do not use this acc)
2016/09/21 05:17:07
Done.
|
| DCHECK_EQ(request_.get(), source); |
| - do { |
| - if (!request_->status().is_success() || bytes_read <= 0) |
| - break; |
| - |
| + while (bytes_read > 0) { |
| data_.append(buffer_->data(), bytes_read); |
| - } while (request_->Read(buffer_.get(), kBufferSize, &bytes_read)); |
| + bytes_read = request_->Read(buffer_.get(), kBufferSize); |
| + } |
| - const net::URLRequestStatus status = request_->status(); |
| + int net_error = bytes_read; |
| + if (net_error == 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_error); |
| + request_.reset(); |
| + on_token_validated_.Run(shared_token); |
| } |
| void TokenValidatorBase::OnReceivedRedirect( |
| @@ -190,12 +189,10 @@ bool TokenValidatorBase::IsValidScope(const std::string& token_scope) { |
| return token_scope == token_scope_; |
| } |
| -std::string TokenValidatorBase::ProcessResponse() { |
| +std::string TokenValidatorBase::ProcessResponse(int net_error) { |
| // 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(); |
| + if (net_error != net::OK) { |
| + LOG(ERROR) << "Error validating token, err=" << net_error; |
| return std::string(); |
| } |