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

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

Issue 2410553002: Show Media Router toolbar icon ephemerally for MR dialogs (Closed)
Patch Set: Address Mark's comments Created 4 years, 1 month 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 #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" 10 #include "chrome/browser/extensions/component_migration_helper.h"
11 #include "chrome/browser/media/router/issues_observer.h" 11 #include "chrome/browser/media/router/issues_observer.h"
12 #include "chrome/browser/media/router/media_routes_observer.h" 12 #include "chrome/browser/media/router/media_routes_observer.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "components/prefs/pref_change_registrar.h" 14 #include "components/prefs/pref_change_registrar.h"
15 15
16 using extensions::ComponentMigrationHelper; 16 using extensions::ComponentMigrationHelper;
17 17
18 // Controller for MediaRouterAction that determines when to show and hide the 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 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. 20 // profile, and it should only be used on the UI thread.
21 class MediaRouterActionController : public media_router::IssuesObserver, 21 class MediaRouterActionController : public media_router::IssuesObserver,
22 public media_router::MediaRoutesObserver { 22 public media_router::MediaRoutesObserver {
23 public: 23 public:
24 explicit MediaRouterActionController(Profile* profile); 24 explicit MediaRouterActionController(Profile* profile);
25 // Constructor for injecting dependencies in tests.
26 MediaRouterActionController(
27 Profile* profile,
28 media_router::MediaRouter* router,
29 ComponentMigrationHelper::ComponentActionDelegate*
30 component_action_delegate,
31 ComponentMigrationHelper* component_migration_helper);
25 ~MediaRouterActionController() override; 32 ~MediaRouterActionController() override;
26 33
27 // media_router::IssuesObserver: 34 // media_router::IssuesObserver:
28 void OnIssueUpdated(const media_router::Issue* issue) override; 35 void OnIssueUpdated(const media_router::Issue* issue) override;
29 36
30 // media_router::MediaRoutesObserver: 37 // media_router::MediaRoutesObserver:
31 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, 38 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes,
32 const std::vector<media_router::MediaRoute::Id>& 39 const std::vector<media_router::MediaRoute::Id>&
33 joinable_route_ids) override; 40 joinable_route_ids) override;
34 41
42 // May show the action icon if any dialog is shown, or hide it otherwise.
mark a. foltz 2016/11/01 02:00:08 I found this comment a bit confusing. Did you me
takumif 2016/11/02 03:16:54 Yeah that sounds better. Thanks.
43 // Overridden in tests.
44 virtual void OnDialogShown();
45 virtual void OnDialogHidden();
46
35 private: 47 private:
36 friend class MediaRouterActionControllerUnitTest; 48 friend class MediaRouterActionControllerUnitTest;
37 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest, EphemeralIcon); 49 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest,
38 50 EphemeralIconForRoutesAndIssues);
39 // Constructor for injecting dependencies in tests. 51 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest,
40 MediaRouterActionController( 52 EphemeralIconForDialog);
41 Profile* profile,
42 media_router::MediaRouter* router,
43 ComponentMigrationHelper::ComponentActionDelegate*
44 component_action_delegate,
45 ComponentMigrationHelper* component_migration_helper);
46 53
47 // Adds or removes the Media Router action icon to/from 54 // Adds or removes the Media Router action icon to/from
48 // |component_action_delegate_| if necessary, depending on whether or not 55 // |component_action_delegate_| if necessary, depending on whether or not
49 // we have issues or local routes. 56 // we have issues, local routes or a dialog.
50 void MaybeAddOrRemoveAction(); 57 virtual void MaybeAddOrRemoveAction();
51 58
52 // Returns |true| if the Media Router action should be present on the toolbar 59 // Returns |true| if the Media Router action should be present on the toolbar
53 // or the overflow menu. 60 // or the overflow menu.
54 bool ShouldEnableAction() const; 61 bool ShouldEnableAction() const;
55 62
56 // The profile |this| is associated with. There should be one instance of this 63 // The profile |this| is associated with. There should be one instance of this
57 // class per profile. 64 // class per profile.
58 Profile* const profile_; 65 Profile* const profile_;
59 66
60 // The delegate that is responsible for showing and hiding the icon on the 67 // The delegate that is responsible for showing and hiding the icon on the
61 // toolbar. It outlives |this|. 68 // toolbar. It outlives |this|.
62 ComponentMigrationHelper::ComponentActionDelegate* const 69 ComponentMigrationHelper::ComponentActionDelegate* const
63 component_action_delegate_; 70 component_action_delegate_;
64 71
65 // Responsible for changing the pref to always show or hide component actions. 72 // Responsible for changing the pref to always show or hide component actions.
66 // It is owned by ToolbarActionsModel and outlives |this|. 73 // It is owned by ToolbarActionsModel and outlives |this|.
67 ComponentMigrationHelper* const component_migration_helper_; 74 ComponentMigrationHelper* const component_migration_helper_;
68 75
69 bool has_issue_ = false; 76 bool has_issue_ = false;
70 bool has_local_display_route_ = false; 77 bool has_local_display_route_ = false;
71 78
79 // The number of dialogs that are currently open.
80 size_t dialog_count_ = 0;
81
72 PrefChangeRegistrar pref_change_registrar_; 82 PrefChangeRegistrar pref_change_registrar_;
73 83
74 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController); 84 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController);
75 }; 85 };
76 86
77 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ 87 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698