Chromium Code Reviews| Index: content/browser/devtools/devtools_system_info_handler.cc |
| diff --git a/content/browser/devtools/devtools_system_info_handler.cc b/content/browser/devtools/devtools_system_info_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..07dfe91721db96f453808330a9b0d7cc60a8a9ef |
| --- /dev/null |
| +++ b/content/browser/devtools/devtools_system_info_handler.cc |
| @@ -0,0 +1,111 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/devtools/devtools_system_info_handler.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/values.h" |
| +#include "content/browser/devtools/devtools_protocol_constants.h" |
| +#include "content/browser/gpu/gpu_data_manager_impl.h" |
| +#include "gpu/config/gpu_info.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +const char kGPU[] = "gpu"; |
| +const char kGPUs[] = "gpus"; |
| +const char kAuxAttributes[] = "auxAttributes"; |
| +const char kMachineModel[] = "machineModel"; |
| + |
| +class GPUInfoEnumerator : public gpu::GPUInfo::Enumerator { |
| + public: |
| + GPUInfoEnumerator(base::DictionaryValue* dictionary) |
| + : current_(dictionary) |
| + , root_(dictionary) |
|
pfeldman
2013/08/14 19:59:03
Use trailing comma as per style guidelines.
Ken Russell (switch to Gerrit)
2013/08/14 23:18:07
Fixed.
|
| + , gpus_(NULL) { } |
| + |
| + virtual void AddInt64(const char* name, int64 value) OVERRIDE { |
| + current_->SetDouble(name, value); |
| + } |
| + |
| + virtual void AddInt(const char* name, int value) OVERRIDE { |
| + current_->SetInteger(name, value); |
| + } |
| + |
| + virtual void AddString(const char* name, const std::string& value) OVERRIDE { |
| + current_->SetString(name, value); |
|
pfeldman
2013/08/14 19:59:03
Filling in gpu data this way does not guarantee th
pfeldman
2013/08/14 20:01:41
Previous iteration was properly filling in kDevice
Ken Russell (switch to Gerrit)
2013/08/14 23:18:07
Explicitly added all required fields in this file
|
| + } |
| + |
| + virtual void AddBool(const char* name, bool value) OVERRIDE { |
| + current_->SetBoolean(name, value); |
| + } |
| + |
| + virtual void AddTimeDeltaInSecondsF(const char* name, |
| + const base::TimeDelta& value) OVERRIDE { |
| + current_->SetDouble(name, value.InSecondsF()); |
| + } |
| + |
| + virtual void BeginGPUDevice() OVERRIDE { |
| + current_ = new base::DictionaryValue; |
| + } |
| + |
| + virtual void EndGPUDevice() OVERRIDE { |
| + if (!gpus_) { |
| + gpus_ = new base::ListValue; |
| + root_->Set(kGPUs, gpus_); |
| + } |
| + |
| + gpus_->Append(current_); |
| + current_ = root_; |
| + } |
| + |
| + virtual void BeginAuxAttributes() OVERRIDE { |
| + current_ = new base::DictionaryValue; |
| + } |
| + |
| + virtual void EndAuxAttributes() OVERRIDE { |
| + root_->Set(kAuxAttributes, current_); |
| + current_ = root_; |
| + } |
| + |
| + private: |
| + base::DictionaryValue* current_; |
| + |
| + base::DictionaryValue* root_; |
| + base::ListValue* gpus_; |
| +}; |
| + |
| +} // namespace |
| + |
| +DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() { |
| + RegisterCommandHandler(devtools::SystemInfo::getInfo::kName, |
| + base::Bind(&DevToolsSystemInfoHandler::OnGetInfo, |
| + base::Unretained(this))); |
| +} |
| + |
| +DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() { |
| +} |
| + |
| +scoped_refptr<DevToolsProtocol::Response> |
| +DevToolsSystemInfoHandler::OnGetInfo( |
| + scoped_refptr<DevToolsProtocol::Command> command) { |
| + gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo(); |
| + base::DictionaryValue* gpu_dict = new base::DictionaryValue; |
| + GPUInfoEnumerator enumerator(gpu_dict); |
| + gpu_info.EnumerateFields(&enumerator); |
| + // Move the "machineModel" field to the SystemInfo dictionary to |
| + // match the DevTools protocol. |
| + scoped_ptr<base::Value> machine_model; |
| + bool found = gpu_dict->Remove(kMachineModel, &machine_model); |
|
pfeldman
2013/08/14 19:59:03
nit: I'd call it modelName
Ken Russell (switch to Gerrit)
2013/08/14 23:18:07
Done.
|
| + DCHECK(found); |
| + DCHECK(machine_model.get()); |
| + base::DictionaryValue* system_dict = new base::DictionaryValue; |
| + system_dict->Set(kMachineModel, machine_model.release()); |
| + system_dict->Set(kGPU, gpu_dict); |
| + return command->SuccessResponse(system_dict); |
| +} |
| + |
| +} // namespace content |