| OLD | NEW |
| 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 UnregisterObserver(); // media_router::IssuesObserver. | 25 UnregisterObserver(); // media_router::IssuesObserver. |
| 26 } | 26 } |
| 27 | 27 |
| 28 // static |
| 29 bool MediaRouterActionController::IsActionShownByPolicy( |
| 30 content::BrowserContext* context) { |
| 31 const PrefService::Preference* pref = |
| 32 user_prefs::UserPrefs::Get(context)->FindPreference( |
| 33 prefs::kShowCastIconInToolbar); |
| 34 bool show = false; |
| 35 if (pref->IsManaged()) |
| 36 pref->GetValue()->GetAsBoolean(&show); |
| 37 return show; |
| 38 } |
| 39 |
| 28 void MediaRouterActionController::OnIssueUpdated( | 40 void MediaRouterActionController::OnIssueUpdated( |
| 29 const media_router::Issue* issue) { | 41 const media_router::Issue* issue) { |
| 30 has_issue_ = issue != nullptr; | 42 has_issue_ = issue != nullptr; |
| 31 MaybeAddOrRemoveAction(); | 43 MaybeAddOrRemoveAction(); |
| 32 } | 44 } |
| 33 | 45 |
| 34 void MediaRouterActionController::OnRoutesUpdated( | 46 void MediaRouterActionController::OnRoutesUpdated( |
| 35 const std::vector<media_router::MediaRoute>& routes, | 47 const std::vector<media_router::MediaRoute>& routes, |
| 36 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { | 48 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) { |
| 37 has_local_display_route_ = | 49 has_local_display_route_ = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 58 MediaRouterActionController::MediaRouterActionController( | 70 MediaRouterActionController::MediaRouterActionController( |
| 59 Profile* profile, | 71 Profile* profile, |
| 60 media_router::MediaRouter* router, | 72 media_router::MediaRouter* router, |
| 61 extensions::ComponentMigrationHelper::ComponentActionDelegate* | 73 extensions::ComponentMigrationHelper::ComponentActionDelegate* |
| 62 component_action_delegate, | 74 component_action_delegate, |
| 63 extensions::ComponentMigrationHelper* component_migration_helper) | 75 extensions::ComponentMigrationHelper* component_migration_helper) |
| 64 : media_router::IssuesObserver(router), | 76 : media_router::IssuesObserver(router), |
| 65 media_router::MediaRoutesObserver(router), | 77 media_router::MediaRoutesObserver(router), |
| 66 profile_(profile), | 78 profile_(profile), |
| 67 component_action_delegate_(component_action_delegate), | 79 component_action_delegate_(component_action_delegate), |
| 68 component_migration_helper_(component_migration_helper) { | 80 component_migration_helper_(component_migration_helper), |
| 81 shown_by_policy_( |
| 82 MediaRouterActionController::IsActionShownByPolicy(profile)) { |
| 69 DCHECK(profile_); | 83 DCHECK(profile_); |
| 70 RegisterObserver(); // media_router::IssuesObserver. | 84 RegisterObserver(); // media_router::IssuesObserver. |
| 71 pref_change_registrar_.Init(profile->GetPrefs()); | 85 pref_change_registrar_.Init(profile->GetPrefs()); |
| 72 pref_change_registrar_.Add( | 86 pref_change_registrar_.Add( |
| 73 prefs::kToolbarMigratedComponentActionStatus, | 87 prefs::kToolbarMigratedComponentActionStatus, |
| 74 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction, | 88 base::Bind(&MediaRouterActionController::MaybeAddOrRemoveAction, |
| 75 base::Unretained(this))); | 89 base::Unretained(this))); |
| 76 } | 90 } |
| 77 | 91 |
| 78 void MediaRouterActionController::MaybeAddOrRemoveAction() { | 92 void MediaRouterActionController::MaybeAddOrRemoveAction() { |
| 79 if (ShouldEnableAction()) { | 93 if (ShouldEnableAction()) { |
| 80 if (!component_action_delegate_->HasComponentAction( | 94 if (!component_action_delegate_->HasComponentAction( |
| 81 ComponentToolbarActionsFactory::kMediaRouterActionId)) { | 95 ComponentToolbarActionsFactory::kMediaRouterActionId)) { |
| 82 component_action_delegate_->AddComponentAction( | 96 component_action_delegate_->AddComponentAction( |
| 83 ComponentToolbarActionsFactory::kMediaRouterActionId); | 97 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 84 } | 98 } |
| 85 } else if (component_action_delegate_->HasComponentAction( | 99 } else if (component_action_delegate_->HasComponentAction( |
| 86 ComponentToolbarActionsFactory::kMediaRouterActionId)) { | 100 ComponentToolbarActionsFactory::kMediaRouterActionId)) { |
| 87 component_action_delegate_->RemoveComponentAction( | 101 component_action_delegate_->RemoveComponentAction( |
| 88 ComponentToolbarActionsFactory::kMediaRouterActionId); | 102 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 89 } | 103 } |
| 90 } | 104 } |
| 91 | 105 |
| 92 bool MediaRouterActionController::ShouldEnableAction() const { | 106 bool MediaRouterActionController::ShouldEnableAction() const { |
| 93 return has_local_display_route_ || has_issue_ || dialog_count_ || | 107 return shown_by_policy_ || has_local_display_route_ || has_issue_ || |
| 108 dialog_count_ || |
| 94 component_migration_helper_->GetComponentActionPref( | 109 component_migration_helper_->GetComponentActionPref( |
| 95 ComponentToolbarActionsFactory::kMediaRouterActionId); | 110 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 96 } | 111 } |
| OLD | NEW |