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

Side by Side Diff: content/browser/media/media_interface_proxy.cc

Issue 2521133002: media: Add MediaInterfaceProxy (Closed)
Patch Set: comments addressed Created 4 years 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
« no previous file with comments | « content/browser/media/media_interface_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/media/media_interface_proxy.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "content/public/browser/content_browser_client.h"
11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/common/content_client.h"
13 #include "content/public/common/service_manager_connection.h"
14 #include "media/mojo/interfaces/media_service.mojom.h"
15 #include "services/service_manager/public/cpp/connector.h"
16
17 #if defined(ENABLE_MOJO_CDM)
18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/provision_fetcher_impl.h"
20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/storage_partition.h"
22 #include "net/url_request/url_request_context_getter.h"
23 #endif
24
25 namespace content {
26
27 MediaInterfaceProxy::MediaInterfaceProxy(
28 RenderFrameHost* render_frame_host,
29 media::mojom::InterfaceFactoryRequest request,
30 const base::Closure& error_handler)
31 : render_frame_host_(render_frame_host),
32 binding_(this, std::move(request)) {
33 DVLOG(1) << __FUNCTION__;
34 DCHECK(render_frame_host_);
35 DCHECK(!error_handler.is_null());
36
37 binding_.set_connection_error_handler(error_handler);
38
39 // |interface_factory_ptr_| will be lazily connected in
40 // GetMediaInterfaceFactory().
41 }
42
43 MediaInterfaceProxy::~MediaInterfaceProxy() {
44 DVLOG(1) << __FUNCTION__;
45 DCHECK(thread_checker_.CalledOnValidThread());
46 }
47
48 void MediaInterfaceProxy::CreateAudioDecoder(
49 media::mojom::AudioDecoderRequest request) {
50 DCHECK(thread_checker_.CalledOnValidThread());
51 GetMediaInterfaceFactory()->CreateAudioDecoder(std::move(request));
52 }
53
54 void MediaInterfaceProxy::CreateVideoDecoder(
55 media::mojom::VideoDecoderRequest request) {
56 DCHECK(thread_checker_.CalledOnValidThread());
57 GetMediaInterfaceFactory()->CreateVideoDecoder(std::move(request));
58 }
59
60 void MediaInterfaceProxy::CreateRenderer(
61 const std::string& audio_device_id,
62 media::mojom::RendererRequest request) {
63 DCHECK(thread_checker_.CalledOnValidThread());
64 GetMediaInterfaceFactory()->CreateRenderer(audio_device_id,
65 std::move(request));
66 }
67
68 void MediaInterfaceProxy::CreateCdm(
69 media::mojom::ContentDecryptionModuleRequest request) {
70 DCHECK(thread_checker_.CalledOnValidThread());
71 GetMediaInterfaceFactory()->CreateCdm(std::move(request));
72 }
73
74 media::mojom::InterfaceFactory*
75 MediaInterfaceProxy::GetMediaInterfaceFactory() {
76 DVLOG(1) << __FUNCTION__;
77 DCHECK(thread_checker_.CalledOnValidThread());
78
79 if (!interface_factory_ptr_)
80 ConnectToService();
81
82 DCHECK(interface_factory_ptr_);
83
84 return interface_factory_ptr_.get();
85 }
86
87 void MediaInterfaceProxy::OnConnectionError() {
88 DVLOG(1) << __FUNCTION__;
89 DCHECK(thread_checker_.CalledOnValidThread());
90
91 interface_factory_ptr_.reset();
92 }
93
94 void MediaInterfaceProxy::ConnectToService() {
95 DVLOG(1) << __FUNCTION__;
96 DCHECK(thread_checker_.CalledOnValidThread());
97 DCHECK(!interface_factory_ptr_);
98
99 // Register frame services.
100 auto registry =
101 base::MakeUnique<service_manager::InterfaceRegistry>(std::string());
102 #if defined(ENABLE_MOJO_CDM)
103 // TODO(slan): Wrap these into a RenderFrame specific ProvisionFetcher impl.
104 net::URLRequestContextGetter* context_getter =
105 BrowserContext::GetDefaultStoragePartition(
106 render_frame_host_->GetProcess()->GetBrowserContext())
107 ->GetURLRequestContext();
108 registry->AddInterface(
109 base::Bind(&ProvisionFetcherImpl::Create, context_getter));
110 #endif // defined(ENABLE_MOJO_CDM)
111 GetContentClient()->browser()->ExposeInterfacesToMediaService(
112 registry.get(), render_frame_host_);
113
114 // Get frame service InterfaceProvider.
115 // TODO(xhwang): Replace this InterfaceProvider with a dedicated media host
116 // interface. See http://crbug.com/660573
117 service_manager::mojom::InterfaceProviderPtr interfaces;
118 registry->Bind(GetProxy(&interfaces), service_manager::Identity(),
119 service_manager::InterfaceProviderSpec(),
120 service_manager::Identity(),
121 service_manager::InterfaceProviderSpec());
122 media_registries_.push_back(std::move(registry));
123
124 // TODO(slan): Use the BrowserContext Connector instead. See crbug.com/638950.
125 media::mojom::MediaServicePtr media_service;
126 service_manager::Connector* connector =
127 ServiceManagerConnection::GetForProcess()->GetConnector();
128 connector->ConnectToInterface("media", &media_service);
129 media_service->CreateInterfaceFactory(GetProxy(&interface_factory_ptr_),
130 std::move(interfaces));
131 interface_factory_ptr_.set_connection_error_handler(base::Bind(
132 &MediaInterfaceProxy::OnConnectionError, base::Unretained(this)));
133 }
134
135 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/media_interface_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698