Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / devtools / device / webrtc / devtools_bridge_instances_request.cc
blob1ddf6e6695c7387a57e49af7ffdd67d1071c3ff0
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/devtools_bridge_instances_request.h"
7 #include "base/values.h"
8 #include "components/cloud_devices/common/cloud_devices_urls.h"
9 #include "net/base/url_util.h"
11 namespace {
13 std::string GetKind(const base::DictionaryValue& value) {
14 std::string result;
15 value.GetString("kind", &result);
16 return result;
19 bool HasCommand(const base::DictionaryValue& commands_defs_value,
20 const std::string& command_name) {
21 const base::DictionaryValue* command_value;
22 return commands_defs_value.GetDictionary(command_name, &command_value) &&
23 GetKind(*command_value) == "clouddevices#commandDef";
26 } // namespace
28 DevToolsBridgeInstancesRequest::Instance::~Instance() {
31 DevToolsBridgeInstancesRequest::DevToolsBridgeInstancesRequest(
32 Delegate* delegate)
33 : delegate_(delegate) {
34 DCHECK(delegate_);
37 DevToolsBridgeInstancesRequest::~DevToolsBridgeInstancesRequest() {
40 void DevToolsBridgeInstancesRequest::OnGCDAPIFlowError(
41 local_discovery::GCDApiFlow::Status status) {
42 delegate_->OnDevToolsBridgeInstancesRequestFailed();
45 void DevToolsBridgeInstancesRequest::OnGCDAPIFlowComplete(
46 const base::DictionaryValue& value) {
47 const base::ListValue* device_list_value = NULL;
48 if (GetKind(value) == "clouddevices#devicesListResponse" &&
49 value.GetList("devices", &device_list_value)) {
50 for (const auto& device_value : *device_list_value) {
51 const base::DictionaryValue* dictionary;
52 if (device_value->GetAsDictionary(&dictionary))
53 TryAddInstance(*dictionary);
57 delegate_->OnDevToolsBridgeInstancesRequestSucceeded(result_);
60 GURL DevToolsBridgeInstancesRequest::GetURL() {
61 return cloud_devices::GetCloudDevicesRelativeURL("devices");
64 void DevToolsBridgeInstancesRequest::TryAddInstance(
65 const base::DictionaryValue& device_value) {
66 if (GetKind(device_value) != "clouddevices#device")
67 return;
69 const base::DictionaryValue* commands_defs_value;
70 if (!device_value.GetDictionary("commandDefs", &commands_defs_value))
71 return;
73 if (!HasCommand(*commands_defs_value, "base._startSession") ||
74 !HasCommand(*commands_defs_value, "base._iceExchange") ||
75 !HasCommand(*commands_defs_value, "base._renegotiate")) {
76 return;
79 Instance instance;
80 if (!device_value.GetString("id", &instance.id))
81 return;
82 if (!device_value.GetString("displayName", &instance.display_name))
83 return;
85 result_.push_back(instance);