Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / devtools / device / webrtc / send_command_request.cc
blob7bfe5f402cb4505a5b77d33ae9bba1010248e559
1 // Copyright 2014 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 "chrome/browser/devtools/device/webrtc/send_command_request.h"
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
9 #include "components/cloud_devices/common/cloud_devices_urls.h"
10 #include "net/base/url_util.h"
12 using local_discovery::GCDApiFlow;
13 using local_discovery::GCDApiFlowRequest;
15 namespace {
17 const char kContentTypeJSON[] = "application/json";
18 const char kCommandTimeoutMs[] = "20000";
20 } // namespace
22 SendCommandRequest::SendCommandRequest(const base::DictionaryValue* request,
23 Delegate* delegate)
24 : delegate_(delegate) {
25 base::JSONWriter::Write(*request, &upload_data_);
26 DCHECK(delegate_);
29 net::URLFetcher::RequestType SendCommandRequest::GetRequestType() {
30 return net::URLFetcher::POST;
33 void SendCommandRequest::GetUploadData(std::string* upload_type,
34 std::string* upload_data) {
35 *upload_type = kContentTypeJSON;
36 *upload_data = upload_data_;
39 void SendCommandRequest::OnGCDAPIFlowError(GCDApiFlow::Status status) {
40 delegate_->OnCommandFailed();
43 void SendCommandRequest::OnGCDAPIFlowComplete(
44 const base::DictionaryValue& value) {
45 delegate_->OnCommandSucceeded(value);
48 GURL SendCommandRequest::GetURL() {
49 GURL url = cloud_devices::GetCloudDevicesRelativeURL("commands");
50 url = net::AppendQueryParameter(url, "expireInMs", kCommandTimeoutMs);
51 url = net::AppendQueryParameter(url, "responseAwaitMs", kCommandTimeoutMs);
52 return url;