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

Unified Diff: chrome/browser/media/router/mojo/media_router_mojo_impl.cc

Issue 2837363002: [Media Router] Use DialMediaSinkService in MediaRouterMojoImpl (Closed)
Patch Set: resolve code review comments from Kevin Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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..70e7ca629167493e72c018705dac25a853d5834d 100644
--- a/chrome/browser/media/router/mojo/media_router_mojo_impl.cc
+++ b/chrome/browser/media/router/mojo/media_router_mojo_impl.cc
@@ -15,8 +15,10 @@
#include "base/observer_list.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
+#include "chrome/browser/media/router/discovery/dial/dial_media_sink_service.h"
#include "chrome/browser/media/router/issues_observer.h"
#include "chrome/browser/media/router/media_router_factory.h"
+#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/media/router/media_routes_observer.h"
#include "chrome/browser/media/router/media_sinks_observer.h"
#include "chrome/browser/media/router/mojo/media_route_controller.h"
@@ -58,11 +60,13 @@ MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default;
MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default;
MediaRouterMojoImpl::MediaRouterMojoImpl(
- extensions::EventPageTracker* event_page_tracker)
+ extensions::EventPageTracker* event_page_tracker,
+ content::BrowserContext* context)
: event_page_tracker_(event_page_tracker),
instance_id_(base::GenerateGUID()),
availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE),
current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT),
+ context_(context),
weak_factory_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(event_page_tracker_);
@@ -151,7 +155,11 @@ void MediaRouterMojoImpl::RegisterMediaRouteProvider(
media_route_provider_ = std::move(media_route_provider_ptr);
media_route_provider_.set_connection_error_handler(base::Bind(
&MediaRouterMojoImpl::OnConnectionError, base::Unretained(this)));
- callback.Run(instance_id_);
+
+ auto config = mojom::MediaRouteProviderConfig::New();
+ config->enable_dial_discovery = !media_router::DialLocalDiscoveryEnabled();
+ config->enable_cast_discovery = !media_router::CastDiscoveryEnabled();
+ callback.Run(instance_id_, std::move(config));
ExecutePendingRequests();
wakeup_attempt_count_ = 0;
#if defined(OS_WIN)
@@ -164,6 +172,9 @@ void MediaRouterMojoImpl::RegisterMediaRouteProvider(
DoEnsureMdnsDiscoveryEnabled();
}
#endif
+
+ if (media_router::DialLocalDiscoveryEnabled())
+ StartDiscovery();
}
void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) {
@@ -430,6 +441,8 @@ void MediaRouterMojoImpl::ProvideSinks(
const std::string& provider_name,
const std::vector<MediaSinkInternal>& sinks) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size()
+ << " devices...";
SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS);
RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks,
@@ -1037,6 +1050,24 @@ void MediaRouterMojoImpl::OnFirewallCheckComplete(
}
#endif
+void MediaRouterMojoImpl::StartDiscovery() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DVLOG_WITH_INSTANCE(1) << "StartDiscovery";
+
+ if (dial_media_sink_service_)
+ return;
+
+ auto* profile = Profile::FromBrowserContext(context_);
+ if (!profile)
+ return;
+
+ dial_media_sink_service_ =
+ new DialMediaSinkService(base::Bind(&MediaRouterMojoImpl::ProvideSinks,
+ base::Unretained(this), "dial"),
+ profile->GetRequestContext());
+ dial_media_sink_service_->Start();
+}
+
void MediaRouterMojoImpl::UpdateMediaSinks(
const MediaSource::Id& source_id) {
SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS);

Powered by Google App Engine
This is Rietveld 408576698