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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/system_info_handler.cc
diff --git a/content/browser/devtools/protocol/system_info_handler.cc b/content/browser/devtools/protocol/system_info_handler.cc
index 2c139c422ebb905d22f2f7a6dc8713c55ff3079c..8ad8b94a180fcc42bf0daa5259829e30f082bd68 100644
--- a/content/browser/devtools/protocol/system_info_handler.cc
+++ b/content/browser/devtools/protocol/system_info_handler.cc
@@ -18,46 +18,47 @@
#include "gpu/config/gpu_switches.h"
namespace content {
-namespace devtools {
-namespace system_info {
+namespace protocol {
namespace {
-using Response = DevToolsProtocolClient::Response;
+using SystemInfo::GPUDevice;
+using SystemInfo::GPUInfo;
+using GetInfoCallback = SystemInfo::Backend::GetInfoCallback;
// Give the GPU process a few seconds to provide GPU info.
const int kGPUInfoWatchdogTimeoutMs = 5000;
class AuxGPUInfoEnumerator : public gpu::GPUInfo::Enumerator {
public:
- AuxGPUInfoEnumerator(base::DictionaryValue* dictionary)
+ AuxGPUInfoEnumerator(protocol::DictionaryValue* dictionary)
: dictionary_(dictionary),
in_aux_attributes_(false) { }
void AddInt64(const char* name, int64_t value) override {
if (in_aux_attributes_)
- dictionary_->SetDouble(name, value);
+ dictionary_->setDouble(name, value);
}
void AddInt(const char* name, int value) override {
if (in_aux_attributes_)
- dictionary_->SetInteger(name, value);
+ dictionary_->setInteger(name, value);
}
void AddString(const char* name, const std::string& value) override {
if (in_aux_attributes_)
- dictionary_->SetString(name, value);
+ dictionary_->setString(name, value);
}
void AddBool(const char* name, bool value) override {
if (in_aux_attributes_)
- dictionary_->SetBoolean(name, value);
+ dictionary_->setBoolean(name, value);
}
void AddTimeDeltaInSecondsF(const char* name,
const base::TimeDelta& value) override {
if (in_aux_attributes_)
- dictionary_->SetDouble(name, value.InSecondsF());
+ dictionary_->setDouble(name, value.InSecondsF());
}
void BeginGPUDevice() override {}
@@ -81,31 +82,72 @@ class AuxGPUInfoEnumerator : public gpu::GPUInfo::Enumerator {
}
private:
- base::DictionaryValue* dictionary_;
+ protocol::DictionaryValue* dictionary_;
bool in_aux_attributes_;
};
-scoped_refptr<GPUDevice> GPUDeviceToProtocol(
+std::unique_ptr<GPUDevice> GPUDeviceToProtocol(
const gpu::GPUInfo::GPUDevice& device) {
- return GPUDevice::Create()->set_vendor_id(device.vendor_id)
- ->set_device_id(device.device_id)
- ->set_vendor_string(device.vendor_string)
- ->set_device_string(device.device_string);
+ return GPUDevice::Create().SetVendorId(device.vendor_id)
+ .SetDeviceId(device.device_id)
+ .SetVendorString(device.vendor_string)
+ .SetDeviceString(device.device_string)
+ .Build();
+}
+
+void SendGetInfoResponse(std::unique_ptr<GetInfoCallback> callback) {
+ gpu::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo();
+ std::unique_ptr<protocol::Array<GPUDevice>> devices =
+ protocol::Array<GPUDevice>::create();
+ devices->addItem(GPUDeviceToProtocol(gpu_info.gpu));
+ for (const auto& device : gpu_info.secondary_gpus)
+ devices->addItem(GPUDeviceToProtocol(device));
+
+ std::unique_ptr<protocol::DictionaryValue> aux_attributes =
+ protocol::DictionaryValue::create();
+ AuxGPUInfoEnumerator enumerator(aux_attributes.get());
+ gpu_info.EnumerateFields(&enumerator);
+
+ std::unique_ptr<base::DictionaryValue> base_feature_status =
+ base::WrapUnique(GetFeatureStatus());
+ std::unique_ptr<protocol::DictionaryValue> feature_status =
+ protocol::DictionaryValue::cast(
+ protocol::toProtocolValue(base_feature_status.get(), 1000));
+
+ std::unique_ptr<protocol::Array<std::string>> driver_bug_workarounds =
+ protocol::Array<std::string>::create();
+ for (const std::string& s : GetDriverBugWorkarounds())
+ driver_bug_workarounds->addItem(s);
+
+ std::unique_ptr<GPUInfo> gpu = GPUInfo::Create()
+ .SetDevices(std::move(devices))
+ .SetAuxAttributes(std::move(aux_attributes))
+ .SetFeatureStatus(std::move(feature_status))
+ .SetDriverBugWorkarounds(std::move(driver_bug_workarounds))
+ .Build();
+
+ callback->sendSuccess(std::move(gpu), gpu_info.machine_model_name,
+ gpu_info.machine_model_version);
}
} // namespace
class SystemInfoHandlerGpuObserver : public content::GpuDataManagerObserver {
public:
- SystemInfoHandlerGpuObserver(base::WeakPtr<SystemInfoHandler> handler,
- DevToolsCommandId command_id)
- : handler_(handler),
- command_id_(command_id),
- observer_id_(++next_observer_id_)
- {
- if (handler_) {
- handler_->AddActiveObserverId(observer_id_);
- }
+ explicit SystemInfoHandlerGpuObserver(
+ std::unique_ptr<GetInfoCallback> callback)
+ : callback_(std::move(callback)),
+ weak_factory_(this) {
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&SystemInfoHandlerGpuObserver::ObserverWatchdogCallback,
+ weak_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(kGPUInfoWatchdogTimeoutMs));
+
+ GpuDataManager::GetInstance()->AddObserver(this);
+ // There's no other method available to request just essential GPU info.
+ GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded();
}
void OnGpuInfoUpdate() override {
@@ -116,42 +158,38 @@ class SystemInfoHandlerGpuObserver : public content::GpuDataManagerObserver {
UnregisterAndSendResponse();
}
+ void ObserverWatchdogCallback() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ UnregisterAndSendResponse();
+ }
+
void UnregisterAndSendResponse() {
GpuDataManager::GetInstance()->RemoveObserver(this);
- if (handler_.get()) {
- if (handler_->RemoveActiveObserverId(observer_id_)) {
- handler_->SendGetInfoResponse(command_id_);
- }
- }
+ SendGetInfoResponse(std::move(callback_));
delete this;
}
- int GetObserverId() {
- return observer_id_;
- }
-
private:
- base::WeakPtr<SystemInfoHandler> handler_;
- DevToolsCommandId command_id_;
- int observer_id_;
-
- static int next_observer_id_;
+ std::unique_ptr<GetInfoCallback> callback_;
+ base::WeakPtrFactory<SystemInfoHandlerGpuObserver> weak_factory_;
};
-int SystemInfoHandlerGpuObserver::next_observer_id_ = 0;
-
-SystemInfoHandler::SystemInfoHandler()
- : weak_factory_(this) {
+SystemInfoHandler::SystemInfoHandler() {
}
SystemInfoHandler::~SystemInfoHandler() {
}
-void SystemInfoHandler::SetClient(std::unique_ptr<Client> client) {
- client_.swap(client);
+void SystemInfoHandler::Wire(UberDispatcher* dispatcher) {
+ SystemInfo::Dispatcher::wire(dispatcher, this);
+}
+
+Response SystemInfoHandler::Disable() {
+ return Response::OK();
}
-Response SystemInfoHandler::GetInfo(DevToolsCommandId command_id) {
+void SystemInfoHandler::GetInfo(
+ std::unique_ptr<GetInfoCallback> callback) {
std::string reason;
if (!GpuDataManager::GetInstance()->GpuAccessAllowed(&reason) ||
GpuDataManager::GetInstance()->IsEssentialGpuInfoAvailable() ||
@@ -167,79 +205,14 @@ Response SystemInfoHandler::GetInfo(DevToolsCommandId command_id) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
- base::Bind(&SystemInfoHandler::SendGetInfoResponse,
- weak_factory_.GetWeakPtr(),
- command_id));
+ base::Bind(&SendGetInfoResponse, base::Passed(std::move(callback))));
} else {
// We will be able to get more information from the GpuDataManager.
// Register a transient observer with it to call us back when the
// information is available.
- SystemInfoHandlerGpuObserver* observer = new SystemInfoHandlerGpuObserver(
- weak_factory_.GetWeakPtr(), command_id);
- BrowserThread::PostDelayedTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&SystemInfoHandler::ObserverWatchdogCallback,
- weak_factory_.GetWeakPtr(),
- observer->GetObserverId(),
- command_id),
- base::TimeDelta::FromMilliseconds(kGPUInfoWatchdogTimeoutMs));
- GpuDataManager::GetInstance()->AddObserver(observer);
- // There's no other method available to request just essential GPU info.
- GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded();
- }
-
- return Response::OK();
-}
-
-void SystemInfoHandler::SendGetInfoResponse(DevToolsCommandId command_id) {
- gpu::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo();
- std::vector<scoped_refptr<GPUDevice>> devices;
- devices.push_back(GPUDeviceToProtocol(gpu_info.gpu));
- for (const auto& device : gpu_info.secondary_gpus)
- devices.push_back(GPUDeviceToProtocol(device));
-
- std::unique_ptr<base::DictionaryValue> aux_attributes(
- new base::DictionaryValue);
- AuxGPUInfoEnumerator enumerator(aux_attributes.get());
- gpu_info.EnumerateFields(&enumerator);
-
- scoped_refptr<GPUInfo> gpu =
- GPUInfo::Create()
- ->set_devices(devices)
- ->set_aux_attributes(std::move(aux_attributes))
- ->set_feature_status(base::WrapUnique(GetFeatureStatus()))
- ->set_driver_bug_workarounds(GetDriverBugWorkarounds());
-
- client_->SendGetInfoResponse(
- command_id,
- GetInfoResponse::Create()->set_gpu(gpu)
- ->set_model_name(gpu_info.machine_model_name)
- ->set_model_version(gpu_info.machine_model_version));
-}
-
-void SystemInfoHandler::AddActiveObserverId(int observer_id) {
- base::AutoLock auto_lock(lock_);
- active_observers_.insert(observer_id);
-}
-
-bool SystemInfoHandler::RemoveActiveObserverId(int observer_id) {
- base::AutoLock auto_lock(lock_);
- int num_removed = active_observers_.erase(observer_id);
- return (num_removed != 0);
-}
-
-void SystemInfoHandler::ObserverWatchdogCallback(int observer_id,
- DevToolsCommandId command_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (RemoveActiveObserverId(observer_id)) {
- SendGetInfoResponse(command_id);
- // For the time being we want to know about this event in the test logs.
- LOG(ERROR) << "SystemInfoHandler: request for GPU info timed out!"
- << " Most recent info sent.";
+ new SystemInfoHandlerGpuObserver(std::move(callback));
}
}
-} // namespace system_info
-} // namespace devtools
+} // namespace protocol
} // namespace content
« 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