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