| OLD | NEW |
| 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/host_list_fetcher.h" | 5 #include "remoting/test/host_list_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
| 14 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 14 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 15 #include "remoting/base/url_request_context_getter.h" | 16 #include "remoting/base/url_request_context_getter.h" |
| 16 | 17 |
| 17 namespace remoting { | 18 namespace remoting { |
| 18 namespace test { | 19 namespace test { |
| 19 | 20 |
| 20 HostListFetcher::HostListFetcher() { | 21 HostListFetcher::HostListFetcher() { |
| 21 } | 22 } |
| 22 | 23 |
| 23 HostListFetcher::~HostListFetcher() { | 24 HostListFetcher::~HostListFetcher() { |
| 24 } | 25 } |
| 25 | 26 |
| 26 void HostListFetcher::RetrieveHostlist(const std::string& access_token, | 27 void HostListFetcher::RetrieveHostlist(const std::string& access_token, |
| 27 const std::string& target_url, | 28 const std::string& target_url, |
| 28 const HostlistCallback& callback) { | 29 const HostlistCallback& callback) { |
| 29 VLOG(2) << "HostListFetcher::RetrieveHostlist() called"; | 30 VLOG(2) << "HostListFetcher::RetrieveHostlist() called"; |
| 30 | 31 |
| 31 DCHECK(!access_token.empty()); | 32 DCHECK(!access_token.empty()); |
| 32 DCHECK(!callback.is_null()); | 33 DCHECK(!callback.is_null()); |
| 33 DCHECK(hostlist_callback_.is_null()); | 34 DCHECK(hostlist_callback_.is_null()); |
| 34 | 35 |
| 35 hostlist_callback_ = callback; | 36 hostlist_callback_ = callback; |
| 36 | 37 |
| 37 request_context_getter_ = new remoting::URLRequestContextGetter( | 38 request_context_getter_ = new remoting::URLRequestContextGetter( |
| 38 /*network_runner=*/base::ThreadTaskRunnerHandle::Get(), | 39 /*network_runner=*/base::ThreadTaskRunnerHandle::Get(), |
| 39 /*file_runner=*/base::ThreadTaskRunnerHandle::Get()); | 40 /*file_runner=*/base::ThreadTaskRunnerHandle::Get()); |
| 40 | 41 |
| 41 request_ = | 42 request_ = net::URLFetcher::Create(GURL(target_url), net::URLFetcher::GET, |
| 42 net::URLFetcher::Create(GURL(target_url), net::URLFetcher::GET, this); | 43 this, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 43 request_->SetRequestContext(request_context_getter_.get()); | 44 request_->SetRequestContext(request_context_getter_.get()); |
| 44 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); | 45 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); |
| 45 request_->Start(); | 46 request_->Start(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 bool HostListFetcher::ProcessResponse( | 49 bool HostListFetcher::ProcessResponse( |
| 49 std::vector<HostInfo>* hostlist) { | 50 std::vector<HostInfo>* hostlist) { |
| 50 int response_code = request_->GetResponseCode(); | 51 int response_code = request_->GetResponseCode(); |
| 51 if (response_code != net::HTTP_OK) { | 52 if (response_code != net::HTTP_OK) { |
| 52 LOG(ERROR) << "Hostlist request failed with error code: " << response_code; | 53 LOG(ERROR) << "Hostlist request failed with error code: " << response_code; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 std::vector<HostInfo> hostlist; | 106 std::vector<HostInfo> hostlist; |
| 106 | 107 |
| 107 if (!ProcessResponse(&hostlist)) { | 108 if (!ProcessResponse(&hostlist)) { |
| 108 hostlist.clear(); | 109 hostlist.clear(); |
| 109 } | 110 } |
| 110 base::ResetAndReturn(&hostlist_callback_).Run(hostlist); | 111 base::ResetAndReturn(&hostlist_callback_).Run(hostlist); |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace test | 114 } // namespace test |
| 114 } // namespace remoting | 115 } // namespace remoting |
| OLD | NEW |