| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/devtools/device/webrtc/send_command_request.h" | 5 #include "chrome/browser/devtools/device/webrtc/send_command_request.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "components/cloud_devices/common/cloud_devices_urls.h" | 9 #include "components/cloud_devices/common/cloud_devices_urls.h" |
| 10 #include "net/base/url_util.h" | 10 #include "net/base/url_util.h" |
| 11 | 11 |
| 12 using local_discovery::GCDApiFlow; | 12 using local_discovery::GCDApiFlow; |
| 13 using local_discovery::GCDApiFlowRequest; | 13 using local_discovery::GCDApiFlowRequest; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const char kContentTypeJSON[] = "application/json"; | 17 const char kContentTypeJSON[] = "application/json"; |
| 18 const char kCommandTimeoutMs[] = "20000"; | 18 const char kCommandTimeoutMs[] = "20000"; |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 SendCommandRequest::SendCommandRequest(const base::DictionaryValue* request, | 22 SendCommandRequest::SendCommandRequest(const base::DictionaryValue* request, |
| 23 Delegate* delegate) | 23 Delegate* delegate) |
| 24 : delegate_(delegate) { | 24 : delegate_(delegate) { |
| 25 base::JSONWriter::Write(request, &upload_data_); | 25 base::JSONWriter::Write(*request, &upload_data_); |
| 26 DCHECK(delegate_); | 26 DCHECK(delegate_); |
| 27 } | 27 } |
| 28 | 28 |
| 29 net::URLFetcher::RequestType SendCommandRequest::GetRequestType() { | 29 net::URLFetcher::RequestType SendCommandRequest::GetRequestType() { |
| 30 return net::URLFetcher::POST; | 30 return net::URLFetcher::POST; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void SendCommandRequest::GetUploadData(std::string* upload_type, | 33 void SendCommandRequest::GetUploadData(std::string* upload_type, |
| 34 std::string* upload_data) { | 34 std::string* upload_data) { |
| 35 *upload_type = kContentTypeJSON; | 35 *upload_type = kContentTypeJSON; |
| 36 *upload_data = upload_data_; | 36 *upload_data = upload_data_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void SendCommandRequest::OnGCDAPIFlowError(GCDApiFlow::Status status) { | 39 void SendCommandRequest::OnGCDAPIFlowError(GCDApiFlow::Status status) { |
| 40 delegate_->OnCommandFailed(); | 40 delegate_->OnCommandFailed(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SendCommandRequest::OnGCDAPIFlowComplete( | 43 void SendCommandRequest::OnGCDAPIFlowComplete( |
| 44 const base::DictionaryValue& value) { | 44 const base::DictionaryValue& value) { |
| 45 delegate_->OnCommandSucceeded(value); | 45 delegate_->OnCommandSucceeded(value); |
| 46 } | 46 } |
| 47 | 47 |
| 48 GURL SendCommandRequest::GetURL() { | 48 GURL SendCommandRequest::GetURL() { |
| 49 GURL url = cloud_devices::GetCloudDevicesRelativeURL("commands"); | 49 GURL url = cloud_devices::GetCloudDevicesRelativeURL("commands"); |
| 50 url = net::AppendQueryParameter(url, "expireInMs", kCommandTimeoutMs); | 50 url = net::AppendQueryParameter(url, "expireInMs", kCommandTimeoutMs); |
| 51 url = net::AppendQueryParameter(url, "responseAwaitMs", kCommandTimeoutMs); | 51 url = net::AppendQueryParameter(url, "responseAwaitMs", kCommandTimeoutMs); |
| 52 return url; | 52 return url; |
| 53 } | 53 } |
| OLD | NEW |