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
3 // found in the LICENSE file.
5 #include "remoting/test/app_remoting_report_issue_request.h"
8 #include "base/callback_helpers.h"
9 #include "base/logging.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "net/http/http_response_headers.h"
12 #include "net/http/http_status_code.h"
13 #include "net/url_request/url_fetcher.h"
14 #include "remoting/base/url_request_context_getter.h"
17 const char kRequestTestOrigin
[] =
18 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk";
24 AppRemotingReportIssueRequest::AppRemotingReportIssueRequest() {
27 AppRemotingReportIssueRequest::~AppRemotingReportIssueRequest() {
30 bool AppRemotingReportIssueRequest::Start(
31 const std::string
& application_id
,
32 const std::string
& host_id
,
33 const std::string
& access_token
,
34 ServiceEnvironment service_environment
,
36 base::Closure done_callback
) {
37 DCHECK(request_complete_callback_
.is_null()) << "Request pending";
39 VLOG(2) << "AppRemotingReportIssueRequest::Start() called";
41 std::string
service_url(
42 GetReportIssueUrl(application_id
, host_id
, service_environment
));
43 if (service_url
.empty()) {
44 LOG(ERROR
) << "Unrecognized service type: " << service_environment
;
47 VLOG(1) << "Sending Report Issue service request to: " << service_url
;
49 request_complete_callback_
= done_callback
;
51 request_context_getter_
= new remoting::URLRequestContextGetter(
52 base::ThreadTaskRunnerHandle::Get(), // network_runner
53 base::ThreadTaskRunnerHandle::Get()); // file_runner
55 std::string upload_data
= abandon_host
? "{ 'abandonHost': 'true' }" : "{}";
58 net::URLFetcher::Create(GURL(service_url
), net::URLFetcher::POST
, this);
59 request_
->SetRequestContext(request_context_getter_
.get());
60 request_
->AddExtraRequestHeader("Authorization: OAuth " + access_token
);
61 request_
->AddExtraRequestHeader(kRequestTestOrigin
);
62 request_
->SetUploadData("application/json; charset=UTF-8", upload_data
);
68 void AppRemotingReportIssueRequest::OnURLFetchComplete(
69 const net::URLFetcher
* source
) {
70 VLOG(2) << "URL Fetch Completed for: " << source
->GetOriginalURL();
72 int response_code
= request_
->GetResponseCode();
73 if (response_code
!= net::HTTP_OK
&& response_code
!= net::HTTP_NO_CONTENT
) {
74 LOG(ERROR
) << "ReportIssue request failed with error code: "
78 base::ResetAndReturn(&request_complete_callback_
).Run();
82 } // namespace remoting