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"; | |
| 19 const char kGPUs[] = "gpus"; | |
| 20 const char kAuxAttributes[] = "auxAttributes"; | |
| 21 const char kMachineModel[] = "machineModel"; | |
| 22 | |
| 23 class GPUInfoEnumerator : public gpu::GPUInfo::Enumerator { | |
| 24 public: | |
| 25 GPUInfoEnumerator(base::DictionaryValue* dictionary) | |
| 26 : current_(dictionary) | |
| 27 , 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.
| |
| 28 , gpus_(NULL) { } | |
| 29 | |
| 30 virtual void AddInt64(const char* name, int64 value) OVERRIDE { | |
| 31 current_->SetDouble(name, value); | |
| 32 } | |
| 33 | |
| 34 virtual void AddInt(const char* name, int value) OVERRIDE { | |
| 35 current_->SetInteger(name, value); | |
| 36 } | |
| 37 | |
| 38 virtual void AddString(const char* name, const std::string& value) OVERRIDE { | |
| 39 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
| |
| 40 } | |
| 41 | |
| 42 virtual void AddBool(const char* name, bool value) OVERRIDE { | |
| 43 current_->SetBoolean(name, value); | |
| 44 } | |
| 45 | |
| 46 virtual void AddTimeDeltaInSecondsF(const char* name, | |
| 47 const base::TimeDelta& value) OVERRIDE { | |
| 48 current_->SetDouble(name, value.InSecondsF()); | |
| 49 } | |
| 50 | |
| 51 virtual void BeginGPUDevice() OVERRIDE { | |
| 52 current_ = new base::DictionaryValue; | |
| 53 } | |
| 54 | |
| 55 virtual void EndGPUDevice() OVERRIDE { | |
| 56 if (!gpus_) { | |
| 57 gpus_ = new base::ListValue; | |
| 58 root_->Set(kGPUs, gpus_); | |
| 59 } | |
| 60 | |
| 61 gpus_->Append(current_); | |
| 62 current_ = root_; | |
| 63 } | |
| 64 | |
| 65 virtual void BeginAuxAttributes() OVERRIDE { | |
| 66 current_ = new base::DictionaryValue; | |
| 67 } | |
| 68 | |
| 69 virtual void EndAuxAttributes() OVERRIDE { | |
| 70 root_->Set(kAuxAttributes, current_); | |
| 71 current_ = root_; | |
| 72 } | |
| 73 | |
| 74 private: | |
| 75 base::DictionaryValue* current_; | |
| 76 | |
| 77 base::DictionaryValue* root_; | |
| 78 base::ListValue* gpus_; | |
| 79 }; | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() { | |
| 84 RegisterCommandHandler(devtools::SystemInfo::getInfo::kName, | |
| 85 base::Bind(&DevToolsSystemInfoHandler::OnGetInfo, | |
| 86 base::Unretained(this))); | |
| 87 } | |
| 88 | |
| 89 DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() { | |
| 90 } | |
| 91 | |
| 92 scoped_refptr<DevToolsProtocol::Response> | |
| 93 DevToolsSystemInfoHandler::OnGetInfo( | |
| 94 scoped_refptr<DevToolsProtocol::Command> command) { | |
| 95 gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo(); | |
| 96 base::DictionaryValue* gpu_dict = new base::DictionaryValue; | |
| 97 GPUInfoEnumerator enumerator(gpu_dict); | |
| 98 gpu_info.EnumerateFields(&enumerator); | |
| 99 // Move the "machineModel" field to the SystemInfo dictionary to | |
| 100 // match the DevTools protocol. | |
| 101 scoped_ptr<base::Value> machine_model; | |
| 102 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.
| |
| 103 DCHECK(found); | |
| 104 DCHECK(machine_model.get()); | |
| 105 base::DictionaryValue* system_dict = new base::DictionaryValue; | |
| 106 system_dict->Set(kMachineModel, machine_model.release()); | |
| 107 system_dict->Set(kGPU, gpu_dict); | |
| 108 return command->SuccessResponse(system_dict); | |
| 109 } | |
| 110 | |
| 111 } // namespace content | |
| OLD | NEW |