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/ui/webui/media_router/media_router_ui.h" | 5 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/media/router/create_presentation_session_request.h" | 10 #include "chrome/browser/media/router/create_presentation_session_request.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (ui_initialized_) | 278 if (ui_initialized_) |
279 handler_->UpdateIssue(issue); | 279 handler_->UpdateIssue(issue); |
280 } | 280 } |
281 | 281 |
282 void MediaRouterUI::OnRoutesUpdated(const std::vector<MediaRoute>& routes) { | 282 void MediaRouterUI::OnRoutesUpdated(const std::vector<MediaRoute>& routes) { |
283 routes_ = routes; | 283 routes_ = routes; |
284 if (ui_initialized_) | 284 if (ui_initialized_) |
285 handler_->UpdateRoutes(routes_); | 285 handler_->UpdateRoutes(routes_); |
286 } | 286 } |
287 | 287 |
288 void MediaRouterUI::OnRouteResponseReceived(const MediaRoute* route, | 288 void MediaRouterUI::OnRouteResponseReceived(const MediaSink::Id& sink_id, |
| 289 const MediaRoute* route, |
289 const std::string& presentation_id, | 290 const std::string& presentation_id, |
290 const std::string& error) { | 291 const std::string& error) { |
291 DVLOG(1) << "OnRouteResponseReceived"; | 292 DVLOG(1) << "OnRouteResponseReceived"; |
292 // TODO(imcheng): Display error in UI. (crbug.com/490372) | 293 // TODO(imcheng): Display error in UI. (crbug.com/490372) |
293 if (!route) | 294 if (!route) |
294 LOG(ERROR) << "MediaRouteResponse returned error: " << error; | 295 DVLOG(0) << "MediaRouteResponse returned error: " << error; |
295 else | |
296 handler_->AddRoute(*route); | |
297 | 296 |
| 297 handler_->OnCreateRouteResponseReceived(sink_id, route); |
298 has_pending_route_request_ = false; | 298 has_pending_route_request_ = false; |
299 requesting_route_for_default_source_ = false; | 299 requesting_route_for_default_source_ = false; |
300 } | 300 } |
301 | 301 |
302 bool MediaRouterUI::DoCreateRoute(const MediaSink::Id& sink_id, | 302 bool MediaRouterUI::DoCreateRoute(const MediaSink::Id& sink_id, |
303 MediaCastMode cast_mode) { | 303 MediaCastMode cast_mode) { |
304 DCHECK(query_result_manager_.get()); | 304 DCHECK(query_result_manager_.get()); |
305 DCHECK(initiator_); | 305 DCHECK(initiator_); |
306 | 306 |
307 // Note that there is a rarely-encountered bug, where the MediaCastMode to | 307 // Note that there is a rarely-encountered bug, where the MediaCastMode to |
(...skipping 27 matching lines...) Expand all Loading... |
335 // notification necessary. | 335 // notification necessary. |
336 // (2) Presentation route request for a Presentation API startSession call. | 336 // (2) Presentation route request for a Presentation API startSession call. |
337 // The startSession (CreatePresentationSessionRequest) will need to be | 337 // The startSession (CreatePresentationSessionRequest) will need to be |
338 // answered with the | 338 // answered with the |
339 // route response. | 339 // route response. |
340 // (3) Browser-initiated presentation route request. If successful, | 340 // (3) Browser-initiated presentation route request. If successful, |
341 // PresentationServiceDelegateImpl will have to be notified. Note that we | 341 // PresentationServiceDelegateImpl will have to be notified. Note that we |
342 // treat subsequent route requests from a Presentation API-initiated dialogs | 342 // treat subsequent route requests from a Presentation API-initiated dialogs |
343 // as browser-initiated. | 343 // as browser-initiated. |
344 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 344 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
345 route_response_callbacks.push_back(base::Bind( | 345 route_response_callbacks.push_back( |
346 &MediaRouterUI::OnRouteResponseReceived, weak_factory_.GetWeakPtr())); | 346 base::Bind(&MediaRouterUI::OnRouteResponseReceived, |
| 347 weak_factory_.GetWeakPtr(), sink_id)); |
347 if (requesting_route_for_default_source_) { | 348 if (requesting_route_for_default_source_) { |
348 if (presentation_request_) { | 349 if (presentation_request_) { |
349 // |presentation_request_| will be nullptr after this call, as the | 350 // |presentation_request_| will be nullptr after this call, as the |
350 // object will be transferred to the callback. | 351 // object will be transferred to the callback. |
351 route_response_callbacks.push_back( | 352 route_response_callbacks.push_back( |
352 base::Bind(&HandleRouteResponseForPresentationApi, | 353 base::Bind(&HandleRouteResponseForPresentationApi, |
353 base::Passed(&presentation_request_))); | 354 base::Passed(&presentation_request_))); |
354 } else if (presentation_service_delegate_) { | 355 } else if (presentation_service_delegate_) { |
355 route_response_callbacks.push_back( | 356 route_response_callbacks.push_back( |
356 base::Bind(&PresentationServiceDelegateImpl::OnRouteResponse, | 357 base::Bind(&PresentationServiceDelegateImpl::OnRouteResponse, |
357 presentation_service_delegate_)); | 358 presentation_service_delegate_)); |
358 } | 359 } |
359 } | 360 } |
360 | 361 |
361 router_->CreateRoute(source.id(), sink_id, origin, | 362 router_->CreateRoute(source.id(), sink_id, origin, |
362 SessionTabHelper::IdForTab(initiator_), | 363 SessionTabHelper::IdForTab(initiator_), |
363 route_response_callbacks); | 364 route_response_callbacks); |
364 return true; | 365 return true; |
365 } | 366 } |
366 | 367 |
367 std::string MediaRouterUI::GetFrameURLHost() const { | 368 std::string MediaRouterUI::GetFrameURLHost() const { |
368 return GetHostFromURL(frame_url_); | 369 return GetHostFromURL(frame_url_); |
369 } | 370 } |
370 | 371 |
371 const std::string& MediaRouterUI::GetRouteProviderExtensionId() const { | 372 const std::string& MediaRouterUI::GetRouteProviderExtensionId() const { |
372 return router_->media_route_provider_extension_id(); | 373 return router_->media_route_provider_extension_id(); |
373 } | 374 } |
374 | 375 |
375 } // namespace media_router | 376 } // namespace media_router |
OLD | NEW |