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.
5 #include "content/browser/devtools/devtools_system_info_handler.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"
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";
31 class AuxGPUInfoEnumerator
: public gpu::GPUInfo::Enumerator
{
33 AuxGPUInfoEnumerator(base::DictionaryValue
* dictionary
)
34 : dictionary_(dictionary
),
35 in_aux_attributes_(false) { }
37 virtual void AddInt64(const char* name
, int64 value
) OVERRIDE
{
38 if (in_aux_attributes_
)
39 dictionary_
->SetDouble(name
, value
);
42 virtual void AddInt(const char* name
, int value
) OVERRIDE
{
43 if (in_aux_attributes_
)
44 dictionary_
->SetInteger(name
, value
);
47 virtual void AddString(const char* name
, const std::string
& value
) OVERRIDE
{
48 if (in_aux_attributes_
)
49 dictionary_
->SetString(name
, value
);
52 virtual void AddBool(const char* name
, bool value
) OVERRIDE
{
53 if (in_aux_attributes_
)
54 dictionary_
->SetBoolean(name
, value
);
57 virtual void AddTimeDeltaInSecondsF(const char* name
,
58 const base::TimeDelta
& value
) OVERRIDE
{
59 if (in_aux_attributes_
)
60 dictionary_
->SetDouble(name
, value
.InSecondsF());
63 virtual void BeginGPUDevice() OVERRIDE
{
66 virtual void EndGPUDevice() OVERRIDE
{
69 virtual void BeginAuxAttributes() OVERRIDE
{
70 in_aux_attributes_
= true;
73 virtual void EndAuxAttributes() OVERRIDE
{
74 in_aux_attributes_
= false;
78 base::DictionaryValue
* dictionary_
;
79 bool in_aux_attributes_
;
82 base::DictionaryValue
* GPUDeviceToDictionary(
83 const gpu::GPUInfo::GPUDevice
& device
) {
84 base::DictionaryValue
* result
= new base::DictionaryValue
;
85 result
->SetInteger(kVendorId
, device
.vendor_id
);
86 result
->SetInteger(kDeviceId
, device
.device_id
);
87 result
->SetString(kVendorString
, device
.vendor_string
);
88 result
->SetString(kDeviceString
, device
.device_string
);
94 DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() {
95 RegisterCommandHandler(devtools::SystemInfo::getInfo::kName
,
96 base::Bind(&DevToolsSystemInfoHandler::OnGetInfo
,
97 base::Unretained(this)));
100 DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() {
103 scoped_refptr
<DevToolsProtocol::Response
>
104 DevToolsSystemInfoHandler::OnGetInfo(
105 scoped_refptr
<DevToolsProtocol::Command
> command
) {
106 gpu::GPUInfo gpu_info
= GpuDataManagerImpl::GetInstance()->GetGPUInfo();
107 base::DictionaryValue
* gpu_dict
= new base::DictionaryValue
;
109 base::ListValue
* devices
= new base::ListValue
;
110 devices
->Append(GPUDeviceToDictionary(gpu_info
.gpu
));
111 for (size_t ii
= 0; ii
< gpu_info
.secondary_gpus
.size(); ++ii
) {
112 devices
->Append(GPUDeviceToDictionary(gpu_info
.secondary_gpus
[ii
]));
114 gpu_dict
->Set(kDevices
, devices
);
116 base::DictionaryValue
* aux_attributes
= new base::DictionaryValue
;
117 AuxGPUInfoEnumerator
enumerator(aux_attributes
);
118 gpu_info
.EnumerateFields(&enumerator
);
119 gpu_dict
->Set(kAuxAttributes
, aux_attributes
);
121 gpu_dict
->Set(kFeatureStatus
, GetFeatureStatus());
123 gpu_dict
->Set(kDriverBugWorkarounds
, GetDriverBugWorkarounds());
125 base::DictionaryValue
* system_dict
= new base::DictionaryValue
;
126 system_dict
->SetString(kModelName
, gpu_info
.machine_model_name
);
127 system_dict
->SetString(kModelVersion
, gpu_info
.machine_model_version
);
128 system_dict
->Set(kGPU
, gpu_dict
);
129 return command
->SuccessResponse(system_dict
);
132 } // namespace content