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

Side by Side Diff: chrome/browser/ui/toolbar/media_router_action_controller.cc

Issue 2559323002: Add a policy to always show the Cast toolbar icon (Closed)
Patch Set: Rebase Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/toolbar/media_router_action_controller.h" 5 #include "chrome/browser/ui/toolbar/media_router_action_controller.h"
6 6
7 #include "chrome/browser/media/router/media_router_factory.h" 7 #include "chrome/browser/media/router/media_router_factory.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" 9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
10 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" 10 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 12
13 MediaRouterActionController::MediaRouterActionController(Profile* profile) 13 MediaRouterActionController::MediaRouterActionController(Profile* profile)
14 : MediaRouterActionController( 14 : MediaRouterActionController(
15 profile, 15 profile,
16 media_router::MediaRouterFactory::GetApiForBrowserContext(profile), 16 media_router::MediaRouterFactory::GetApiForBrowserContext(profile),
17 ToolbarActionsModel::Get(profile), 17 ToolbarActionsModel::Get(profile),
18 ToolbarActionsModel::Get(profile)->component_migration_helper()) { 18 ToolbarActionsModel::Get(profile)->component_migration_helper()) {
19 DCHECK(component_action_delegate_); 19 DCHECK(component_action_delegate_);
20 DCHECK(component_migration_helper_); 20 DCHECK(component_migration_helper_);
21 } 21 }
22 22
23 MediaRouterActionController::~MediaRouterActionController() { 23 MediaRouterActionController::~MediaRouterActionController() {
24 DCHECK_EQ(dialog_count_, 0u); 24 DCHECK_EQ(dialog_count_, 0u);
25 } 25 }
26 26
27 // static
28 bool MediaRouterActionController::IsActionShownByPolicy(Profile* profile) {
29 CHECK(profile);
30 const PrefService::Preference* pref =
31 profile->GetPrefs()->FindPreference(prefs::kShowCastIconInToolbar);
32 bool show = false;
33 if (pref->IsManaged())
34 pref->GetValue()->GetAsBoolean(&show);
35 return show;
36 }
37
27 void MediaRouterActionController::OnIssue(const media_router::Issue& issue) { 38 void MediaRouterActionController::OnIssue(const media_router::Issue& issue) {
28 has_issue_ = true; 39 has_issue_ = true;
29 MaybeAddOrRemoveAction(); 40 MaybeAddOrRemoveAction();
30 } 41 }
31 42
32 void MediaRouterActionController::OnIssuesCleared() { 43 void MediaRouterActionController::OnIssuesCleared() {
33 has_issue_ = false; 44 has_issue_ = false;
34 MaybeAddOrRemoveAction(); 45 MaybeAddOrRemoveAction();
35 } 46 }
36 47
(...skipping 24 matching lines...) Expand all
61 MediaRouterActionController::MediaRouterActionController( 72 MediaRouterActionController::MediaRouterActionController(
62 Profile* profile, 73 Profile* profile,
63 media_router::MediaRouter* router, 74 media_router::MediaRouter* router,
64 extensions::ComponentMigrationHelper::ComponentActionDelegate* 75 extensions::ComponentMigrationHelper::ComponentActionDelegate*
65 component_action_delegate, 76 component_action_delegate,
66 extensions::ComponentMigrationHelper* component_migration_helper) 77 extensions::ComponentMigrationHelper* component_migration_helper)
67 : media_router::IssuesObserver(router), 78 : media_router::IssuesObserver(router),
68 media_router::MediaRoutesObserver(router), 79 media_router::MediaRoutesObserver(router),
69 profile_(profile), 80 profile_(profile),
70 component_action_delegate_(component_action_delegate), 81 component_action_delegate_(component_action_delegate),
71 component_migration_helper_(component_migration_helper) { 82 component_migration_helper_(component_migration_helper),
72 DCHECK(profile_); 83 shown_by_policy_(
84 MediaRouterActionController::IsActionShownByPolicy(profile)) {
85 CHECK(profile_);
73 media_router::IssuesObserver::Init(); 86 media_router::IssuesObserver::Init();
74 pref_change_registrar_.Init(profile->GetPrefs()); 87 pref_change_registrar_.Init(profile->GetPrefs());
75 pref_change_registrar_.Add( 88 pref_change_registrar_.Add(
76 prefs::kToolbarMigratedComponentActionStatus, 89 prefs::kToolbarMigratedComponentActionStatus,
77 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction, 90 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction,
78 base::Unretained(this))); 91 base::Unretained(this)));
79 } 92 }
80 93
81 void MediaRouterActionController::MaybeAddOrRemoveAction() { 94 void MediaRouterActionController::MaybeAddOrRemoveAction() {
82 if (ShouldEnableAction()) { 95 if (ShouldEnableAction()) {
83 if (!component_action_delegate_->HasComponentAction( 96 if (!component_action_delegate_->HasComponentAction(
84 ComponentToolbarActionsFactory::kMediaRouterActionId)) { 97 ComponentToolbarActionsFactory::kMediaRouterActionId)) {
85 component_action_delegate_->AddComponentAction( 98 component_action_delegate_->AddComponentAction(
86 ComponentToolbarActionsFactory::kMediaRouterActionId); 99 ComponentToolbarActionsFactory::kMediaRouterActionId);
87 } 100 }
88 } else if (component_action_delegate_->HasComponentAction( 101 } else if (component_action_delegate_->HasComponentAction(
89 ComponentToolbarActionsFactory::kMediaRouterActionId)) { 102 ComponentToolbarActionsFactory::kMediaRouterActionId)) {
90 component_action_delegate_->RemoveComponentAction( 103 component_action_delegate_->RemoveComponentAction(
91 ComponentToolbarActionsFactory::kMediaRouterActionId); 104 ComponentToolbarActionsFactory::kMediaRouterActionId);
92 } 105 }
93 } 106 }
94 107
95 bool MediaRouterActionController::ShouldEnableAction() const { 108 bool MediaRouterActionController::ShouldEnableAction() const {
96 return has_local_display_route_ || has_issue_ || dialog_count_ || 109 return shown_by_policy_ || has_local_display_route_ || has_issue_ ||
110 dialog_count_ ||
97 component_migration_helper_->GetComponentActionPref( 111 component_migration_helper_->GetComponentActionPref(
98 ComponentToolbarActionsFactory::kMediaRouterActionId); 112 ComponentToolbarActionsFactory::kMediaRouterActionId);
99 } 113 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/media_router_action_controller.h ('k') | chrome/browser/ui/toolbar/media_router_contextual_menu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698