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

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

Issue 1268553002: Reflect the current state in Media Router Action icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_H_ 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ 6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
7 7
8 #include "chrome/browser/media/router/issues_observer.h"
9 #include "chrome/browser/media/router/media_routes_observer.h"
8 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" 10 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
9 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
12 #include "extensions/browser/process_manager.h"
10 13
11 class Browser; 14 class Browser;
15 class MediaRouterAction;
12 class MediaRouterActionPlatformDelegate; 16 class MediaRouterActionPlatformDelegate;
13 17
14 namespace media_router { 18 namespace media_router {
15 class MediaRouterDialogController; 19 class MediaRouterDialogController;
20 class Issue;
Kevin M 2015/07/31 18:18:40 Sorting
apacible 2015/08/01 02:05:29 Done.
21 class MediaRoute;
22 class MediaRouter;
16 } // namespace media_router 23 } // namespace media_router
17 24
25 // Observes when there is an updated issue and passes it to |action_|.
Kevin M 2015/07/31 18:18:39 You can create a single Observer class that implem
apacible 2015/08/01 02:05:29 Switching to single Observer class. We don't alwa
26 class ActionIssuesObserver : public media_router::IssuesObserver {
27 public:
28 ActionIssuesObserver(media_router::MediaRouter* router,
29 MediaRouterAction* action);
30 ~ActionIssuesObserver() override;
31
32 // media_router::IssuesObserver:
33 void OnIssueUpdated(const media_router::Issue* issue) override;
34
35 private:
36 MediaRouterAction* action_;
37
38 DISALLOW_COPY_AND_ASSIGN(ActionIssuesObserver);
39 };
40
41 // Observes when there is an updated list of routes and passes them to
42 // |action_|.
43 class ActionMediaRoutesObserver : public media_router::MediaRoutesObserver {
44 public:
45 ActionMediaRoutesObserver(media_router::MediaRouter* router,
46 MediaRouterAction* action);
47 ~ActionMediaRoutesObserver() override;
48
49 // media_router::MediaRoutesObserver:
50 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes)
51 override;
52
53 private:
54 MediaRouterAction* action_;
55
56 DISALLOW_COPY_AND_ASSIGN(ActionMediaRoutesObserver);
57 };
58
59 // The current state of the MediaRouterAction.
60 enum MediaRouterActionState {
61 // Indicates that the current Chrome profile is not using any devices.
62 // Devices may or may not be available.
63 MEDIA_ROUTER_ACTION_IDLE,
64
65 // Indicates that the current Chrome profile is using at least one device.
66 MEDIA_ROUTER_ACTION_ACTIVE,
67
68 // Indicates a failure, e.g. session launch failure.
69 MEDIA_ROUTER_ACTION_ERROR,
70
71 // Indicates warning messages.
72 MEDIA_ROUTER_ACTION_WARNING,
73 };
74
18 // The class for the Media Router component action that will be shown in 75 // The class for the Media Router component action that will be shown in
19 // the toolbar. 76 // the toolbar.
20 class MediaRouterAction : public ToolbarActionViewController { 77 class MediaRouterAction : public ToolbarActionViewController {
21 public: 78 public:
22 explicit MediaRouterAction(Browser* browser); 79 explicit MediaRouterAction(Browser* browser);
23 ~MediaRouterAction() override; 80 ~MediaRouterAction() override;
24 81
25 // ToolbarActionViewController implementation. 82 // ToolbarActionViewController implementation.
26 const std::string& GetId() const override; 83 const std::string& GetId() const override;
27 void SetDelegate(ToolbarActionViewDelegate* delegate) override; 84 void SetDelegate(ToolbarActionViewDelegate* delegate) override;
28 gfx::Image GetIcon(content::WebContents* web_contents, 85 gfx::Image GetIcon(content::WebContents* web_contents,
29 const gfx::Size& size) override; 86 const gfx::Size& size) override;
30 base::string16 GetActionName() const override; 87 base::string16 GetActionName() const override;
31 base::string16 GetAccessibleName(content::WebContents* web_contents) 88 base::string16 GetAccessibleName(content::WebContents* web_contents)
32 const override; 89 const override;
33 base::string16 GetTooltip(content::WebContents* web_contents) 90 base::string16 GetTooltip(content::WebContents* web_contents)
34 const override; 91 const override;
35 bool IsEnabled(content::WebContents* web_contents) const override; 92 bool IsEnabled(content::WebContents* web_contents) const override;
36 bool WantsToRun(content::WebContents* web_contents) const override; 93 bool WantsToRun(content::WebContents* web_contents) const override;
37 bool HasPopup(content::WebContents* web_contents) const override; 94 bool HasPopup(content::WebContents* web_contents) const override;
38 void HidePopup() override; 95 void HidePopup() override;
39 gfx::NativeView GetPopupNativeView() override; 96 gfx::NativeView GetPopupNativeView() override;
40 ui::MenuModel* GetContextMenu() override; 97 ui::MenuModel* GetContextMenu() override;
41 bool CanDrag() const override; 98 bool CanDrag() const override;
42 bool ExecuteAction(bool by_user) override; 99 bool ExecuteAction(bool by_user) override;
43 void UpdateState() override; 100 void UpdateState() override;
44 bool DisabledClickOpensMenu() const override; 101 bool DisabledClickOpensMenu() const override;
45 102
103 // Updates |issue_|. |issue| may be null.
104 void UpdateCurrentIssue(const media_router::Issue* issue);
Kevin M 2015/07/31 18:18:40 I think "SetCurrentIssue" works better here, becau
apacible 2015/08/01 02:05:29 Done.
105
106 // Updates |local_active_route_exists_| if |routes| has an active local route.
107 // |routes| may be empty.
108 void UpdateCurrentRoutes(const std::vector<media_router::MediaRoute>& routes);
Kevin M 2015/07/31 18:18:39 Suggestion: IMO it makes more sense for this to ta
apacible 2015/08/01 02:05:29 Done.
109
46 private: 110 private:
47 // Returns a reference to the MediaRouterDialogController associated with 111 // Returns a reference to the MediaRouterDialogController associated with
48 // |delegate_|'s current WebContents. Guaranteed to be non-null. 112 // |delegate_|'s current WebContents. Guaranteed to be non-null.
49 // |delegate_| and its current WebContents must not be null. 113 // |delegate_| and its current WebContents must not be null.
50 media_router::MediaRouterDialogController* GetMediaRouterDialogController(); 114 media_router::MediaRouterDialogController* GetMediaRouterDialogController();
51 115
116 // Marked virtual to use in tests.
117 virtual media_router::MediaRouter* GetMediaRouter();
118
119 // Checks if the currents state of MediaRouterAction has changed. Updates
120 // |state_|. If |state_| has changed, update |state_| and then update
121 // MediaRouterAction's icon.
122 void MaybeUpdateIcon();
123
124 // Called when |issue_| or |local_active_route_exists_| may have changed.
125 MediaRouterActionState GetUpdatedMediaRouterActionState();
Kevin M 2015/07/31 18:18:40 No "updated"?
apacible 2015/08/01 02:05:29 Done.
126
52 const std::string id_; 127 const std::string id_;
53 const base::string16 name_; 128 const base::string16 name_;
54 129
55 // Cached icons. 130 // Cached icons.
131 gfx::Image media_router_active_icon_;
132 gfx::Image media_router_error_icon_;
56 gfx::Image media_router_idle_icon_; 133 gfx::Image media_router_idle_icon_;
134 gfx::Image media_router_warning_icon_;
135
136 // Current state of the MediaRouterAction.
137 MediaRouterActionState state_;
138
139 // Used to determine current state of the MediaRouterAction.
140 scoped_ptr<const media_router::Issue> issue_;
Kevin M 2015/07/31 18:18:39 Why have a const here? Callers will wrap this poin
apacible 2015/08/01 02:05:29 Removed.
141
142 // Whether there exists a local active route.
143 bool local_active_route_exists_;
57 144
58 ToolbarActionViewDelegate* delegate_; 145 ToolbarActionViewDelegate* delegate_;
146 scoped_ptr<media_router::IssuesObserver> issues_observer_;
147 scoped_ptr<media_router::MediaRoutesObserver> routes_observer_;
59 148
60 // The delegate to handle platform-specific implementations. 149 // The delegate to handle platform-specific implementations.
61 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; 150 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_;
62 151
63 MediaRouterContextualMenu contextual_menu_; 152 MediaRouterContextualMenu contextual_menu_;
64 153
154 friend class TestMediaRouterAction;
155 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, Initialization);
Kevin M 2015/07/31 18:18:39 These go at the top of the private: section
apacible 2015/08/01 02:05:29 Done.
156 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssues);
157 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateRoutes);
158 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssuesAndRoutes);
65 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); 159 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction);
66 }; 160 };
67 161
68 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ 162 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698