| 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/app_remoting_report_issue_request.h" | 5 #include "remoting/test/app_remoting_report_issue_request.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
| 12 #include "net/http/http_status_code.h" | 12 #include "net/http/http_status_code.h" |
| 13 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 13 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
| 14 #include "remoting/base/url_request_context_getter.h" | 15 #include "remoting/base/url_request_context_getter.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 const char kRequestTestOrigin[] = | 18 const char kRequestTestOrigin[] = |
| 18 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk"; | 19 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk"; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace remoting { | 22 namespace remoting { |
| 22 namespace test { | 23 namespace test { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 VLOG(1) << "Sending Report Issue service request to: " << service_url; | 48 VLOG(1) << "Sending Report Issue service request to: " << service_url; |
| 48 | 49 |
| 49 request_complete_callback_ = done_callback; | 50 request_complete_callback_ = done_callback; |
| 50 | 51 |
| 51 request_context_getter_ = new remoting::URLRequestContextGetter( | 52 request_context_getter_ = new remoting::URLRequestContextGetter( |
| 52 base::ThreadTaskRunnerHandle::Get(), // network_runner | 53 base::ThreadTaskRunnerHandle::Get(), // network_runner |
| 53 base::ThreadTaskRunnerHandle::Get()); // file_runner | 54 base::ThreadTaskRunnerHandle::Get()); // file_runner |
| 54 | 55 |
| 55 std::string upload_data = abandon_host ? "{ 'abandonHost': 'true' }" : "{}"; | 56 std::string upload_data = abandon_host ? "{ 'abandonHost': 'true' }" : "{}"; |
| 56 | 57 |
| 57 request_ = | 58 request_ = net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST, |
| 58 net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST, this); | 59 this, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 59 request_->SetRequestContext(request_context_getter_.get()); | 60 request_->SetRequestContext(request_context_getter_.get()); |
| 60 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); | 61 request_->AddExtraRequestHeader("Authorization: OAuth " + access_token); |
| 61 request_->AddExtraRequestHeader(kRequestTestOrigin); | 62 request_->AddExtraRequestHeader(kRequestTestOrigin); |
| 62 request_->SetUploadData("application/json; charset=UTF-8", upload_data); | 63 request_->SetUploadData("application/json; charset=UTF-8", upload_data); |
| 63 request_->Start(); | 64 request_->Start(); |
| 64 | 65 |
| 65 return true; | 66 return true; |
| 66 } | 67 } |
| 67 | 68 |
| 68 void AppRemotingReportIssueRequest::OnURLFetchComplete( | 69 void AppRemotingReportIssueRequest::OnURLFetchComplete( |
| 69 const net::URLFetcher* source) { | 70 const net::URLFetcher* source) { |
| 70 VLOG(2) << "URL Fetch Completed for: " << source->GetOriginalURL(); | 71 VLOG(2) << "URL Fetch Completed for: " << source->GetOriginalURL(); |
| 71 | 72 |
| 72 int response_code = request_->GetResponseCode(); | 73 int response_code = request_->GetResponseCode(); |
| 73 if (response_code != net::HTTP_OK && response_code != net::HTTP_NO_CONTENT) { | 74 if (response_code != net::HTTP_OK && response_code != net::HTTP_NO_CONTENT) { |
| 74 LOG(ERROR) << "ReportIssue request failed with error code: " | 75 LOG(ERROR) << "ReportIssue request failed with error code: " |
| 75 << response_code; | 76 << response_code; |
| 76 } | 77 } |
| 77 | 78 |
| 78 base::ResetAndReturn(&request_complete_callback_).Run(); | 79 base::ResetAndReturn(&request_complete_callback_).Run(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 } // namespace test | 82 } // namespace test |
| 82 } // namespace remoting | 83 } // namespace remoting |
| OLD | NEW |