Commit 0320fa7c authored by apacible's avatar apacible Committed by Commit bot

[Media Router] Add enable cloud services menu item to contextual menu.

Part 7.

Add menu item to Media Router contextual menu to toggle the cloud services preference. It will be checked if cloud services is currently enabled.

This will only appear in Chrome branded builds.

BUG=560457

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

Cr-Commit-Position: refs/heads/master@{#371689}
parent 1cd114a3
......@@ -349,6 +349,9 @@
#define IDC_MEDIA_ROUTER_LEARN_MORE 51202
#define IDC_MEDIA_ROUTER_REPORT_ISSUE 51203
#define IDC_MEDIA_ROUTER_REMOVE_TOOLBAR_ACTION 51204
#if defined(GOOGLE_CHROME_BUILD)
#define IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE 51205
#endif // defined(GOOGLE_CHROME_BUILD)
// Context menu items for media stream status tray
#define IDC_MEDIA_STREAM_DEVICE_STATUS_TRAY 51300
......
......@@ -38,6 +38,11 @@
<message name="IDS_MEDIA_ROUTER_ABOUT" desc="Title of a menu item which, on click, opens a page with product information about Chromecast.">
About
</message>
<if expr="_google_chrome">
<message name="IDS_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE" desc="Title of a menu item which, on click, toggles the preference to opt in or out of cloud services.">
Enable Cloud Services
</message>
</if>
<message name="IDS_MEDIA_ROUTER_HELP" desc="Title of a menu item which, on click, opens a page to the Chromecast help center.">
Help
</message>
......
......@@ -20,12 +20,21 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/menu_model_delegate.h"
#if defined(GOOGLE_CHROME_BUILD)
#include "base/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
#endif // defined(GOOGLE_CHROME_BUILD)
MediaRouterContextualMenu::MediaRouterContextualMenu(Browser* browser)
: browser_(browser),
menu_model_(this) {
menu_model_.AddItemWithStringId(IDC_MEDIA_ROUTER_ABOUT,
IDS_MEDIA_ROUTER_ABOUT);
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
#if defined(GOOGLE_CHROME_BUILD)
menu_model_.AddCheckItemWithStringId(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE,
IDS_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE);
#endif // defined(GOOGLE_CHROME_BUILD)
menu_model_.AddItemWithStringId(IDC_MEDIA_ROUTER_LEARN_MORE,
IDS_MEDIA_ROUTER_LEARN_MORE);
menu_model_.AddItemWithStringId(IDC_MEDIA_ROUTER_HELP,
......@@ -41,6 +50,12 @@ MediaRouterContextualMenu::~MediaRouterContextualMenu() {
}
bool MediaRouterContextualMenu::IsCommandIdChecked(int command_id) const {
#if defined(GOOGLE_CHROME_BUILD)
if (command_id == IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE) {
return browser_->profile()->GetPrefs()->GetBoolean(
prefs::kMediaRouterEnableCloudServices);
}
#endif // defined(GOOGLE_CHROME_BUILD)
return false;
}
......@@ -48,6 +63,15 @@ bool MediaRouterContextualMenu::IsCommandIdEnabled(int command_id) const {
return true;
}
bool MediaRouterContextualMenu::IsCommandIdVisible(int command_id) const {
#if defined(GOOGLE_CHROME_BUILD)
// Cloud services preference is not set or used if sync is disabled.
if (command_id == IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)
return browser_->profile()->IsSyncAllowed();
#endif // defined(GOOGLE_CHROME_BUILD)
return true;
}
bool MediaRouterContextualMenu::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) {
......@@ -63,10 +87,24 @@ void MediaRouterContextualMenu::ExecuteCommand(int command_id,
const char kCastLearnMorePageUrl[] =
"https://www.google.com/chrome/devices/chromecast/learn.html";
#if defined(GOOGLE_CHROME_BUILD)
PrefService* pref_service;
#endif // defined(GOOGLE_CHROME_BUILD)
switch (command_id) {
case IDC_MEDIA_ROUTER_ABOUT:
chrome::ShowSingletonTab(browser_, GURL(kAboutPageUrl));
break;
#if defined(GOOGLE_CHROME_BUILD)
case IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE:
pref_service = browser_->profile()->GetPrefs();
pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices,
!pref_service->GetBoolean(prefs::kMediaRouterEnableCloudServices));
// If this has been set before, this is a no-op.
pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet,
true);
break;
#endif // defined(GOOGLE_CHROME_BUILD)
case IDC_MEDIA_ROUTER_HELP:
chrome::ShowSingletonTab(browser_, GURL(kCastHelpCenterPageUrl));
base::RecordAction(base::UserMetricsAction(
......
......@@ -23,6 +23,7 @@ class MediaRouterContextualMenu : public ui::SimpleMenuModel::Delegate {
// ui::SimpleMenuModel::Delegate:
bool IsCommandIdChecked(int command_id) const override;
bool IsCommandIdEnabled(int command_id) const override;
bool IsCommandIdVisible(int command_id) const override;
bool GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) override;
void ExecuteCommand(int command_id, int event_flags) override;
......
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