OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/gpu/compositor_util.h" | 8 #include "content/browser/gpu/compositor_util.h" |
9 #include "content/public/browser/gpu_data_manager.h" | 9 #include "content/public/browser/gpu_data_manager.h" |
10 #include "gpu/config/gpu_info.h" | 10 #include "gpu/config/gpu_info.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ->set_device_id(device.device_id) | 83 ->set_device_id(device.device_id) |
84 ->set_vendor_string(device.vendor_string) | 84 ->set_vendor_string(device.vendor_string) |
85 ->set_device_string(device.device_string); | 85 ->set_device_string(device.device_string); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 class SystemInfoHandlerGpuObserver : public content::GpuDataManagerObserver { | 90 class SystemInfoHandlerGpuObserver : public content::GpuDataManagerObserver { |
91 public: | 91 public: |
92 SystemInfoHandlerGpuObserver(base::WeakPtr<SystemInfoHandler> handler, | 92 SystemInfoHandlerGpuObserver(base::WeakPtr<SystemInfoHandler> handler, |
| 93 int session_id, |
93 DevToolsCommandId command_id) | 94 DevToolsCommandId command_id) |
94 : handler_(handler), | 95 : handler_(handler), |
| 96 session_id_(session_id), |
95 command_id_(command_id), | 97 command_id_(command_id), |
96 observer_id_(++next_observer_id_) | 98 observer_id_(++next_observer_id_) { |
97 { | |
98 if (handler_) { | 99 if (handler_) { |
99 handler_->AddActiveObserverId(observer_id_); | 100 handler_->AddActiveObserverId(observer_id_); |
100 } | 101 } |
101 } | 102 } |
102 | 103 |
103 void OnGpuInfoUpdate() override { | 104 void OnGpuInfoUpdate() override { |
104 UnregisterAndSendResponse(); | 105 UnregisterAndSendResponse(); |
105 } | 106 } |
106 | 107 |
107 void OnGpuProcessCrashed(base::TerminationStatus exit_code) override { | 108 void OnGpuProcessCrashed(base::TerminationStatus exit_code) override { |
108 UnregisterAndSendResponse(); | 109 UnregisterAndSendResponse(); |
109 } | 110 } |
110 | 111 |
111 void UnregisterAndSendResponse() { | 112 void UnregisterAndSendResponse() { |
112 GpuDataManager::GetInstance()->RemoveObserver(this); | 113 GpuDataManager::GetInstance()->RemoveObserver(this); |
113 if (handler_.get()) { | 114 if (handler_.get()) { |
114 if (handler_->RemoveActiveObserverId(observer_id_)) { | 115 if (handler_->RemoveActiveObserverId(observer_id_)) { |
115 handler_->SendGetInfoResponse(command_id_); | 116 handler_->SendGetInfoResponse(session_id_, command_id_); |
116 } | 117 } |
117 } | 118 } |
118 delete this; | 119 delete this; |
119 } | 120 } |
120 | 121 |
121 int GetObserverId() { | 122 int GetObserverId() { |
122 return observer_id_; | 123 return observer_id_; |
123 } | 124 } |
124 | 125 |
125 private: | 126 private: |
126 base::WeakPtr<SystemInfoHandler> handler_; | 127 base::WeakPtr<SystemInfoHandler> handler_; |
| 128 int session_id_; |
127 DevToolsCommandId command_id_; | 129 DevToolsCommandId command_id_; |
128 int observer_id_; | 130 int observer_id_; |
129 | 131 |
130 static int next_observer_id_; | 132 static int next_observer_id_; |
131 }; | 133 }; |
132 | 134 |
133 int SystemInfoHandlerGpuObserver::next_observer_id_ = 0; | 135 int SystemInfoHandlerGpuObserver::next_observer_id_ = 0; |
134 | 136 |
135 SystemInfoHandler::SystemInfoHandler() | 137 SystemInfoHandler::SystemInfoHandler() |
136 : weak_factory_(this) { | 138 : weak_factory_(this) { |
137 } | 139 } |
138 | 140 |
139 SystemInfoHandler::~SystemInfoHandler() { | 141 SystemInfoHandler::~SystemInfoHandler() { |
140 } | 142 } |
141 | 143 |
142 void SystemInfoHandler::SetClient(scoped_ptr<Client> client) { | 144 void SystemInfoHandler::SetClient(scoped_ptr<Client> client) { |
143 client_.swap(client); | 145 client_.swap(client); |
144 } | 146 } |
145 | 147 |
146 Response SystemInfoHandler::GetInfo(DevToolsCommandId command_id) { | 148 Response SystemInfoHandler::GetInfo(int session_id, |
| 149 DevToolsCommandId command_id) { |
147 std::string reason; | 150 std::string reason; |
148 if (!GpuDataManager::GetInstance()->GpuAccessAllowed(&reason) || | 151 if (!GpuDataManager::GetInstance()->GpuAccessAllowed(&reason) || |
149 GpuDataManager::GetInstance()->IsEssentialGpuInfoAvailable()) { | 152 GpuDataManager::GetInstance()->IsEssentialGpuInfoAvailable()) { |
150 // The GpuDataManager already has all of the information needed to make | 153 // The GpuDataManager already has all of the information needed to make |
151 // GPU-based blacklisting decisions. Post a task to give it to the | 154 // GPU-based blacklisting decisions. Post a task to give it to the |
152 // client asynchronously. | 155 // client asynchronously. |
153 // | 156 // |
154 // Waiting for complete GPU info in the if-test above seems to | 157 // Waiting for complete GPU info in the if-test above seems to |
155 // frequently hit internal timeouts in the launching of the unsandboxed | 158 // frequently hit internal timeouts in the launching of the unsandboxed |
156 // GPU process in debug builds on Windows. | 159 // GPU process in debug builds on Windows. |
157 BrowserThread::PostTask( | 160 BrowserThread::PostTask( |
158 BrowserThread::UI, | 161 BrowserThread::UI, FROM_HERE, |
159 FROM_HERE, | |
160 base::Bind(&SystemInfoHandler::SendGetInfoResponse, | 162 base::Bind(&SystemInfoHandler::SendGetInfoResponse, |
161 weak_factory_.GetWeakPtr(), | 163 weak_factory_.GetWeakPtr(), session_id, command_id)); |
162 command_id)); | |
163 } else { | 164 } else { |
164 // We will be able to get more information from the GpuDataManager. | 165 // We will be able to get more information from the GpuDataManager. |
165 // Register a transient observer with it to call us back when the | 166 // Register a transient observer with it to call us back when the |
166 // information is available. | 167 // information is available. |
167 SystemInfoHandlerGpuObserver* observer = new SystemInfoHandlerGpuObserver( | 168 SystemInfoHandlerGpuObserver* observer = new SystemInfoHandlerGpuObserver( |
168 weak_factory_.GetWeakPtr(), command_id); | 169 weak_factory_.GetWeakPtr(), session_id, command_id); |
169 BrowserThread::PostDelayedTask( | 170 BrowserThread::PostDelayedTask( |
170 BrowserThread::UI, | 171 BrowserThread::UI, FROM_HERE, |
171 FROM_HERE, | |
172 base::Bind(&SystemInfoHandler::ObserverWatchdogCallback, | 172 base::Bind(&SystemInfoHandler::ObserverWatchdogCallback, |
173 weak_factory_.GetWeakPtr(), | 173 weak_factory_.GetWeakPtr(), observer->GetObserverId(), |
174 observer->GetObserverId(), | 174 session_id, command_id), |
175 command_id), | |
176 base::TimeDelta::FromMilliseconds(kGPUInfoWatchdogTimeoutMs)); | 175 base::TimeDelta::FromMilliseconds(kGPUInfoWatchdogTimeoutMs)); |
177 GpuDataManager::GetInstance()->AddObserver(observer); | 176 GpuDataManager::GetInstance()->AddObserver(observer); |
178 // There's no other method available to request just essential GPU info. | 177 // There's no other method available to request just essential GPU info. |
179 GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); | 178 GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); |
180 } | 179 } |
181 | 180 |
182 return Response::OK(); | 181 return Response::OK(); |
183 } | 182 } |
184 | 183 |
185 void SystemInfoHandler::SendGetInfoResponse(DevToolsCommandId command_id) { | 184 void SystemInfoHandler::SendGetInfoResponse(int session_id, |
| 185 DevToolsCommandId command_id) { |
186 gpu::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo(); | 186 gpu::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo(); |
187 std::vector<scoped_refptr<GPUDevice>> devices; | 187 std::vector<scoped_refptr<GPUDevice>> devices; |
188 devices.push_back(GPUDeviceToProtocol(gpu_info.gpu)); | 188 devices.push_back(GPUDeviceToProtocol(gpu_info.gpu)); |
189 for (const auto& device : gpu_info.secondary_gpus) | 189 for (const auto& device : gpu_info.secondary_gpus) |
190 devices.push_back(GPUDeviceToProtocol(device)); | 190 devices.push_back(GPUDeviceToProtocol(device)); |
191 | 191 |
192 scoped_ptr<base::DictionaryValue> aux_attributes(new base::DictionaryValue); | 192 scoped_ptr<base::DictionaryValue> aux_attributes(new base::DictionaryValue); |
193 AuxGPUInfoEnumerator enumerator(aux_attributes.get()); | 193 AuxGPUInfoEnumerator enumerator(aux_attributes.get()); |
194 gpu_info.EnumerateFields(&enumerator); | 194 gpu_info.EnumerateFields(&enumerator); |
195 | 195 |
196 scoped_refptr<GPUInfo> gpu = GPUInfo::Create() | 196 scoped_refptr<GPUInfo> gpu = GPUInfo::Create() |
197 ->set_devices(devices) | 197 ->set_devices(devices) |
198 ->set_aux_attributes(aux_attributes.Pass()) | 198 ->set_aux_attributes(aux_attributes.Pass()) |
199 ->set_feature_status(make_scoped_ptr(GetFeatureStatus())) | 199 ->set_feature_status(make_scoped_ptr(GetFeatureStatus())) |
200 ->set_driver_bug_workarounds(GetDriverBugWorkarounds()); | 200 ->set_driver_bug_workarounds(GetDriverBugWorkarounds()); |
201 | 201 |
202 client_->SendGetInfoResponse( | 202 client_->SendGetInfoResponse( |
203 command_id, | 203 session_id, command_id, |
204 GetInfoResponse::Create()->set_gpu(gpu) | 204 GetInfoResponse::Create() |
205 ->set_model_name(gpu_info.machine_model_name) | 205 ->set_gpu(gpu) |
206 ->set_model_version(gpu_info.machine_model_version)); | 206 ->set_model_name(gpu_info.machine_model_name) |
| 207 ->set_model_version(gpu_info.machine_model_version)); |
207 } | 208 } |
208 | 209 |
209 void SystemInfoHandler::AddActiveObserverId(int observer_id) { | 210 void SystemInfoHandler::AddActiveObserverId(int observer_id) { |
210 base::AutoLock auto_lock(lock_); | 211 base::AutoLock auto_lock(lock_); |
211 active_observers_.insert(observer_id); | 212 active_observers_.insert(observer_id); |
212 } | 213 } |
213 | 214 |
214 bool SystemInfoHandler::RemoveActiveObserverId(int observer_id) { | 215 bool SystemInfoHandler::RemoveActiveObserverId(int observer_id) { |
215 base::AutoLock auto_lock(lock_); | 216 base::AutoLock auto_lock(lock_); |
216 int num_removed = active_observers_.erase(observer_id); | 217 int num_removed = active_observers_.erase(observer_id); |
217 return (num_removed != 0); | 218 return (num_removed != 0); |
218 } | 219 } |
219 | 220 |
220 void SystemInfoHandler::ObserverWatchdogCallback(int observer_id, | 221 void SystemInfoHandler::ObserverWatchdogCallback(int observer_id, |
| 222 int session_id, |
221 DevToolsCommandId command_id) { | 223 DevToolsCommandId command_id) { |
222 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 224 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
223 if (RemoveActiveObserverId(observer_id)) { | 225 if (RemoveActiveObserverId(observer_id)) { |
224 SendGetInfoResponse(command_id); | 226 SendGetInfoResponse(session_id, command_id); |
225 // For the time being we want to know about this event in the test logs. | 227 // For the time being we want to know about this event in the test logs. |
226 LOG(ERROR) << "SystemInfoHandler: request for GPU info timed out!" | 228 LOG(ERROR) << "SystemInfoHandler: request for GPU info timed out!" |
227 << " Most recent info sent."; | 229 << " Most recent info sent."; |
228 } | 230 } |
229 } | 231 } |
230 | 232 |
231 } // namespace system_info | 233 } // namespace system_info |
232 } // namespace devtools | 234 } // namespace devtools |
233 } // namespace content | 235 } // namespace content |
OLD | NEW |