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/remote_host_info_fetcher.h" | 5 #include "remoting/test/remote_host_info_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/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
15 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation_test_helper.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 char kRequestTestOrigin[] = | 21 const char kRequestTestOrigin[] = |
21 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk"; | 22 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk"; |
22 } | 23 } |
23 | 24 |
24 namespace remoting { | 25 namespace remoting { |
25 namespace test { | 26 namespace test { |
(...skipping 23 matching lines...) Expand all Loading... |
49 return false; | 50 return false; |
50 } | 51 } |
51 VLOG(1) << "Using remote host service request url: " << service_url; | 52 VLOG(1) << "Using remote host service request url: " << service_url; |
52 | 53 |
53 remote_host_info_callback_ = callback; | 54 remote_host_info_callback_ = callback; |
54 | 55 |
55 request_context_getter_ = new remoting::URLRequestContextGetter( | 56 request_context_getter_ = new remoting::URLRequestContextGetter( |
56 base::ThreadTaskRunnerHandle::Get(), // network_runner | 57 base::ThreadTaskRunnerHandle::Get(), // network_runner |
57 base::ThreadTaskRunnerHandle::Get()); // file_runner | 58 base::ThreadTaskRunnerHandle::Get()); // file_runner |
58 | 59 |
59 request_ = | 60 request_ = net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST, |
60 net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST, this); | 61 this, TRAFFIC_ANNOTATION_FOR_TESTS); |
61 request_->SetRequestContext(request_context_getter_.get()); | 62 request_->SetRequestContext(request_context_getter_.get()); |
62 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); | 63 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); |
63 request_->AddExtraRequestHeader(kRequestTestOrigin); | 64 request_->AddExtraRequestHeader(kRequestTestOrigin); |
64 request_->SetUploadData("application/json; charset=UTF-8", "{}"); | 65 request_->SetUploadData("application/json; charset=UTF-8", "{}"); |
65 request_->Start(); | 66 request_->Start(); |
66 | 67 |
67 return true; | 68 return true; |
68 } | 69 } |
69 | 70 |
70 void RemoteHostInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 71 void RemoteHostInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 response->GetString("authorizationCode", | 116 response->GetString("authorizationCode", |
116 &remote_host_info.authorization_code); | 117 &remote_host_info.authorization_code); |
117 response->GetString("sharedSecret", &remote_host_info.shared_secret); | 118 response->GetString("sharedSecret", &remote_host_info.shared_secret); |
118 } | 119 } |
119 | 120 |
120 base::ResetAndReturn(&remote_host_info_callback_).Run(remote_host_info); | 121 base::ResetAndReturn(&remote_host_info_callback_).Run(remote_host_info); |
121 } | 122 } |
122 | 123 |
123 } // namespace test | 124 } // namespace test |
124 } // namespace remoting | 125 } // namespace remoting |
OLD | NEW |