1 // Copyright 2013 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. 4 5 #include "content/browser/devtools/devtools_system_info_handler.h" 6 7 #include "base/bind.h" 8 #include "base/callback.h" 9 #include "base/values.h" 10 #include "content/browser/devtools/devtools_protocol_constants.h" 11 #include "content/browser/gpu/compositor_util.h" 12 #include "content/browser/gpu/gpu_data_manager_impl.h" 13 #include "gpu/config/gpu_info.h" 14 15 namespace content { 16 17 namespace { 18 19 const char kAuxAttributes[] = "auxAttributes"; 20 const char kDeviceId[] = "deviceId"; 21 const char kDeviceString[] = "deviceString"; 22 const char kDevices[] = "devices"; 23 const char kDriverBugWorkarounds[] = "driverBugWorkarounds"; 24 const char kFeatureStatus[] = "featureStatus"; 25 const char kGPU[] = "gpu"; 26 const char kModelName[] = "modelName"; 27 const char kModelVersion[] = "modelVersion"; 28 const char kVendorId[] = "vendorId"; 29 const char kVendorString[] = "vendorString"; 30 31 class AuxGPUInfoEnumerator : public gpu::GPUInfo::Enumerator { 32 public: 33 AuxGPUInfoEnumerator(base::DictionaryValue* dictionary) 34 : dictionary_(dictionary), 35 in_aux_attributes_(false) { } 36 37 virtual void AddInt64(const char* name, int64 value) OVERRIDE { 38 if (in_aux_attributes_) 39 dictionary_->SetDouble(name, value); 40 } 41 42 virtual void AddInt(const char* name, int value) OVERRIDE { 43 if (in_aux_attributes_) 44 dictionary_->SetInteger(name, value); 45 } 46 47 virtual void AddString(const char* name, const std::string& value) OVERRIDE { 48 if (in_aux_attributes_) 49 dictionary_->SetString(name, value); 50 } 51 52 virtual void AddBool(const char* name, bool value) OVERRIDE { 53 if (in_aux_attributes_) 54 dictionary_->SetBoolean(name, value); 55 } 56 57 virtual void AddTimeDeltaInSecondsF(const char* name, 58 const base::TimeDelta& value) OVERRIDE { 59 if (in_aux_attributes_) 60 dictionary_->SetDouble(name, value.InSecondsF()); 61 } 62 63 virtual void BeginGPUDevice() OVERRIDE { 64 } 65 66 virtual void EndGPUDevice() OVERRIDE { 67 } 68 69 virtual void BeginVideoEncodeAcceleratorSupportedProfile() OVERRIDE {} 70 71 virtual void EndVideoEncodeAcceleratorSupportedProfile() OVERRIDE {} 72 73 virtual void BeginAuxAttributes() OVERRIDE { 74 in_aux_attributes_ = true; 75 } 76 77 virtual void EndAuxAttributes() OVERRIDE { 78 in_aux_attributes_ = false; 79 } 80 81 private: 82 base::DictionaryValue* dictionary_; 83 bool in_aux_attributes_; 84 }; 85 86 base::DictionaryValue* GPUDeviceToDictionary( 87 const gpu::GPUInfo::GPUDevice& device) { 88 base::DictionaryValue* result = new base::DictionaryValue; 89 result->SetInteger(kVendorId, device.vendor_id); 90 result->SetInteger(kDeviceId, device.device_id); 91 result->SetString(kVendorString, device.vendor_string); 92 result->SetString(kDeviceString, device.device_string); 93 return result; 94 } 95 96 } // namespace 97 98 DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() { 99 RegisterCommandHandler(devtools::SystemInfo::getInfo::kName, 100 base::Bind(&DevToolsSystemInfoHandler::OnGetInfo, 101 base::Unretained(this))); 102 } 103 104 DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() { 105 } 106 107 scoped_refptr<DevToolsProtocol::Response> 108 DevToolsSystemInfoHandler::OnGetInfo( 109 scoped_refptr<DevToolsProtocol::Command> command) { 110 gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo(); 111 base::DictionaryValue* gpu_dict = new base::DictionaryValue; 112 113 base::ListValue* devices = new base::ListValue; 114 devices->Append(GPUDeviceToDictionary(gpu_info.gpu)); 115 for (size_t ii = 0; ii < gpu_info.secondary_gpus.size(); ++ii) { 116 devices->Append(GPUDeviceToDictionary(gpu_info.secondary_gpus[ii])); 117 } 118 gpu_dict->Set(kDevices, devices); 119 120 base::DictionaryValue* aux_attributes = new base::DictionaryValue; 121 AuxGPUInfoEnumerator enumerator(aux_attributes); 122 gpu_info.EnumerateFields(&enumerator); 123 gpu_dict->Set(kAuxAttributes, aux_attributes); 124 125 gpu_dict->Set(kFeatureStatus, GetFeatureStatus()); 126 127 gpu_dict->Set(kDriverBugWorkarounds, GetDriverBugWorkarounds()); 128 129 base::DictionaryValue* system_dict = new base::DictionaryValue; 130 system_dict->SetString(kModelName, gpu_info.machine_model_name); 131 system_dict->SetString(kModelVersion, gpu_info.machine_model_version); 132 system_dict->Set(kGPU, gpu_dict); 133 return command->SuccessResponse(system_dict); 134 } 135 136 } // namespace content 137