ExtensionInstallDialogView: fix scrolling behavior on Views (Win,Linux)
[chromium-blink-merge.git] / remoting / test / app_remoting_report_issue_request.cc
blob7a10edd3836191430d251b7caa0f23c781179940
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"
7 #include "base/bind.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"
16 namespace {
17 const char kRequestTestOrigin[] =
18 "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk";
21 namespace remoting {
22 namespace test {
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,
35 bool abandon_host,
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;
45 return false;
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' }" : "{}";
57 request_ =
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);
63 request_->Start();
65 return true;
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: "
75 << response_code;
78 base::ResetAndReturn(&request_complete_callback_).Run();
81 } // namespace test
82 } // namespace remoting