Commit 508fbf0e authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

Record casting source metrics even if MediaRouterViewsUI is destroyed

When the Cast dialog is closed, MediaRouterViewsUI gets destroyed. If
that happened before casting succeeded, we weren't recording the cast
source. This CL fixes that.

Change-Id: I58fb7d9db16867bce1728788b8c21694b33d3dc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904821Reviewed-by: default avatarBrandon Tolsch <btolsch@chromium.org>
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715779}
parent 74c6a7de
...@@ -85,6 +85,12 @@ MediaSource GetSourceForRouteObserver(const std::vector<MediaSource>& sources) { ...@@ -85,6 +85,12 @@ MediaSource GetSourceForRouteObserver(const std::vector<MediaSource>& sources) {
return source_it != sources.end() ? *source_it : MediaSource(std::string()); return source_it != sources.end() ? *source_it : MediaSource(std::string());
} }
void MaybeReportCastingSource(MediaCastMode cast_mode,
const RouteRequestResult& result) {
if (result.result_code() == RouteRequestResult::OK)
MediaRouterMetrics::RecordMediaRouterCastingSource(cast_mode);
}
} // namespace } // namespace
// Observes a WebContents and requests fullscreening of its first // Observes a WebContents and requests fullscreening of its first
...@@ -342,13 +348,6 @@ void MediaRouterViewsUI::TerminateRoute(const MediaRoute::Id& route_id) { ...@@ -342,13 +348,6 @@ void MediaRouterViewsUI::TerminateRoute(const MediaRoute::Id& route_id) {
GetMediaRouter()->TerminateRoute(route_id); GetMediaRouter()->TerminateRoute(route_id);
} }
void MediaRouterViewsUI::MaybeReportCastingSource(
MediaCastMode cast_mode,
const RouteRequestResult& result) {
if (result.result_code() == RouteRequestResult::OK)
MediaRouterMetrics::RecordMediaRouterCastingSource(cast_mode);
}
std::vector<MediaSinkWithCastModes> MediaRouterViewsUI::GetEnabledSinks() std::vector<MediaSinkWithCastModes> MediaRouterViewsUI::GetEnabledSinks()
const { const {
if (!display_observer_) if (!display_observer_)
...@@ -626,8 +625,7 @@ base::Optional<RouteParameters> MediaRouterViewsUI::GetRouteParameters( ...@@ -626,8 +625,7 @@ base::Optional<RouteParameters> MediaRouterViewsUI::GetRouteParameters(
// HandleCreateSessionRequestRouteResponse(), which closes the dialog and // HandleCreateSessionRequestRouteResponse(), which closes the dialog and
// destroys |this|. // destroys |this|.
params.route_result_callbacks.push_back( params.route_result_callbacks.push_back(
base::BindOnce(&MediaRouterViewsUI::MaybeReportCastingSource, base::BindOnce(&MaybeReportCastingSource, cast_mode));
weak_factory_.GetWeakPtr(), cast_mode));
// There are 3 cases. In cases (1) and (3) the MediaRouterViewsUI will need to // There are 3 cases. In cases (1) and (3) the MediaRouterViewsUI will need to
// be notified via OnRouteResponseReceived(). In case (2) the dialog will be // be notified via OnRouteResponseReceived(). In case (2) the dialog will be
...@@ -901,8 +899,7 @@ base::Optional<RouteParameters> MediaRouterViewsUI::GetLocalFileRouteParameters( ...@@ -901,8 +899,7 @@ base::Optional<RouteParameters> MediaRouterViewsUI::GetLocalFileRouteParameters(
GetPresentationRequestSourceName())); GetPresentationRequestSourceName()));
params.route_result_callbacks.push_back( params.route_result_callbacks.push_back(
base::BindOnce(&MediaRouterViewsUI::MaybeReportCastingSource, base::BindOnce(&MaybeReportCastingSource, MediaCastMode::LOCAL_FILE));
weak_factory_.GetWeakPtr(), MediaCastMode::LOCAL_FILE));
params.route_result_callbacks.push_back( params.route_result_callbacks.push_back(
base::BindOnce(&MediaRouterViewsUI::MaybeReportFileInformation, base::BindOnce(&MediaRouterViewsUI::MaybeReportFileInformation,
......
...@@ -114,10 +114,6 @@ class MediaRouterViewsUI ...@@ -114,10 +114,6 @@ class MediaRouterViewsUI
// Calls MediaRouter to terminate the given route. // Calls MediaRouter to terminate the given route.
void TerminateRoute(const MediaRoute::Id& route_id); void TerminateRoute(const MediaRoute::Id& route_id);
// Logs a UMA stat for the source that was cast if the result is successful.
void MaybeReportCastingSource(MediaCastMode cast_mode,
const RouteRequestResult& result);
// Returns a subset of |sinks_| that should be listed in the dialog. This // Returns a subset of |sinks_| that should be listed in the dialog. This
// excludes the wired display that the initiator WebContents is on. // excludes the wired display that the initiator WebContents is on.
// Also filters cloud sinks in incognito windows. // Also filters cloud sinks in incognito windows.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment