Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| 12 class MediaRouterActionPlatformDelegate; | 15 class MediaRouterActionPlatformDelegate; |
| 13 | 16 |
| 14 namespace media_router { | 17 namespace media_router { |
| 15 class MediaRouterDialogController; | 18 class MediaRouterDialogController; |
| 16 } // namespace media_router | 19 } // namespace media_router |
| 17 | 20 |
| 21 // The current state of the MediaRouterAction. | |
| 22 enum MediaRouterActionState { | |
|
Peter Kasting
2015/08/03 21:28:51
Why not make this public inside MediaRouterAction
apacible
2015/08/05 06:47:55
Acknowledged; ended up removing the enum.
| |
| 23 // Indicates that the current Chrome profile is not using any devices. | |
| 24 // Devices may or may not be available. | |
| 25 MEDIA_ROUTER_ACTION_IDLE, | |
| 26 | |
| 27 // Indicates that the current Chrome profile is using at least one device. | |
| 28 MEDIA_ROUTER_ACTION_ACTIVE, | |
| 29 | |
| 30 // Indicates a failure, e.g. session launch failure. | |
| 31 MEDIA_ROUTER_ACTION_ERROR, | |
| 32 | |
| 33 // Indicates warning messages. | |
| 34 MEDIA_ROUTER_ACTION_WARNING, | |
| 35 }; | |
| 36 | |
| 18 // The class for the Media Router component action that will be shown in | 37 // The class for the Media Router component action that will be shown in |
| 19 // the toolbar. | 38 // the toolbar. |
| 20 class MediaRouterAction : public ToolbarActionViewController { | 39 class MediaRouterAction : public ToolbarActionViewController, |
| 40 public media_router::IssuesObserver, | |
| 41 public media_router::MediaRoutesObserver { | |
| 21 public: | 42 public: |
| 22 explicit MediaRouterAction(Browser* browser); | 43 explicit MediaRouterAction(Browser* browser); |
| 23 ~MediaRouterAction() override; | 44 ~MediaRouterAction() override; |
| 24 | 45 |
| 25 // ToolbarActionViewController implementation. | 46 // ToolbarActionViewController implementation. |
| 26 const std::string& GetId() const override; | 47 const std::string& GetId() const override; |
| 27 void SetDelegate(ToolbarActionViewDelegate* delegate) override; | 48 void SetDelegate(ToolbarActionViewDelegate* delegate) override; |
| 28 gfx::Image GetIcon(content::WebContents* web_contents, | 49 gfx::Image GetIcon(content::WebContents* web_contents, |
| 29 const gfx::Size& size) override; | 50 const gfx::Size& size) override; |
| 30 base::string16 GetActionName() const override; | 51 base::string16 GetActionName() const override; |
| 31 base::string16 GetAccessibleName(content::WebContents* web_contents) | 52 base::string16 GetAccessibleName(content::WebContents* web_contents) |
| 32 const override; | 53 const override; |
| 33 base::string16 GetTooltip(content::WebContents* web_contents) | 54 base::string16 GetTooltip(content::WebContents* web_contents) |
| 34 const override; | 55 const override; |
| 35 bool IsEnabled(content::WebContents* web_contents) const override; | 56 bool IsEnabled(content::WebContents* web_contents) const override; |
| 36 bool WantsToRun(content::WebContents* web_contents) const override; | 57 bool WantsToRun(content::WebContents* web_contents) const override; |
| 37 bool HasPopup(content::WebContents* web_contents) const override; | 58 bool HasPopup(content::WebContents* web_contents) const override; |
| 38 void HidePopup() override; | 59 void HidePopup() override; |
| 39 gfx::NativeView GetPopupNativeView() override; | 60 gfx::NativeView GetPopupNativeView() override; |
| 40 ui::MenuModel* GetContextMenu() override; | 61 ui::MenuModel* GetContextMenu() override; |
| 41 bool CanDrag() const override; | 62 bool CanDrag() const override; |
| 42 bool ExecuteAction(bool by_user) override; | 63 bool ExecuteAction(bool by_user) override; |
| 43 void UpdateState() override; | 64 void UpdateState() override; |
| 44 bool DisabledClickOpensMenu() const override; | 65 bool DisabledClickOpensMenu() const override; |
| 45 | 66 |
| 67 // media_router::IssuesObserver: | |
| 68 void OnIssueUpdated(const media_router::Issue* issue) override; | |
| 69 | |
| 70 // media_router::MediaRoutesObserver: | |
| 71 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes) | |
| 72 override; | |
| 73 | |
| 46 private: | 74 private: |
| 75 friend class TestMediaRouterAction; | |
| 76 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, Initialization); | |
| 77 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssues); | |
| 78 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateRoutes); | |
| 79 FRIEND_TEST_ALL_PREFIXES(MediaRouterActionUnitTest, UpdateIssuesAndRoutes); | |
|
Peter Kasting
2015/08/03 21:28:51
I think in this case these friend declarations sig
apacible
2015/08/05 06:47:55
Thanks for bringing this up; from the changes (bas
| |
| 80 | |
| 47 // Returns a reference to the MediaRouterDialogController associated with | 81 // Returns a reference to the MediaRouterDialogController associated with |
| 48 // |delegate_|'s current WebContents. Guaranteed to be non-null. | 82 // |delegate_|'s current WebContents. Guaranteed to be non-null. |
| 49 // |delegate_| and its current WebContents must not be null. | 83 // |delegate_| and its current WebContents must not be null. |
| 50 media_router::MediaRouterDialogController* GetMediaRouterDialogController(); | 84 media_router::MediaRouterDialogController* GetMediaRouterDialogController(); |
| 51 | 85 |
| 86 // Marked virtual to use in tests. | |
|
Peter Kasting
2015/08/03 21:28:51
Nit: "Overridden by tests." would probably be clea
apacible
2015/08/05 06:47:55
Done.
| |
| 87 virtual media_router::MediaRouter* GetMediaRouter(Browser* browser); | |
| 88 | |
| 89 // Checks if the currents state of MediaRouterAction has changed. Updates | |
| 90 // |state_|. If |state_| has changed, update |state_| and then update | |
|
Peter Kasting
2015/08/03 21:28:51
Nit: update -> updates (2x)
apacible
2015/08/05 06:47:55
Done.
| |
| 91 // MediaRouterAction's icon. | |
|
Peter Kasting
2015/08/03 21:28:51
This updates |state_|, not just the icon. So eith
apacible
2015/08/05 06:47:55
Switched to keeping track of the current icon rath
| |
| 92 void MaybeUpdateIcon(); | |
| 93 | |
| 94 // Called when |issue_| or |local_active_route_exists_| may have changed. | |
|
Peter Kasting
2015/08/03 21:28:51
This comment is confusing, since it's not really p
apacible
2015/08/05 06:47:55
Done.
| |
| 95 MediaRouterActionState GetMediaRouterActionState(); | |
| 96 | |
| 52 const std::string id_; | 97 const std::string id_; |
| 53 const base::string16 name_; | 98 const base::string16 name_; |
| 54 | 99 |
| 55 // Cached icons. | 100 // Cached icons. |
| 101 gfx::Image media_router_active_icon_; | |
| 102 gfx::Image media_router_error_icon_; | |
| 56 gfx::Image media_router_idle_icon_; | 103 gfx::Image media_router_idle_icon_; |
| 104 gfx::Image media_router_warning_icon_; | |
| 105 | |
| 106 // Current state of the MediaRouterAction. | |
| 107 MediaRouterActionState state_; | |
| 108 | |
| 109 // Used to determine current state of the MediaRouterAction. | |
|
Peter Kasting
2015/08/03 21:28:51
This doesn't actually say what |issue_| is, how it
apacible
2015/08/05 06:47:55
Done.
| |
| 110 scoped_ptr<media_router::Issue> issue_; | |
| 111 | |
| 112 // Whether there exists a local active route. | |
| 113 bool has_local_routes_; | |
| 57 | 114 |
| 58 ToolbarActionViewDelegate* delegate_; | 115 ToolbarActionViewDelegate* delegate_; |
| 59 | 116 |
| 60 // The delegate to handle platform-specific implementations. | 117 // The delegate to handle platform-specific implementations. |
| 61 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; | 118 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; |
| 62 | 119 |
| 63 MediaRouterContextualMenu contextual_menu_; | 120 MediaRouterContextualMenu contextual_menu_; |
| 64 | 121 |
| 65 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); | 122 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); |
| 66 }; | 123 }; |
| 67 | 124 |
| 68 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ | 125 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ |
| OLD | NEW |