Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: content/browser/devtools/protocol/system_info_handler.cc

Issue 2515613006: [DevTools] Move Memory, SystemInfo and Tethering domains to new generator. (Closed)
Patch Set: fixed review comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/devtools/protocol/system_info_handler.h" 5 #include "content/browser/devtools/protocol/system_info_handler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "content/browser/gpu/compositor_util.h" 14 #include "content/browser/gpu/compositor_util.h"
15 #include "content/public/browser/gpu_data_manager.h" 15 #include "content/public/browser/gpu_data_manager.h"
16 #include "gpu/config/gpu_feature_type.h" 16 #include "gpu/config/gpu_feature_type.h"
17 #include "gpu/config/gpu_info.h" 17 #include "gpu/config/gpu_info.h"
18 #include "gpu/config/gpu_switches.h" 18 #include "gpu/config/gpu_switches.h"
19 19
20 namespace content { 20 namespace content {
21 namespace devtools { 21 namespace protocol {
22 namespace system_info {
23 22
24 namespace { 23 namespace {
25 24
26 using Response = DevToolsProtocolClient::Response; 25 using SystemInfo::GPUDevice;
26 using SystemInfo::GPUInfo;
27 using GetInfoCallback = SystemInfo::Backend::GetInfoCallback;
27 28
28 // Give the GPU process a few seconds to provide GPU info. 29 // Give the GPU process a few seconds to provide GPU info.
29 const int kGPUInfoWatchdogTimeoutMs = 5000; 30 const int kGPUInfoWatchdogTimeoutMs = 5000;
30 31
31 class AuxGPUInfoEnumerator : public gpu::GPUInfo::Enumerator { 32 class AuxGPUInfoEnumerator : public gpu::GPUInfo::Enumerator {
32 public: 33 public:
33 AuxGPUInfoEnumerator(base::DictionaryValue* dictionary) 34 AuxGPUInfoEnumerator(protocol::DictionaryValue* dictionary)
34 : dictionary_(dictionary), 35 : dictionary_(dictionary),
35 in_aux_attributes_(false) { } 36 in_aux_attributes_(false) { }
36 37
37 void AddInt64(const char* name, int64_t value) override { 38 void AddInt64(const char* name, int64_t value) override {
38 if (in_aux_attributes_) 39 if (in_aux_attributes_)
39 dictionary_->SetDouble(name, value); 40 dictionary_->setDouble(name, value);
40 } 41 }
41 42
42 void AddInt(const char* name, int value) override { 43 void AddInt(const char* name, int value) override {
43 if (in_aux_attributes_) 44 if (in_aux_attributes_)
44 dictionary_->SetInteger(name, value); 45 dictionary_->setInteger(name, value);
45 } 46 }
46 47
47 void AddString(const char* name, const std::string& value) override { 48 void AddString(const char* name, const std::string& value) override {
48 if (in_aux_attributes_) 49 if (in_aux_attributes_)
49 dictionary_->SetString(name, value); 50 dictionary_->setString(name, value);
50 } 51 }
51 52
52 void AddBool(const char* name, bool value) override { 53 void AddBool(const char* name, bool value) override {
53 if (in_aux_attributes_) 54 if (in_aux_attributes_)
54 dictionary_->SetBoolean(name, value); 55 dictionary_->setBoolean(name, value);
55 } 56 }
56 57
57 void AddTimeDeltaInSecondsF(const char* name, 58 void AddTimeDeltaInSecondsF(const char* name,
58 const base::TimeDelta& value) override { 59 const base::TimeDelta& value) override {
59 if (in_aux_attributes_) 60 if (in_aux_attributes_)
60 dictionary_->SetDouble(name, value.InSecondsF()); 61 dictionary_->setDouble(name, value.InSecondsF());
61 } 62 }
62 63
63 void BeginGPUDevice() override {} 64 void BeginGPUDevice() override {}
64 65
65 void EndGPUDevice() override {} 66 void EndGPUDevice() override {}
66 67
67 void BeginVideoDecodeAcceleratorSupportedProfile() override {} 68 void BeginVideoDecodeAcceleratorSupportedProfile() override {}
68 69
69 void EndVideoDecodeAcceleratorSupportedProfile() override {} 70 void EndVideoDecodeAcceleratorSupportedProfile() override {}
70 71
71 void BeginVideoEncodeAcceleratorSupportedProfile() override {} 72 void BeginVideoEncodeAcceleratorSupportedProfile() override {}
72 73
73 void EndVideoEncodeAcceleratorSupportedProfile() override {} 74 void EndVideoEncodeAcceleratorSupportedProfile() override {}
74 75
75 void BeginAuxAttributes() override { 76 void BeginAuxAttributes() override {
76 in_aux_attributes_ = true; 77 in_aux_attributes_ = true;
77 } 78 }
78 79
79 void EndAuxAttributes() override { 80 void EndAuxAttributes() override {
80 in_aux_attributes_ = false; 81 in_aux_attributes_ = false;
81 } 82 }
82 83
83 private: 84 private:
84 base::DictionaryValue* dictionary_; 85 protocol::DictionaryValue* dictionary_;
85 bool in_aux_attributes_; 86 bool in_aux_attributes_;
86 }; 87 };
87 88
88 scoped_refptr<GPUDevice> GPUDeviceToProtocol( 89 std::unique_ptr<GPUDevice> GPUDeviceToProtocol(
89 const gpu::GPUInfo::GPUDevice& device) { 90 const gpu::GPUInfo::GPUDevice& device) {
90 return GPUDevice::Create()->set_vendor_id(device.vendor_id) 91 return GPUDevice::Create().SetVendorId(device.vendor_id)
91 ->set_device_id(device.device_id) 92 .SetDeviceId(device.device_id)
92 ->set_vendor_string(device.vendor_string) 93 .SetVendorString(device.vendor_string)
93 ->set_device_string(device.device_string); 94 .SetDeviceString(device.device_string)
95 .Build();
96 }
97
98 void SendGetInfoResponse(std::unique_ptr<GetInfoCallback> callback) {
99 gpu::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo();
100 std::unique_ptr<protocol::Array<GPUDevice>> devices =
101 protocol::Array<GPUDevice>::create();
102 devices->addItem(GPUDeviceToProtocol(gpu_info.gpu));
103 for (const auto& device : gpu_info.secondary_gpus)
104 devices->addItem(GPUDeviceToProtocol(device));
105
106 std::unique_ptr<protocol::DictionaryValue> aux_attributes =
107 protocol::DictionaryValue::create();
108 AuxGPUInfoEnumerator enumerator(aux_attributes.get());
109 gpu_info.EnumerateFields(&enumerator);
110
111 std::unique_ptr<base::DictionaryValue> base_feature_status =
112 base::WrapUnique(GetFeatureStatus());
113 std::unique_ptr<protocol::DictionaryValue> feature_status =
114 protocol::DictionaryValue::cast(
115 protocol::toProtocolValue(base_feature_status.get(), 1000));
116
117 std::unique_ptr<protocol::Array<std::string>> driver_bug_workarounds =
118 protocol::Array<std::string>::create();
119 for (const std::string& s : GetDriverBugWorkarounds())
120 driver_bug_workarounds->addItem(s);
121
122 std::unique_ptr<GPUInfo> gpu = GPUInfo::Create()
123 .SetDevices(std::move(devices))
124 .SetAuxAttributes(std::move(aux_attributes))
125 .SetFeatureStatus(std::move(feature_status))
126 .SetDriverBugWorkarounds(std::move(driver_bug_workarounds))
127 .Build();
128
129 callback->sendSuccess(std::move(gpu), gpu_info.machine_model_name,
130 gpu_info.machine_model_version);
94 } 131 }
95 132
96 } // namespace 133 } // namespace
97 134
98 class SystemInfoHandlerGpuObserver : public content::GpuDataManagerObserver { 135 class SystemInfoHandlerGpuObserver : public content::GpuDataManagerObserver {
99 public: 136 public:
100 SystemInfoHandlerGpuObserver(base::WeakPtr<SystemInfoHandler> handler, 137 explicit SystemInfoHandlerGpuObserver(
101 DevToolsCommandId command_id) 138 std::unique_ptr<GetInfoCallback> callback)
102 : handler_(handler), 139 : callback_(std::move(callback)),
103 command_id_(command_id), 140 weak_factory_(this) {
104 observer_id_(++next_observer_id_) 141 BrowserThread::PostDelayedTask(
105 { 142 BrowserThread::UI,
106 if (handler_) { 143 FROM_HERE,
107 handler_->AddActiveObserverId(observer_id_); 144 base::Bind(&SystemInfoHandlerGpuObserver::ObserverWatchdogCallback,
108 } 145 weak_factory_.GetWeakPtr()),
146 base::TimeDelta::FromMilliseconds(kGPUInfoWatchdogTimeoutMs));
147
148 GpuDataManager::GetInstance()->AddObserver(this);
149 // There's no other method available to request just essential GPU info.
150 GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded();
109 } 151 }
110 152
111 void OnGpuInfoUpdate() override { 153 void OnGpuInfoUpdate() override {
112 UnregisterAndSendResponse(); 154 UnregisterAndSendResponse();
113 } 155 }
114 156
115 void OnGpuProcessCrashed(base::TerminationStatus exit_code) override { 157 void OnGpuProcessCrashed(base::TerminationStatus exit_code) override {
116 UnregisterAndSendResponse(); 158 UnregisterAndSendResponse();
117 } 159 }
118 160
161 void ObserverWatchdogCallback() {
162 DCHECK_CURRENTLY_ON(BrowserThread::UI);
163 UnregisterAndSendResponse();
164 }
165
119 void UnregisterAndSendResponse() { 166 void UnregisterAndSendResponse() {
120 GpuDataManager::GetInstance()->RemoveObserver(this); 167 GpuDataManager::GetInstance()->RemoveObserver(this);
121 if (handler_.get()) { 168 SendGetInfoResponse(std::move(callback_));
122 if (handler_->RemoveActiveObserverId(observer_id_)) {
123 handler_->SendGetInfoResponse(command_id_);
124 }
125 }
126 delete this; 169 delete this;
127 } 170 }
128 171
129 int GetObserverId() {
130 return observer_id_;
131 }
132
133 private: 172 private:
134 base::WeakPtr<SystemInfoHandler> handler_; 173 std::unique_ptr<GetInfoCallback> callback_;
135 DevToolsCommandId command_id_; 174 base::WeakPtrFactory<SystemInfoHandlerGpuObserver> weak_factory_;
136 int observer_id_;
137
138 static int next_observer_id_;
139 }; 175 };
140 176
141 int SystemInfoHandlerGpuObserver::next_observer_id_ = 0; 177 SystemInfoHandler::SystemInfoHandler() {
142
143 SystemInfoHandler::SystemInfoHandler()
144 : weak_factory_(this) {
145 } 178 }
146 179
147 SystemInfoHandler::~SystemInfoHandler() { 180 SystemInfoHandler::~SystemInfoHandler() {
148 } 181 }
149 182
150 void SystemInfoHandler::SetClient(std::unique_ptr<Client> client) { 183 void SystemInfoHandler::Wire(UberDispatcher* dispatcher) {
151 client_.swap(client); 184 SystemInfo::Dispatcher::wire(dispatcher, this);
152 } 185 }
153 186
154 Response SystemInfoHandler::GetInfo(DevToolsCommandId command_id) { 187 Response SystemInfoHandler::Disable() {
188 return Response::OK();
189 }
190
191 void SystemInfoHandler::GetInfo(
192 std::unique_ptr<GetInfoCallback> callback) {
155 std::string reason; 193 std::string reason;
156 if (!GpuDataManager::GetInstance()->GpuAccessAllowed(&reason) || 194 if (!GpuDataManager::GetInstance()->GpuAccessAllowed(&reason) ||
157 GpuDataManager::GetInstance()->IsEssentialGpuInfoAvailable() || 195 GpuDataManager::GetInstance()->IsEssentialGpuInfoAvailable() ||
158 base::CommandLine::ForCurrentProcess()->HasSwitch( 196 base::CommandLine::ForCurrentProcess()->HasSwitch(
159 switches::kGpuTestingNoCompleteInfoCollection)) { 197 switches::kGpuTestingNoCompleteInfoCollection)) {
160 // The GpuDataManager already has all of the information needed to make 198 // The GpuDataManager already has all of the information needed to make
161 // GPU-based blacklisting decisions. Post a task to give it to the 199 // GPU-based blacklisting decisions. Post a task to give it to the
162 // client asynchronously. 200 // client asynchronously.
163 // 201 //
164 // Waiting for complete GPU info in the if-test above seems to 202 // Waiting for complete GPU info in the if-test above seems to
165 // frequently hit internal timeouts in the launching of the unsandboxed 203 // frequently hit internal timeouts in the launching of the unsandboxed
166 // GPU process in debug builds on Windows. 204 // GPU process in debug builds on Windows.
167 BrowserThread::PostTask( 205 BrowserThread::PostTask(
168 BrowserThread::UI, 206 BrowserThread::UI,
169 FROM_HERE, 207 FROM_HERE,
170 base::Bind(&SystemInfoHandler::SendGetInfoResponse, 208 base::Bind(&SendGetInfoResponse, base::Passed(std::move(callback))));
171 weak_factory_.GetWeakPtr(),
172 command_id));
173 } else { 209 } else {
174 // We will be able to get more information from the GpuDataManager. 210 // We will be able to get more information from the GpuDataManager.
175 // Register a transient observer with it to call us back when the 211 // Register a transient observer with it to call us back when the
176 // information is available. 212 // information is available.
177 SystemInfoHandlerGpuObserver* observer = new SystemInfoHandlerGpuObserver( 213 new SystemInfoHandlerGpuObserver(std::move(callback));
178 weak_factory_.GetWeakPtr(), command_id);
179 BrowserThread::PostDelayedTask(
180 BrowserThread::UI,
181 FROM_HERE,
182 base::Bind(&SystemInfoHandler::ObserverWatchdogCallback,
183 weak_factory_.GetWeakPtr(),
184 observer->GetObserverId(),
185 command_id),
186 base::TimeDelta::FromMilliseconds(kGPUInfoWatchdogTimeoutMs));
187 GpuDataManager::GetInstance()->AddObserver(observer);
188 // There's no other method available to request just essential GPU info.
189 GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded();
190 }
191
192 return Response::OK();
193 }
194
195 void SystemInfoHandler::SendGetInfoResponse(DevToolsCommandId command_id) {
196 gpu::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo();
197 std::vector<scoped_refptr<GPUDevice>> devices;
198 devices.push_back(GPUDeviceToProtocol(gpu_info.gpu));
199 for (const auto& device : gpu_info.secondary_gpus)
200 devices.push_back(GPUDeviceToProtocol(device));
201
202 std::unique_ptr<base::DictionaryValue> aux_attributes(
203 new base::DictionaryValue);
204 AuxGPUInfoEnumerator enumerator(aux_attributes.get());
205 gpu_info.EnumerateFields(&enumerator);
206
207 scoped_refptr<GPUInfo> gpu =
208 GPUInfo::Create()
209 ->set_devices(devices)
210 ->set_aux_attributes(std::move(aux_attributes))
211 ->set_feature_status(base::WrapUnique(GetFeatureStatus()))
212 ->set_driver_bug_workarounds(GetDriverBugWorkarounds());
213
214 client_->SendGetInfoResponse(
215 command_id,
216 GetInfoResponse::Create()->set_gpu(gpu)
217 ->set_model_name(gpu_info.machine_model_name)
218 ->set_model_version(gpu_info.machine_model_version));
219 }
220
221 void SystemInfoHandler::AddActiveObserverId(int observer_id) {
222 base::AutoLock auto_lock(lock_);
223 active_observers_.insert(observer_id);
224 }
225
226 bool SystemInfoHandler::RemoveActiveObserverId(int observer_id) {
227 base::AutoLock auto_lock(lock_);
228 int num_removed = active_observers_.erase(observer_id);
229 return (num_removed != 0);
230 }
231
232 void SystemInfoHandler::ObserverWatchdogCallback(int observer_id,
233 DevToolsCommandId command_id) {
234 DCHECK_CURRENTLY_ON(BrowserThread::UI);
235 if (RemoveActiveObserverId(observer_id)) {
236 SendGetInfoResponse(command_id);
237 // For the time being we want to know about this event in the test logs.
238 LOG(ERROR) << "SystemInfoHandler: request for GPU info timed out!"
239 << " Most recent info sent.";
240 } 214 }
241 } 215 }
242 216
243 } // namespace system_info 217 } // namespace protocol
244 } // namespace devtools
245 } // namespace content 218 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/system_info_handler.h ('k') | content/browser/devtools/protocol/tethering_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698