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

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

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 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/chromoting_test_driver_environment.h" 5 #include "remoting/test/chromoting_test_driver_environment.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"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (!access_token_.empty()) { 49 if (!access_token_.empty()) {
50 return true; 50 return true;
51 } 51 }
52 52
53 if (!base::MessageLoop::current()) { 53 if (!base::MessageLoop::current()) {
54 message_loop_.reset(new base::MessageLoopForIO); 54 message_loop_.reset(new base::MessageLoopForIO);
55 } 55 }
56 56
57 // If a unit test has set |test_refresh_token_store_| then we should use it 57 // If a unit test has set |test_refresh_token_store_| then we should use it
58 // below. Note that we do not want to destroy the test object. 58 // below. Note that we do not want to destroy the test object.
59 scoped_ptr<RefreshTokenStore> temporary_refresh_token_store; 59 std::unique_ptr<RefreshTokenStore> temporary_refresh_token_store;
60 RefreshTokenStore* refresh_token_store = test_refresh_token_store_; 60 RefreshTokenStore* refresh_token_store = test_refresh_token_store_;
61 if (!refresh_token_store) { 61 if (!refresh_token_store) {
62 temporary_refresh_token_store = 62 temporary_refresh_token_store =
63 RefreshTokenStore::OnDisk(user_name_, refresh_token_file_path_); 63 RefreshTokenStore::OnDisk(user_name_, refresh_token_file_path_);
64 refresh_token_store = temporary_refresh_token_store.get(); 64 refresh_token_store = temporary_refresh_token_store.get();
65 } 65 }
66 66
67 // Check to see if we have a refresh token stored for this user. 67 // Check to see if we have a refresh token stored for this user.
68 refresh_token_ = refresh_token_store->FetchRefreshToken(); 68 refresh_token_ = refresh_token_store->FetchRefreshToken();
69 if (refresh_token_.empty()) { 69 if (refresh_token_.empty()) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 access_token_.clear(); 193 access_token_.clear();
194 194
195 AccessTokenCallback access_token_callback = 195 AccessTokenCallback access_token_callback =
196 base::Bind(&ChromotingTestDriverEnvironment::OnAccessTokenRetrieved, 196 base::Bind(&ChromotingTestDriverEnvironment::OnAccessTokenRetrieved,
197 base::Unretained(this), run_loop.QuitClosure()); 197 base::Unretained(this), run_loop.QuitClosure());
198 198
199 // If a unit test has set |test_access_token_fetcher_| then we should use it 199 // If a unit test has set |test_access_token_fetcher_| then we should use it
200 // below. Note that we do not want to destroy the test object at the end of 200 // below. Note that we do not want to destroy the test object at the end of
201 // the function which is why we have the dance below. 201 // the function which is why we have the dance below.
202 scoped_ptr<AccessTokenFetcher> temporary_access_token_fetcher; 202 std::unique_ptr<AccessTokenFetcher> temporary_access_token_fetcher;
203 AccessTokenFetcher* access_token_fetcher = test_access_token_fetcher_; 203 AccessTokenFetcher* access_token_fetcher = test_access_token_fetcher_;
204 if (!access_token_fetcher) { 204 if (!access_token_fetcher) {
205 temporary_access_token_fetcher.reset(new AccessTokenFetcher()); 205 temporary_access_token_fetcher.reset(new AccessTokenFetcher());
206 access_token_fetcher = temporary_access_token_fetcher.get(); 206 access_token_fetcher = temporary_access_token_fetcher.get();
207 } 207 }
208 208
209 if (!auth_code.empty()) { 209 if (!auth_code.empty()) {
210 // If the user passed in an authcode, then use it to retrieve an 210 // If the user passed in an authcode, then use it to retrieve an
211 // updated access/refresh token. 211 // updated access/refresh token.
212 access_token_fetcher->GetAccessTokenFromAuthCode(auth_code, 212 access_token_fetcher->GetAccessTokenFromAuthCode(auth_code,
213 access_token_callback); 213 access_token_callback);
214 } else { 214 } else {
215 DCHECK(!refresh_token_.empty()); 215 DCHECK(!refresh_token_.empty());
216 216
217 access_token_fetcher->GetAccessTokenFromRefreshToken(refresh_token_, 217 access_token_fetcher->GetAccessTokenFromRefreshToken(refresh_token_,
218 access_token_callback); 218 access_token_callback);
219 } 219 }
220 220
221 run_loop.Run(); 221 run_loop.Run();
222 222
223 // If we were using an auth_code and received a valid refresh token, 223 // If we were using an auth_code and received a valid refresh token,
224 // then we want to store it locally. If we had an auth code and did not 224 // then we want to store it locally. If we had an auth code and did not
225 // receive a refresh token, then we should let the user know and exit. 225 // receive a refresh token, then we should let the user know and exit.
226 if (!auth_code.empty()) { 226 if (!auth_code.empty()) {
227 if (!refresh_token_.empty()) { 227 if (!refresh_token_.empty()) {
228 // If a unit test has set |test_refresh_token_store_| then we should use 228 // If a unit test has set |test_refresh_token_store_| then we should use
229 // it below. Note that we do not want to destroy the test object. 229 // it below. Note that we do not want to destroy the test object.
230 scoped_ptr<RefreshTokenStore> temporary_refresh_token_store; 230 std::unique_ptr<RefreshTokenStore> temporary_refresh_token_store;
231 RefreshTokenStore* refresh_token_store = test_refresh_token_store_; 231 RefreshTokenStore* refresh_token_store = test_refresh_token_store_;
232 if (!refresh_token_store) { 232 if (!refresh_token_store) {
233 temporary_refresh_token_store = 233 temporary_refresh_token_store =
234 RefreshTokenStore::OnDisk(user_name_, refresh_token_file_path_); 234 RefreshTokenStore::OnDisk(user_name_, refresh_token_file_path_);
235 refresh_token_store = temporary_refresh_token_store.get(); 235 refresh_token_store = temporary_refresh_token_store.get();
236 } 236 }
237 237
238 if (!refresh_token_store->StoreRefreshToken(refresh_token_)) { 238 if (!refresh_token_store->StoreRefreshToken(refresh_token_)) {
239 // If we failed to persist the refresh token, then we should let the 239 // If we failed to persist the refresh token, then we should let the
240 // user sort out the issue before continuing. 240 // user sort out the issue before continuing.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 bool ChromotingTestDriverEnvironment::RetrieveHostList() { 277 bool ChromotingTestDriverEnvironment::RetrieveHostList() {
278 base::RunLoop run_loop; 278 base::RunLoop run_loop;
279 279
280 // Clear the previous host info. 280 // Clear the previous host info.
281 host_info_ = HostInfo(); 281 host_info_ = HostInfo();
282 282
283 // If a unit test has set |test_host_list_fetcher_| then we should use it 283 // If a unit test has set |test_host_list_fetcher_| then we should use it
284 // below. Note that we do not want to destroy the test object at the end of 284 // below. Note that we do not want to destroy the test object at the end of
285 // the function which is why we have the dance below. 285 // the function which is why we have the dance below.
286 scoped_ptr<HostListFetcher> temporary_host_list_fetcher; 286 std::unique_ptr<HostListFetcher> temporary_host_list_fetcher;
287 HostListFetcher* host_list_fetcher = test_host_list_fetcher_; 287 HostListFetcher* host_list_fetcher = test_host_list_fetcher_;
288 if (!host_list_fetcher) { 288 if (!host_list_fetcher) {
289 temporary_host_list_fetcher.reset(new HostListFetcher()); 289 temporary_host_list_fetcher.reset(new HostListFetcher());
290 host_list_fetcher = temporary_host_list_fetcher.get(); 290 host_list_fetcher = temporary_host_list_fetcher.get();
291 } 291 }
292 292
293 remoting::test::HostListFetcher::HostlistCallback host_list_callback = 293 remoting::test::HostListFetcher::HostlistCallback host_list_callback =
294 base::Bind(&ChromotingTestDriverEnvironment::OnHostListRetrieved, 294 base::Bind(&ChromotingTestDriverEnvironment::OnHostListRetrieved,
295 base::Unretained(this), run_loop.QuitClosure()); 295 base::Unretained(this), run_loop.QuitClosure());
296 296
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 const std::vector<HostInfo>& retrieved_host_list) { 334 const std::vector<HostInfo>& retrieved_host_list) {
335 VLOG(1) << "OnHostListRetrieved() Called"; 335 VLOG(1) << "OnHostListRetrieved() Called";
336 336
337 host_list_ = retrieved_host_list; 337 host_list_ = retrieved_host_list;
338 338
339 done_closure.Run(); 339 done_closure.Run();
340 } 340 }
341 341
342 } // namespace test 342 } // namespace test
343 } // namespace remoting 343 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/chromoting_test_driver_environment.h ('k') | remoting/test/chromoting_test_driver_environment_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698