Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "chrome/browser/media/router/issues_observer.h" | 18 #include "chrome/browser/media/router/issues_observer.h" |
| 19 #include "chrome/browser/media/router/media_router_factory.h" | 19 #include "chrome/browser/media/router/media_router_factory.h" |
| 20 #include "chrome/browser/media/router/media_routes_observer.h" | 20 #include "chrome/browser/media/router/media_routes_observer.h" |
| 21 #include "chrome/browser/media/router/media_sinks_observer.h" | 21 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 22 #include "chrome/browser/media/router/media_source_helper.h" | 22 #include "chrome/browser/media/router/media_source_helper.h" |
| 23 #include "chrome/browser/media/router/mojo/media_route_controller.h" | |
| 23 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" | 24 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" |
| 24 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 25 #include "chrome/browser/media/router/route_message.h" | 26 #include "chrome/browser/media/router/route_message.h" |
| 26 #include "chrome/browser/media/router/route_message_observer.h" | 27 #include "chrome/browser/media/router/route_message_observer.h" |
| 27 #include "chrome/browser/sessions/session_tab_helper.h" | 28 #include "chrome/browser/sessions/session_tab_helper.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "extensions/browser/process_manager.h" | 30 #include "extensions/browser/process_manager.h" |
| 30 | 31 |
| 31 #define DVLOG_WITH_INSTANCE(level) \ | 32 #define DVLOG_WITH_INSTANCE(level) \ |
| 32 DVLOG(level) << "MR #" << instance_id_ << ": " | 33 DVLOG(level) << "MR #" << instance_id_ << ": " |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 routes_query->joinable_route_ids = joinable_route_ids; | 224 routes_query->joinable_route_ids = joinable_route_ids; |
| 224 | 225 |
| 225 if (routes_query->observers.might_have_observers()) { | 226 if (routes_query->observers.might_have_observers()) { |
| 226 for (auto& observer : routes_query->observers) | 227 for (auto& observer : routes_query->observers) |
| 227 observer.OnRoutesUpdated(routes, joinable_route_ids); | 228 observer.OnRoutesUpdated(routes, joinable_route_ids); |
| 228 } else { | 229 } else { |
| 229 DVLOG_WITH_INSTANCE(1) | 230 DVLOG_WITH_INSTANCE(1) |
| 230 << "Received routes update without any active observers: " | 231 << "Received routes update without any active observers: " |
| 231 << media_source; | 232 << media_source; |
| 232 } | 233 } |
| 234 RemoveInvalidRouteControllers(routes); | |
| 233 } | 235 } |
| 234 | 236 |
| 235 void MediaRouterMojoImpl::RouteResponseReceived( | 237 void MediaRouterMojoImpl::RouteResponseReceived( |
| 236 const std::string& presentation_id, | 238 const std::string& presentation_id, |
| 237 bool is_incognito, | 239 bool is_incognito, |
| 238 const std::vector<MediaRouteResponseCallback>& callbacks, | 240 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 239 bool is_join, | 241 bool is_join, |
| 240 const base::Optional<MediaRoute>& media_route, | 242 const base::Optional<MediaRoute>& media_route, |
| 241 const base::Optional<std::string>& error_text, | 243 const base::Optional<std::string>& error_text, |
| 242 RouteRequestResult::ResultCode result_code) { | 244 RouteRequestResult::ResultCode result_code) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 270 const MediaSink::Id& sink_id, | 272 const MediaSink::Id& sink_id, |
| 271 const url::Origin& origin, | 273 const url::Origin& origin, |
| 272 content::WebContents* web_contents, | 274 content::WebContents* web_contents, |
| 273 const std::vector<MediaRouteResponseCallback>& callbacks, | 275 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 274 base::TimeDelta timeout, | 276 base::TimeDelta timeout, |
| 275 bool incognito) { | 277 bool incognito) { |
| 276 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 278 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 277 | 279 |
| 278 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); | 280 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); |
| 279 int tab_id = SessionTabHelper::IdForTab(web_contents); | 281 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 280 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, | 282 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoCreateRoute, |
| 281 base::Unretained(this), source_id, sink_id, origin, | 283 base::Unretained(this), source_id, sink_id, origin, |
| 282 tab_id, callbacks, timeout, incognito)); | 284 tab_id, callbacks, timeout, incognito)); |
| 283 } | 285 } |
| 284 | 286 |
| 285 void MediaRouterMojoImpl::JoinRoute( | 287 void MediaRouterMojoImpl::JoinRoute( |
| 286 const MediaSource::Id& source_id, | 288 const MediaSource::Id& source_id, |
| 287 const std::string& presentation_id, | 289 const std::string& presentation_id, |
| 288 const url::Origin& origin, | 290 const url::Origin& origin, |
| 289 content::WebContents* web_contents, | 291 content::WebContents* web_contents, |
| 290 const std::vector<MediaRouteResponseCallback>& callbacks, | 292 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 291 base::TimeDelta timeout, | 293 base::TimeDelta timeout, |
| 292 bool incognito) { | 294 bool incognito) { |
| 293 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 295 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 294 | 296 |
| 295 if (!HasJoinableRoute()) { | 297 if (!HasJoinableRoute()) { |
| 296 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; | 298 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; |
| 297 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | 299 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( |
| 298 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); | 300 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); |
| 299 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); | 301 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); |
| 300 RunRouteRequestCallbacks(std::move(result), callbacks); | 302 RunRouteRequestCallbacks(std::move(result), callbacks); |
| 301 return; | 303 return; |
| 302 } | 304 } |
| 303 | 305 |
| 304 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); | 306 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); |
| 305 int tab_id = SessionTabHelper::IdForTab(web_contents); | 307 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 306 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, | 308 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoJoinRoute, |
| 307 base::Unretained(this), source_id, presentation_id, | 309 base::Unretained(this), source_id, presentation_id, |
| 308 origin, tab_id, callbacks, timeout, incognito)); | 310 origin, tab_id, callbacks, timeout, incognito)); |
| 309 } | 311 } |
| 310 | 312 |
| 311 void MediaRouterMojoImpl::ConnectRouteByRouteId( | 313 void MediaRouterMojoImpl::ConnectRouteByRouteId( |
| 312 const MediaSource::Id& source_id, | 314 const MediaSource::Id& source_id, |
| 313 const MediaRoute::Id& route_id, | 315 const MediaRoute::Id& route_id, |
| 314 const url::Origin& origin, | 316 const url::Origin& origin, |
| 315 content::WebContents* web_contents, | 317 content::WebContents* web_contents, |
| 316 const std::vector<MediaRouteResponseCallback>& callbacks, | 318 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 317 base::TimeDelta timeout, | 319 base::TimeDelta timeout, |
| 318 bool incognito) { | 320 bool incognito) { |
| 319 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 321 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 320 | 322 |
| 321 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); | 323 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); |
| 322 int tab_id = SessionTabHelper::IdForTab(web_contents); | 324 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 323 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoConnectRouteByRouteId, | 325 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoConnectRouteByRouteId, |
| 324 base::Unretained(this), source_id, route_id, origin, | 326 base::Unretained(this), source_id, route_id, origin, |
| 325 tab_id, callbacks, timeout, incognito)); | 327 tab_id, callbacks, timeout, incognito)); |
| 326 } | 328 } |
| 327 | 329 |
| 328 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { | 330 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { |
| 329 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 331 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 330 DVLOG(2) << "TerminateRoute " << route_id; | 332 DVLOG(2) << "TerminateRoute " << route_id; |
| 331 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); | 333 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); |
| 332 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoTerminateRoute, | 334 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoTerminateRoute, |
| 333 base::Unretained(this), route_id)); | 335 base::Unretained(this), route_id)); |
| 334 } | 336 } |
| 335 | 337 |
| 336 void MediaRouterMojoImpl::DetachRoute(const MediaRoute::Id& route_id) { | 338 void MediaRouterMojoImpl::DetachRoute(const MediaRoute::Id& route_id) { |
| 337 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 339 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 338 | 340 |
| 339 SetWakeReason(MediaRouteProviderWakeReason::DETACH_ROUTE); | 341 SetWakeReason(MediaRouteProviderWakeReason::DETACH_ROUTE); |
| 340 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoDetachRoute, | 342 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoDetachRoute, |
| 341 base::Unretained(this), route_id)); | 343 base::Unretained(this), route_id)); |
| 342 } | 344 } |
| 343 | 345 |
| 344 void MediaRouterMojoImpl::SendRouteMessage( | 346 void MediaRouterMojoImpl::SendRouteMessage( |
| 345 const MediaRoute::Id& route_id, | 347 const MediaRoute::Id& route_id, |
| 346 const std::string& message, | 348 const std::string& message, |
| 347 const SendRouteMessageCallback& callback) { | 349 const SendRouteMessageCallback& callback) { |
| 348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 349 | 351 |
| 350 SetWakeReason(MediaRouteProviderWakeReason::SEND_SESSION_MESSAGE); | 352 SetWakeReason(MediaRouteProviderWakeReason::SEND_SESSION_MESSAGE); |
| 351 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoSendSessionMessage, | 353 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoSendSessionMessage, |
| 352 base::Unretained(this), route_id, message, callback)); | 354 base::Unretained(this), route_id, message, |
| 355 callback)); | |
| 353 } | 356 } |
| 354 | 357 |
| 355 void MediaRouterMojoImpl::SendRouteBinaryMessage( | 358 void MediaRouterMojoImpl::SendRouteBinaryMessage( |
| 356 const MediaRoute::Id& route_id, | 359 const MediaRoute::Id& route_id, |
| 357 std::unique_ptr<std::vector<uint8_t>> data, | 360 std::unique_ptr<std::vector<uint8_t>> data, |
| 358 const SendRouteMessageCallback& callback) { | 361 const SendRouteMessageCallback& callback) { |
| 359 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 362 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 360 | 363 |
| 361 SetWakeReason(MediaRouteProviderWakeReason::SEND_SESSION_BINARY_MESSAGE); | 364 SetWakeReason(MediaRouteProviderWakeReason::SEND_SESSION_BINARY_MESSAGE); |
| 362 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoSendSessionBinaryMessage, | 365 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoSendSessionBinaryMessage, |
| 363 base::Unretained(this), route_id, | 366 base::Unretained(this), route_id, |
| 364 base::Passed(std::move(data)), callback)); | 367 base::Passed(std::move(data)), callback)); |
| 365 } | 368 } |
| 366 | 369 |
| 367 void MediaRouterMojoImpl::AddIssue(const IssueInfo& issue_info) { | 370 void MediaRouterMojoImpl::AddIssue(const IssueInfo& issue_info) { |
| 368 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 371 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 369 issue_manager_.AddIssue(issue_info); | 372 issue_manager_.AddIssue(issue_info); |
| 370 } | 373 } |
| 371 | 374 |
| 372 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { | 375 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { |
| 373 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 376 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 374 issue_manager_.ClearIssue(issue_id); | 377 issue_manager_.ClearIssue(issue_id); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 386 | 389 |
| 387 void MediaRouterMojoImpl::SearchSinks( | 390 void MediaRouterMojoImpl::SearchSinks( |
| 388 const MediaSink::Id& sink_id, | 391 const MediaSink::Id& sink_id, |
| 389 const MediaSource::Id& source_id, | 392 const MediaSource::Id& source_id, |
| 390 const std::string& search_input, | 393 const std::string& search_input, |
| 391 const std::string& domain, | 394 const std::string& domain, |
| 392 const MediaSinkSearchResponseCallback& sink_callback) { | 395 const MediaSinkSearchResponseCallback& sink_callback) { |
| 393 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 394 | 397 |
| 395 SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); | 398 SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); |
| 396 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoSearchSinks, | 399 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoSearchSinks, |
| 397 base::Unretained(this), sink_id, source_id, | 400 base::Unretained(this), sink_id, source_id, |
| 398 search_input, domain, sink_callback)); | 401 search_input, domain, sink_callback)); |
| 402 } | |
| 403 | |
| 404 scoped_refptr<MediaRouteController> MediaRouterMojoImpl::GetRouteController( | |
| 405 const MediaRoute::Id& route_id) { | |
| 406 if (!IsRouteValid(route_id)) | |
| 407 return nullptr; | |
| 408 | |
| 409 auto it = route_controllers_.find(route_id); | |
| 410 if (it != route_controllers_.end()) | |
| 411 return scoped_refptr<MediaRouteController>(it->second); | |
| 412 | |
| 413 mojom::MediaControllerPtr mojo_media_controller; | |
| 414 mojom::MediaControllerRequest mojo_media_controller_request = | |
| 415 mojo::MakeRequest(&mojo_media_controller); | |
| 416 scoped_refptr<MediaRouteController> route_controller = | |
| 417 new MediaRouteController(route_id, std::move(mojo_media_controller), | |
| 418 this); | |
| 419 | |
| 420 RunOrDefer( | |
|
imcheng
2017/04/06 21:14:05
Please add a SetWakeReason() call here for UMA pur
takumif
2017/04/07 21:07:56
Done.
| |
| 421 base::BindOnce(&MediaRouterMojoImpl::DoCreateMediaRouteController, | |
|
imcheng
2017/04/06 21:14:05
Is there a reason why we still need separate metho
takumif
2017/04/07 21:07:55
None of the other Do.. methods call multiple MRP m
| |
| 422 base::Unretained(this), route_id, | |
| 423 std::move(mojo_media_controller_request), | |
| 424 base::Bind(&MediaRouterMojoImpl::OnMediaControllerCreated, | |
|
imcheng
2017/04/06 21:14:05
You don't have to Bind OnMediaControllerCreated be
takumif
2017/04/07 21:07:55
Done.
| |
| 425 base::Unretained(this), route_id))); | |
| 426 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoSetMediaRouteStatusObserver, | |
| 427 base::Unretained(this), route_id, | |
| 428 route_controller->BindObserverPtr())); | |
| 429 route_controllers_.insert({route_id, route_controller.get()}); | |
| 430 return route_controller; | |
| 399 } | 431 } |
| 400 | 432 |
| 401 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 433 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 402 MediaSinksObserver* observer) { | 434 MediaSinksObserver* observer) { |
| 403 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 435 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 404 | 436 |
| 405 // Create an observer list for the media source and add |observer| | 437 // Create an observer list for the media source and add |observer| |
| 406 // to it. Fail if |observer| is already registered. | 438 // to it. Fail if |observer| is already registered. |
| 407 const std::string& source_id = observer->source().id(); | 439 const std::string& source_id = observer->source().id(); |
| 408 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; | 440 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; |
| 409 bool is_new_query = false; | 441 bool is_new_query = false; |
| 410 if (!sinks_query) { | 442 if (!sinks_query) { |
| 411 is_new_query = true; | 443 is_new_query = true; |
| 412 sinks_query = base::MakeUnique<MediaSinksQuery>(); | 444 sinks_query = base::MakeUnique<MediaSinksQuery>(); |
| 413 } else { | 445 } else { |
| 414 DCHECK(!sinks_query->observers.HasObserver(observer)); | 446 DCHECK(!sinks_query->observers.HasObserver(observer)); |
| 415 } | 447 } |
| 416 | 448 |
| 417 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. | 449 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. |
| 418 // |observer| can be immediately notified with an empty list. | 450 // |observer| can be immediately notified with an empty list. |
| 419 sinks_query->observers.AddObserver(observer); | 451 sinks_query->observers.AddObserver(observer); |
| 420 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { | 452 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { |
| 421 observer->OnSinksUpdated(std::vector<MediaSink>(), | 453 observer->OnSinksUpdated(std::vector<MediaSink>(), |
| 422 std::vector<url::Origin>()); | 454 std::vector<url::Origin>()); |
| 423 } else { | 455 } else { |
| 424 // Need to call MRPM to start observing sinks if the query is new. | 456 // Need to call MRPM to start observing sinks if the query is new. |
| 425 if (is_new_query) { | 457 if (is_new_query) { |
| 426 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); | 458 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); |
| 427 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, | 459 RunOrDefer( |
| 428 base::Unretained(this), source_id)); | 460 base::BindOnce(&MediaRouterMojoImpl::DoStartObservingMediaSinks, |
| 461 base::Unretained(this), source_id)); | |
| 429 } else if (sinks_query->cached_sink_list) { | 462 } else if (sinks_query->cached_sink_list) { |
| 430 observer->OnSinksUpdated(*sinks_query->cached_sink_list, | 463 observer->OnSinksUpdated(*sinks_query->cached_sink_list, |
| 431 sinks_query->origins); | 464 sinks_query->origins); |
| 432 } | 465 } |
| 433 } | 466 } |
| 434 return true; | 467 return true; |
| 435 } | 468 } |
| 436 | 469 |
| 437 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( | 470 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( |
| 438 MediaSinksObserver* observer) { | 471 MediaSinksObserver* observer) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 452 it->second->observers.RemoveObserver(observer); | 485 it->second->observers.RemoveObserver(observer); |
| 453 if (!it->second->observers.might_have_observers()) { | 486 if (!it->second->observers.might_have_observers()) { |
| 454 // Only ask MRPM to stop observing media sinks if the availability is not | 487 // Only ask MRPM to stop observing media sinks if the availability is not |
| 455 // UNAVAILABLE. | 488 // UNAVAILABLE. |
| 456 // Otherwise, the MRPM would have discarded the queries already. | 489 // Otherwise, the MRPM would have discarded the queries already. |
| 457 if (availability_ != | 490 if (availability_ != |
| 458 mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { | 491 mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { |
| 459 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS); | 492 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS); |
| 460 // The |sinks_queries_| entry will be removed in the immediate or deferred | 493 // The |sinks_queries_| entry will be removed in the immediate or deferred |
| 461 // |DoStopObservingMediaSinks| call. | 494 // |DoStopObservingMediaSinks| call. |
| 462 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaSinks, | 495 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoStopObservingMediaSinks, |
| 463 base::Unretained(this), source_id)); | 496 base::Unretained(this), source_id)); |
| 464 } else { | 497 } else { |
| 465 sinks_queries_.erase(source_id); | 498 sinks_queries_.erase(source_id); |
| 466 } | 499 } |
| 467 } | 500 } |
| 468 } | 501 } |
| 469 | 502 |
| 470 void MediaRouterMojoImpl::RegisterMediaRoutesObserver( | 503 void MediaRouterMojoImpl::RegisterMediaRoutesObserver( |
| 471 MediaRoutesObserver* observer) { | 504 MediaRoutesObserver* observer) { |
| 472 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 505 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 473 const MediaSource::Id source_id = observer->source_id(); | 506 const MediaSource::Id source_id = observer->source_id(); |
| 474 auto& routes_query = routes_queries_[source_id]; | 507 auto& routes_query = routes_queries_[source_id]; |
| 475 bool is_new_query = false; | 508 bool is_new_query = false; |
| 476 if (!routes_query) { | 509 if (!routes_query) { |
| 477 is_new_query = true; | 510 is_new_query = true; |
| 478 routes_query = base::MakeUnique<MediaRoutesQuery>(); | 511 routes_query = base::MakeUnique<MediaRoutesQuery>(); |
| 479 } else { | 512 } else { |
| 480 DCHECK(!routes_query->observers.HasObserver(observer)); | 513 DCHECK(!routes_query->observers.HasObserver(observer)); |
| 481 } | 514 } |
| 482 | 515 |
| 483 routes_query->observers.AddObserver(observer); | 516 routes_query->observers.AddObserver(observer); |
| 484 if (is_new_query) { | 517 if (is_new_query) { |
| 485 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_ROUTES); | 518 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_ROUTES); |
| 486 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaRoutes, | 519 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoStartObservingMediaRoutes, |
| 487 base::Unretained(this), source_id)); | 520 base::Unretained(this), source_id)); |
| 488 // The MRPM will call MediaRouterMojoImpl::OnRoutesUpdated() soon, if there | 521 // The MRPM will call MediaRouterMojoImpl::OnRoutesUpdated() soon, if there |
| 489 // are any existing routes the new observer should be aware of. | 522 // are any existing routes the new observer should be aware of. |
| 490 } else if (routes_query->cached_route_list) { | 523 } else if (routes_query->cached_route_list) { |
| 491 // Return to the event loop before notifying of a cached route list because | 524 // Return to the event loop before notifying of a cached route list because |
| 492 // MediaRoutesObserver is calling this method from its constructor, and that | 525 // MediaRoutesObserver is calling this method from its constructor, and that |
| 493 // must complete before invoking its virtual OnRoutesUpdated() method. | 526 // must complete before invoking its virtual OnRoutesUpdated() method. |
| 494 content::BrowserThread::PostTask( | 527 content::BrowserThread::PostTask( |
| 495 content::BrowserThread::UI, FROM_HERE, | 528 content::BrowserThread::UI, FROM_HERE, |
| 496 base::Bind(&MediaRouterMojoImpl::NotifyOfExistingRoutesIfRegistered, | 529 base::Bind(&MediaRouterMojoImpl::NotifyOfExistingRoutesIfRegistered, |
| 497 weak_factory_.GetWeakPtr(), source_id, observer)); | 530 weak_factory_.GetWeakPtr(), source_id, observer)); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 525 return; | 558 return; |
| 526 } | 559 } |
| 527 | 560 |
| 528 // If we are removing the final observer for the source, then stop | 561 // If we are removing the final observer for the source, then stop |
| 529 // observing routes for it. | 562 // observing routes for it. |
| 530 // might_have_observers() is reliable here on the assumption that this call | 563 // might_have_observers() is reliable here on the assumption that this call |
| 531 // is not inside the ObserverList iteration. | 564 // is not inside the ObserverList iteration. |
| 532 it->second->observers.RemoveObserver(observer); | 565 it->second->observers.RemoveObserver(observer); |
| 533 if (!it->second->observers.might_have_observers()) { | 566 if (!it->second->observers.might_have_observers()) { |
| 534 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_ROUTES); | 567 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_ROUTES); |
| 535 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaRoutes, | 568 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoStopObservingMediaRoutes, |
| 536 base::Unretained(this), source_id)); | 569 base::Unretained(this), source_id)); |
| 537 } | 570 } |
| 538 } | 571 } |
| 539 | 572 |
| 540 void MediaRouterMojoImpl::RegisterIssuesObserver(IssuesObserver* observer) { | 573 void MediaRouterMojoImpl::RegisterIssuesObserver(IssuesObserver* observer) { |
| 541 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 574 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 542 issue_manager_.RegisterObserver(observer); | 575 issue_manager_.RegisterObserver(observer); |
| 543 } | 576 } |
| 544 | 577 |
| 545 void MediaRouterMojoImpl::UnregisterIssuesObserver(IssuesObserver* observer) { | 578 void MediaRouterMojoImpl::UnregisterIssuesObserver(IssuesObserver* observer) { |
| 546 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 579 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 const MediaRoute::Id& route_id = observer->route_id(); | 612 const MediaRoute::Id& route_id = observer->route_id(); |
| 580 auto it = message_observers_.find(route_id); | 613 auto it = message_observers_.find(route_id); |
| 581 if (it == message_observers_.end() || !it->second->HasObserver(observer)) | 614 if (it == message_observers_.end() || !it->second->HasObserver(observer)) |
| 582 return; | 615 return; |
| 583 | 616 |
| 584 it->second->RemoveObserver(observer); | 617 it->second->RemoveObserver(observer); |
| 585 if (!it->second->might_have_observers()) { | 618 if (!it->second->might_have_observers()) { |
| 586 message_observers_.erase(route_id); | 619 message_observers_.erase(route_id); |
| 587 SetWakeReason( | 620 SetWakeReason( |
| 588 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); | 621 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); |
| 589 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, | 622 RunOrDefer( |
| 590 base::Unretained(this), route_id)); | 623 base::BindOnce(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, |
| 624 base::Unretained(this), route_id)); | |
| 591 } | 625 } |
| 592 } | 626 } |
| 593 | 627 |
| 628 void MediaRouterMojoImpl::DetachRouteController( | |
| 629 const MediaRoute::Id& route_id, | |
| 630 MediaRouteController* controller) { | |
| 631 auto it = route_controllers_.find(route_id); | |
| 632 if (it != route_controllers_.end() && it->second == controller) | |
| 633 route_controllers_.erase(it); | |
| 634 } | |
| 635 | |
| 594 void MediaRouterMojoImpl::DoCreateRoute( | 636 void MediaRouterMojoImpl::DoCreateRoute( |
| 595 const MediaSource::Id& source_id, | 637 const MediaSource::Id& source_id, |
| 596 const MediaSink::Id& sink_id, | 638 const MediaSink::Id& sink_id, |
| 597 const url::Origin& origin, | 639 const url::Origin& origin, |
| 598 int tab_id, | 640 int tab_id, |
| 599 const std::vector<MediaRouteResponseCallback>& callbacks, | 641 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 600 base::TimeDelta timeout, | 642 base::TimeDelta timeout, |
| 601 bool incognito) { | 643 bool incognito) { |
| 602 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 644 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 603 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id | 645 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 const std::string& domain, | 737 const std::string& domain, |
| 696 const MediaSinkSearchResponseCallback& sink_callback) { | 738 const MediaSinkSearchResponseCallback& sink_callback) { |
| 697 DVLOG_WITH_INSTANCE(1) << "SearchSinks"; | 739 DVLOG_WITH_INSTANCE(1) << "SearchSinks"; |
| 698 auto sink_search_criteria = mojom::SinkSearchCriteria::New(); | 740 auto sink_search_criteria = mojom::SinkSearchCriteria::New(); |
| 699 sink_search_criteria->input = search_input; | 741 sink_search_criteria->input = search_input; |
| 700 sink_search_criteria->domain = domain; | 742 sink_search_criteria->domain = domain; |
| 701 media_route_provider_->SearchSinks( | 743 media_route_provider_->SearchSinks( |
| 702 sink_id, source_id, std::move(sink_search_criteria), sink_callback); | 744 sink_id, source_id, std::move(sink_search_criteria), sink_callback); |
| 703 } | 745 } |
| 704 | 746 |
| 747 void MediaRouterMojoImpl::DoCreateMediaRouteController( | |
| 748 const MediaRoute::Id& route_id, | |
| 749 mojom::MediaControllerRequest mojo_media_controller_request, | |
| 750 base::Callback<void(bool)> callback) { | |
| 751 DVLOG_WITH_INSTANCE(1) << "DoCreateMediaRouteController"; | |
| 752 media_route_provider_->CreateMediaRouteController( | |
| 753 route_id, std::move(mojo_media_controller_request), callback); | |
| 754 } | |
| 755 | |
| 756 void MediaRouterMojoImpl::DoSetMediaRouteStatusObserver( | |
| 757 const MediaRoute::Id& route_id, | |
| 758 mojom::MediaStatusObserverPtr mojo_observer) { | |
| 759 DVLOG_WITH_INSTANCE(1) << "DoSetMediaRouteStatusObserver"; | |
| 760 media_route_provider_->SetMediaRouteStatusObserver(route_id, | |
| 761 std::move(mojo_observer)); | |
| 762 } | |
| 763 | |
| 705 void MediaRouterMojoImpl::OnRouteMessagesReceived( | 764 void MediaRouterMojoImpl::OnRouteMessagesReceived( |
| 706 const std::string& route_id, | 765 const std::string& route_id, |
| 707 const std::vector<RouteMessage>& messages) { | 766 const std::vector<RouteMessage>& messages) { |
| 708 DVLOG_WITH_INSTANCE(1) << "OnRouteMessagesReceived"; | 767 DVLOG_WITH_INSTANCE(1) << "OnRouteMessagesReceived"; |
| 709 | 768 |
| 710 if (messages.empty()) | 769 if (messages.empty()) |
| 711 return; | 770 return; |
| 712 | 771 |
| 713 auto it = message_observers_.find(route_id); | 772 auto it = message_observers_.find(route_id); |
| 714 if (it == message_observers_.end()) { | 773 if (it == message_observers_.end()) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 729 // Sinks are no longer available. MRPM has already removed all sink queries. | 788 // Sinks are no longer available. MRPM has already removed all sink queries. |
| 730 for (auto& source_and_query : sinks_queries_) { | 789 for (auto& source_and_query : sinks_queries_) { |
| 731 const auto& query = source_and_query.second; | 790 const auto& query = source_and_query.second; |
| 732 query->is_active = false; | 791 query->is_active = false; |
| 733 query->cached_sink_list = base::nullopt; | 792 query->cached_sink_list = base::nullopt; |
| 734 query->origins.clear(); | 793 query->origins.clear(); |
| 735 } | 794 } |
| 736 } else { | 795 } else { |
| 737 // Sinks are now available. Tell MRPM to start all sink queries again. | 796 // Sinks are now available. Tell MRPM to start all sink queries again. |
| 738 for (const auto& source_and_query : sinks_queries_) { | 797 for (const auto& source_and_query : sinks_queries_) { |
| 739 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, | 798 RunOrDefer( |
| 740 base::Unretained(this), source_and_query.first)); | 799 base::BindOnce(&MediaRouterMojoImpl::DoStartObservingMediaSinks, |
| 800 base::Unretained(this), source_and_query.first)); | |
| 741 } | 801 } |
| 742 } | 802 } |
| 743 } | 803 } |
| 744 | 804 |
| 745 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( | 805 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( |
| 746 const std::string& route_id, | 806 const std::string& route_id, |
| 747 content::PresentationConnectionState state) { | 807 content::PresentationConnectionState state) { |
| 748 NotifyPresentationConnectionStateChange(route_id, state); | 808 NotifyPresentationConnectionStateChange(route_id, state); |
| 749 } | 809 } |
| 750 | 810 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 826 if (it == routes_queries_.end() || !it->second->is_active || | 886 if (it == routes_queries_.end() || !it->second->is_active || |
| 827 it->second->observers.might_have_observers()) { | 887 it->second->observers.might_have_observers()) { |
| 828 return; | 888 return; |
| 829 } | 889 } |
| 830 | 890 |
| 831 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id; | 891 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id; |
| 832 media_route_provider_->StopObservingMediaRoutes(source_id); | 892 media_route_provider_->StopObservingMediaRoutes(source_id); |
| 833 routes_queries_.erase(source_id); | 893 routes_queries_.erase(source_id); |
| 834 } | 894 } |
| 835 | 895 |
| 836 void MediaRouterMojoImpl::EnqueueTask(const base::Closure& closure) { | 896 void MediaRouterMojoImpl::EnqueueTask(base::OnceClosure closure) { |
| 837 pending_requests_.push_back(closure); | 897 pending_requests_.push_back(std::move(closure)); |
| 838 if (pending_requests_.size() > kMaxPendingRequests) { | 898 if (pending_requests_.size() > kMaxPendingRequests) { |
| 839 DLOG_WITH_INSTANCE(ERROR) << "Reached max queue size. Dropping oldest " | 899 DLOG_WITH_INSTANCE(ERROR) << "Reached max queue size. Dropping oldest " |
| 840 << "request."; | 900 << "request."; |
| 841 pending_requests_.pop_front(); | 901 pending_requests_.pop_front(); |
| 842 } | 902 } |
| 843 DVLOG_WITH_INSTANCE(2) << "EnqueueTask (queue-length=" | 903 DVLOG_WITH_INSTANCE(2) << "EnqueueTask (queue-length=" |
| 844 << pending_requests_.size() << ")"; | 904 << pending_requests_.size() << ")"; |
| 845 } | 905 } |
| 846 | 906 |
| 847 void MediaRouterMojoImpl::RunOrDefer(const base::Closure& request) { | 907 void MediaRouterMojoImpl::RunOrDefer(base::OnceClosure request) { |
| 848 DCHECK(event_page_tracker_); | 908 DCHECK(event_page_tracker_); |
| 849 | 909 |
| 850 if (media_route_provider_extension_id_.empty()) { | 910 if (media_route_provider_extension_id_.empty()) { |
| 851 DVLOG_WITH_INSTANCE(1) << "Extension ID not known yet."; | 911 DVLOG_WITH_INSTANCE(1) << "Extension ID not known yet."; |
| 852 EnqueueTask(request); | 912 EnqueueTask(std::move(request)); |
| 853 } else if (event_page_tracker_->IsEventPageSuspended( | 913 } else if (event_page_tracker_->IsEventPageSuspended( |
| 854 media_route_provider_extension_id_)) { | 914 media_route_provider_extension_id_)) { |
| 855 DVLOG_WITH_INSTANCE(1) << "Waking event page."; | 915 DVLOG_WITH_INSTANCE(1) << "Waking event page."; |
| 856 EnqueueTask(request); | 916 EnqueueTask(std::move(request)); |
| 857 AttemptWakeEventPage(); | 917 AttemptWakeEventPage(); |
| 858 media_route_provider_.reset(); | 918 media_route_provider_.reset(); |
| 859 } else if (!media_route_provider_) { | 919 } else if (!media_route_provider_) { |
| 860 DVLOG_WITH_INSTANCE(1) << "Extension is awake, awaiting ProvideMediaRouter " | 920 DVLOG_WITH_INSTANCE(1) << "Extension is awake, awaiting ProvideMediaRouter " |
| 861 " to be called."; | 921 " to be called."; |
| 862 EnqueueTask(request); | 922 EnqueueTask(std::move(request)); |
| 863 } else { | 923 } else { |
| 864 request.Run(); | 924 std::move(request).Run(); |
| 865 } | 925 } |
| 866 } | 926 } |
| 867 | 927 |
| 868 void MediaRouterMojoImpl::AttemptWakeEventPage() { | 928 void MediaRouterMojoImpl::AttemptWakeEventPage() { |
| 869 ++wakeup_attempt_count_; | 929 ++wakeup_attempt_count_; |
| 870 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { | 930 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { |
| 871 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event " | 931 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event " |
| 872 << "page."; | 932 << "page."; |
| 873 DrainPendingRequests(); | 933 DrainPendingRequests(); |
| 874 wakeup_attempt_count_ = 0; | 934 wakeup_attempt_count_ = 0; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 890 DLOG_WITH_INSTANCE(ERROR) << "Failed to schedule a wakeup for event page."; | 950 DLOG_WITH_INSTANCE(ERROR) << "Failed to schedule a wakeup for event page."; |
| 891 } | 951 } |
| 892 } | 952 } |
| 893 | 953 |
| 894 void MediaRouterMojoImpl::ExecutePendingRequests() { | 954 void MediaRouterMojoImpl::ExecutePendingRequests() { |
| 895 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 955 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 896 DCHECK(media_route_provider_); | 956 DCHECK(media_route_provider_); |
| 897 DCHECK(event_page_tracker_); | 957 DCHECK(event_page_tracker_); |
| 898 DCHECK(!media_route_provider_extension_id_.empty()); | 958 DCHECK(!media_route_provider_extension_id_.empty()); |
| 899 | 959 |
| 900 for (const auto& next_request : pending_requests_) | 960 for (auto& next_request : pending_requests_) |
| 901 next_request.Run(); | 961 std::move(next_request).Run(); |
| 902 | 962 |
| 903 pending_requests_.clear(); | 963 pending_requests_.clear(); |
| 904 } | 964 } |
| 905 | 965 |
| 906 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { | 966 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { |
| 907 if (success) { | 967 if (success) { |
| 908 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( | 968 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( |
| 909 current_wake_reason_); | 969 current_wake_reason_); |
| 910 ClearWakeReason(); | 970 ClearWakeReason(); |
| 911 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( | 971 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 939 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); | 999 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 940 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; | 1000 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; |
| 941 } | 1001 } |
| 942 | 1002 |
| 943 #if defined(OS_WIN) | 1003 #if defined(OS_WIN) |
| 944 void MediaRouterMojoImpl::EnsureMdnsDiscoveryEnabled() { | 1004 void MediaRouterMojoImpl::EnsureMdnsDiscoveryEnabled() { |
| 945 if (is_mdns_enabled_) | 1005 if (is_mdns_enabled_) |
| 946 return; | 1006 return; |
| 947 | 1007 |
| 948 SetWakeReason(MediaRouteProviderWakeReason::ENABLE_MDNS_DISCOVERY); | 1008 SetWakeReason(MediaRouteProviderWakeReason::ENABLE_MDNS_DISCOVERY); |
| 949 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled, | 1009 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled, |
| 950 base::Unretained(this))); | 1010 base::Unretained(this))); |
| 951 should_enable_mdns_discovery_ = true; | 1011 should_enable_mdns_discovery_ = true; |
| 952 } | 1012 } |
| 953 | 1013 |
| 954 void MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled() { | 1014 void MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled() { |
| 955 DVLOG_WITH_INSTANCE(1) << "DoEnsureMdnsDiscoveryEnabled"; | 1015 DVLOG_WITH_INSTANCE(1) << "DoEnsureMdnsDiscoveryEnabled"; |
| 956 if (!is_mdns_enabled_) { | 1016 if (!is_mdns_enabled_) { |
| 957 media_route_provider_->EnableMdnsDiscovery(); | 1017 media_route_provider_->EnableMdnsDiscovery(); |
| 958 is_mdns_enabled_ = true; | 1018 is_mdns_enabled_ = true; |
| 959 } | 1019 } |
| 960 } | 1020 } |
| 961 | 1021 |
| 962 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1022 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 963 bool firewall_can_use_local_ports) { | 1023 bool firewall_can_use_local_ports) { |
| 964 if (firewall_can_use_local_ports) | 1024 if (firewall_can_use_local_ports) |
| 965 EnsureMdnsDiscoveryEnabled(); | 1025 EnsureMdnsDiscoveryEnabled(); |
| 966 } | 1026 } |
| 967 #endif | 1027 #endif |
| 968 | 1028 |
| 969 void MediaRouterMojoImpl::UpdateMediaSinks( | 1029 void MediaRouterMojoImpl::UpdateMediaSinks( |
| 970 const MediaSource::Id& source_id) { | 1030 const MediaSource::Id& source_id) { |
| 971 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); | 1031 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); |
| 972 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1032 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 973 base::Unretained(this), source_id)); | 1033 base::Unretained(this), source_id)); |
| 974 } | 1034 } |
| 975 | 1035 |
| 976 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1036 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 977 const MediaSource::Id& source_id) { | 1037 const MediaSource::Id& source_id) { |
| 978 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; | 1038 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; |
| 979 media_route_provider_->UpdateMediaSinks(source_id); | 1039 media_route_provider_->UpdateMediaSinks(source_id); |
| 980 } | 1040 } |
| 981 | 1041 |
| 1042 void MediaRouterMojoImpl::RemoveInvalidRouteControllers( | |
| 1043 const std::vector<MediaRoute>& routes) { | |
| 1044 auto it = route_controllers_.begin(); | |
| 1045 while (it != route_controllers_.end()) { | |
| 1046 if (IsRouteValid(it->first)) { | |
| 1047 ++it; | |
| 1048 } else { | |
| 1049 it->second->Invalidate(); | |
| 1050 it = route_controllers_.erase(it); | |
| 1051 } | |
| 1052 } | |
| 1053 } | |
| 1054 | |
| 1055 void MediaRouterMojoImpl::OnMediaControllerCreated( | |
| 1056 const MediaRoute::Id& route_id, | |
| 1057 bool success) { | |
| 1058 if (success) | |
| 1059 return; | |
| 1060 | |
|
imcheng
2017/04/06 21:14:05
Could you add a DVLOG_WITH_INSTANCE here for dev p
takumif
2017/04/07 21:07:55
Done.
| |
| 1061 auto it = route_controllers_.find(route_id); | |
| 1062 if (it != route_controllers_.end()) { | |
| 1063 it->second->Invalidate(); | |
| 1064 it = route_controllers_.erase(it); | |
|
imcheng
2017/04/06 21:14:05
No need to assign |it| with returned value.
takumif
2017/04/07 21:07:55
Oops, done.
| |
| 1065 } | |
| 1066 } | |
| 1067 | |
| 982 } // namespace media_router | 1068 } // namespace media_router |
| OLD | NEW |