| 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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
| 16 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 17 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 18 #include "remoting/base/url_request_context_getter.h" | 18 #include "remoting/base/url_request_context_getter.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 const char kRequestTestOrigin[] = | 21 const char kRequestTestOrigin[] = |
| 22 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk"; | 22 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk"; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace remoting { | 25 namespace remoting { |
| 26 namespace test { | 26 namespace test { |
| 27 | 27 |
| 28 RemoteHostInfoFetcher::RemoteHostInfoFetcher() {} | 28 RemoteHostInfoFetcher::RemoteHostInfoFetcher() { |
| 29 } |
| 29 | 30 |
| 30 RemoteHostInfoFetcher::~RemoteHostInfoFetcher() {} | 31 RemoteHostInfoFetcher::~RemoteHostInfoFetcher() { |
| 32 } |
| 31 | 33 |
| 32 bool RemoteHostInfoFetcher::RetrieveRemoteHostInfo( | 34 bool RemoteHostInfoFetcher::RetrieveRemoteHostInfo( |
| 33 const std::string& application_id, | 35 const std::string& application_id, |
| 34 const std::string& access_token, | 36 const std::string& access_token, |
| 35 ServiceEnvironment service_environment, | 37 ServiceEnvironment service_environment, |
| 36 const RemoteHostInfoCallback& callback) { | 38 const RemoteHostInfoCallback& callback) { |
| 37 DCHECK(!application_id.empty()); | 39 DCHECK(!application_id.empty()); |
| 38 DCHECK(!access_token.empty()); | 40 DCHECK(!access_token.empty()); |
| 39 DCHECK(!callback.is_null()); | 41 DCHECK(!callback.is_null()); |
| 40 DCHECK(remote_host_info_callback_.is_null()); | 42 DCHECK(remote_host_info_callback_.is_null()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 application_id.c_str()); | 57 application_id.c_str()); |
| 56 break; | 58 break; |
| 57 | 59 |
| 58 default: | 60 default: |
| 59 LOG(ERROR) << "Unrecognized service type: " << service_environment; | 61 LOG(ERROR) << "Unrecognized service type: " << service_environment; |
| 60 return false; | 62 return false; |
| 61 } | 63 } |
| 62 | 64 |
| 63 remote_host_info_callback_ = callback; | 65 remote_host_info_callback_ = callback; |
| 64 | 66 |
| 65 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; | 67 request_context_getter_ = new remoting::URLRequestContextGetter( |
| 66 request_context_getter = new remoting::URLRequestContextGetter( | |
| 67 base::ThreadTaskRunnerHandle::Get(), // network_runner | 68 base::ThreadTaskRunnerHandle::Get(), // network_runner |
| 68 base::ThreadTaskRunnerHandle::Get()); // file_runner | 69 base::ThreadTaskRunnerHandle::Get()); // file_runner |
| 69 | 70 |
| 70 request_.reset( | 71 request_.reset( |
| 71 net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST, this)); | 72 net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST, this)); |
| 72 request_->SetRequestContext(request_context_getter.get()); | 73 request_->SetRequestContext(request_context_getter_.get()); |
| 73 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); | 74 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); |
| 74 request_->AddExtraRequestHeader(kRequestTestOrigin); | 75 request_->AddExtraRequestHeader(kRequestTestOrigin); |
| 75 request_->SetUploadData("application/json; charset=UTF-8", "{}"); | 76 request_->SetUploadData("application/json; charset=UTF-8", "{}"); |
| 76 request_->Start(); | 77 request_->Start(); |
| 77 | 78 |
| 78 return true; | 79 return true; |
| 79 } | 80 } |
| 80 | 81 |
| 81 void RemoteHostInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 82 void RemoteHostInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 82 DCHECK(source); | 83 DCHECK(source); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 &remote_host_info.authorization_code); | 132 &remote_host_info.authorization_code); |
| 132 response->GetString("sharedSecret", &remote_host_info.shared_secret); | 133 response->GetString("sharedSecret", &remote_host_info.shared_secret); |
| 133 } | 134 } |
| 134 | 135 |
| 135 remote_host_info_callback_.Run(remote_host_info); | 136 remote_host_info_callback_.Run(remote_host_info); |
| 136 remote_host_info_callback_.Reset(); | 137 remote_host_info_callback_.Reset(); |
| 137 } | 138 } |
| 138 | 139 |
| 139 } // namespace test | 140 } // namespace test |
| 140 } // namespace remoting | 141 } // namespace remoting |
| OLD | NEW |