Skip to content

Commit

Permalink
Migrate pref registration from to media_router_feature.cc
Browse files Browse the repository at this point in the history
Some of the media_router prefs are registered in browser_prefs.cc,
which is being deprecated. This CL migrates these pref registration to
media_router::RegisterProfilePrefs().

Bug: 1308056
Change-Id: Ib2717c5bad815eec58e2f0e9cdefbec08da54ed8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3562371
Reviewed-by: Takumi Fujimoto <takumif@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Muyao Xu <muyaoxu@google.com>
Cr-Commit-Position: refs/heads/main@{#988185}
  • Loading branch information
muyao-xu authored and Chromium LUCI CQ committed Apr 1, 2022
1 parent fd75ec4 commit b8211e2
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 34 deletions.
1 change: 1 addition & 0 deletions chrome/browser/media/router/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static_library("media_router_feature") {
deps = [
"//chrome/browser/profiles:profile",
"//chrome/common:constants",
"//components/media_router/common:common",
"//components/prefs:prefs",
"//components/user_prefs:user_prefs",
"//content/public/browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "chrome/browser/media/router/media_router_feature.h"
#include "components/cast_channel/cast_socket_service.h"
#include "components/media_router/common/media_sink.h"
#include "components/media_router/common/pref_names.h"
#include "components/prefs/pref_service.h"

namespace media_router {
Expand Down
15 changes: 14 additions & 1 deletion chrome/browser/media/router/media_router_feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "chrome/common/pref_names.h"
#include "components/media_router/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
Expand Down Expand Up @@ -101,9 +102,21 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
}

void RegisterProfilePrefs(PrefRegistrySimple* registry) {
// TODO(crbug.com/1308056): Migrate existing Media Router prefs to here.
registry->RegisterStringPref(prefs::kMediaRouterReceiverIdHashToken, "",
PrefRegistry::PUBLIC);

registry->RegisterBooleanPref(
media_router::prefs::kMediaRouterMediaRemotingEnabled, true);
registry->RegisterListPref(
media_router::prefs::kMediaRouterTabMirroringSources);

// TODO(crbug.com/1308053): Register it on ChromeOS after Cast+GMC ships on
// ChromeOS.
#if !BUILDFLAG(IS_CHROMEOS)
registry->RegisterBooleanPref(
media_router::prefs::kMediaRouterShowCastSessionsStartedByOtherDevices,
true);
#endif
}

bool GetCastAllowAllIPsPref(PrefService* pref_service) {
Expand Down
10 changes: 0 additions & 10 deletions chrome/browser/media/router/media_router_feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ extern const base::Feature kAllowAllSitesToInitiateMirroring;
// TODO(crbug.com/1270509): Remove this base::Feature once fully launched.
extern const base::Feature kDialEnforceUrlIPAddress;

namespace prefs {
// Pref name for the enterprise policy for allowing Cast devices on all IPs.
constexpr char kMediaRouterCastAllowAllIPs[] =
"media_router.cast_allow_all_ips";
// Pref name for the per-profile randomly generated token to include with the
// hash when externalizing MediaSink IDs.
constexpr char kMediaRouterReceiverIdHashToken[] =
"media_router.receiver_id_hash_token";
} // namespace prefs

// Registers |kMediaRouterCastAllowAllIPs| with local state pref |registry|.
void RegisterLocalStatePrefs(PrefRegistrySimple* registry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "build/build_config.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/media_router/common/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@
#include "chrome/browser/enterprise/connectors/enterprise_connectors_policy_handler.h"
#include "chrome/browser/enterprise/reporting/extension_request/extension_request_policy_handler.h"
#include "chrome/browser/media/router/discovery/access_code/access_code_cast_feature.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/policy/local_sync_policy_handler.h"
#include "chrome/browser/policy/managed_account_policy_handler.h"
#include "components/history_clusters/core/history_clusters_prefs.h"
#include "components/media_router/common/pref_names.h"
#endif // BUILDFLAG(IS_ANDROID)

#if !BUILDFLAG(IS_CHROMEOS)
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/policy/test/cast_policy_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/toolbar/media_router_action_controller.h"
#include "components/media_router/common/pref_names.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
Expand Down
18 changes: 0 additions & 18 deletions chrome/browser/prefs/browser_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@
#include "chrome/browser/ui/webui/whats_new/whats_new_ui.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h"
#include "components/live_caption/live_caption_controller.h"
#include "components/media_router/common/pref_names.h"
#include "components/ntp_tiles/custom_links_manager_impl.h"
#endif // BUILDFLAG(IS_ANDROID)

Expand Down Expand Up @@ -1523,23 +1522,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,

registry->RegisterBooleanPref(prefs::kPrivacyGuideViewed, false);

// TODO(crbug.com/1308056): Migrate media_router prefs to
// media_router::RegisterProfilePrefs().
#if !BUILDFLAG(IS_ANDROID)
registry->RegisterBooleanPref(
media_router::prefs::kMediaRouterMediaRemotingEnabled, true);
registry->RegisterListPref(
media_router::prefs::kMediaRouterTabMirroringSources);
#endif

// TODO(crbug.com/1308053): Register it on ChromeOS after Cast+GMC ships on
// ChromeOS.
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS)
registry->RegisterBooleanPref(
media_router::prefs::kMediaRouterShowCastSessionsStartedByOtherDevices,
true);
#endif

RegisterProfilePrefsForMigration(registry);
}

Expand Down
12 changes: 9 additions & 3 deletions components/media_router/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
namespace media_router {
namespace prefs {

// Whether the enterprise policy allows Cast devices on all IPs.
const char kMediaRouterCastAllowAllIPs[] = "media_router.cast_allow_all_ips";
// Whether or not the user has enabled Media Remoting. Defaults to true.
const char kMediaRouterMediaRemotingEnabled[] =
"media_router.media_remoting.enabled";
// A list of website origins on which the user has chosen to use tab mirroring.
const char kMediaRouterTabMirroringSources[] =
"media_router.tab_mirroring_sources";
// The per-profile randomly generated token to include with the hash when
// externalizing MediaSink IDs.
const char kMediaRouterReceiverIdHashToken[] =
"media_router.receiver_id_hash_token";
// Whether or not the user has enabled to show Cast sessions started by
// other devices on the same network. This change only affects the Zenith
// dialog. Defaults to true.
const char kMediaRouterShowCastSessionsStartedByOtherDevices[] =
"media_router.show_cast_sessions_started_by_other_devices.enabled";
// A list of website origins on which the user has chosen to use tab mirroring.
const char kMediaRouterTabMirroringSources[] =
"media_router.tab_mirroring_sources";

} // namespace prefs
} // namespace media_router
4 changes: 3 additions & 1 deletion components/media_router/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
namespace media_router {
namespace prefs {

extern const char kMediaRouterCastAllowAllIPs[];
extern const char kMediaRouterMediaRemotingEnabled[];
extern const char kMediaRouterTabMirroringSources[];
extern const char kMediaRouterReceiverIdHashToken[];
extern const char kMediaRouterShowCastSessionsStartedByOtherDevices[];
extern const char kMediaRouterTabMirroringSources[];

} // namespace prefs
} // namespace media_router
Expand Down

0 comments on commit b8211e2

Please sign in to comment.