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

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

Issue 1911183002: [Media Router] Implement an internal Media Routes observer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 error, mojo::RouteRequestResultCodeFromMojo(result_code)); 283 error, mojo::RouteRequestResultCodeFromMojo(result_code));
284 } else if (media_route->off_the_record != off_the_record) { 284 } else if (media_route->off_the_record != off_the_record) {
285 std::string error = base::StringPrintf( 285 std::string error = base::StringPrintf(
286 "Mismatch in off the record status: request = %d, response = %d", 286 "Mismatch in off the record status: request = %d, response = %d",
287 off_the_record, media_route->off_the_record); 287 off_the_record, media_route->off_the_record);
288 result = RouteRequestResult::FromError( 288 result = RouteRequestResult::FromError(
289 error, RouteRequestResult::OFF_THE_RECORD_MISMATCH); 289 error, RouteRequestResult::OFF_THE_RECORD_MISMATCH);
290 } else { 290 } else {
291 result = RouteRequestResult::FromSuccess( 291 result = RouteRequestResult::FromSuccess(
292 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id); 292 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id);
293 if (result->route()->off_the_record())
294 OnOffTheRecordRouteCreated(result->route()->media_route_id());
295 } 293 }
296 294
297 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044). 295 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044).
298 for (const MediaRouteResponseCallback& callback : callbacks) 296 for (const MediaRouteResponseCallback& callback : callbacks)
299 callback.Run(*result); 297 callback.Run(*result);
300 } 298 }
301 299
302 void MediaRouterMojoImpl::CreateRoute( 300 void MediaRouterMojoImpl::CreateRoute(
303 const MediaSource::Id& source_id, 301 const MediaSource::Id& source_id,
304 const MediaSink::Id& sink_id, 302 const MediaSink::Id& sink_id,
(...skipping 24 matching lines...) Expand all
329 void MediaRouterMojoImpl::JoinRoute( 327 void MediaRouterMojoImpl::JoinRoute(
330 const MediaSource::Id& source_id, 328 const MediaSource::Id& source_id,
331 const std::string& presentation_id, 329 const std::string& presentation_id,
332 const GURL& origin, 330 const GURL& origin,
333 content::WebContents* web_contents, 331 content::WebContents* web_contents,
334 const std::vector<MediaRouteResponseCallback>& callbacks, 332 const std::vector<MediaRouteResponseCallback>& callbacks,
335 base::TimeDelta timeout, 333 base::TimeDelta timeout,
336 bool off_the_record) { 334 bool off_the_record) {
337 DCHECK(thread_checker_.CalledOnValidThread()); 335 DCHECK(thread_checker_.CalledOnValidThread());
338 336
337 std::unique_ptr<RouteRequestResult> error_result;
339 if (!origin.is_valid()) { 338 if (!origin.is_valid()) {
340 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; 339 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin;
341 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( 340 error_result = RouteRequestResult::FromError(
342 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); 341 "Invalid origin", RouteRequestResult::INVALID_ORIGIN);
342 }
343
344 if (!HasLocalRoute()) {
345 error_result = RouteRequestResult::FromError(
346 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND);
347 }
348
349 if (error_result) {
343 for (const MediaRouteResponseCallback& callback : callbacks) 350 for (const MediaRouteResponseCallback& callback : callbacks)
344 callback.Run(*result); 351 callback.Run(*error_result);
345 return; 352 return;
346 } 353 }
347 354
348 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); 355 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE);
349 int tab_id = SessionTabHelper::IdForTab(web_contents); 356 int tab_id = SessionTabHelper::IdForTab(web_contents);
350 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, 357 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute,
351 base::Unretained(this), source_id, presentation_id, 358 base::Unretained(this), source_id, presentation_id,
352 origin.is_empty() ? "" : origin.spec(), tab_id, 359 origin.is_empty() ? "" : origin.spec(), tab_id,
353 callbacks, timeout, off_the_record)); 360 callbacks, timeout, off_the_record));
354 } 361 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 source_id, route_id, presentation_id, origin, tab_id, 659 source_id, route_id, presentation_id, origin, tab_id,
653 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, 660 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0,
654 off_the_record, base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, 661 off_the_record, base::Bind(&MediaRouterMojoImpl::RouteResponseReceived,
655 base::Unretained(this), presentation_id, 662 base::Unretained(this), presentation_id,
656 off_the_record, callbacks)); 663 off_the_record, callbacks));
657 } 664 }
658 665
659 void MediaRouterMojoImpl::DoTerminateRoute(const MediaRoute::Id& route_id) { 666 void MediaRouterMojoImpl::DoTerminateRoute(const MediaRoute::Id& route_id) {
660 DVLOG_WITH_INSTANCE(1) << "DoTerminateRoute " << route_id; 667 DVLOG_WITH_INSTANCE(1) << "DoTerminateRoute " << route_id;
661 media_route_provider_->TerminateRoute(route_id); 668 media_route_provider_->TerminateRoute(route_id);
662 OnRouteTerminated(route_id);
663 } 669 }
664 670
665 void MediaRouterMojoImpl::DoDetachRoute(const MediaRoute::Id& route_id) { 671 void MediaRouterMojoImpl::DoDetachRoute(const MediaRoute::Id& route_id) {
666 DVLOG_WITH_INSTANCE(1) << "DoDetachRoute " << route_id; 672 DVLOG_WITH_INSTANCE(1) << "DoDetachRoute " << route_id;
667 media_route_provider_->DetachRoute(route_id); 673 media_route_provider_->DetachRoute(route_id);
668 } 674 }
669 675
670 void MediaRouterMojoImpl::DoSendSessionMessage( 676 void MediaRouterMojoImpl::DoSendSessionMessage(
671 const MediaRoute::Id& route_id, 677 const MediaRoute::Id& route_id,
672 const std::string& message, 678 const std::string& message,
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 base::Unretained(this), source_id)); 1004 base::Unretained(this), source_id));
999 } 1005 }
1000 1006
1001 void MediaRouterMojoImpl::DoUpdateMediaSinks( 1007 void MediaRouterMojoImpl::DoUpdateMediaSinks(
1002 const MediaSource::Id& source_id) { 1008 const MediaSource::Id& source_id) {
1003 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; 1009 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id;
1004 media_route_provider_->UpdateMediaSinks(source_id); 1010 media_route_provider_->UpdateMediaSinks(source_id);
1005 } 1011 }
1006 1012
1007 } // namespace media_router 1013 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698