Chromium Code Reviews| Index: chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
| diff --git a/chrome/browser/media/router/mojo/media_router_mojo_impl.cc b/chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
| index 48b99eb88f9c02d0cdf89716adb6692cf2aa53d6..9ab36a3e688a980b368d18f0a4cc1b395559f6c9 100644 |
| --- a/chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
| +++ b/chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
| @@ -153,17 +153,9 @@ void MediaRouterMojoImpl::RegisterMediaRouteProvider( |
| &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| callback.Run(instance_id_); |
| ExecutePendingRequests(); |
| + EnsureMediaRouteProviderStateSynced(); |
| + |
| wakeup_attempt_count_ = 0; |
| -#if defined(OS_WIN) |
| - // The MRPM extension already turns on mDNS discovery for platforms other than |
| - // Windows. It only relies on this signalling from MR on Windows to avoid |
| - // triggering a firewall prompt out of the context of MR from the user's |
| - // perspective. This particular call reminds the extension to enable mDNS |
| - // discovery when it wakes up, has been upgraded, etc. |
| - if (should_enable_mdns_discovery_) { |
| - DoEnsureMdnsDiscoveryEnabled(); |
| - } |
| -#endif |
| } |
| void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { |
| @@ -846,13 +838,14 @@ void MediaRouterMojoImpl::DoStartObservingMediaSinks( |
| return; |
| // No need to call MRPM if all observers have been removed in the meantime. |
| - auto* sinks_query = sinks_queries_[source_id].get(); |
| - if (!sinks_query || !sinks_query->observers.might_have_observers()) |
| + auto it = sinks_queries_.find(source_id); |
| + if (it == sinks_queries_.end() || |
| + !it->second->observers.might_have_observers()) |
| return; |
| DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; |
| media_route_provider_->StartObservingMediaSinks(source_id); |
| - sinks_query->is_active = true; |
| + it->second->is_active = true; |
| } |
| void MediaRouterMojoImpl::DoStopObservingMediaSinks( |
| @@ -884,7 +877,6 @@ void MediaRouterMojoImpl::DoStartObservingMediaRoutes( |
| DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaRoutes: " << source_id; |
| media_route_provider_->StartObservingMediaRoutes(source_id); |
| - it->second->is_active = true; |
| } |
| void MediaRouterMojoImpl::DoStopObservingMediaRoutes( |
| @@ -894,7 +886,7 @@ void MediaRouterMojoImpl::DoStopObservingMediaRoutes( |
| // No need to call MRPM if observers have been added in the meantime, |
| // or StopObservingMediaRoutes has already been called. |
| auto it = routes_queries_.find(source_id); |
| - if (it == routes_queries_.end() || !it->second->is_active || |
| + if (it == routes_queries_.end() || |
| it->second->observers.might_have_observers()) { |
| return; |
| } |
| @@ -974,6 +966,38 @@ void MediaRouterMojoImpl::ExecutePendingRequests() { |
| pending_requests_.clear(); |
| } |
| +void MediaRouterMojoImpl::EnsureMediaRouteProviderStateSynced() { |
| + DCHECK(media_route_provider_); |
| + |
| + // Sink queries. |
| + if (availability_ != mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { |
| + for (const auto& it : sinks_queries_) { |
| + DoStartObservingMediaSinks(it.first); |
| + } |
| + } |
| + |
| + // Route queries. |
| + for (const auto& it : routes_queries_) { |
| + DoStartObservingMediaRoutes(it.first); |
| + } |
| + |
| + // Route messages. |
| + for (const auto& it : message_observers_) { |
| + DoStartListeningForRouteMessages(it.first); |
| + } |
| + |
| +#if defined(OS_WIN) |
| + // The MRPM extension already turns on mDNS discovery for platforms other than |
| + // Windows. It only relies on this signalling from MR on Windows to avoid |
| + // triggering a firewall prompt out of the context of MR from the user's |
| + // perspective. This particular call reminds the extension to enable mDNS |
| + // discovery when it wakes up, has been upgraded, etc. |
| + if (should_enable_mdns_discovery_) { |
| + DoEnsureMdnsDiscoveryEnabled(); |
|
mark a. foltz
2017/05/03 17:37:08
Would prefer DoEnableMdnsDiscovery(), but not nece
imcheng
2017/05/03 18:22:41
Acknowledged.
|
| + } |
| +#endif |
| +} |
| + |
| void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { |
| if (success) { |
| MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( |