Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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/gpu_data_manager_impl.h" | |
| 12 #include "gpu/config/gpu_info.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char kGPU[] = "gpu"; | |
|
pfeldman
2013/08/07 13:01:58
How is this information going to be used? Do you i
Ken Russell (switch to Gerrit)
2013/08/08 02:42:37
The CL description describes how it's going to be
Ken Russell (switch to Gerrit)
2013/08/14 00:54:40
Per discussion above, I've uploaded https://codere
| |
| 19 const char kVendorId[] = "vendor_id"; | |
|
pfeldman
2013/08/07 13:01:58
Please use camelCase for property names.
Ken Russell (switch to Gerrit)
2013/08/08 02:42:37
Is this strictly necessary? Doing so is going to r
Ken Russell (switch to Gerrit)
2013/08/14 00:54:40
Done. Also modified GPUInfo::EnumerateFields in gp
| |
| 20 const char kDeviceId[] = "device_id"; | |
| 21 const char kVendorString[] = "vendor_string"; | |
| 22 const char kDeviceString[] = "device_string"; | |
| 23 const char kSecondaryGPUs[] = "secondary_gpus"; | |
| 24 | |
| 25 class GPUInfoEnumerator : public gpu::GPUInfo::Enumerator { | |
| 26 public: | |
| 27 GPUInfoEnumerator(base::DictionaryValue* dictionary) | |
| 28 : dictionary_(dictionary) { } | |
| 29 | |
| 30 virtual void AddInt64(const char* name, int64 value) OVERRIDE { | |
| 31 dictionary_->SetDouble(name, value); | |
| 32 } | |
| 33 | |
| 34 virtual void AddString(const char* name, const std::string& value) OVERRIDE { | |
| 35 dictionary_->SetString(name, value); | |
| 36 } | |
| 37 | |
| 38 virtual void AddBool(const char* name, bool value) OVERRIDE { | |
| 39 dictionary_->SetBoolean(name, value); | |
| 40 } | |
| 41 | |
| 42 virtual void AddTimeDeltaInSecondsF(const char* name, | |
| 43 const base::TimeDelta& value) OVERRIDE { | |
| 44 dictionary_->SetDouble(name, value.InSecondsF()); | |
| 45 } | |
| 46 | |
| 47 virtual void AddGPUDevice(const gpu::GPUInfo::GPUDevice& device) OVERRIDE { | |
| 48 base::DictionaryValue* gpu_device = new base::DictionaryValue; | |
| 49 | |
| 50 // Ideally this logic would be in GPUInfo::EnumerateFields, but | |
| 51 // describing nested objects would be difficult, and add | |
| 52 // undesirable state to the Enumerator. | |
| 53 gpu_device->SetInteger(kVendorId, device.vendor_id); | |
| 54 gpu_device->SetInteger(kDeviceId, device.device_id); | |
| 55 gpu_device->SetString(kVendorString, device.vendor_string); | |
| 56 gpu_device->SetString(kDeviceString, device.device_string); | |
| 57 | |
| 58 if (!dictionary_->HasKey(kGPU)) { | |
| 59 dictionary_->Set(kGPU, gpu_device); | |
| 60 return; | |
| 61 } | |
| 62 | |
| 63 base::ListValue* secondary_gpus = NULL; | |
| 64 if (dictionary_->HasKey(kSecondaryGPUs)) { | |
| 65 bool success = dictionary_->GetList(kSecondaryGPUs, &secondary_gpus); | |
| 66 DCHECK(success); | |
| 67 } else { | |
| 68 secondary_gpus = new base::ListValue; | |
| 69 dictionary_->Set(kSecondaryGPUs, secondary_gpus); | |
| 70 } | |
| 71 | |
| 72 secondary_gpus->Append(gpu_device); | |
| 73 } | |
| 74 | |
| 75 private: | |
| 76 base::DictionaryValue* dictionary_; | |
| 77 }; | |
| 78 | |
| 79 } // namespace | |
| 80 | |
| 81 DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() { | |
| 82 RegisterCommandHandler(devtools::SystemInfo::getGPUInfo::kName, | |
| 83 base::Bind(&DevToolsSystemInfoHandler::OnGetGPUInfo, | |
| 84 base::Unretained(this))); | |
| 85 } | |
| 86 | |
| 87 DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() { | |
| 88 } | |
| 89 | |
| 90 scoped_ptr<DevToolsProtocol::Response> | |
| 91 DevToolsSystemInfoHandler::OnGetGPUInfo(DevToolsProtocol::Command* command) { | |
| 92 gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo(); | |
| 93 base::DictionaryValue* result = new base::DictionaryValue; | |
| 94 GPUInfoEnumerator enumerator(result); | |
| 95 gpu_info.EnumerateFields(&enumerator); | |
| 96 return command->SuccessResponse(result); | |
| 97 } | |
| 98 | |
| 99 } // namespace content | |
| OLD | NEW |