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

Side by Side Diff: content/gpu/gpu_child_thread.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gpu/gpu_child_thread.h" 5 #include "content/gpu/gpu_child_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "media/base/android/media_client_android.h" 53 #include "media/base/android/media_client_android.h"
54 #include "media/gpu/avda_surface_tracker.h" 54 #include "media/gpu/avda_surface_tracker.h"
55 #endif 55 #endif
56 56
57 namespace content { 57 namespace content {
58 namespace { 58 namespace {
59 59
60 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > 60 static base::LazyInstance<scoped_refptr<ThreadSafeSender> >
61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; 61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER;
62 62
63 bool GpuProcessLogMessageHandler(int severity,
64 const char* file, int line,
65 size_t message_start,
66 const std::string& str) {
67 std::string header = str.substr(0, message_start);
68 std::string message = str.substr(message_start);
69
70 g_thread_safe_sender.Get()->Send(
71 new GpuHostMsg_OnLogMessage(severity, header, message));
72
73 return false;
74 }
75
76 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages 63 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages
77 // on the IO thread. This allows the UI thread in the browser process to remain 64 // on the IO thread. This allows the UI thread in the browser process to remain
78 // fast at all times. 65 // fast at all times.
79 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { 66 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
80 public: 67 public:
81 explicit GpuMemoryBufferMessageFilter( 68 explicit GpuMemoryBufferMessageFilter(
82 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 69 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
83 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 70 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
84 sender_(nullptr) {} 71 sender_(nullptr) {}
85 72
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 builder.AddStartupFilter(message_filter); 122 builder.AddStartupFilter(message_filter);
136 #endif 123 #endif
137 124
138 builder.ConnectToBrowser(true); 125 builder.ConnectToBrowser(true);
139 126
140 return builder.Build(); 127 return builder.Build();
141 } 128 }
142 129
143 } // namespace 130 } // namespace
144 131
132 void GpuProcessLogMessageListener::OnMessage(int severity,
133 const char* file,
134 int line,
135 size_t message_start,
136 const std::string& str) {
137 std::string header = str.substr(0, message_start);
138 std::string message = str.substr(message_start);
139
140 g_thread_safe_sender.Get()->Send(
141 new GpuHostMsg_OnLogMessage(severity, header, message));
142 }
143
145 GpuChildThread::GpuChildThread( 144 GpuChildThread::GpuChildThread(
146 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 145 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
147 bool dead_on_arrival, 146 bool dead_on_arrival,
148 const gpu::GPUInfo& gpu_info, 147 const gpu::GPUInfo& gpu_info,
149 const DeferredMessages& deferred_messages, 148 const DeferredMessages& deferred_messages,
150 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 149 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
151 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), 150 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)),
152 dead_on_arrival_(dead_on_arrival), 151 dead_on_arrival_(dead_on_arrival),
153 watchdog_thread_(std::move(watchdog_thread)), 152 watchdog_thread_(std::move(watchdog_thread)),
154 gpu_info_(gpu_info), 153 gpu_info_(gpu_info),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 187
189 GpuChildThread::~GpuChildThread() { 188 GpuChildThread::~GpuChildThread() {
190 while (!deferred_messages_.empty()) { 189 while (!deferred_messages_.empty()) {
191 delete deferred_messages_.front(); 190 delete deferred_messages_.front();
192 deferred_messages_.pop(); 191 deferred_messages_.pop();
193 } 192 }
194 } 193 }
195 194
196 void GpuChildThread::Shutdown() { 195 void GpuChildThread::Shutdown() {
197 ChildThreadImpl::Shutdown(); 196 ChildThreadImpl::Shutdown();
198 logging::SetLogMessageHandler(NULL); 197 if (!in_browser_process_)
198 log_listener_.reset();
199 } 199 }
200 200
201 void GpuChildThread::Init(const base::Time& process_start_time) { 201 void GpuChildThread::Init(const base::Time& process_start_time) {
202 process_start_time_ = process_start_time; 202 process_start_time_ = process_start_time;
203 203
204 #if defined(OS_ANDROID) 204 #if defined(OS_ANDROID)
205 // When running in in-process mode, this has been set in the browser at 205 // When running in in-process mode, this has been set in the browser at
206 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). 206 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun().
207 if (!in_browser_process_) 207 if (!in_browser_process_)
208 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); 208 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid());
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 326
327 if (dead_on_arrival_) { 327 if (dead_on_arrival_) {
328 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; 328 LOG(ERROR) << "Exiting GPU process due to errors during initialization";
329 base::MessageLoop::current()->QuitWhenIdle(); 329 base::MessageLoop::current()->QuitWhenIdle();
330 return; 330 return;
331 } 331 }
332 332
333 // We don't need to pipe log messages if we are running the GPU thread in 333 // We don't need to pipe log messages if we are running the GPU thread in
334 // the browser process. 334 // the browser process.
335 if (!in_browser_process_) 335 if (!in_browser_process_)
336 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); 336 log_listener_ = base::MakeUnique<GpuProcessLogMessageListener>();
337 337
338 gpu::SyncPointManager* sync_point_manager = nullptr; 338 gpu::SyncPointManager* sync_point_manager = nullptr;
339 // Note SyncPointManager from ContentGpuClient cannot be owned by this. 339 // Note SyncPointManager from ContentGpuClient cannot be owned by this.
340 if (GetContentClient()->gpu()) 340 if (GetContentClient()->gpu())
341 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); 341 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager();
342 if (!sync_point_manager) { 342 if (!sync_point_manager) {
343 if (!owned_sync_point_manager_) { 343 if (!owned_sync_point_manager_) {
344 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); 344 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false));
345 } 345 }
346 sync_point_manager = owned_sync_point_manager_.get(); 346 sync_point_manager = owned_sync_point_manager_.get();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 524
525 void GpuChildThread::BindServiceFactoryRequest( 525 void GpuChildThread::BindServiceFactoryRequest(
526 service_manager::mojom::ServiceFactoryRequest request) { 526 service_manager::mojom::ServiceFactoryRequest request) {
527 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; 527 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest";
528 DCHECK(service_factory_); 528 DCHECK(service_factory_);
529 service_factory_bindings_.AddBinding(service_factory_.get(), 529 service_factory_bindings_.AddBinding(service_factory_.get(),
530 std::move(request)); 530 std::move(request));
531 } 531 }
532 532
533 } // namespace content 533 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698