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

Side by Side Diff: chrome/browser/media/router/mojo/media_router_mojo_impl.cc

Issue 2185293002: [Media Router] Rename mojo namespace from interfaces to mojom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename mojo namespace in tests Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/media/router/mojo/media_router_mojo_impl.h" 5 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 18 matching lines...) Expand all
29 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
30 #include "extensions/browser/process_manager.h" 30 #include "extensions/browser/process_manager.h"
31 31
32 #define DVLOG_WITH_INSTANCE(level) \ 32 #define DVLOG_WITH_INSTANCE(level) \
33 DVLOG(level) << "MR #" << instance_id_ << ": " 33 DVLOG(level) << "MR #" << instance_id_ << ": "
34 34
35 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " 35 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": "
36 36
37 namespace media_router { 37 namespace media_router {
38 38
39 using SinkAvailability = interfaces::MediaRouter::SinkAvailability; 39 using SinkAvailability = mojom::MediaRouter::SinkAvailability;
40 40
41 namespace { 41 namespace {
42 42
43 std::unique_ptr<content::PresentationSessionMessage> 43 std::unique_ptr<content::PresentationSessionMessage>
44 ConvertToPresentationSessionMessage(interfaces::RouteMessagePtr input) { 44 ConvertToPresentationSessionMessage(mojom::RouteMessagePtr input) {
45 DCHECK(!input.is_null()); 45 DCHECK(!input.is_null());
46 std::unique_ptr<content::PresentationSessionMessage> output; 46 std::unique_ptr<content::PresentationSessionMessage> output;
47 switch (input->type) { 47 switch (input->type) {
48 case interfaces::RouteMessage::Type::TEXT: { 48 case mojom::RouteMessage::Type::TEXT: {
49 DCHECK(input->message); 49 DCHECK(input->message);
50 DCHECK(!input->data); 50 DCHECK(!input->data);
51 output.reset(new content::PresentationSessionMessage( 51 output.reset(new content::PresentationSessionMessage(
52 content::PresentationMessageType::TEXT)); 52 content::PresentationMessageType::TEXT));
53 output->message = std::move(*input->message); 53 output->message = std::move(*input->message);
54 return output; 54 return output;
55 } 55 }
56 case interfaces::RouteMessage::Type::BINARY: { 56 case mojom::RouteMessage::Type::BINARY: {
57 DCHECK(input->data); 57 DCHECK(input->data);
58 DCHECK(!input->message); 58 DCHECK(!input->message);
59 output.reset(new content::PresentationSessionMessage( 59 output.reset(new content::PresentationSessionMessage(
60 content::PresentationMessageType::ARRAY_BUFFER)); 60 content::PresentationMessageType::ARRAY_BUFFER));
61 output->data.reset(new std::vector<uint8_t>(std::move(*input->data))); 61 output->data.reset(new std::vector<uint8_t>(std::move(*input->data)));
62 return output; 62 return output;
63 } 63 }
64 } 64 }
65 65
66 NOTREACHED() << "Invalid route message type " << input->type; 66 NOTREACHED() << "Invalid route message type " << input->type;
67 return output; 67 return output;
68 } 68 }
69 69
70 } // namespace 70 } // namespace
71 71
72 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; 72 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default;
73 73
74 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; 74 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default;
75 75
76 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; 76 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default;
77 77
78 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; 78 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default;
79 79
80 MediaRouterMojoImpl::MediaRouterMojoImpl( 80 MediaRouterMojoImpl::MediaRouterMojoImpl(
81 extensions::EventPageTracker* event_page_tracker) 81 extensions::EventPageTracker* event_page_tracker)
82 : event_page_tracker_(event_page_tracker), 82 : event_page_tracker_(event_page_tracker),
83 instance_id_(base::GenerateGUID()), 83 instance_id_(base::GenerateGUID()),
84 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE), 84 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE),
85 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), 85 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT),
86 weak_factory_(this) { 86 weak_factory_(this) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88 DCHECK(event_page_tracker_); 88 DCHECK(event_page_tracker_);
89 #if defined(OS_WIN) 89 #if defined(OS_WIN)
90 CanFirewallUseLocalPorts( 90 CanFirewallUseLocalPorts(
91 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, 91 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete,
92 weak_factory_.GetWeakPtr())); 92 weak_factory_.GetWeakPtr()));
93 #endif 93 #endif
94 } 94 }
95 95
96 MediaRouterMojoImpl::~MediaRouterMojoImpl() { 96 MediaRouterMojoImpl::~MediaRouterMojoImpl() {
97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
98 } 98 }
99 99
100 // static 100 // static
101 void MediaRouterMojoImpl::BindToRequest( 101 void MediaRouterMojoImpl::BindToRequest(
102 const extensions::Extension* extension, 102 const extensions::Extension* extension,
103 content::BrowserContext* context, 103 content::BrowserContext* context,
104 mojo::InterfaceRequest<interfaces::MediaRouter> request) { 104 mojo::InterfaceRequest<mojom::MediaRouter> request) {
105 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( 105 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>(
106 MediaRouterFactory::GetApiForBrowserContext(context)); 106 MediaRouterFactory::GetApiForBrowserContext(context));
107 DCHECK(impl); 107 DCHECK(impl);
108 108
109 impl->BindToMojoRequest(std::move(request), *extension); 109 impl->BindToMojoRequest(std::move(request), *extension);
110 } 110 }
111 111
112 void MediaRouterMojoImpl::BindToMojoRequest( 112 void MediaRouterMojoImpl::BindToMojoRequest(
113 mojo::InterfaceRequest<interfaces::MediaRouter> request, 113 mojo::InterfaceRequest<mojom::MediaRouter> request,
114 const extensions::Extension& extension) { 114 const extensions::Extension& extension) {
115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
116 116
117 binding_.reset( 117 binding_.reset(
118 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request))); 118 new mojo::Binding<mojom::MediaRouter>(this, std::move(request)));
119 binding_->set_connection_error_handler(base::Bind( 119 binding_->set_connection_error_handler(base::Bind(
120 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); 120 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this)));
121 121
122 media_route_provider_extension_id_ = extension.id(); 122 media_route_provider_extension_id_ = extension.id();
123 if (!provider_version_was_recorded_) { 123 if (!provider_version_was_recorded_) {
124 MediaRouterMojoMetrics::RecordMediaRouteProviderVersion(extension); 124 MediaRouterMojoMetrics::RecordMediaRouteProviderVersion(extension);
125 provider_version_was_recorded_ = true; 125 provider_version_was_recorded_ = true;
126 } 126 }
127 } 127 }
128 128
129 void MediaRouterMojoImpl::OnConnectionError() { 129 void MediaRouterMojoImpl::OnConnectionError() {
130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
131 131
132 media_route_provider_.reset(); 132 media_route_provider_.reset();
133 binding_.reset(); 133 binding_.reset();
134 134
135 // If |OnConnectionError| is invoked while there are pending requests, then 135 // If |OnConnectionError| is invoked while there are pending requests, then
136 // it means we tried to wake the extension, but weren't able to complete the 136 // it means we tried to wake the extension, but weren't able to complete the
137 // connection to media route provider. Since we do not know whether the error 137 // connection to media route provider. Since we do not know whether the error
138 // is transient, reattempt the wakeup. 138 // is transient, reattempt the wakeup.
139 if (!pending_requests_.empty()) { 139 if (!pending_requests_.empty()) {
140 DLOG_WITH_INSTANCE(ERROR) << "A connection error while there are pending " 140 DLOG_WITH_INSTANCE(ERROR) << "A connection error while there are pending "
141 "requests."; 141 "requests.";
142 SetWakeReason(MediaRouteProviderWakeReason::CONNECTION_ERROR); 142 SetWakeReason(MediaRouteProviderWakeReason::CONNECTION_ERROR);
143 AttemptWakeEventPage(); 143 AttemptWakeEventPage();
144 } 144 }
145 } 145 }
146 146
147 void MediaRouterMojoImpl::RegisterMediaRouteProvider( 147 void MediaRouterMojoImpl::RegisterMediaRouteProvider(
148 interfaces::MediaRouteProviderPtr media_route_provider_ptr, 148 mojom::MediaRouteProviderPtr media_route_provider_ptr,
149 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& 149 const mojom::MediaRouter::RegisterMediaRouteProviderCallback&
150 callback) { 150 callback) {
151 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 151 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
152 #if defined(OS_WIN) 152 #if defined(OS_WIN)
153 // The MRPM may have been upgraded or otherwise reload such that we could be 153 // The MRPM may have been upgraded or otherwise reload such that we could be
154 // seeing an MRPM that doesn't know mDNS is enabled, even if we've told a 154 // seeing an MRPM that doesn't know mDNS is enabled, even if we've told a
155 // previously registered MRPM it should be enabled. Furthermore, there may be 155 // previously registered MRPM it should be enabled. Furthermore, there may be
156 // a pending request to enable mDNS, so don't clear this flag after 156 // a pending request to enable mDNS, so don't clear this flag after
157 // ExecutePendingRequests(). 157 // ExecutePendingRequests().
158 is_mdns_enabled_ = false; 158 is_mdns_enabled_ = false;
159 #endif 159 #endif
(...skipping 19 matching lines...) Expand all
179 // Windows. It only relies on this signalling from MR on Windows to avoid 179 // Windows. It only relies on this signalling from MR on Windows to avoid
180 // triggering a firewall prompt out of the context of MR from the user's 180 // triggering a firewall prompt out of the context of MR from the user's
181 // perspective. This particular call reminds the extension to enable mDNS 181 // perspective. This particular call reminds the extension to enable mDNS
182 // discovery when it wakes up, has been upgraded, etc. 182 // discovery when it wakes up, has been upgraded, etc.
183 if (should_enable_mdns_discovery_) { 183 if (should_enable_mdns_discovery_) {
184 DoEnsureMdnsDiscoveryEnabled(); 184 DoEnsureMdnsDiscoveryEnabled();
185 } 185 }
186 #endif 186 #endif
187 } 187 }
188 188
189 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { 189 void MediaRouterMojoImpl::OnIssue(const mojom::IssuePtr issue) {
190 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 190 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
191 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; 191 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title;
192 const Issue& issue_converted = issue.To<Issue>(); 192 const Issue& issue_converted = issue.To<Issue>();
193 issue_manager_.AddIssue(issue_converted); 193 issue_manager_.AddIssue(issue_converted);
194 } 194 }
195 195
196 void MediaRouterMojoImpl::OnSinksReceived( 196 void MediaRouterMojoImpl::OnSinksReceived(
197 const std::string& media_source, 197 const std::string& media_source,
198 std::vector<interfaces::MediaSinkPtr> sinks, 198 std::vector<mojom::MediaSinkPtr> sinks,
199 const std::vector<std::string>& origins) { 199 const std::vector<std::string>& origins) {
200 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 200 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
201 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived"; 201 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived";
202 auto it = sinks_queries_.find(media_source); 202 auto it = sinks_queries_.find(media_source);
203 if (it == sinks_queries_.end()) { 203 if (it == sinks_queries_.end()) {
204 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery."; 204 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery.";
205 return; 205 return;
206 } 206 }
207 207
208 std::vector<GURL> origin_list; 208 std::vector<GURL> origin_list;
(...skipping 22 matching lines...) Expand all
231 DVLOG_WITH_INSTANCE(1) 231 DVLOG_WITH_INSTANCE(1)
232 << "Received sink list without any active observers: " << media_source; 232 << "Received sink list without any active observers: " << media_source;
233 } else { 233 } else {
234 FOR_EACH_OBSERVER( 234 FOR_EACH_OBSERVER(
235 MediaSinksObserver, sinks_query->observers, 235 MediaSinksObserver, sinks_query->observers,
236 OnSinksUpdated(sinks_query->cached_sink_list, sinks_query->origins)); 236 OnSinksUpdated(sinks_query->cached_sink_list, sinks_query->origins));
237 } 237 }
238 } 238 }
239 239
240 void MediaRouterMojoImpl::OnRoutesUpdated( 240 void MediaRouterMojoImpl::OnRoutesUpdated(
241 std::vector<interfaces::MediaRoutePtr> routes, 241 std::vector<mojom::MediaRoutePtr> routes,
242 const std::string& media_source, 242 const std::string& media_source,
243 const std::vector<std::string>& joinable_route_ids) { 243 const std::vector<std::string>& joinable_route_ids) {
244 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 244 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
245 245
246 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; 246 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated";
247 auto it = routes_queries_.find(media_source); 247 auto it = routes_queries_.find(media_source);
248 if (it == routes_queries_.end() || 248 if (it == routes_queries_.end() ||
249 !(it->second->observers.might_have_observers())) { 249 !(it->second->observers.might_have_observers())) {
250 DVLOG_WITH_INSTANCE(1) 250 DVLOG_WITH_INSTANCE(1)
251 << "Received route list without any active observers: " << media_source; 251 << "Received route list without any active observers: " << media_source;
252 return; 252 return;
253 } 253 }
254 254
255 std::vector<MediaRoute> routes_converted; 255 std::vector<MediaRoute> routes_converted;
256 routes_converted.reserve(routes.size()); 256 routes_converted.reserve(routes.size());
257 for (size_t i = 0; i < routes.size(); ++i) 257 for (size_t i = 0; i < routes.size(); ++i)
258 routes_converted.push_back(routes[i].To<MediaRoute>()); 258 routes_converted.push_back(routes[i].To<MediaRoute>());
259 259
260 FOR_EACH_OBSERVER( 260 FOR_EACH_OBSERVER(
261 MediaRoutesObserver, it->second->observers, 261 MediaRoutesObserver, it->second->observers,
262 OnRoutesUpdated(routes_converted, joinable_route_ids)); 262 OnRoutesUpdated(routes_converted, joinable_route_ids));
263 } 263 }
264 264
265 void MediaRouterMojoImpl::RouteResponseReceived( 265 void MediaRouterMojoImpl::RouteResponseReceived(
266 const std::string& presentation_id, 266 const std::string& presentation_id,
267 bool incognito, 267 bool incognito,
268 const std::vector<MediaRouteResponseCallback>& callbacks, 268 const std::vector<MediaRouteResponseCallback>& callbacks,
269 interfaces::MediaRoutePtr media_route, 269 mojom::MediaRoutePtr media_route,
270 const base::Optional<std::string>& error_text, 270 const base::Optional<std::string>& error_text,
271 interfaces::RouteRequestResultCode result_code) { 271 mojom::RouteRequestResultCode result_code) {
272 std::unique_ptr<RouteRequestResult> result; 272 std::unique_ptr<RouteRequestResult> result;
273 if (media_route.is_null()) { 273 if (media_route.is_null()) {
274 // An error occurred. 274 // An error occurred.
275 const std::string& error = (error_text && !error_text->empty()) 275 const std::string& error = (error_text && !error_text->empty())
276 ? *error_text : std::string("Unknown error."); 276 ? *error_text : std::string("Unknown error.");
277 result = RouteRequestResult::FromError( 277 result = RouteRequestResult::FromError(
278 error, mojo::RouteRequestResultCodeFromMojo(result_code)); 278 error, mojo::RouteRequestResultCodeFromMojo(result_code));
279 } else if (media_route->incognito != incognito) { 279 } else if (media_route->incognito != incognito) {
280 std::string error = base::StringPrintf( 280 std::string error = base::StringPrintf(
281 "Mismatch in incognito status: request = %d, response = %d", incognito, 281 "Mismatch in incognito status: request = %d, response = %d", incognito,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 new_query = true; 468 new_query = true;
469 sinks_query = new MediaSinksQuery; 469 sinks_query = new MediaSinksQuery;
470 sinks_queries_.add(source_id, base::WrapUnique(sinks_query)); 470 sinks_queries_.add(source_id, base::WrapUnique(sinks_query));
471 } else { 471 } else {
472 DCHECK(!sinks_query->observers.HasObserver(observer)); 472 DCHECK(!sinks_query->observers.HasObserver(observer));
473 } 473 }
474 474
475 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. 475 // If sink availability is UNAVAILABLE, then there is no need to call MRPM.
476 // |observer| can be immediately notified with an empty list. 476 // |observer| can be immediately notified with an empty list.
477 sinks_query->observers.AddObserver(observer); 477 sinks_query->observers.AddObserver(observer);
478 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 478 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) {
479 observer->OnSinksUpdated(std::vector<MediaSink>(), std::vector<GURL>()); 479 observer->OnSinksUpdated(std::vector<MediaSink>(), std::vector<GURL>());
480 } else { 480 } else {
481 // Need to call MRPM to start observing sinks if the query is new. 481 // Need to call MRPM to start observing sinks if the query is new.
482 if (new_query) { 482 if (new_query) {
483 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); 483 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS);
484 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 484 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
485 base::Unretained(this), source_id)); 485 base::Unretained(this), source_id));
486 } else if (sinks_query->has_cached_result) { 486 } else if (sinks_query->has_cached_result) {
487 observer->OnSinksUpdated(sinks_query->cached_sink_list, 487 observer->OnSinksUpdated(sinks_query->cached_sink_list,
488 sinks_query->origins); 488 sinks_query->origins);
(...skipping 15 matching lines...) Expand all
504 // If we are removing the final observer for the source, then stop 504 // If we are removing the final observer for the source, then stop
505 // observing sinks for it. 505 // observing sinks for it.
506 // might_have_observers() is reliable here on the assumption that this call 506 // might_have_observers() is reliable here on the assumption that this call
507 // is not inside the ObserverList iteration. 507 // is not inside the ObserverList iteration.
508 sinks_query->observers.RemoveObserver(observer); 508 sinks_query->observers.RemoveObserver(observer);
509 if (!sinks_query->observers.might_have_observers()) { 509 if (!sinks_query->observers.might_have_observers()) {
510 // Only ask MRPM to stop observing media sinks if the availability is not 510 // Only ask MRPM to stop observing media sinks if the availability is not
511 // UNAVAILABLE. 511 // UNAVAILABLE.
512 // Otherwise, the MRPM would have discarded the queries already. 512 // Otherwise, the MRPM would have discarded the queries already.
513 if (availability_ != 513 if (availability_ !=
514 interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 514 mojom::MediaRouter::SinkAvailability::UNAVAILABLE) {
515 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS); 515 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS);
516 // The |sinks_queries_| entry will be removed in the immediate or deferred 516 // The |sinks_queries_| entry will be removed in the immediate or deferred
517 // |DoStopObservingMediaSinks| call. 517 // |DoStopObservingMediaSinks| call.
518 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaSinks, 518 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaSinks,
519 base::Unretained(this), source_id)); 519 base::Unretained(this), source_id));
520 } else { 520 } else {
521 sinks_queries_.erase(source_id); 521 sinks_queries_.erase(source_id);
522 } 522 }
523 } 523 }
524 } 524 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 media_route_provider_->StopListeningForRouteMessages(route_id); 716 media_route_provider_->StopListeningForRouteMessages(route_id);
717 } 717 }
718 718
719 void MediaRouterMojoImpl::DoSearchSinks( 719 void MediaRouterMojoImpl::DoSearchSinks(
720 const MediaSink::Id& sink_id, 720 const MediaSink::Id& sink_id,
721 const MediaSource::Id& source_id, 721 const MediaSource::Id& source_id,
722 const std::string& search_input, 722 const std::string& search_input,
723 const std::string& domain, 723 const std::string& domain,
724 const MediaSinkSearchResponseCallback& sink_callback) { 724 const MediaSinkSearchResponseCallback& sink_callback) {
725 DVLOG_WITH_INSTANCE(1) << "SearchSinks"; 725 DVLOG_WITH_INSTANCE(1) << "SearchSinks";
726 auto sink_search_criteria = interfaces::SinkSearchCriteria::New(); 726 auto sink_search_criteria = mojom::SinkSearchCriteria::New();
727 sink_search_criteria->input = search_input; 727 sink_search_criteria->input = search_input;
728 sink_search_criteria->domain = domain; 728 sink_search_criteria->domain = domain;
729 media_route_provider_->SearchSinks( 729 media_route_provider_->SearchSinks(
730 sink_id, source_id, std::move(sink_search_criteria), sink_callback); 730 sink_id, source_id, std::move(sink_search_criteria), sink_callback);
731 } 731 }
732 732
733 void MediaRouterMojoImpl::OnRouteMessagesReceived( 733 void MediaRouterMojoImpl::OnRouteMessagesReceived(
734 const std::string& route_id, 734 const std::string& route_id,
735 std::vector<interfaces::RouteMessagePtr> messages) { 735 std::vector<mojom::RouteMessagePtr> messages) {
736 DVLOG_WITH_INSTANCE(1) << "OnRouteMessagesReceived"; 736 DVLOG_WITH_INSTANCE(1) << "OnRouteMessagesReceived";
737 737
738 DCHECK(!messages.empty()); 738 DCHECK(!messages.empty());
739 739
740 auto* observer_list = messages_observers_.get(route_id); 740 auto* observer_list = messages_observers_.get(route_id);
741 if (!observer_list) { 741 if (!observer_list) {
742 return; 742 return;
743 } 743 }
744 744
745 ScopedVector<content::PresentationSessionMessage> session_messages; 745 ScopedVector<content::PresentationSessionMessage> session_messages;
746 session_messages.reserve(messages.size()); 746 session_messages.reserve(messages.size());
747 for (size_t i = 0; i < messages.size(); ++i) { 747 for (size_t i = 0; i < messages.size(); ++i) {
748 session_messages.push_back( 748 session_messages.push_back(
749 ConvertToPresentationSessionMessage(std::move(messages[i]))); 749 ConvertToPresentationSessionMessage(std::move(messages[i])));
750 } 750 }
751 base::ObserverList<PresentationSessionMessagesObserver>::Iterator observer_it( 751 base::ObserverList<PresentationSessionMessagesObserver>::Iterator observer_it(
752 observer_list); 752 observer_list);
753 bool single_observer = 753 bool single_observer =
754 observer_it.GetNext() != nullptr && observer_it.GetNext() == nullptr; 754 observer_it.GetNext() != nullptr && observer_it.GetNext() == nullptr;
755 FOR_EACH_OBSERVER(PresentationSessionMessagesObserver, *observer_list, 755 FOR_EACH_OBSERVER(PresentationSessionMessagesObserver, *observer_list,
756 OnMessagesReceived(session_messages, single_observer)); 756 OnMessagesReceived(session_messages, single_observer));
757 } 757 }
758 758
759 void MediaRouterMojoImpl::OnSinkAvailabilityUpdated( 759 void MediaRouterMojoImpl::OnSinkAvailabilityUpdated(
760 SinkAvailability availability) { 760 SinkAvailability availability) {
761 if (availability_ == availability) 761 if (availability_ == availability)
762 return; 762 return;
763 763
764 availability_ = availability; 764 availability_ = availability;
765 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 765 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) {
766 // Sinks are no longer available. MRPM has already removed all sink queries. 766 // Sinks are no longer available. MRPM has already removed all sink queries.
767 for (auto& source_and_query : sinks_queries_) { 767 for (auto& source_and_query : sinks_queries_) {
768 auto* query = source_and_query.second; 768 auto* query = source_and_query.second;
769 query->is_active = false; 769 query->is_active = false;
770 query->has_cached_result = false; 770 query->has_cached_result = false;
771 query->cached_sink_list.clear(); 771 query->cached_sink_list.clear();
772 query->origins.clear(); 772 query->origins.clear();
773 } 773 }
774 } else { 774 } else {
775 // Sinks are now available. Tell MRPM to start all sink queries again. 775 // Sinks are now available. Tell MRPM to start all sink queries again.
776 for (const auto& source_and_query : sinks_queries_) { 776 for (const auto& source_and_query : sinks_queries_) {
777 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 777 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
778 base::Unretained(this), source_and_query.first)); 778 base::Unretained(this), source_and_query.first));
779 } 779 }
780 } 780 }
781 } 781 }
782 782
783 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( 783 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged(
784 const std::string& route_id, 784 const std::string& route_id,
785 interfaces::MediaRouter::PresentationConnectionState state) { 785 mojom::MediaRouter::PresentationConnectionState state) {
786 NotifyPresentationConnectionStateChange( 786 NotifyPresentationConnectionStateChange(
787 route_id, mojo::PresentationConnectionStateFromMojo(state)); 787 route_id, mojo::PresentationConnectionStateFromMojo(state));
788 } 788 }
789 789
790 void MediaRouterMojoImpl::OnPresentationConnectionClosed( 790 void MediaRouterMojoImpl::OnPresentationConnectionClosed(
791 const std::string& route_id, 791 const std::string& route_id,
792 interfaces::MediaRouter::PresentationConnectionCloseReason reason, 792 mojom::MediaRouter::PresentationConnectionCloseReason reason,
793 const std::string& message) { 793 const std::string& message) {
794 NotifyPresentationConnectionClose( 794 NotifyPresentationConnectionClose(
795 route_id, mojo::PresentationConnectionCloseReasonFromMojo(reason), 795 route_id, mojo::PresentationConnectionCloseReasonFromMojo(reason),
796 message); 796 message);
797 } 797 }
798 798
799 void MediaRouterMojoImpl::OnTerminateRouteResult( 799 void MediaRouterMojoImpl::OnTerminateRouteResult(
800 const MediaRoute::Id& route_id, 800 const MediaRoute::Id& route_id,
801 const base::Optional<std::string>& error_text, 801 const base::Optional<std::string>& error_text,
802 interfaces::RouteRequestResultCode result_code) { 802 mojom::RouteRequestResultCode result_code) {
803 if (result_code != interfaces::RouteRequestResultCode::OK) { 803 if (result_code != mojom::RouteRequestResultCode::OK) {
804 LOG(WARNING) << "Failed to terminate route " << route_id 804 LOG(WARNING) << "Failed to terminate route " << route_id
805 << ": result_code = " << result_code << ", " 805 << ": result_code = " << result_code << ", "
806 << error_text.value_or(std::string()); 806 << error_text.value_or(std::string());
807 } 807 }
808 MediaRouterMojoMetrics::RecordMediaRouteProviderTerminateRoute( 808 MediaRouterMojoMetrics::RecordMediaRouteProviderTerminateRoute(
809 mojo::RouteRequestResultCodeFromMojo(result_code)); 809 mojo::RouteRequestResultCodeFromMojo(result_code));
810 } 810 }
811 811
812 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 812 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
813 const MediaSource::Id& source_id) { 813 const MediaSource::Id& source_id) {
814 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; 814 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
815 // No need to call MRPM if there are no sinks available. 815 // No need to call MRPM if there are no sinks available.
816 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) 816 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE)
817 return; 817 return;
818 818
819 // No need to call MRPM if all observers have been removed in the meantime. 819 // No need to call MRPM if all observers have been removed in the meantime.
820 auto* sinks_query = sinks_queries_.get(source_id); 820 auto* sinks_query = sinks_queries_.get(source_id);
821 if (!sinks_query || !sinks_query->observers.might_have_observers()) 821 if (!sinks_query || !sinks_query->observers.might_have_observers())
822 return; 822 return;
823 823
824 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; 824 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id;
825 media_route_provider_->StartObservingMediaSinks(source_id); 825 media_route_provider_->StartObservingMediaSinks(source_id);
826 sinks_query->is_active = true; 826 sinks_query->is_active = true;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 base::Unretained(this), source_id)); 1014 base::Unretained(this), source_id));
1015 } 1015 }
1016 1016
1017 void MediaRouterMojoImpl::DoUpdateMediaSinks( 1017 void MediaRouterMojoImpl::DoUpdateMediaSinks(
1018 const MediaSource::Id& source_id) { 1018 const MediaSource::Id& source_id) {
1019 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; 1019 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id;
1020 media_route_provider_->UpdateMediaSinks(source_id); 1020 media_route_provider_->UpdateMediaSinks(source_id);
1021 } 1021 }
1022 1022
1023 } // namespace media_router 1023 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698