Chromium Code Reviews| Index: services/ui/gpu/gpu_service.cc |
| diff --git a/services/ui/gpu/gpu_service.cc b/services/ui/gpu/gpu_service.cc |
| index 86711a59befc121470358ac6d1dff39cd567e5f5..2c13a88e08d3d9b96ed43c8efd660adcf5b7f5a7 100644 |
| --- a/services/ui/gpu/gpu_service.cc |
| +++ b/services/ui/gpu/gpu_service.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/debug/crash_logging.h" |
| +#include "base/lazy_instance.h" |
| #include "base/memory/shared_memory.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| @@ -43,6 +44,23 @@ |
| namespace ui { |
| +namespace { |
| + |
| +static base::LazyInstance<base::Callback< |
| + void(int severity, size_t message_start, const std::string& message)>>:: |
| + Leaky g_log_callback = LAZY_INSTANCE_INITIALIZER; |
| + |
| +bool GpuLogMessageHandler(int severity, |
| + const char* file, |
| + int line, |
| + size_t message_start, |
| + const std::string& message) { |
| + g_log_callback.Get().Run(severity, message_start, message); |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| GpuService::GpuService(const gpu::GPUInfo& gpu_info, |
| std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
| gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| @@ -58,6 +76,9 @@ GpuService::GpuService(const gpu::GPUInfo& gpu_info, |
| sync_point_manager_(nullptr) {} |
| GpuService::~GpuService() { |
| + logging::SetLogMessageHandler(nullptr); |
| + g_log_callback.Get() = |
| + base::Callback<void(int, size_t, const std::string&)>(); |
| bindings_.CloseAllBindings(); |
| media_gpu_channel_manager_.reset(); |
| gpu_channel_manager_.reset(); |
| @@ -88,6 +109,16 @@ void GpuService::InitializeWithHost(mojom::GpuHostPtr gpu_host, |
| IsAcceleratedJpegDecodeSupported(); |
| gpu_host_->DidInitialize(gpu_info_); |
| + if (!in_host_process_) { |
| + // The global callback is reset from the dtor. So Unretained() here is safe. |
| + // Note that the callback can be called from any thread. Consequently, the |
| + // callback cannot use a WeakPtr. |
| + g_log_callback.Get() = |
| + base::Bind(&GpuService::RecordLogMessage, base::Unretained(this), |
| + base::ThreadTaskRunnerHandle::Get()); |
|
piman
2017/03/20 21:20:26
So, this has different properties than the previou
sadrul
2017/03/20 21:40:17
There is ThreadSafeInterfacePtrBase<> that I could
Ken Rockot(use gerrit already)
2017/03/21 00:56:01
Well one option would be to move the GpuHostPtr to
|
| + logging::SetLogMessageHandler(GpuLogMessageHandler); |
| + } |
| + |
| sync_point_manager_ = sync_point_manager; |
| if (!sync_point_manager_) { |
| owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>(); |
| @@ -112,6 +143,23 @@ void GpuService::Bind(mojom::GpuServiceRequest request) { |
| bindings_.AddBinding(this, std::move(request)); |
| } |
| +void GpuService::RecordLogMessage( |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| + int severity, |
| + size_t message_start, |
| + const std::string& str) { |
| + if (!task_runner->BelongsToCurrentThread()) { |
| + task_runner->PostTask( |
| + FROM_HERE, |
| + base::Bind(base::IgnoreResult(&GpuLogMessageHandler), severity, |
| + nullptr /* file */, 0 /* line */, message_start, str)); |
| + return; |
| + } |
| + std::string header = str.substr(0, message_start); |
| + std::string message = str.substr(message_start); |
| + gpu_host_->RecordLogMessage(severity, header, message); |
| +} |
| + |
| void GpuService::CreateGpuMemoryBuffer( |
| gfx::GpuMemoryBufferId id, |
| const gfx::Size& size, |