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

Side by Side Diff: remoting/test/access_token_fetcher.cc

Issue 1064863004: Use base::ResetAndReturn() in remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/test/access_token_fetcher.h" 5 #include "remoting/test/access_token_fetcher.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback_helpers.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "google_apis/gaia/gaia_constants.h" 15 #include "google_apis/gaia/gaia_constants.h"
15 #include "google_apis/google_api_keys.h" 16 #include "google_apis/google_api_keys.h"
16 #include "net/url_request/url_fetcher.h" 17 #include "net/url_request/url_fetcher.h"
17 #include "remoting/base/url_request_context_getter.h" 18 #include "remoting/base/url_request_context_getter.h"
18 19
19 namespace { 20 namespace {
20 const int kMaxGetTokensRetries = 3; 21 const int kMaxGetTokensRetries = 3;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 143
143 LOG(ERROR) << "OnGetTokenInfoResponse returned an error. " 144 LOG(ERROR) << "OnGetTokenInfoResponse returned an error. "
144 << "error: " << error_string << ", " 145 << "error: " << error_string << ", "
145 << "description: " << error_description; 146 << "description: " << error_description;
146 access_token_.clear(); 147 access_token_.clear();
147 refresh_token_.clear(); 148 refresh_token_.clear();
148 } else { 149 } else {
149 DVLOG(1) << "Access Token has been validated"; 150 DVLOG(1) << "Access Token has been validated";
150 } 151 }
151 152
152 access_token_callback_.Run(access_token_, refresh_token_); 153 base::ResetAndReturn(&access_token_callback_)
153 access_token_callback_.Reset(); 154 .Run(access_token_, refresh_token_);
154 } 155 }
155 156
156 void AccessTokenFetcher::OnOAuthError() { 157 void AccessTokenFetcher::OnOAuthError() {
157 LOG(ERROR) << "AccessTokenFetcher::OnOAuthError() Called"; 158 LOG(ERROR) << "AccessTokenFetcher::OnOAuthError() Called";
158 159
159 access_token_.clear(); 160 access_token_.clear();
160 refresh_token_.clear(); 161 refresh_token_.clear();
161 162
162 access_token_callback_.Run(access_token_, refresh_token_); 163 base::ResetAndReturn(&access_token_callback_)
163 access_token_callback_.Reset(); 164 .Run(access_token_, refresh_token_);
164 } 165 }
165 166
166 void AccessTokenFetcher::OnNetworkError(int response_code) { 167 void AccessTokenFetcher::OnNetworkError(int response_code) {
167 LOG(ERROR) << "AccessTokenFetcher::OnNetworkError() Called"; 168 LOG(ERROR) << "AccessTokenFetcher::OnNetworkError() Called";
168 LOG(ERROR) << "response code: " << response_code; 169 LOG(ERROR) << "response code: " << response_code;
169 170
170 access_token_.clear(); 171 access_token_.clear();
171 refresh_token_.clear(); 172 refresh_token_.clear();
172 173
173 access_token_callback_.Run(access_token_, refresh_token_); 174 base::ResetAndReturn(&access_token_callback_)
174 access_token_callback_.Reset(); 175 .Run(access_token_, refresh_token_);
175 } 176 }
176 177
177 void AccessTokenFetcher::ValidateAccessToken() { 178 void AccessTokenFetcher::ValidateAccessToken() {
178 DVLOG(2) << "Calling GetTokenInfo to validate access token"; 179 DVLOG(2) << "Calling GetTokenInfo to validate access token";
179 180
180 // Create a new GaiaOAuthClient for each request to GAIA. 181 // Create a new GaiaOAuthClient for each request to GAIA.
181 CreateNewGaiaOAuthClientInstance(); 182 CreateNewGaiaOAuthClientInstance();
182 auth_client_->GetTokenInfo(access_token_, kMaxGetTokensRetries, 183 auth_client_->GetTokenInfo(access_token_, kMaxGetTokensRetries,
183 this); // GaiaOAuthClient::Delegate* delegate 184 this); // GaiaOAuthClient::Delegate* delegate
184 } 185 }
185 186
186 } // namespace test 187 } // namespace test
187 } // namespace remoting 188 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698