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

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

Issue 1383653002: MediaRouterAction: Only observe Media Routes when there is a local route. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 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 "base/scoped_observer.h" 8 #include "base/scoped_observer.h"
9 #include "chrome/browser/media/router/issues_observer.h" 9 #include "chrome/browser/media/router/issues_observer.h"
10 #include "chrome/browser/media/router/local_media_routes_observer.h"
10 #include "chrome/browser/media/router/media_routes_observer.h" 11 #include "chrome/browser/media/router/media_routes_observer.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
12 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h" 13 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
14 15
15 class Browser; 16 class Browser;
16 class MediaRouterActionPlatformDelegate; 17 class MediaRouterActionPlatformDelegate;
17 class TabStripModel; 18 class TabStripModel;
18 19
19 namespace media_router { 20 namespace media_router {
20 class MediaRouterDialogControllerImpl; 21 class MediaRouterDialogControllerImpl;
21 } // namespace media_router 22 } // namespace media_router
22 23
23 // The class for the Media Router component action that will be shown in 24 // The class for the Media Router component action that will be shown in
24 // the toolbar. 25 // the toolbar.
25 class MediaRouterAction : public ToolbarActionViewController, 26 class MediaRouterAction : public ToolbarActionViewController,
26 public media_router::IssuesObserver, 27 public media_router::IssuesObserver,
27 public media_router::MediaRoutesObserver, 28 public media_router::LocalMediaRoutesObserver,
28 public TabStripModelObserver { 29 public TabStripModelObserver {
29 public: 30 public:
30 explicit MediaRouterAction(Browser* browser); 31 explicit MediaRouterAction(Browser* browser);
31 ~MediaRouterAction() override; 32 ~MediaRouterAction() override;
32 33
33 // ToolbarActionViewController implementation. 34 // ToolbarActionViewController implementation.
34 std::string GetId() const override; 35 std::string GetId() const override;
35 void SetDelegate(ToolbarActionViewDelegate* delegate) override; 36 void SetDelegate(ToolbarActionViewDelegate* delegate) override;
36 gfx::Image GetIcon(content::WebContents* web_contents, 37 gfx::Image GetIcon(content::WebContents* web_contents,
37 const gfx::Size& size) override; 38 const gfx::Size& size) override;
38 base::string16 GetActionName() const override; 39 base::string16 GetActionName() const override;
39 base::string16 GetAccessibleName(content::WebContents* web_contents) 40 base::string16 GetAccessibleName(content::WebContents* web_contents)
40 const override; 41 const override;
41 base::string16 GetTooltip(content::WebContents* web_contents) 42 base::string16 GetTooltip(content::WebContents* web_contents)
42 const override; 43 const override;
43 bool IsEnabled(content::WebContents* web_contents) const override; 44 bool IsEnabled(content::WebContents* web_contents) const override;
44 bool WantsToRun(content::WebContents* web_contents) const override; 45 bool WantsToRun(content::WebContents* web_contents) const override;
45 bool HasPopup(content::WebContents* web_contents) const override; 46 bool HasPopup(content::WebContents* web_contents) const override;
46 void HidePopup() override; 47 void HidePopup() override;
47 gfx::NativeView GetPopupNativeView() override; 48 gfx::NativeView GetPopupNativeView() override;
48 ui::MenuModel* GetContextMenu() override; 49 ui::MenuModel* GetContextMenu() override;
49 bool ExecuteAction(bool by_user) override; 50 bool ExecuteAction(bool by_user) override;
50 void UpdateState() override; 51 void UpdateState() override;
51 bool DisabledClickOpensMenu() const override; 52 bool DisabledClickOpensMenu() const override;
52 53
53 // media_router::IssuesObserver: 54 // media_router::IssuesObserver:
54 void OnIssueUpdated(const media_router::Issue* issue) override; 55 void OnIssueUpdated(const media_router::Issue* issue) override;
55 56
56 // media_router::MediaRoutesObserver: 57 // media_router::LocalMediaRoutesObserver:
57 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes) 58 void OnLocalRouteCreated() override;
58 override;
59 59
60 // ToolbarStripModelObserver: 60 // ToolbarStripModelObserver:
61 void ActiveTabChanged(content::WebContents* old_contents, 61 void ActiveTabChanged(content::WebContents* old_contents,
62 content::WebContents* new_contents, 62 content::WebContents* new_contents,
63 int index, 63 int index,
64 int reason) override; 64 int reason) override;
65 65
66 void OnPopupHidden(); 66 void OnPopupHidden();
67 void OnPopupShown(); 67 void OnPopupShown();
68 68
69 void SetHasLocalRoute(bool has_local_route);
70
69 private: 71 private:
72 class ActionMediaRoutesObserver : public media_router::MediaRoutesObserver {
73 public:
74 ActionMediaRoutesObserver(media_router::MediaRouter* router,
75 MediaRouterAction* action);
76 ~ActionMediaRoutesObserver() override;
77
78 // media_router::MediaRoutesObserver:
79 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes)
80 override;
81
82 private:
83 MediaRouterAction* action_;
imcheng 2015/10/01 18:46:50 MediaRouterAction* const action_;
apacible 2015/10/01 23:21:47 Done (moved to MediaRouterMojoImpl).
84
85 DISALLOW_COPY_AND_ASSIGN(ActionMediaRoutesObserver);
86 };
87
70 void UpdatePopupState(); 88 void UpdatePopupState();
71 89
72 // Returns a reference to the MediaRouterDialogControllerImpl associated with 90 // Returns a reference to the MediaRouterDialogControllerImpl associated with
73 // |delegate_|'s current WebContents. Guaranteed to be non-null. 91 // |delegate_|'s current WebContents. Guaranteed to be non-null.
74 // |delegate_| and its current WebContents must not be null. 92 // |delegate_| and its current WebContents must not be null.
75 // Marked virtual for tests. 93 // Marked virtual for tests.
76 virtual media_router::MediaRouterDialogControllerImpl* 94 virtual media_router::MediaRouterDialogControllerImpl*
77 GetMediaRouterDialogController(); 95 GetMediaRouterDialogController();
78 96
79 // Overridden by tests. 97 // Overridden by tests.
(...skipping 25 matching lines...) Expand all
105 // in OnIssueUpdated(), which is called by the IssueManager. 123 // in OnIssueUpdated(), which is called by the IssueManager.
106 scoped_ptr<media_router::Issue> issue_; 124 scoped_ptr<media_router::Issue> issue_;
107 125
108 // Whether a local active route exists. 126 // Whether a local active route exists.
109 bool has_local_route_; 127 bool has_local_route_;
110 128
111 ToolbarActionViewDelegate* delegate_; 129 ToolbarActionViewDelegate* delegate_;
112 130
113 Browser* const browser_; 131 Browser* const browser_;
114 132
133 // |routes_observer_| listens for updated MediaRoutes. We only listen when
134 // there is a local route that could be closed. |routes_observer_| is only
135 // set and registered on creation of |this| or when |has_local_route_| is
136 // true.
137 scoped_ptr<media_router::MediaRoutesObserver> routes_observer_;
138
115 // The delegate to handle platform-specific implementations. 139 // The delegate to handle platform-specific implementations.
116 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; 140 scoped_ptr<MediaRouterActionPlatformDelegate> platform_delegate_;
117 141
118 MediaRouterContextualMenu contextual_menu_; 142 MediaRouterContextualMenu contextual_menu_;
119 143
120 ScopedObserver<TabStripModel, TabStripModelObserver> 144 ScopedObserver<TabStripModel, TabStripModelObserver>
121 tab_strip_model_observer_; 145 tab_strip_model_observer_;
122 146
123 base::WeakPtrFactory<MediaRouterAction> weak_ptr_factory_; 147 base::WeakPtrFactory<MediaRouterAction> weak_ptr_factory_;
124 148
125 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); 149 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction);
126 }; 150 };
127 151
128 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ 152 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698