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

Unified Diff: chrome/browser/ui/toolbar/media_router_contextual_menu.cc

Issue 2332693003: Show media router toolbar icon ephemerally for active local routes and issues (Closed)
Patch Set: Address Mike's comments Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/media_router_contextual_menu.cc
diff --git a/chrome/browser/ui/toolbar/media_router_contextual_menu.cc b/chrome/browser/ui/toolbar/media_router_contextual_menu.cc
index 51b8744a0f4751dcd147f9aca63bc76464b24d68..d060a7984b325a98ce3540df34ffdad513dc8ac6 100644
--- a/chrome/browser/ui/toolbar/media_router_contextual_menu.cc
+++ b/chrome/browser/ui/toolbar/media_router_contextual_menu.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
+
#include "base/logging.h"
#include "base/metrics/user_metrics.h"
#include "chrome/app/chrome_command_ids.h"
@@ -14,6 +16,7 @@
#include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
#include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
@@ -22,14 +25,21 @@
#if defined(GOOGLE_CHROME_BUILD)
#include "chrome/browser/signin/signin_manager_factory.h"
-#include "chrome/common/pref_names.h"
-#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/signin_manager.h"
#endif // defined(GOOGLE_CHROME_BUILD)
MediaRouterContextualMenu::MediaRouterContextualMenu(Browser* browser)
+ : MediaRouterContextualMenu(browser,
+ ToolbarActionsModel::Get(browser->profile())) {}
+
+MediaRouterContextualMenu::~MediaRouterContextualMenu() {}
+
+MediaRouterContextualMenu::MediaRouterContextualMenu(
+ Browser* browser,
+ ToolbarActionsModel* toolbar_actions_model)
: browser_(browser),
- menu_model_(this) {
+ menu_model_(this),
+ toolbar_actions_model_(toolbar_actions_model) {
Devlin 2016/09/21 17:15:12 It looks like we only ever use this for the Compon
takumif 2016/09/21 17:27:15 This is to be able to inject a non-NULL ToolbarAct
Devlin 2016/09/21 17:32:57 What uses it that needs it to be non-null, rather
takumif 2016/09/21 17:45:45 Right, it's only used for the migration helper. Bu
Devlin 2016/09/21 17:52:45 Why? We have a ctor explicitly for injecting depe
takumif 2016/09/21 17:59:16 I was thinking that if the real ctor gets called i
Devlin 2016/09/21 18:17:30 So these are tests that construct a MediaRouterCon
takumif 2016/09/21 18:49:31 Sorry, I'd mistakenly thought that both the MRCont
menu_model_.AddItemWithStringId(IDC_MEDIA_ROUTER_ABOUT,
IDS_MEDIA_ROUTER_ABOUT);
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
@@ -37,8 +47,9 @@ MediaRouterContextualMenu::MediaRouterContextualMenu(Browser* browser)
IDS_MEDIA_ROUTER_LEARN_MORE);
menu_model_.AddItemWithStringId(IDC_MEDIA_ROUTER_HELP,
IDS_MEDIA_ROUTER_HELP);
- menu_model_.AddItemWithStringId(IDC_MEDIA_ROUTER_REMOVE_TOOLBAR_ACTION,
- IDS_MEDIA_ROUTER_REMOVE_TOOLBAR_ACTION);
+ menu_model_.AddCheckItemWithStringId(
+ IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION,
+ IDS_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION);
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
menu_model_.AddItemWithStringId(IDC_MEDIA_ROUTER_MANAGE_DEVICES,
@@ -52,7 +63,15 @@ MediaRouterContextualMenu::MediaRouterContextualMenu(Browser* browser)
IDS_MEDIA_ROUTER_REPORT_ISSUE);
}
-MediaRouterContextualMenu::~MediaRouterContextualMenu() {
+bool MediaRouterContextualMenu::GetAlwaysShowActionPref() const {
+ return toolbar_actions_model_->component_migration_helper()
+ ->GetComponentActionPref(
+ ComponentToolbarActionsFactory::kMediaRouterActionId);
+}
+
+void MediaRouterContextualMenu::SetAlwaysShowActionPref(bool always_show) {
+ toolbar_actions_model_->component_migration_helper()->SetComponentActionPref(
+ ComponentToolbarActionsFactory::kMediaRouterActionId, always_show);
}
bool MediaRouterContextualMenu::IsCommandIdChecked(int command_id) const {
@@ -62,6 +81,9 @@ bool MediaRouterContextualMenu::IsCommandIdChecked(int command_id) const {
prefs::kMediaRouterEnableCloudServices);
}
#endif // defined(GOOGLE_CHROME_BUILD)
+ if (command_id == IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION) {
+ return GetAlwaysShowActionPref();
+ }
return false;
}
@@ -98,6 +120,9 @@ void MediaRouterContextualMenu::ExecuteCommand(int command_id,
case IDC_MEDIA_ROUTER_ABOUT:
chrome::ShowSingletonTab(browser_, GURL(kAboutPageUrl));
break;
+ case IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION:
+ SetAlwaysShowActionPref(!GetAlwaysShowActionPref());
+ break;
#if defined(GOOGLE_CHROME_BUILD)
case IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE:
pref_service = browser_->profile()->GetPrefs();
@@ -105,8 +130,7 @@ void MediaRouterContextualMenu::ExecuteCommand(int command_id,
!pref_service->GetBoolean(prefs::kMediaRouterEnableCloudServices));
// If this has been set before, this is a no-op.
- pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet,
- true);
+ pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true);
break;
#endif // defined(GOOGLE_CHROME_BUILD)
case IDC_MEDIA_ROUTER_HELP:
@@ -122,9 +146,6 @@ void MediaRouterContextualMenu::ExecuteCommand(int command_id,
chrome::ShowSingletonTab(browser_, GURL(chrome::kChromeUICastURL));
break;
#endif
- case IDC_MEDIA_ROUTER_REMOVE_TOOLBAR_ACTION:
- RemoveMediaRouterComponentAction();
- break;
case IDC_MEDIA_ROUTER_REPORT_ISSUE:
ReportIssue();
break;
@@ -149,8 +170,3 @@ void MediaRouterContextualMenu::ReportIssue() {
"/feedback.html");
chrome::ShowSingletonTab(browser_, GURL(feedback_url));
}
-
-void MediaRouterContextualMenu::RemoveMediaRouterComponentAction() {
- ToolbarActionsModel::Get(browser_->profile())->component_migration_helper()
- ->OnActionRemoved(ComponentToolbarActionsFactory::kMediaRouterActionId);
-}

Powered by Google App Engine
This is Rietveld 408576698