OLD | NEW |
| (Empty) |
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 void AddInt64(const char* name, int64 value) override { | |
38 if (in_aux_attributes_) | |
39 dictionary_->SetDouble(name, value); | |
40 } | |
41 | |
42 void AddInt(const char* name, int value) override { | |
43 if (in_aux_attributes_) | |
44 dictionary_->SetInteger(name, value); | |
45 } | |
46 | |
47 void AddString(const char* name, const std::string& value) override { | |
48 if (in_aux_attributes_) | |
49 dictionary_->SetString(name, value); | |
50 } | |
51 | |
52 void AddBool(const char* name, bool value) override { | |
53 if (in_aux_attributes_) | |
54 dictionary_->SetBoolean(name, value); | |
55 } | |
56 | |
57 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 void BeginGPUDevice() override {} | |
64 | |
65 void EndGPUDevice() override {} | |
66 | |
67 void BeginVideoEncodeAcceleratorSupportedProfile() override {} | |
68 | |
69 void EndVideoEncodeAcceleratorSupportedProfile() override {} | |
70 | |
71 void BeginAuxAttributes() override { in_aux_attributes_ = true; } | |
72 | |
73 void EndAuxAttributes() override { in_aux_attributes_ = false; } | |
74 | |
75 private: | |
76 base::DictionaryValue* dictionary_; | |
77 bool in_aux_attributes_; | |
78 }; | |
79 | |
80 base::DictionaryValue* GPUDeviceToDictionary( | |
81 const gpu::GPUInfo::GPUDevice& device) { | |
82 base::DictionaryValue* result = new base::DictionaryValue; | |
83 result->SetInteger(kVendorId, device.vendor_id); | |
84 result->SetInteger(kDeviceId, device.device_id); | |
85 result->SetString(kVendorString, device.vendor_string); | |
86 result->SetString(kDeviceString, device.device_string); | |
87 return result; | |
88 } | |
89 | |
90 } // namespace | |
91 | |
92 DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() { | |
93 RegisterCommandHandler(devtools::SystemInfo::getInfo::kName, | |
94 base::Bind(&DevToolsSystemInfoHandler::OnGetInfo, | |
95 base::Unretained(this))); | |
96 } | |
97 | |
98 DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() { | |
99 } | |
100 | |
101 scoped_refptr<DevToolsProtocol::Response> | |
102 DevToolsSystemInfoHandler::OnGetInfo( | |
103 scoped_refptr<DevToolsProtocol::Command> command) { | |
104 gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo(); | |
105 base::DictionaryValue* gpu_dict = new base::DictionaryValue; | |
106 | |
107 base::ListValue* devices = new base::ListValue; | |
108 devices->Append(GPUDeviceToDictionary(gpu_info.gpu)); | |
109 for (size_t ii = 0; ii < gpu_info.secondary_gpus.size(); ++ii) { | |
110 devices->Append(GPUDeviceToDictionary(gpu_info.secondary_gpus[ii])); | |
111 } | |
112 gpu_dict->Set(kDevices, devices); | |
113 | |
114 base::DictionaryValue* aux_attributes = new base::DictionaryValue; | |
115 AuxGPUInfoEnumerator enumerator(aux_attributes); | |
116 gpu_info.EnumerateFields(&enumerator); | |
117 gpu_dict->Set(kAuxAttributes, aux_attributes); | |
118 | |
119 gpu_dict->Set(kFeatureStatus, GetFeatureStatus()); | |
120 | |
121 gpu_dict->Set(kDriverBugWorkarounds, GetDriverBugWorkarounds()); | |
122 | |
123 base::DictionaryValue* system_dict = new base::DictionaryValue; | |
124 system_dict->SetString(kModelName, gpu_info.machine_model_name); | |
125 system_dict->SetString(kModelVersion, gpu_info.machine_model_version); | |
126 system_dict->Set(kGPU, gpu_dict); | |
127 return command->SuccessResponse(system_dict); | |
128 } | |
129 | |
130 } // namespace content | |
OLD | NEW |