OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "chrome/browser/extensions/component_migration_helper.h" |
| 11 #include "chrome/browser/media/router/issues_observer.h" |
| 12 #include "chrome/browser/media/router/media_routes_observer.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "components/prefs/pref_change_registrar.h" |
| 15 |
| 16 using extensions::ComponentMigrationHelper; |
| 17 |
| 18 // Controller for MediaRouterAction that determines when to show and hide the |
| 19 // action icon on the toolbar. There should be one instance of this class per |
| 20 // profile, and it should only be used on the UI thread. |
| 21 class MediaRouterActionController : public media_router::IssuesObserver, |
| 22 public media_router::MediaRoutesObserver { |
| 23 public: |
| 24 explicit MediaRouterActionController(Profile* profile); |
| 25 ~MediaRouterActionController() override; |
| 26 |
| 27 // media_router::IssuesObserver: |
| 28 void OnIssueUpdated(const media_router::Issue* issue) override; |
| 29 |
| 30 // media_router::MediaRoutesObserver: |
| 31 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, |
| 32 const std::vector<media_router::MediaRoute::Id>& |
| 33 joinable_route_ids) override; |
| 34 |
| 35 private: |
| 36 friend class MediaRouterActionControllerUnitTest; |
| 37 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest, EphemeralIcon); |
| 38 |
| 39 // Constructor for injecting dependencies in tests. |
| 40 MediaRouterActionController( |
| 41 Profile* profile, |
| 42 media_router::MediaRouter* router, |
| 43 ComponentMigrationHelper::ComponentActionDelegate* |
| 44 component_action_delegate, |
| 45 ComponentMigrationHelper* component_migration_helper); |
| 46 |
| 47 // Adds or removes the Media Router action icon to/from |
| 48 // |component_action_delegate_| if necessary, depending on whether or not |
| 49 // we have issues or local routes. |
| 50 void MaybeAddOrRemoveAction(); |
| 51 |
| 52 // Returns |true| if the Media Router action should be present on the toolbar |
| 53 // or the overflow menu. |
| 54 bool ShouldEnableAction() const; |
| 55 |
| 56 // The profile |this| is associated with. There should be one instance of this |
| 57 // class per profile. |
| 58 Profile* const profile_; |
| 59 |
| 60 // The delegate that is responsible for showing and hiding the icon on the |
| 61 // toolbar. It outlives |this|. |
| 62 ComponentMigrationHelper::ComponentActionDelegate* const |
| 63 component_action_delegate_; |
| 64 |
| 65 // Responsible for changing the pref to always show or hide component actions. |
| 66 // It is owned by ToolbarActionsModel and outlives |this|. |
| 67 ComponentMigrationHelper* const component_migration_helper_; |
| 68 |
| 69 bool has_issue_ = false; |
| 70 bool has_local_display_route_ = false; |
| 71 |
| 72 PrefChangeRegistrar pref_change_registrar_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController); |
| 75 }; |
| 76 |
| 77 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ |
OLD | NEW |