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

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: Changes per kmarshall@'s comments. 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 {
19 class Issue;
20 class MediaRoute;
21 class MediaRouter;
15 class MediaRouterDialogController; 22 class MediaRouterDialogController;
16 } // namespace media_router 23 } // namespace media_router
17 24
25 class MediaRouterActionObserver : public media_router::IssuesObserver,
Kevin M 2015/08/03 17:15:37 Add a comment about the class' function?
apacible 2015/08/03 20:47:22 Acknowledged.
26 public media_router::MediaRoutesObserver {
27 public:
28 MediaRouterActionObserver(media_router::MediaRouter* router,
Kevin M 2015/08/03 17:15:37 As per our discussion, the MediaRouter* will not c
apacible 2015/08/03 20:47:22 Done.
29 MediaRouterAction* action);
30 ~MediaRouterActionObserver() override;
31
32 // media_router::IssuesObserver:
33 void OnIssueUpdated(const media_router::Issue* issue) override;
34
35 // media_router::MediaRoutesObserver:
36 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes)
37 override;
38
39 private:
40 MediaRouterAction* action_;
41
42 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionObserver);
43 };
44
45 // The current state of the MediaRouterAction.
46 enum MediaRouterActionState {
47 // Indicates that the current Chrome profile is not using any devices.
48 // Devices may or may not be available.
49 MEDIA_ROUTER_ACTION_IDLE,
50
51 // Indicates that the current Chrome profile is using at least one device.
52 MEDIA_ROUTER_ACTION_ACTIVE,
53
54 // Indicates a failure, e.g. session launch failure.
55 MEDIA_ROUTER_ACTION_ERROR,
56
57 // Indicates warning messages.
58 MEDIA_ROUTER_ACTION_WARNING,
59 };
60
18 // The class for the Media Router component action that will be shown in 61 // The class for the Media Router component action that will be shown in
19 // the toolbar. 62 // the toolbar.
20 class MediaRouterAction : public ToolbarActionViewController { 63 class MediaRouterAction : public ToolbarActionViewController {
21 public: 64 public:
22 explicit MediaRouterAction(Browser* browser); 65 explicit MediaRouterAction(Browser* browser);
23 ~MediaRouterAction() override; 66 ~MediaRouterAction() override;
24 67
25 // ToolbarActionViewController implementation. 68 // ToolbarActionViewController implementation.
26 const std::string& GetId() const override; 69 const std::string& GetId() const override;
27 void SetDelegate(ToolbarActionViewDelegate* delegate) override; 70 void SetDelegate(ToolbarActionViewDelegate* delegate) override;
28 gfx::Image GetIcon(content::WebContents* web_contents, 71 gfx::Image GetIcon(content::WebContents* web_contents,
29 const gfx::Size& size) override; 72 const gfx::Size& size) override;
30 base::string16 GetActionName() const override; 73 base::string16 GetActionName() const override;
31 base::string16 GetAccessibleName(content::WebContents* web_contents) 74 base::string16 GetAccessibleName(content::WebContents* web_contents)
32 const override; 75 const override;
33 base::string16 GetTooltip(content::WebContents* web_contents) 76 base::string16 GetTooltip(content::WebContents* web_contents)
34 const override; 77 const override;
35 bool IsEnabled(content::WebContents* web_contents) const override; 78 bool IsEnabled(content::WebContents* web_contents) const override;
36 bool WantsToRun(content::WebContents* web_contents) const override; 79 bool WantsToRun(content::WebContents* web_contents) const override;
37 bool HasPopup(content::WebContents* web_contents) const override; 80 bool HasPopup(content::WebContents* web_contents) const override;
38 void HidePopup() override; 81 void HidePopup() override;
39 gfx::NativeView GetPopupNativeView() override; 82 gfx::NativeView GetPopupNativeView() override;
40 ui::MenuModel* GetContextMenu() override; 83 ui::MenuModel* GetContextMenu() override;
41 bool CanDrag() const override; 84 bool CanDrag() const override;
42 bool ExecuteAction(bool by_user) override; 85 bool ExecuteAction(bool by_user) override;
43 void UpdateState() override; 86 void UpdateState() override;
44 bool DisabledClickOpensMenu() const override; 87 bool DisabledClickOpensMenu() const override;
45 88
89 // Updates |issue_|. |issue| may be null.
90 void SetCurrentIssue(const media_router::Issue* issue);
91
92 // Updates |has_local_routes_|.
93 void SetHasLocalRoutes(bool has_local_routes);
94
46 private: 95 private:
96 friend class TestMediaRouterAction;
97 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, Initialization);
98 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssues);
99 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateRoutes);
100 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssuesAndRoutes);
101
47 // Returns a reference to the MediaRouterDialogController associated with 102 // Returns a reference to the MediaRouterDialogController associated with
48 // |delegate_|'s current WebContents. Guaranteed to be non-null. 103 // |delegate_|'s current WebContents. Guaranteed to be non-null.
49 // |delegate_| and its current WebContents must not be null. 104 // |delegate_| and its current WebContents must not be null.
50 media_router::MediaRouterDialogController* GetMediaRouterDialogController(); 105 media_router::MediaRouterDialogController* GetMediaRouterDialogController();
51 106
107 // Marked virtual to use in tests.
108 virtual media_router::MediaRouter* GetMediaRouter();
109
110 // Checks if the currents state of MediaRouterAction has changed. Updates
111 // |state_|. If |state_| has changed, update |state_| and then update
112 // MediaRouterAction's icon.
113 void MaybeUpdateIcon();
114
115 // Called when |issue_| or |local_active_route_exists_| may have changed.
116 MediaRouterActionState GetMediaRouterActionState();
117
52 const std::string id_; 118 const std::string id_;
53 const base::string16 name_; 119 const base::string16 name_;
54 120
55 // Cached icons. 121 // Cached icons.
122 gfx::Image media_router_active_icon_;
123 gfx::Image media_router_error_icon_;
56 gfx::Image media_router_idle_icon_; 124 gfx::Image media_router_idle_icon_;
125 gfx::Image media_router_warning_icon_;
126
127 // Current state of the MediaRouterAction.
128 MediaRouterActionState state_;
129
130 // Used to determine current state of the MediaRouterAction.
131 scoped_ptr<media_router::Issue> issue_;
132
133 // Whether there exists a local active route.
134 bool has_local_routes_;
57 135
58 ToolbarActionViewDelegate* delegate_; 136 ToolbarActionViewDelegate* delegate_;
137 // scoped_ptr<media_router::IssuesObserver> issues_observer_;
Kevin M 2015/08/03 17:15:37 Remove these?
apacible 2015/08/03 20:47:22 Done.
138 // scoped_ptr<media_router::MediaRoutesObserver> routes_observer_;
139 scoped_ptr<MediaRouterActionObserver> action_observer_;
59 140
60 // The delegate to handle platform-specific implementations. 141 // The delegate to handle platform-specific implementations.
61 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; 142 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_;
62 143
63 MediaRouterContextualMenu contextual_menu_; 144 MediaRouterContextualMenu contextual_menu_;
64 145
65 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); 146 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction);
66 }; 147 };
67 148
68 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ 149 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698