Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/browser/extensions/component_migration_helper.h" | |
| 11 #include "chrome/browser/media/router/issues_observer.h" | 10 #include "chrome/browser/media/router/issues_observer.h" |
| 12 #include "chrome/browser/media/router/media_routes_observer.h" | 11 #include "chrome/browser/media/router/media_routes_observer.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/toolbar/component_action_delegate.h" | |
| 14 #include "components/prefs/pref_change_registrar.h" | 14 #include "components/prefs/pref_change_registrar.h" |
| 15 | 15 |
| 16 using extensions::ComponentMigrationHelper; | |
| 17 | |
| 18 // Controller for MediaRouterAction that determines when to show and hide the | 16 // 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 | 17 // 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. | 18 // profile, and it should only be used on the UI thread. |
| 21 class MediaRouterActionController : public media_router::IssuesObserver, | 19 class MediaRouterActionController : public media_router::IssuesObserver, |
| 22 public media_router::MediaRoutesObserver { | 20 public media_router::MediaRoutesObserver { |
| 23 public: | 21 public: |
| 24 explicit MediaRouterActionController(Profile* profile); | 22 explicit MediaRouterActionController(Profile* profile); |
| 25 // Constructor for injecting dependencies in tests. | 23 // Constructor for injecting dependencies in tests. |
| 26 MediaRouterActionController( | 24 MediaRouterActionController( |
| 27 Profile* profile, | 25 Profile* profile, |
| 28 media_router::MediaRouter* router, | 26 media_router::MediaRouter* router, |
| 29 ComponentMigrationHelper::ComponentActionDelegate* | 27 ComponentActionDelegate* component_action_delegate); |
|
imcheng
2017/02/08 22:59:29
Can this be forward declared?
takumif
2017/02/09 00:05:56
Done.
| |
| 30 component_action_delegate, | |
| 31 ComponentMigrationHelper* component_migration_helper); | |
| 32 ~MediaRouterActionController() override; | 28 ~MediaRouterActionController() override; |
| 33 | 29 |
| 34 // Whether the media router action is shown by an administrator policy. | 30 // Whether the media router action is shown by an administrator policy. |
| 35 static bool IsActionShownByPolicy(Profile* profile); | 31 static bool IsActionShownByPolicy(Profile* profile); |
| 36 | 32 |
| 33 // Gets and sets the preference for whether the media router action should be | |
| 34 // pinned to the toolbar/overflow menu. | |
| 35 static bool GetAlwaysShowActionPref(Profile* profile); | |
| 36 static void SetAlwaysShowActionPref(Profile* profile, bool always_show); | |
| 37 | |
| 37 // media_router::IssuesObserver: | 38 // media_router::IssuesObserver: |
| 38 void OnIssue(const media_router::Issue& issue) override; | 39 void OnIssue(const media_router::Issue& issue) override; |
| 39 void OnIssuesCleared() override; | 40 void OnIssuesCleared() override; |
| 40 | 41 |
| 41 // media_router::MediaRoutesObserver: | 42 // media_router::MediaRoutesObserver: |
| 42 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, | 43 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, |
| 43 const std::vector<media_router::MediaRoute::Id>& | 44 const std::vector<media_router::MediaRoute::Id>& |
| 44 joinable_route_ids) override; | 45 joinable_route_ids) override; |
| 45 | 46 |
| 46 // Called when a Media Router dialog is shown or hidden, and updates the | 47 // Called when a Media Router dialog is shown or hidden, and updates the |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 63 // Returns |true| if the Media Router action should be present on the toolbar | 64 // Returns |true| if the Media Router action should be present on the toolbar |
| 64 // or the overflow menu. | 65 // or the overflow menu. |
| 65 bool ShouldEnableAction() const; | 66 bool ShouldEnableAction() const; |
| 66 | 67 |
| 67 // The profile |this| is associated with. There should be one instance of this | 68 // The profile |this| is associated with. There should be one instance of this |
| 68 // class per profile. | 69 // class per profile. |
| 69 Profile* const profile_; | 70 Profile* const profile_; |
| 70 | 71 |
| 71 // The delegate that is responsible for showing and hiding the icon on the | 72 // The delegate that is responsible for showing and hiding the icon on the |
| 72 // toolbar. It outlives |this|. | 73 // toolbar. It outlives |this|. |
| 73 ComponentMigrationHelper::ComponentActionDelegate* const | 74 ComponentActionDelegate* const component_action_delegate_; |
| 74 component_action_delegate_; | |
| 75 | |
| 76 // Responsible for changing the pref to always show or hide component actions. | |
| 77 // It is owned by ToolbarActionsModel and outlives |this|. | |
| 78 ComponentMigrationHelper* const component_migration_helper_; | |
| 79 | 75 |
| 80 bool has_issue_ = false; | 76 bool has_issue_ = false; |
| 81 bool has_local_display_route_ = false; | 77 bool has_local_display_route_ = false; |
| 82 | 78 |
| 83 // Whether the media router action is shown by an administrator policy. | 79 // Whether the media router action is shown by an administrator policy. |
| 84 bool shown_by_policy_; | 80 bool shown_by_policy_; |
| 85 | 81 |
| 86 // The number of dialogs that are currently open. | 82 // The number of dialogs that are currently open. |
| 87 size_t dialog_count_ = 0; | 83 size_t dialog_count_ = 0; |
| 88 | 84 |
| 89 PrefChangeRegistrar pref_change_registrar_; | 85 PrefChangeRegistrar pref_change_registrar_; |
| 90 | 86 |
| 91 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController); | 87 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController); |
| 92 }; | 88 }; |
| 93 | 89 |
| 94 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ | 90 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ |
| OLD | NEW |