Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / browser / devtools / devtools_system_info_handler.cc
blob1fee64246764a29a2caf0f297224dd858818b319
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"
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"
14 namespace content {
16 namespace {
18 const char kAuxAttributes[] = "auxAttributes";
19 const char kDeviceId[] = "deviceId";
20 const char kDeviceString[] = "deviceString";
21 const char kDevices[] = "devices";
22 const char kGPU[] = "gpu";
23 const char kModelName[] = "modelName";
24 const char kVendorId[] = "vendorId";
25 const char kVendorString[] = "vendorString";
27 class AuxGPUInfoEnumerator : public gpu::GPUInfo::Enumerator {
28 public:
29 AuxGPUInfoEnumerator(base::DictionaryValue* dictionary)
30 : dictionary_(dictionary),
31 in_aux_attributes_(false) { }
33 virtual void AddInt64(const char* name, int64 value) OVERRIDE {
34 if (in_aux_attributes_)
35 dictionary_->SetDouble(name, value);
38 virtual void AddInt(const char* name, int value) OVERRIDE {
39 if (in_aux_attributes_)
40 dictionary_->SetInteger(name, value);
43 virtual void AddString(const char* name, const std::string& value) OVERRIDE {
44 if (in_aux_attributes_)
45 dictionary_->SetString(name, value);
48 virtual void AddBool(const char* name, bool value) OVERRIDE {
49 if (in_aux_attributes_)
50 dictionary_->SetBoolean(name, value);
53 virtual void AddTimeDeltaInSecondsF(const char* name,
54 const base::TimeDelta& value) OVERRIDE {
55 if (in_aux_attributes_)
56 dictionary_->SetDouble(name, value.InSecondsF());
59 virtual void BeginGPUDevice() OVERRIDE {
62 virtual void EndGPUDevice() OVERRIDE {
65 virtual void BeginAuxAttributes() OVERRIDE {
66 in_aux_attributes_ = true;
69 virtual void EndAuxAttributes() OVERRIDE {
70 in_aux_attributes_ = false;
73 private:
74 base::DictionaryValue* dictionary_;
75 bool in_aux_attributes_;
78 base::DictionaryValue* GPUDeviceToDictionary(
79 const gpu::GPUInfo::GPUDevice& device) {
80 base::DictionaryValue* result = new base::DictionaryValue;
81 result->SetInteger(kVendorId, device.vendor_id);
82 result->SetInteger(kDeviceId, device.device_id);
83 result->SetString(kVendorString, device.vendor_string);
84 result->SetString(kDeviceString, device.device_string);
85 return result;
88 } // namespace
90 DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() {
91 RegisterCommandHandler(devtools::SystemInfo::getInfo::kName,
92 base::Bind(&DevToolsSystemInfoHandler::OnGetInfo,
93 base::Unretained(this)));
96 DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() {
99 scoped_refptr<DevToolsProtocol::Response>
100 DevToolsSystemInfoHandler::OnGetInfo(
101 scoped_refptr<DevToolsProtocol::Command> command) {
102 gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo();
103 base::DictionaryValue* gpu_dict = new base::DictionaryValue;
105 base::ListValue* devices = new base::ListValue;
106 devices->Append(GPUDeviceToDictionary(gpu_info.gpu));
107 for (size_t ii = 0; ii < gpu_info.secondary_gpus.size(); ++ii) {
108 devices->Append(GPUDeviceToDictionary(gpu_info.secondary_gpus[ii]));
110 gpu_dict->Set(kDevices, devices);
112 base::DictionaryValue* aux_attributes = new base::DictionaryValue;
113 AuxGPUInfoEnumerator enumerator(aux_attributes);
114 gpu_info.EnumerateFields(&enumerator);
115 gpu_dict->Set(kAuxAttributes, aux_attributes);
117 base::DictionaryValue* system_dict = new base::DictionaryValue;
118 system_dict->SetString(kModelName, gpu_info.machine_model);
119 system_dict->Set(kGPU, gpu_dict);
120 return command->SuccessResponse(system_dict);
123 } // namespace content