Commit 40dd5a18 authored by apacible's avatar apacible Committed by Commit bot

[Media Router] Add cloud services preferences.

Part 6.

This change adds two syncable preferences related to using cloud services with Media Router.

kMediaRouterCloudServicesPrefSet tracks whether or not the user has explicitly acknowledged the first run flow with the cloud services preference present. This is important to keep track of since there are users who have acknowledged the first run flow before the work related to the cloud services lands (currently in progress). This will be used to surface a different prompt to ask if users want to enable cloud services.

kMediaRouterEnableCloudServices tracks whether the user has enabled cloud services.

BUG=560457

Review URL: https://codereview.chromium.org/1582943003

Cr-Commit-Position: refs/heads/master@{#371456}
parent 92b3e973
...@@ -152,6 +152,16 @@ void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { ...@@ -152,6 +152,16 @@ void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
#endif #endif
#if defined(ENABLE_MEDIA_ROUTER) #if defined(ENABLE_MEDIA_ROUTER)
#if defined(GOOGLE_CHROME_BUILD)
registry->RegisterBooleanPref(
prefs::kMediaRouterCloudServicesPrefSet,
false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(
prefs::kMediaRouterEnableCloudServices,
false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
#endif // defined(GOOGLE_CHROME_BUILD)
registry->RegisterBooleanPref( registry->RegisterBooleanPref(
prefs::kMediaRouterFirstRunFlowAcknowledged, prefs::kMediaRouterFirstRunFlowAcknowledged,
false, false,
......
...@@ -406,8 +406,14 @@ Polymer({ ...@@ -406,8 +406,14 @@ Polymer({
* @private * @private
*/ */
acknowledgeFirstRunFlow_: function() { acknowledgeFirstRunFlow_: function() {
var userOptedIntoCloudServices = this.$$('#first-run-cloud-checkbox') ?
this.$$('#first-run-cloud-checkbox').checked : false;
this.fire('acknowledge-first-run-flow', {
optedIntoCloudServices: userOptedIntoCloudServices,
});
this.showFirstRunFlow = false; this.showFirstRunFlow = false;
this.fire('acknowledge-first-run-flow'); this.showFirstRunFlowCloudPref = false;
}, },
/** /**
......
...@@ -81,9 +81,17 @@ cr.define('media_router', function() { ...@@ -81,9 +81,17 @@ cr.define('media_router', function() {
* Updates the preference that the user has seen the first run flow. * Updates the preference that the user has seen the first run flow.
* Called when the user clicks on the acknowledgement button on the first run * Called when the user clicks on the acknowledgement button on the first run
* flow. * flow.
*
* @param {!Event} event
* Parameters in |event|.detail:
* optedIntoCloudServices - whether or not the user opted into cloud
* services.
*/ */
function onAcknowledgeFirstRunFlow() { function onAcknowledgeFirstRunFlow(event) {
media_router.browserApi.acknowledgeFirstRunFlow(); /** @type {{optedIntoCloudServices: boolean}} */
var detail = event.detail;
media_router.browserApi.acknowledgeFirstRunFlow(
detail.optedIntoCloudServices);
} }
/** /**
......
...@@ -55,7 +55,8 @@ cr.define('media_router.ui', function() { ...@@ -55,7 +55,8 @@ cr.define('media_router.ui', function() {
* sinks: !Array<!media_router.Sink>, * sinks: !Array<!media_router.Sink>,
* routes: !Array<!media_router.Route>, * routes: !Array<!media_router.Route>,
* castModes: !Array<!media_router.CastMode>, * castModes: !Array<!media_router.CastMode>,
* wasFirstRunFlowAcknowledged: boolean}} data * wasFirstRunFlowAcknowledged: boolean,
* showFirstRunFlowCloudPref: boolean}} data
* Parameters in data: * Parameters in data:
* firstRunFlowCloudPrefLearnMoreUrl - url to open when the cloud services * firstRunFlowCloudPrefLearnMoreUrl - url to open when the cloud services
* pref learn more link is clicked. * pref learn more link is clicked.
...@@ -65,6 +66,8 @@ cr.define('media_router.ui', function() { ...@@ -65,6 +66,8 @@ cr.define('media_router.ui', function() {
* castModes - list of available cast modes. * castModes - list of available cast modes.
* wasFirstRunFlowAcknowledged - true if first run flow was previously * wasFirstRunFlowAcknowledged - true if first run flow was previously
* acknowledged by user. * acknowledged by user.
* showFirstRunFlowCloudPref - true if the cloud pref option should be
* shown.
*/ */
function setInitialData(data) { function setInitialData(data) {
container.firstRunFlowCloudPrefLearnMoreUrl = container.firstRunFlowCloudPrefLearnMoreUrl =
...@@ -74,6 +77,8 @@ cr.define('media_router.ui', function() { ...@@ -74,6 +77,8 @@ cr.define('media_router.ui', function() {
container.allSinks = data['sinks']; container.allSinks = data['sinks'];
container.routeList = data['routes']; container.routeList = data['routes'];
container.showFirstRunFlow = !data['wasFirstRunFlowAcknowledged']; container.showFirstRunFlow = !data['wasFirstRunFlowAcknowledged'];
container.showFirstRunFlowCloudPref =
data['showFirstRunFlowCloudPref'];
container.maybeShowRouteDetailsOnOpen(); container.maybeShowRouteDetailsOnOpen();
media_router.browserApi.onInitialDataReceived(); media_router.browserApi.onInitialDataReceived();
} }
...@@ -134,9 +139,12 @@ cr.define('media_router.browserApi', function() { ...@@ -134,9 +139,12 @@ cr.define('media_router.browserApi', function() {
/** /**
* Indicates that the user has acknowledged the first run flow. * Indicates that the user has acknowledged the first run flow.
*
* @param {boolean} optedIntoCloudServices Whether or not the user opted into
* cloud services.
*/ */
function acknowledgeFirstRunFlow() { function acknowledgeFirstRunFlow(optedIntoCloudServices) {
chrome.send('acknowledgeFirstRunFlow'); chrome.send('acknowledgeFirstRunFlow', [optedIntoCloudServices]);
} }
/** /**
......
...@@ -348,11 +348,24 @@ void MediaRouterWebUIMessageHandler::OnRequestInitialData( ...@@ -348,11 +348,24 @@ void MediaRouterWebUIMessageHandler::OnRequestInitialData(
media_router_ui_->GetPresentationRequestSourceName())); media_router_ui_->GetPresentationRequestSourceName()));
initial_data.Set("castModes", cast_modes_list.release()); initial_data.Set("castModes", cast_modes_list.release());
Profile* profile = Profile::FromWebUI(web_ui());
bool first_run_flow_acknowledged = bool first_run_flow_acknowledged =
Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( profile->GetPrefs()->GetBoolean(
prefs::kMediaRouterFirstRunFlowAcknowledged); prefs::kMediaRouterFirstRunFlowAcknowledged);
initial_data.SetBoolean("wasFirstRunFlowAcknowledged", initial_data.SetBoolean("wasFirstRunFlowAcknowledged",
first_run_flow_acknowledged); first_run_flow_acknowledged);
bool show_cloud_pref = false;
#if defined(GOOGLE_CHROME_BUILD)
// Cloud services preference is shown if user has sync enabled.
// If the user enables sync after acknowledging the first run flow, this is
// treated as the user opting into Google services, including cloud services,
// if the browser is a Chrome branded build.
show_cloud_pref = profile->IsSyncAllowed() &&
!profile->GetPrefs()->GetBoolean(
prefs::kMediaRouterCloudServicesPrefSet);
#endif // defined(GOOGLE_CHROME_BUILD)
initial_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref);
web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); web_ui()->CallJavascriptFunction(kSetInitialData, initial_data);
media_router_ui_->UIInitialized(); media_router_ui_->UIInitialized();
...@@ -414,6 +427,19 @@ void MediaRouterWebUIMessageHandler::OnAcknowledgeFirstRunFlow( ...@@ -414,6 +427,19 @@ void MediaRouterWebUIMessageHandler::OnAcknowledgeFirstRunFlow(
DVLOG(1) << "OnAcknowledgeFirstRunFlow"; DVLOG(1) << "OnAcknowledgeFirstRunFlow";
Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
prefs::kMediaRouterFirstRunFlowAcknowledged, true); prefs::kMediaRouterFirstRunFlowAcknowledged, true);
#if defined(GOOGLE_CHROME_BUILD)
bool enabled_cloud_services = false;
if (!args->GetBoolean(0, &enabled_cloud_services)) {
DVLOG(1) << "Unable to extract args.";
return;
}
Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
prefs::kMediaRouterEnableCloudServices, enabled_cloud_services);
Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
prefs::kMediaRouterCloudServicesPrefSet, true);
#endif // defined(GOOGLE_CHROME_BUILD)
} }
void MediaRouterWebUIMessageHandler::OnActOnIssue( void MediaRouterWebUIMessageHandler::OnActOnIssue(
......
...@@ -2162,6 +2162,15 @@ const char kClickedUpdateMenuItem[] = "omaha.clicked_update_menu_item"; ...@@ -2162,6 +2162,15 @@ const char kClickedUpdateMenuItem[] = "omaha.clicked_update_menu_item";
#endif #endif
#if defined(ENABLE_MEDIA_ROUTER) #if defined(ENABLE_MEDIA_ROUTER)
#if defined(GOOGLE_CHROME_BUILD)
// Whether or not the user has explicitly set the cloud services preference
// through the first run flow.
const char kMediaRouterCloudServicesPrefSet[] =
"media_router.cloudservices.prefset";
// Whether or not the user has enabled cloud services with Media Router.
const char kMediaRouterEnableCloudServices[] =
"media_router.cloudservices.enabled";
#endif // defined(GOOGLE_CHROME_BUILD)
// Whether or not the Media Router first run flow has been acknowledged by the // Whether or not the Media Router first run flow has been acknowledged by the
// user. // user.
const char kMediaRouterFirstRunFlowAcknowledged[] = const char kMediaRouterFirstRunFlowAcknowledged[] =
......
...@@ -796,6 +796,10 @@ extern const char kClickedUpdateMenuItem[]; ...@@ -796,6 +796,10 @@ extern const char kClickedUpdateMenuItem[];
#endif #endif
#if defined(ENABLE_MEDIA_ROUTER) #if defined(ENABLE_MEDIA_ROUTER)
#if defined(GOOGLE_CHROME_BUILD)
extern const char kMediaRouterCloudServicesPrefSet[];
extern const char kMediaRouterEnableCloudServices[];
#endif // defined(GOOGLE_CHROME_BUILD)
extern const char kMediaRouterFirstRunFlowAcknowledged[]; extern const char kMediaRouterFirstRunFlowAcknowledged[];
#endif #endif
......
...@@ -173,7 +173,9 @@ cr.define('media_router_container', function() { ...@@ -173,7 +173,9 @@ cr.define('media_router_container', function() {
container.showFirstRunFlow = true; container.showFirstRunFlow = true;
setTimeout(function() { setTimeout(function() {
container.addEventListener('acknowledge-first-run-flow', function() { container.addEventListener('acknowledge-first-run-flow',
function(data) {
assertFalse(data.detail.optedIntoCloudServices);
done(); done();
}); });
MockInteractions.tap(container.shadowRoot.getElementById( MockInteractions.tap(container.shadowRoot.getElementById(
...@@ -181,6 +183,45 @@ cr.define('media_router_container', function() { ...@@ -181,6 +183,45 @@ cr.define('media_router_container', function() {
}); });
}); });
// Tests for 'acknowledge-first-run-flow' event firing when the
// 'first-run-button' button is clicked and the cloud preference checkbox
// is also shown.
test('first run button with cloud pref click', function(done) {
container.showFirstRunFlow = true;
container.showFirstRunFlowCloudPref = true;
setTimeout(function() {
container.addEventListener('acknowledge-first-run-flow',
function(data) {
assertTrue(data.detail.optedIntoCloudServices);
done();
});
MockInteractions.tap(container.shadowRoot.getElementById(
'first-run-button'));
});
});
// Tests for 'acknowledge-first-run-flow' event firing when the
// 'first-run-button' button is clicked after the cloud preference
// checkbox is deselected.
test('first run button with cloud pref deselected click',
function(done) {
container.showFirstRunFlow = true;
container.showFirstRunFlowCloudPref = true;
setTimeout(function() {
container.addEventListener('acknowledge-first-run-flow',
function(data) {
assertFalse(data.detail.optedIntoCloudServices);
done();
});
MockInteractions.tap(container.shadowRoot.getElementById(
'first-run-cloud-checkbox'));
MockInteractions.tap(container.shadowRoot.getElementById(
'first-run-button'));
});
});
// Tests for 'create-route' event firing when a sink with no associated // Tests for 'create-route' event firing when a sink with no associated
// route is clicked. // route is clicked.
test('select sink without a route', function(done) { test('select sink without a route', function(done) {
......
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