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/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" |
| 11 #include "chrome/browser/media/router/issue.h" | 11 #include "chrome/browser/media/router/issue.h" |
| 12 #include "chrome/browser/media/router/issues_observer.h" | 12 #include "chrome/browser/media/router/issues_observer.h" |
| 13 #include "chrome/browser/media/router/media_route.h" | 13 #include "chrome/browser/media/router/media_route.h" |
| 14 #include "chrome/browser/media/router/media_router.h" | 14 #include "chrome/browser/media/router/media_router.h" |
| 15 #include "chrome/browser/media/router/media_router_factory.h" | 15 #include "chrome/browser/media/router/media_router_factory.h" |
| 16 #include "chrome/browser/media/router/media_router_mojo_impl.h" | 16 #include "chrome/browser/media/router/media_router_mojo_impl.h" |
| 17 #include "chrome/browser/media/router/media_routes_observer.h" | 17 #include "chrome/browser/media/router/media_routes_observer.h" |
| 18 #include "chrome/browser/media/router/media_sink.h" | 18 #include "chrome/browser/media/router/media_sink.h" |
| 19 #include "chrome/browser/media/router/media_sinks_observer.h" | 19 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 20 #include "chrome/browser/media/router/media_source.h" | 20 #include "chrome/browser/media/router/media_source.h" |
| 21 #include "chrome/browser/media/router/media_source_helper.h" | 21 #include "chrome/browser/media/router/media_source_helper.h" |
| 22 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" | 22 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 24 #include "chrome/browser/sessions/session_tab_helper.h" |
| 25 #include "chrome/browser/ui/webui/media_router/media_router_localized_strings_pr ovider.h" | 25 #include "chrome/browser/ui/webui/media_router/media_router_localized_strings_pr ovider.h" |
| 26 #include "chrome/browser/ui/webui/media_router/media_router_resources_provider.h " | 26 #include "chrome/browser/ui/webui/media_router/media_router_resources_provider.h " |
| 27 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle r.h" | 27 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle r.h" |
| 28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "chrome/grit/generated_resources.h" | |
| 29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/browser/web_ui.h" | 31 #include "content/public/browser/web_ui.h" |
| 31 #include "content/public/browser/web_ui_data_source.h" | 32 #include "content/public/browser/web_ui_data_source.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | |
| 32 #include "ui/web_dialogs/web_dialog_delegate.h" | 34 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 33 | 35 |
| 34 namespace media_router { | 36 namespace media_router { |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 40 // The amount of time to wait for a response when creating a new route. | |
| 41 static const int kCreateRouteTimeoutSeconds = 20; | |
|
imcheng
2015/09/22 21:45:12
no need to be static since it's already in anonymo
apacible
2015/09/22 22:37:18
Done.
| |
| 42 | |
| 38 std::string GetHostFromURL(const GURL& gurl) { | 43 std::string GetHostFromURL(const GURL& gurl) { |
| 39 if (gurl.is_empty()) | 44 if (gurl.is_empty()) |
| 40 return std::string(); | 45 return std::string(); |
| 41 std::string host = gurl.host(); | 46 std::string host = gurl.host(); |
| 42 if (base::StartsWith(host, "www.", base::CompareCase::INSENSITIVE_ASCII)) | 47 if (base::StartsWith(host, "www.", base::CompareCase::INSENSITIVE_ASCII)) |
| 43 host = host.substr(4); | 48 host = host.substr(4); |
| 44 return host; | 49 return host; |
| 45 } | 50 } |
| 46 | 51 |
| 47 } // namespace | 52 } // namespace |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 const std::string& error) { | 300 const std::string& error) { |
| 296 DVLOG(1) << "OnRouteResponseReceived"; | 301 DVLOG(1) << "OnRouteResponseReceived"; |
| 297 if (!route) { | 302 if (!route) { |
| 298 // The provider will handle sending an issue for a failed route request. | 303 // The provider will handle sending an issue for a failed route request. |
| 299 DVLOG(0) << "MediaRouteResponse returned error: " << error; | 304 DVLOG(0) << "MediaRouteResponse returned error: " << error; |
| 300 } | 305 } |
| 301 | 306 |
| 302 handler_->OnCreateRouteResponseReceived(sink_id, route); | 307 handler_->OnCreateRouteResponseReceived(sink_id, route); |
| 303 has_pending_route_request_ = false; | 308 has_pending_route_request_ = false; |
| 304 requesting_route_for_default_source_ = false; | 309 requesting_route_for_default_source_ = false; |
| 310 route_creation_timer_.Stop(); | |
| 305 } | 311 } |
| 306 | 312 |
| 307 bool MediaRouterUI::DoCreateRoute(const MediaSink::Id& sink_id, | 313 bool MediaRouterUI::DoCreateRoute(const MediaSink::Id& sink_id, |
| 308 MediaCastMode cast_mode) { | 314 MediaCastMode cast_mode) { |
| 309 DCHECK(query_result_manager_.get()); | 315 DCHECK(query_result_manager_.get()); |
| 310 DCHECK(initiator_); | 316 DCHECK(initiator_); |
| 311 | 317 |
| 312 // Note that there is a rarely-encountered bug, where the MediaCastMode to | 318 // Note that there is a rarely-encountered bug, where the MediaCastMode to |
| 313 // MediaSource mapping could have been updated, between when the user | 319 // MediaSource mapping could have been updated, between when the user |
| 314 // clicked on the UI to start a create route request, | 320 // clicked on the UI to start a create route request, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 } else if (presentation_service_delegate_) { | 366 } else if (presentation_service_delegate_) { |
| 361 route_response_callbacks.push_back( | 367 route_response_callbacks.push_back( |
| 362 base::Bind(&PresentationServiceDelegateImpl::OnRouteResponse, | 368 base::Bind(&PresentationServiceDelegateImpl::OnRouteResponse, |
| 363 presentation_service_delegate_)); | 369 presentation_service_delegate_)); |
| 364 } | 370 } |
| 365 } | 371 } |
| 366 | 372 |
| 367 router_->CreateRoute(source.id(), sink_id, origin, | 373 router_->CreateRoute(source.id(), sink_id, origin, |
| 368 SessionTabHelper::IdForTab(initiator_), | 374 SessionTabHelper::IdForTab(initiator_), |
| 369 route_response_callbacks); | 375 route_response_callbacks); |
| 376 | |
| 377 // Start the timer. | |
|
imcheng
2015/09/22 21:45:12
You should probably start the timer before CreateR
apacible
2015/09/22 22:37:18
Done.
| |
| 378 route_creation_timer_.Start( | |
| 379 FROM_HERE, base::TimeDelta::FromSeconds(kCreateRouteTimeoutSeconds), | |
| 380 this, &MediaRouterUI::RouteCreationTimeout); | |
| 381 | |
| 370 return true; | 382 return true; |
| 371 } | 383 } |
| 372 | 384 |
| 385 void MediaRouterUI::RouteCreationTimeout() { | |
|
imcheng
2015/09/22 21:45:12
Hmm... two things. We will have to think about thi
apacible
2015/09/22 22:37:19
1) Done.
2) Hmm, some questions:
- Can we tell the
imcheng
2015/09/29 19:08:53
Re #2: In general, we don't have a way to cancel a
| |
| 386 Issue issue( | |
| 387 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT), | |
| 388 std::string(), IssueAction(IssueAction::TYPE_DISMISS), | |
| 389 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | |
| 390 false, std::string()); | |
| 391 AddIssue(issue); | |
|
imcheng
2015/09/22 21:45:12
nit: no need to have |issue| local variable. But i
apacible
2015/09/22 22:37:19
Keeping as is; I also did this for readability in
| |
| 392 } | |
| 393 | |
| 373 std::string MediaRouterUI::GetFrameURLHost() const { | 394 std::string MediaRouterUI::GetFrameURLHost() const { |
| 374 return GetHostFromURL(frame_url_); | 395 return GetHostFromURL(frame_url_); |
| 375 } | 396 } |
| 376 | 397 |
| 377 const std::string& MediaRouterUI::GetRouteProviderExtensionId() const { | 398 const std::string& MediaRouterUI::GetRouteProviderExtensionId() const { |
| 378 return router_->media_route_provider_extension_id(); | 399 return router_->media_route_provider_extension_id(); |
| 379 } | 400 } |
| 380 | 401 |
| 381 } // namespace media_router | 402 } // namespace media_router |
| OLD | NEW |