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

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: Deleted the first patch set on accident, responded to Mark's comments inline below Created 4 years, 2 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 #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 namespace media_router {
19 class MockMediaRouterActionController;
20 } // namespace media_router
21
18 // Controller for MediaRouterAction that determines when to show and hide the 22 // 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 23 // 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. 24 // profile, and it should only be used on the UI thread.
21 class MediaRouterActionController : public media_router::IssuesObserver, 25 class MediaRouterActionController : public media_router::IssuesObserver,
22 public media_router::MediaRoutesObserver { 26 public media_router::MediaRoutesObserver {
23 public: 27 public:
24 explicit MediaRouterActionController(Profile* profile); 28 explicit MediaRouterActionController(Profile* profile);
25 ~MediaRouterActionController() override; 29 ~MediaRouterActionController() override;
26 30
27 // media_router::IssuesObserver: 31 // media_router::IssuesObserver:
28 void OnIssueUpdated(const media_router::Issue* issue) override; 32 void OnIssueUpdated(const media_router::Issue* issue) override;
29 33
30 // media_router::MediaRoutesObserver: 34 // media_router::MediaRoutesObserver:
31 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, 35 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes,
32 const std::vector<media_router::MediaRoute::Id>& 36 const std::vector<media_router::MediaRoute::Id>&
33 joinable_route_ids) override; 37 joinable_route_ids) override;
34 38
39 // Overridden in tests.
mark a. foltz 2016/10/17 18:57:40 While that's true, can you also document what thes
takumif 2016/10/27 23:06:38 Done.
40 virtual void OnDialogShown();
41 virtual void OnDialogHidden();
42
35 private: 43 private:
36 friend class MediaRouterActionControllerUnitTest; 44 friend class MediaRouterActionControllerUnitTest;
37 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest, EphemeralIcon); 45 friend class media_router::MockMediaRouterActionController;
46 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest,
47 EphemeralIconForRoutesAndIssues);
48 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionControllerUnitTest,
49 EphemeralIconForDialog);
38 50
39 // Constructor for injecting dependencies in tests. 51 // Constructor for injecting dependencies in tests.
mark a. foltz 2016/10/17 18:57:40 Would prefer making this public versus having to f
takumif 2016/10/27 23:06:38 Done.
40 MediaRouterActionController( 52 MediaRouterActionController(
41 Profile* profile, 53 Profile* profile,
42 media_router::MediaRouter* router, 54 media_router::MediaRouter* router,
43 ComponentMigrationHelper::ComponentActionDelegate* 55 ComponentMigrationHelper::ComponentActionDelegate*
44 component_action_delegate, 56 component_action_delegate,
45 ComponentMigrationHelper* component_migration_helper); 57 ComponentMigrationHelper* component_migration_helper);
46 58
47 // Adds or removes the Media Router action icon to/from 59 // Adds or removes the Media Router action icon to/from
48 // |component_action_delegate_| if necessary, depending on whether or not 60 // |component_action_delegate_| if necessary, depending on whether or not
49 // we have issues or local routes. 61 // we have issues, local routes or a dialog.
50 void MaybeAddOrRemoveAction(); 62 virtual void MaybeAddOrRemoveAction();
51 63
52 // 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
53 // or the overflow menu. 65 // or the overflow menu.
54 bool ShouldEnableAction() const; 66 bool ShouldEnableAction() const;
55 67
56 // 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
57 // class per profile. 69 // class per profile.
58 Profile* const profile_; 70 Profile* const profile_;
59 71
60 // 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
61 // toolbar. It outlives |this|. 73 // toolbar. It outlives |this|.
62 ComponentMigrationHelper::ComponentActionDelegate* const 74 ComponentMigrationHelper::ComponentActionDelegate* const
63 component_action_delegate_; 75 component_action_delegate_;
64 76
65 // Responsible for changing the pref to always show or hide component actions. 77 // Responsible for changing the pref to always show or hide component actions.
66 // It is owned by ToolbarActionsModel and outlives |this|. 78 // It is owned by ToolbarActionsModel and outlives |this|.
67 ComponentMigrationHelper* const component_migration_helper_; 79 ComponentMigrationHelper* const component_migration_helper_;
68 80
69 bool has_issue_ = false; 81 bool has_issue_ = false;
70 bool has_local_display_route_ = false; 82 bool has_local_display_route_ = false;
71 83
84 // The number of dialogs that are currently open.
85 size_t dialog_count_ = 0;
86
72 PrefChangeRegistrar pref_change_registrar_; 87 PrefChangeRegistrar pref_change_registrar_;
73 88
74 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController); 89 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionController);
75 }; 90 };
76 91
77 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_ 92 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698