Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc

Issue 2487673003: [Media Router] Make per-hostname cast mode selections persist (Closed)
Patch Set: Address Derek's comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_webui_message_handle r.h" 5 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle r.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
13 #include "base/metrics/user_metrics.h" 13 #include "base/metrics/user_metrics.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/media/router/issue.h" 17 #include "chrome/browser/media/router/issue.h"
18 #include "chrome/browser/media/router/media_router_metrics.h" 18 #include "chrome/browser/media/router/media_router_metrics.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/sync/profile_sync_service_factory.h" 21 #include "chrome/browser/sync/profile_sync_service_factory.h"
22 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h"
22 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" 23 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
25 #include "components/browser_sync/profile_sync_service.h" 26 #include "components/browser_sync/profile_sync_service.h"
26 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
27 #include "components/signin/core/browser/signin_manager.h" 28 #include "components/signin/core/browser/signin_manager.h"
28 #include "content/public/browser/web_ui.h" 29 #include "content/public/browser/web_ui.h"
29 #include "extensions/common/constants.h" 30 #include "extensions/common/constants.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 32
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 std::unique_ptr<base::ListValue> routes(RoutesToValue( 413 std::unique_ptr<base::ListValue> routes(RoutesToValue(
413 media_router_ui_->routes(), media_router_ui_->joinable_route_ids(), 414 media_router_ui_->routes(), media_router_ui_->joinable_route_ids(),
414 media_router_ui_->current_cast_modes())); 415 media_router_ui_->current_cast_modes()));
415 initial_data.Set("routes", routes.release()); 416 initial_data.Set("routes", routes.release());
416 417
417 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); 418 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes();
418 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( 419 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue(
419 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); 420 cast_modes, media_router_ui_->GetPresentationRequestSourceName()));
420 initial_data.Set("castModes", cast_modes_list.release()); 421 initial_data.Set("castModes", cast_modes_list.release());
421 422
423 // If the cast mode last chosen for the current hostname is tab mirroring,
424 // that should be the cast mode initially selected in the dialog. Otherwise
425 // the initial cast mode should be chosen automatically by the dialog.
426 bool use_tab_mirroring =
427 base::ContainsKey(cast_modes, MediaCastMode::TAB_MIRROR) &&
428 media_router_ui_->UserSelectedTabMirroringForCurrentHost();
apacible 2016/11/16 18:51:10 nitty nit: indent four spaces.
takumif 2016/11/17 01:54:51 Do you mean that L428 should be indented by four m
apacible 2016/11/30 21:54:24 Yes, but I defer to the formatting tool. I'd gotte
429 initial_data.SetBoolean("useTabMirroring", use_tab_mirroring);
430
422 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data); 431 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data);
423 media_router_ui_->UIInitialized(); 432 media_router_ui_->UIInitialized();
424 } 433 }
425 434
426 void MediaRouterWebUIMessageHandler::OnCreateRoute( 435 void MediaRouterWebUIMessageHandler::OnCreateRoute(
427 const base::ListValue* args) { 436 const base::ListValue* args) {
428 DVLOG(1) << "OnCreateRoute"; 437 DVLOG(1) << "OnCreateRoute";
429 const base::DictionaryValue* args_dict = nullptr; 438 const base::DictionaryValue* args_dict = nullptr;
430 std::string sink_id; 439 std::string sink_id;
431 int cast_mode_num = -1; 440 int cast_mode_num = -1;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 } 698 }
690 699
691 void MediaRouterWebUIMessageHandler::OnReportSelectedCastMode( 700 void MediaRouterWebUIMessageHandler::OnReportSelectedCastMode(
692 const base::ListValue* args) { 701 const base::ListValue* args) {
693 DVLOG(1) << "OnReportSelectedCastMode"; 702 DVLOG(1) << "OnReportSelectedCastMode";
694 int cast_mode_type; 703 int cast_mode_type;
695 if (!args->GetInteger(0, &cast_mode_type)) { 704 if (!args->GetInteger(0, &cast_mode_type)) {
696 DVLOG(1) << "Unable to extract args."; 705 DVLOG(1) << "Unable to extract args.";
697 return; 706 return;
698 } 707 }
708 DCHECK(IsValidCastModeNum(cast_mode_type));
699 UMA_HISTOGRAM_SPARSE_SLOWLY("MediaRouter.Ui.Navigate.SourceSelection", 709 UMA_HISTOGRAM_SPARSE_SLOWLY("MediaRouter.Ui.Navigate.SourceSelection",
700 cast_mode_type); 710 cast_mode_type);
711 media_router_ui_->RecordCastModeSelection(
712 static_cast<MediaCastMode>(cast_mode_type));
701 } 713 }
702 714
703 void MediaRouterWebUIMessageHandler::OnReportSinkCount( 715 void MediaRouterWebUIMessageHandler::OnReportSinkCount(
704 const base::ListValue* args) { 716 const base::ListValue* args) {
705 DVLOG(1) << "OnReportSinkCount"; 717 DVLOG(1) << "OnReportSinkCount";
706 int sink_count; 718 int sink_count;
707 if (!args->GetInteger(0, &sink_count)) { 719 if (!args->GetInteger(0, &sink_count)) {
708 DVLOG(1) << "Unable to extract args."; 720 DVLOG(1) << "Unable to extract args.";
709 return; 721 return;
710 } 722 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 } 892 }
881 893
882 return value; 894 return value;
883 } 895 }
884 896
885 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 897 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
886 set_web_ui(web_ui); 898 set_web_ui(web_ui);
887 } 899 }
888 900
889 } // namespace media_router 901 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698