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

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 Derek'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_action_delegate.h"
9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" 10 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
10 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" 11 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 13
13 MediaRouterActionController::MediaRouterActionController(Profile* profile) 14 MediaRouterActionController::MediaRouterActionController(Profile* profile)
14 : MediaRouterActionController( 15 : MediaRouterActionController(
15 profile, 16 profile,
16 media_router::MediaRouterFactory::GetApiForBrowserContext(profile), 17 media_router::MediaRouterFactory::GetApiForBrowserContext(profile),
17 ToolbarActionsModel::Get(profile), 18 ToolbarActionsModel::Get(profile)) {
18 ToolbarActionsModel::Get(profile)->component_migration_helper()) {
19 DCHECK(component_action_delegate_); 19 DCHECK(component_action_delegate_);
20 DCHECK(component_migration_helper_);
21 } 20 }
22 21
23 MediaRouterActionController::~MediaRouterActionController() { 22 MediaRouterActionController::~MediaRouterActionController() {
24 DCHECK_EQ(dialog_count_, 0u); 23 DCHECK_EQ(dialog_count_, 0u);
25 } 24 }
26 25
27 // static 26 // static
28 bool MediaRouterActionController::IsActionShownByPolicy(Profile* profile) { 27 bool MediaRouterActionController::IsActionShownByPolicy(Profile* profile) {
29 CHECK(profile); 28 CHECK(profile);
30 const PrefService::Preference* pref = 29 const PrefService::Preference* pref =
31 profile->GetPrefs()->FindPreference(prefs::kShowCastIconInToolbar); 30 profile->GetPrefs()->FindPreference(prefs::kShowCastIconInToolbar);
32 bool show = false; 31 bool show = false;
33 if (pref->IsManaged()) 32 if (pref->IsManaged())
34 pref->GetValue()->GetAsBoolean(&show); 33 pref->GetValue()->GetAsBoolean(&show);
35 return show; 34 return show;
36 } 35 }
37 36
37 // static
38 bool MediaRouterActionController::GetAlwaysShowActionPref(Profile* profile) {
39 CHECK(profile);
40 return profile->GetPrefs()->GetBoolean(prefs::kShowCastIconInToolbar);
41 }
42
43 // static
44 void MediaRouterActionController::SetAlwaysShowActionPref(Profile* profile,
45 bool always_show) {
46 CHECK(profile);
47 profile->GetPrefs()->SetBoolean(prefs::kShowCastIconInToolbar, always_show);
48 }
49
38 void MediaRouterActionController::OnIssue(const media_router::Issue& issue) { 50 void MediaRouterActionController::OnIssue(const media_router::Issue& issue) {
39 has_issue_ = true; 51 has_issue_ = true;
40 MaybeAddOrRemoveAction(); 52 MaybeAddOrRemoveAction();
41 } 53 }
42 54
43 void MediaRouterActionController::OnIssuesCleared() { 55 void MediaRouterActionController::OnIssuesCleared() {
44 has_issue_ = false; 56 has_issue_ = false;
45 MaybeAddOrRemoveAction(); 57 MaybeAddOrRemoveAction();
46 } 58 }
47 59
(...skipping 17 matching lines...) Expand all
65 void MediaRouterActionController::OnDialogHidden() { 77 void MediaRouterActionController::OnDialogHidden() {
66 DCHECK_GT(dialog_count_, 0u); 78 DCHECK_GT(dialog_count_, 0u);
67 if (dialog_count_) 79 if (dialog_count_)
68 dialog_count_--; 80 dialog_count_--;
69 MaybeAddOrRemoveAction(); 81 MaybeAddOrRemoveAction();
70 } 82 }
71 83
72 MediaRouterActionController::MediaRouterActionController( 84 MediaRouterActionController::MediaRouterActionController(
73 Profile* profile, 85 Profile* profile,
74 media_router::MediaRouter* router, 86 media_router::MediaRouter* router,
75 extensions::ComponentMigrationHelper::ComponentActionDelegate* 87 ComponentActionDelegate* component_action_delegate)
76 component_action_delegate,
77 extensions::ComponentMigrationHelper* component_migration_helper)
78 : media_router::IssuesObserver(router), 88 : media_router::IssuesObserver(router),
79 media_router::MediaRoutesObserver(router), 89 media_router::MediaRoutesObserver(router),
80 profile_(profile), 90 profile_(profile),
81 component_action_delegate_(component_action_delegate), 91 component_action_delegate_(component_action_delegate),
82 component_migration_helper_(component_migration_helper),
83 shown_by_policy_( 92 shown_by_policy_(
84 MediaRouterActionController::IsActionShownByPolicy(profile)) { 93 MediaRouterActionController::IsActionShownByPolicy(profile)) {
85 CHECK(profile_); 94 CHECK(profile_);
86 media_router::IssuesObserver::Init(); 95 media_router::IssuesObserver::Init();
87 pref_change_registrar_.Init(profile->GetPrefs()); 96 pref_change_registrar_.Init(profile->GetPrefs());
88 pref_change_registrar_.Add( 97 pref_change_registrar_.Add(
89 prefs::kToolbarMigratedComponentActionStatus, 98 prefs::kShowCastIconInToolbar,
90 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction, 99 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction,
91 base::Unretained(this))); 100 base::Unretained(this)));
92 } 101 }
93 102
94 void MediaRouterActionController::MaybeAddOrRemoveAction() { 103 void MediaRouterActionController::MaybeAddOrRemoveAction() {
95 if (ShouldEnableAction()) { 104 if (ShouldEnableAction()) {
96 if (!component_action_delegate_->HasComponentAction( 105 if (!component_action_delegate_->HasComponentAction(
97 ComponentToolbarActionsFactory::kMediaRouterActionId)) { 106 ComponentToolbarActionsFactory::kMediaRouterActionId)) {
98 component_action_delegate_->AddComponentAction( 107 component_action_delegate_->AddComponentAction(
99 ComponentToolbarActionsFactory::kMediaRouterActionId); 108 ComponentToolbarActionsFactory::kMediaRouterActionId);
100 } 109 }
101 } else if (component_action_delegate_->HasComponentAction( 110 } else if (component_action_delegate_->HasComponentAction(
102 ComponentToolbarActionsFactory::kMediaRouterActionId)) { 111 ComponentToolbarActionsFactory::kMediaRouterActionId)) {
103 component_action_delegate_->RemoveComponentAction( 112 component_action_delegate_->RemoveComponentAction(
104 ComponentToolbarActionsFactory::kMediaRouterActionId); 113 ComponentToolbarActionsFactory::kMediaRouterActionId);
105 } 114 }
106 } 115 }
107 116
108 bool MediaRouterActionController::ShouldEnableAction() const { 117 bool MediaRouterActionController::ShouldEnableAction() const {
109 return shown_by_policy_ || has_local_display_route_ || has_issue_ || 118 return shown_by_policy_ || has_local_display_route_ || has_issue_ ||
110 dialog_count_ || 119 dialog_count_ || GetAlwaysShowActionPref(profile_);
111 component_migration_helper_->GetComponentActionPref(
112 ComponentToolbarActionsFactory::kMediaRouterActionId);
113 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698