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

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

Issue 2819903004: Migrate GpuChildThread to use ConnectionFilter instead of the ChildThread's InterfaceRegistry to exp (Closed)
Patch Set: . Created 3 years, 8 months 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"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
13 #include "content/child/child_process.h" 15 #include "content/child/child_process.h"
14 #include "content/common/field_trial_recorder.mojom.h" 16 #include "content/common/field_trial_recorder.mojom.h"
15 #include "content/gpu/gpu_service_factory.h" 17 #include "content/gpu/gpu_service_factory.h"
18 #include "content/public/common/connection_filter.h"
16 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
17 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
18 #include "content/public/common/service_manager_connection.h" 21 #include "content/public/common/service_manager_connection.h"
19 #include "content/public/common/service_names.mojom.h" 22 #include "content/public/common/service_names.mojom.h"
20 #include "content/public/gpu/content_gpu_client.h" 23 #include "content/public/gpu/content_gpu_client.h"
21 #include "gpu/command_buffer/common/activity_flags.h" 24 #include "gpu/command_buffer/common/activity_flags.h"
22 #include "gpu/ipc/service/gpu_watchdog_thread.h" 25 #include "gpu/ipc/service/gpu_watchdog_thread.h"
23 #include "ipc/ipc_sync_message_filter.h" 26 #include "ipc/ipc_sync_message_filter.h"
24 #include "media/gpu/ipc/service/media_gpu_channel_manager.h" 27 #include "media/gpu/ipc/service/media_gpu_channel_manager.h"
28 #include "services/service_manager/public/cpp/binder_registry.h"
25 #include "services/service_manager/public/cpp/connector.h" 29 #include "services/service_manager/public/cpp/connector.h"
26 #include "services/service_manager/public/cpp/interface_registry.h"
27 #include "services/ui/gpu/interfaces/gpu_service.mojom.h" 30 #include "services/ui/gpu/interfaces/gpu_service.mojom.h"
28 31
29 #if defined(USE_OZONE) 32 #if defined(USE_OZONE)
30 #include "ui/ozone/public/ozone_platform.h" 33 #include "ui/ozone/public/ozone_platform.h"
31 #endif 34 #endif
32 35
33 #if defined(OS_ANDROID) 36 #if defined(OS_ANDROID)
34 #include "media/base/android/media_drm_bridge_client.h" 37 #include "media/base/android/media_drm_bridge_client.h"
35 #endif 38 #endif
36 39
37 namespace content { 40 namespace content {
38 namespace { 41 namespace {
39 42
40 ChildThreadImpl::Options GetOptions() { 43 ChildThreadImpl::Options GetOptions() {
41 ChildThreadImpl::Options::Builder builder; 44 ChildThreadImpl::Options::Builder builder;
42 45
43 #if defined(USE_OZONE) 46 #if defined(USE_OZONE)
44 IPC::MessageFilter* message_filter = 47 IPC::MessageFilter* message_filter =
45 ui::OzonePlatform::GetInstance()->GetGpuMessageFilter(); 48 ui::OzonePlatform::GetInstance()->GetGpuMessageFilter();
46 if (message_filter) 49 if (message_filter)
47 builder.AddStartupFilter(message_filter); 50 builder.AddStartupFilter(message_filter);
48 #endif 51 #endif
49 52
53 builder.AutoStartServiceManagerConnection(false);
50 builder.ConnectToBrowser(true); 54 builder.ConnectToBrowser(true);
51 55
52 return builder.Build(); 56 return builder.Build();
53 } 57 }
54 58
55 } // namespace 59 } // namespace
56 60
61 // This ConnectionFilter queues all incoming bind interface requests until
62 // Release() is called.
63 class GpuChildThread::QueueingConnectionFilter : public ConnectionFilter {
64 public:
65 QueueingConnectionFilter(
66 scoped_refptr<base::SequencedTaskRunner> io_task_runner,
67 std::unique_ptr<service_manager::BinderRegistry> registry)
68 : io_task_runner_(io_task_runner),
69 registry_(std::move(registry)),
70 weak_factory_(this) {
71 // This will be reattached by any of the IO thread functions on first call.
72 io_thread_checker_.DetachFromThread();
73 }
74 ~QueueingConnectionFilter() override {
75 DCHECK(io_thread_checker_.CalledOnValidThread());
76 }
77
78 base::Closure GetReleaseCallback() {
79 return base::Bind(base::IgnoreResult(&base::TaskRunner::PostTask),
80 io_task_runner_, FROM_HERE,
81 base::Bind(&QueueingConnectionFilter::Release,
82 weak_factory_.GetWeakPtr()));
83 }
84
85 private:
86 struct PendingRequest {
87 service_manager::Identity source_identity;
88 std::string interface_name;
89 mojo::ScopedMessagePipeHandle interface_pipe;
90 };
91
92 // ConnectionFilter:
93 void OnBindInterface(const service_manager::ServiceInfo& source_info,
94 const std::string& interface_name,
95 mojo::ScopedMessagePipeHandle* interface_pipe,
96 service_manager::Connector* connector) override {
97 DCHECK(io_thread_checker_.CalledOnValidThread());
98 if (registry_->CanBindInterface(interface_name)) {
99 base::AutoLock lock(lock_);
100 if (released_) {
101 registry_->BindInterface(source_info.identity, interface_name,
102 std::move(*interface_pipe));
103 } else {
104 std::unique_ptr<PendingRequest> request =
105 base::MakeUnique<PendingRequest>();
106 request->source_identity = source_info.identity;
107 request->interface_name = interface_name;
108 request->interface_pipe = std::move(*interface_pipe);
109 pending_requests_.push_back(std::move(request));
110 }
111 }
112 }
113
114 void Release() {
115 DCHECK(io_thread_checker_.CalledOnValidThread());
116 for (auto& request : pending_requests_) {
117 registry_->BindInterface(request->source_identity,
118 request->interface_name,
119 std::move(request->interface_pipe));
120 }
121 }
122
123 base::ThreadChecker io_thread_checker_;
124 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
125 // Guards |released_|.
126 base::Lock lock_;
127 bool released_ = false;
128 std::vector<std::unique_ptr<PendingRequest>> pending_requests_;
129 std::unique_ptr<service_manager::BinderRegistry> registry_;
130
131 base::WeakPtrFactory<QueueingConnectionFilter> weak_factory_;
132
133 DISALLOW_COPY_AND_ASSIGN(QueueingConnectionFilter);
134 };
135
57 GpuChildThread::GpuChildThread( 136 GpuChildThread::GpuChildThread(
58 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 137 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
59 bool dead_on_arrival, 138 bool dead_on_arrival,
60 const gpu::GPUInfo& gpu_info, 139 const gpu::GPUInfo& gpu_info,
61 const gpu::GpuFeatureInfo& gpu_feature_info, 140 const gpu::GpuFeatureInfo& gpu_feature_info,
62 DeferredMessages deferred_messages) 141 DeferredMessages deferred_messages)
63 : GpuChildThread(GetOptions(), 142 : GpuChildThread(GetOptions(),
64 std::move(watchdog_thread), 143 std::move(watchdog_thread),
65 dead_on_arrival, 144 dead_on_arrival,
66 false /* in_browser_process */, 145 false /* in_browser_process */,
67 gpu_info, 146 gpu_info,
68 gpu_feature_info) { 147 gpu_feature_info) {
69 deferred_messages_ = std::move(deferred_messages); 148 deferred_messages_ = std::move(deferred_messages);
70 } 149 }
71 150
72 GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params, 151 GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params,
73 const gpu::GPUInfo& gpu_info, 152 const gpu::GPUInfo& gpu_info,
74 const gpu::GpuFeatureInfo& gpu_feature_info) 153 const gpu::GpuFeatureInfo& gpu_feature_info)
75 : GpuChildThread(ChildThreadImpl::Options::Builder() 154 : GpuChildThread(ChildThreadImpl::Options::Builder()
76 .InBrowserProcess(params) 155 .InBrowserProcess(params)
156 .AutoStartServiceManagerConnection(false)
77 .ConnectToBrowser(true) 157 .ConnectToBrowser(true)
78 .Build(), 158 .Build(),
79 nullptr /* watchdog_thread */, 159 nullptr /* watchdog_thread */,
80 false /* dead_on_arrival */, 160 false /* dead_on_arrival */,
81 true /* in_browser_process */, 161 true /* in_browser_process */,
82 gpu_info, 162 gpu_info,
83 gpu_feature_info) {} 163 gpu_feature_info) {}
84 164
85 GpuChildThread::GpuChildThread( 165 GpuChildThread::GpuChildThread(
86 const ChildThreadImpl::Options& options, 166 const ChildThreadImpl::Options& options,
(...skipping 25 matching lines...) Expand all
112 void GpuChildThread::Init(const base::Time& process_start_time) { 192 void GpuChildThread::Init(const base::Time& process_start_time) {
113 gpu_service_->set_start_time(process_start_time); 193 gpu_service_->set_start_time(process_start_time);
114 194
115 #if defined(OS_ANDROID) 195 #if defined(OS_ANDROID)
116 // When running in in-process mode, this has been set in the browser at 196 // When running in in-process mode, this has been set in the browser at
117 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). 197 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun().
118 if (!in_browser_process_) 198 if (!in_browser_process_)
119 media::SetMediaDrmBridgeClient( 199 media::SetMediaDrmBridgeClient(
120 GetContentClient()->GetMediaDrmBridgeClient()); 200 GetContentClient()->GetMediaDrmBridgeClient());
121 #endif 201 #endif
122 // We don't want to process any incoming interface requests until 202 AssociatedInterfaceRegistry* associated_registry = &associated_interfaces_;
123 // OnInitialize() is invoked. 203 associated_registry->AddInterface(base::Bind(
124 GetInterfaceRegistry()->PauseBinding(); 204 &GpuChildThread::CreateGpuMainService, base::Unretained(this)));
125 205
206 auto registry = base::MakeUnique<service_manager::BinderRegistry>();
207 registry->AddInterface(base::Bind(&GpuChildThread::BindServiceFactoryRequest,
208 base::Unretained(this)),
209 base::ThreadTaskRunnerHandle::Get());
126 if (GetContentClient()->gpu()) // NULL in tests. 210 if (GetContentClient()->gpu()) // NULL in tests.
127 GetContentClient()->gpu()->Initialize(this); 211 GetContentClient()->gpu()->Initialize(this, registry.get());
128 AssociatedInterfaceRegistry* registry = &associated_interfaces_; 212
129 registry->AddInterface(base::Bind( 213 std::unique_ptr<QueueingConnectionFilter> filter =
130 &GpuChildThread::CreateGpuMainService, base::Unretained(this))); 214 base::MakeUnique<QueueingConnectionFilter>(GetIOTaskRunner(),
215 std::move(registry));
216 release_closure_ = filter->GetReleaseCallback();
Ken Rockot(use gerrit already) 2017/04/20 17:41:44 nit: Maybe a better name than release_closure_ sin
217 GetServiceManagerConnection()->AddConnectionFilter(std::move(filter));
218
219 StartServiceManagerConnection();
131 } 220 }
132 221
133 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name, 222 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name,
134 const std::string& group_name) { 223 const std::string& group_name) {
135 mojom::FieldTrialRecorderPtr field_trial_recorder; 224 mojom::FieldTrialRecorderPtr field_trial_recorder;
136 GetConnector()->BindInterface(mojom::kBrowserServiceName, 225 GetConnector()->BindInterface(mojom::kBrowserServiceName,
137 &field_trial_recorder); 226 &field_trial_recorder);
138 field_trial_recorder->FieldTrialActivated(trial_name); 227 field_trial_recorder->FieldTrialActivated(trial_name);
139 } 228 }
140 229
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 gpu_service_->InitializeWithHost( 278 gpu_service_->InitializeWithHost(
190 std::move(gpu_host), 279 std::move(gpu_host),
191 gpu::GpuProcessActivityFlags(std::move(activity_flags)), 280 gpu::GpuProcessActivityFlags(std::move(activity_flags)),
192 sync_point_manager, ChildProcess::current()->GetShutDownEvent()); 281 sync_point_manager, ChildProcess::current()->GetShutDownEvent());
193 CHECK(gpu_service_->media_gpu_channel_manager()); 282 CHECK(gpu_service_->media_gpu_channel_manager());
194 283
195 // Only set once per process instance. 284 // Only set once per process instance.
196 service_factory_.reset(new GpuServiceFactory( 285 service_factory_.reset(new GpuServiceFactory(
197 gpu_service_->media_gpu_channel_manager()->AsWeakPtr())); 286 gpu_service_->media_gpu_channel_manager()->AsWeakPtr()));
198 287
199 GetInterfaceRegistry()->AddInterface(base::Bind( 288 if (GetContentClient()->gpu()) // NULL in tests.
200 &GpuChildThread::BindServiceFactoryRequest, base::Unretained(this))); 289 GetContentClient()->gpu()->GpuServiceInitialized(gpu_preferences);
201 290
202 if (GetContentClient()->gpu()) { // NULL in tests. 291 release_closure_.Run();
203 GetContentClient()->gpu()->ExposeInterfacesToBrowser(GetInterfaceRegistry(),
204 gpu_preferences);
205 GetContentClient()->gpu()->ConsumeInterfacesFromBrowser(GetConnector());
206 }
207
208 GetInterfaceRegistry()->ResumeBinding();
209 } 292 }
210 293
211 void GpuChildThread::CreateFrameSinkManager( 294 void GpuChildThread::CreateFrameSinkManager(
212 cc::mojom::FrameSinkManagerRequest request, 295 cc::mojom::FrameSinkManagerRequest request,
213 cc::mojom::FrameSinkManagerClientPtr client) { 296 cc::mojom::FrameSinkManagerClientPtr client) {
214 NOTREACHED(); 297 NOTREACHED();
215 } 298 }
216 299
217 void GpuChildThread::BindServiceFactoryRequest( 300 void GpuChildThread::BindServiceFactoryRequest(
218 service_manager::mojom::ServiceFactoryRequest request) { 301 service_manager::mojom::ServiceFactoryRequest request) {
219 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; 302 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest";
220 DCHECK(service_factory_); 303 DCHECK(service_factory_);
221 service_factory_bindings_.AddBinding(service_factory_.get(), 304 service_factory_bindings_.AddBinding(service_factory_.get(),
222 std::move(request)); 305 std::move(request));
223 } 306 }
224 307
225 } // namespace content 308 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698