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

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

Issue 2678083005: Remove extension-to-component migration mechanism (Closed)
Patch Set: Address Mike's comments 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()) {
19 DCHECK(component_action_delegate_); 18 DCHECK(component_action_delegate_);
20 DCHECK(component_migration_helper_);
21 } 19 }
22 20
23 MediaRouterActionController::~MediaRouterActionController() { 21 MediaRouterActionController::~MediaRouterActionController() {
24 DCHECK_EQ(dialog_count_, 0u); 22 DCHECK_EQ(dialog_count_, 0u);
25 } 23 }
26 24
27 // static 25 // static
28 bool MediaRouterActionController::IsActionShownByPolicy(Profile* profile) { 26 bool MediaRouterActionController::IsActionShownByPolicy(Profile* profile) {
29 CHECK(profile); 27 CHECK(profile);
30 const PrefService::Preference* pref = 28 const PrefService::Preference* pref =
31 profile->GetPrefs()->FindPreference(prefs::kShowCastIconInToolbar); 29 profile->GetPrefs()->FindPreference(prefs::kShowCastIconInToolbar);
32 bool show = false; 30 bool show = false;
33 if (pref->IsManaged()) 31 if (pref->IsManaged())
34 pref->GetValue()->GetAsBoolean(&show); 32 pref->GetValue()->GetAsBoolean(&show);
35 return show; 33 return show;
36 } 34 }
37 35
36 // static
37 bool MediaRouterActionController::GetAlwaysShowActionPref(Profile* profile) {
38 CHECK(profile);
39 return profile->GetPrefs()->GetBoolean(prefs::kShowCastIconInToolbar);
40 }
41
42 // static
43 void MediaRouterActionController::SetAlwaysShowActionPref(Profile* profile,
44 bool always_show) {
45 CHECK(profile);
46 profile->GetPrefs()->SetBoolean(prefs::kShowCastIconInToolbar, always_show);
47 }
48
38 void MediaRouterActionController::OnIssue(const media_router::Issue& issue) { 49 void MediaRouterActionController::OnIssue(const media_router::Issue& issue) {
39 has_issue_ = true; 50 has_issue_ = true;
40 MaybeAddOrRemoveAction(); 51 MaybeAddOrRemoveAction();
41 } 52 }
42 53
43 void MediaRouterActionController::OnIssuesCleared() { 54 void MediaRouterActionController::OnIssuesCleared() {
44 has_issue_ = false; 55 has_issue_ = false;
45 MaybeAddOrRemoveAction(); 56 MaybeAddOrRemoveAction();
46 } 57 }
47 58
(...skipping 17 matching lines...) Expand all
65 void MediaRouterActionController::OnDialogHidden() { 76 void MediaRouterActionController::OnDialogHidden() {
66 DCHECK_GT(dialog_count_, 0u); 77 DCHECK_GT(dialog_count_, 0u);
67 if (dialog_count_) 78 if (dialog_count_)
68 dialog_count_--; 79 dialog_count_--;
69 MaybeAddOrRemoveAction(); 80 MaybeAddOrRemoveAction();
70 } 81 }
71 82
72 MediaRouterActionController::MediaRouterActionController( 83 MediaRouterActionController::MediaRouterActionController(
73 Profile* profile, 84 Profile* profile,
74 media_router::MediaRouter* router, 85 media_router::MediaRouter* router,
75 extensions::ComponentMigrationHelper::ComponentActionDelegate* 86 ComponentActionDelegate* component_action_delegate)
76 component_action_delegate,
77 extensions::ComponentMigrationHelper* component_migration_helper)
78 : media_router::IssuesObserver(router), 87 : media_router::IssuesObserver(router),
79 media_router::MediaRoutesObserver(router), 88 media_router::MediaRoutesObserver(router),
80 profile_(profile), 89 profile_(profile),
81 component_action_delegate_(component_action_delegate), 90 component_action_delegate_(component_action_delegate),
82 component_migration_helper_(component_migration_helper),
83 shown_by_policy_( 91 shown_by_policy_(
84 MediaRouterActionController::IsActionShownByPolicy(profile)) { 92 MediaRouterActionController::IsActionShownByPolicy(profile)) {
85 CHECK(profile_); 93 CHECK(profile_);
86 media_router::IssuesObserver::Init(); 94 media_router::IssuesObserver::Init();
87 pref_change_registrar_.Init(profile->GetPrefs()); 95 pref_change_registrar_.Init(profile->GetPrefs());
88 pref_change_registrar_.Add( 96 pref_change_registrar_.Add(
89 prefs::kToolbarMigratedComponentActionStatus, 97 prefs::kShowCastIconInToolbar,
90 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction, 98 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction,
91 base::Unretained(this))); 99 base::Unretained(this)));
92 } 100 }
93 101
94 void MediaRouterActionController::MaybeAddOrRemoveAction() { 102 void MediaRouterActionController::MaybeAddOrRemoveAction() {
95 if (ShouldEnableAction()) { 103 if (ShouldEnableAction()) {
96 if (!component_action_delegate_->HasComponentAction( 104 if (!component_action_delegate_->HasComponentAction(
97 ComponentToolbarActionsFactory::kMediaRouterActionId)) { 105 ComponentToolbarActionsFactory::kMediaRouterActionId)) {
98 component_action_delegate_->AddComponentAction( 106 component_action_delegate_->AddComponentAction(
99 ComponentToolbarActionsFactory::kMediaRouterActionId); 107 ComponentToolbarActionsFactory::kMediaRouterActionId);
100 } 108 }
101 } else if (component_action_delegate_->HasComponentAction( 109 } else if (component_action_delegate_->HasComponentAction(
102 ComponentToolbarActionsFactory::kMediaRouterActionId)) { 110 ComponentToolbarActionsFactory::kMediaRouterActionId)) {
103 component_action_delegate_->RemoveComponentAction( 111 component_action_delegate_->RemoveComponentAction(
104 ComponentToolbarActionsFactory::kMediaRouterActionId); 112 ComponentToolbarActionsFactory::kMediaRouterActionId);
105 } 113 }
106 } 114 }
107 115
108 bool MediaRouterActionController::ShouldEnableAction() const { 116 bool MediaRouterActionController::ShouldEnableAction() const {
109 return shown_by_policy_ || has_local_display_route_ || has_issue_ || 117 return shown_by_policy_ || has_local_display_route_ || has_issue_ ||
110 dialog_count_ || 118 dialog_count_ ||
111 component_migration_helper_->GetComponentActionPref( 119 MediaRouterActionController::GetAlwaysShowActionPref(profile_);
Devlin 2017/02/08 15:20:01 nit: no need to prefix this, just GetAlwaysShowAct
takumif 2017/02/08 17:38:15 Done.
112 ComponentToolbarActionsFactory::kMediaRouterActionId);
113 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698