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

Side by Side Diff: chrome/browser/media/router/media_router_mojo_impl.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: Rebase. 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_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/containers/scoped_ptr_hash_map.h" 14 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
22 #include "base/threading/thread_checker.h" 22 #include "base/threading/thread_checker.h"
23 #include "chrome/browser/media/router/issue.h" 23 #include "chrome/browser/media/router/issue.h"
24 #include "chrome/browser/media/router/issue_manager.h" 24 #include "chrome/browser/media/router/issue_manager.h"
25 #include "chrome/browser/media/router/media_router.h" 25 #include "chrome/browser/media/router/media_router.h"
26 #include "chrome/browser/media/router/media_router.mojom.h" 26 #include "chrome/browser/media/router/media_router.mojom.h"
27 #include "chrome/browser/media/router/media_routes_observer.h"
27 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" 28 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
28 29
29 namespace content { 30 namespace content {
30 class BrowserContext; 31 class BrowserContext;
31 } 32 }
32 33
33 namespace extensions { 34 namespace extensions {
34 class EventPageTracker; 35 class EventPageTracker;
35 } 36 }
36 37
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 void SendRouteMessage(const MediaRoute::Id& route_id, 77 void SendRouteMessage(const MediaRoute::Id& route_id,
77 const std::string& message, 78 const std::string& message,
78 const SendRouteMessageCallback& callback) override; 79 const SendRouteMessageCallback& callback) override;
79 void SendRouteBinaryMessage( 80 void SendRouteBinaryMessage(
80 const MediaRoute::Id& route_id, 81 const MediaRoute::Id& route_id,
81 scoped_ptr<std::vector<uint8>> data, 82 scoped_ptr<std::vector<uint8>> data,
82 const SendRouteMessageCallback& callback) override; 83 const SendRouteMessageCallback& callback) override;
83 void AddIssue(const Issue& issue) override; 84 void AddIssue(const Issue& issue) override;
84 void ClearIssue(const Issue::Id& issue_id) override; 85 void ClearIssue(const Issue::Id& issue_id) override;
85 void OnPresentationSessionDetached(const MediaRoute::Id& route_id) override; 86 void OnPresentationSessionDetached(const MediaRoute::Id& route_id) override;
87 bool HasLocalRoute() const override;
86 88
87 const std::string& media_route_provider_extension_id() const { 89 const std::string& media_route_provider_extension_id() const {
88 return media_route_provider_extension_id_; 90 return media_route_provider_extension_id_;
89 } 91 }
90 92
91 void set_instance_id_for_test(const std::string& instance_id) { 93 void set_instance_id_for_test(const std::string& instance_id) {
92 instance_id_ = instance_id; 94 instance_id_ = instance_id;
93 } 95 }
94 96
95 private: 97 private:
96 friend class MediaRouterFactory; 98 friend class MediaRouterFactory;
97 friend class MediaRouterMojoExtensionTest; 99 friend class MediaRouterMojoExtensionTest;
98 friend class MediaRouterMojoTest; 100 friend class MediaRouterMojoTest;
99 101
100 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 102 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
101 RegisterAndUnregisterMediaSinksObserver); 103 RegisterAndUnregisterMediaSinksObserver);
102 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 104 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
103 RegisterAndUnregisterMediaRoutesObserver); 105 RegisterAndUnregisterMediaRoutesObserver);
104 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue); 106 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue);
105 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 107 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
106 DeferredBindingAndSuspension); 108 DeferredBindingAndSuspension);
107 109
110 class MediaRouterMediaRoutesObserver :
111 public media_router::MediaRoutesObserver {
112 public:
113 explicit MediaRouterMediaRoutesObserver(MediaRouterMojoImpl* router);
114 ~MediaRouterMediaRoutesObserver() override;
115
116 // media_router::MediaRoutesObserver:
117 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes)
118 override;
119
120 private:
121 MediaRouterMojoImpl* const router_;
122
123 DISALLOW_COPY_AND_ASSIGN(MediaRouterMediaRoutesObserver);
124 };
125
108 // Standard constructor, used by 126 // Standard constructor, used by
109 // MediaRouterMojoImplFactory::GetApiForBrowserContext. 127 // MediaRouterMojoImplFactory::GetApiForBrowserContext.
110 explicit MediaRouterMojoImpl( 128 explicit MediaRouterMojoImpl(
111 extensions::EventPageTracker* event_page_tracker); 129 extensions::EventPageTracker* event_page_tracker);
112 130
113 // Binds |this| to a Mojo interface request, so that clients can acquire a 131 // Binds |this| to a Mojo interface request, so that clients can acquire a
114 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. 132 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
115 // Stores the |extension_id| of the component extension. 133 // Stores the |extension_id| of the component extension.
116 void BindToMojoRequest( 134 void BindToMojoRequest(
117 mojo::InterfaceRequest<interfaces::MediaRouter> request, 135 mojo::InterfaceRequest<interfaces::MediaRouter> request,
(...skipping 13 matching lines...) Expand all
131 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override; 149 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
132 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; 150 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
133 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 151 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
134 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 152 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
135 void RegisterIssuesObserver(IssuesObserver* observer) override; 153 void RegisterIssuesObserver(IssuesObserver* observer) override;
136 void UnregisterIssuesObserver(IssuesObserver* observer) override; 154 void UnregisterIssuesObserver(IssuesObserver* observer) override;
137 void RegisterPresentationSessionMessagesObserver( 155 void RegisterPresentationSessionMessagesObserver(
138 PresentationSessionMessagesObserver* observer) override; 156 PresentationSessionMessagesObserver* observer) override;
139 void UnregisterPresentationSessionMessagesObserver( 157 void UnregisterPresentationSessionMessagesObserver(
140 PresentationSessionMessagesObserver* observer) override; 158 PresentationSessionMessagesObserver* observer) override;
159 void RegisterLocalMediaRoutesObserver(
160 LocalMediaRoutesObserver* observer) override;
161 void UnregisterLocalMediaRoutesObserver(
162 LocalMediaRoutesObserver* observer) override;
141 163
142 // These calls invoke methods in the component extension via Mojo. 164 // These calls invoke methods in the component extension via Mojo.
143 void DoCreateRoute(const MediaSource::Id& source_id, 165 void DoCreateRoute(const MediaSource::Id& source_id,
144 const MediaSink::Id& sink_id, 166 const MediaSink::Id& sink_id,
145 const std::string& origin, 167 const std::string& origin,
146 int tab_id, 168 int tab_id,
147 const std::vector<MediaRouteResponseCallback>& callbacks); 169 const std::vector<MediaRouteResponseCallback>& callbacks);
148 void DoJoinRoute(const MediaSource::Id& source_id, 170 void DoJoinRoute(const MediaSource::Id& source_id,
149 const std::string& presentation_id, 171 const std::string& presentation_id,
150 const std::string& origin, 172 const std::string& origin,
(...skipping 29 matching lines...) Expand all
180 // interfaces::MediaRouter implementation. 202 // interfaces::MediaRouter implementation.
181 void RegisterMediaRouteProvider( 203 void RegisterMediaRouteProvider(
182 interfaces::MediaRouteProviderPtr media_route_provider_ptr, 204 interfaces::MediaRouteProviderPtr media_route_provider_ptr,
183 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& 205 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback&
184 callback) override; 206 callback) override;
185 void OnIssue(interfaces::IssuePtr issue) override; 207 void OnIssue(interfaces::IssuePtr issue) override;
186 void OnSinksReceived(const mojo::String& media_source, 208 void OnSinksReceived(const mojo::String& media_source,
187 mojo::Array<interfaces::MediaSinkPtr> sinks) override; 209 mojo::Array<interfaces::MediaSinkPtr> sinks) override;
188 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override; 210 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override;
189 211
212 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute()
213 // into a local callback.
214 void RouteResponseReceived(
215 const std::string& presentation_id,
216 const std::vector<MediaRouteResponseCallback>& callbacks,
217 interfaces::MediaRoutePtr media_route,
218 const mojo::String& error_text);
219
220 void UpdateHasLocalRoute(bool has_local_route);
221
190 // Pending requests queued to be executed once component extension 222 // Pending requests queued to be executed once component extension
191 // becomes ready. 223 // becomes ready.
192 std::vector<base::Closure> pending_requests_; 224 std::vector<base::Closure> pending_requests_;
193 225
194 base::ScopedPtrHashMap<MediaSource::Id, 226 base::ScopedPtrHashMap<MediaSource::Id,
195 scoped_ptr<base::ObserverList<MediaSinksObserver>>> 227 scoped_ptr<base::ObserverList<MediaSinksObserver>>>
196 sinks_observers_; 228 sinks_observers_;
197 229
230 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_;
231
198 base::ObserverList<MediaRoutesObserver> routes_observers_; 232 base::ObserverList<MediaRoutesObserver> routes_observers_;
199 233
200 using PresentationSessionMessagesObserverList = 234 using PresentationSessionMessagesObserverList =
201 base::ObserverList<PresentationSessionMessagesObserver>; 235 base::ObserverList<PresentationSessionMessagesObserver>;
202 base::ScopedPtrHashMap<MediaRoute::Id, 236 base::ScopedPtrHashMap<MediaRoute::Id,
203 scoped_ptr<PresentationSessionMessagesObserverList>> 237 scoped_ptr<PresentationSessionMessagesObserverList>>
204 messages_observers_; 238 messages_observers_;
205 // IDs of MediaRoutes being listened for messages. Note that this is 239 // IDs of MediaRoutes being listened for messages. Note that this is
206 // different from |message_observers_| because we might be waiting for 240 // different from |message_observers_| because we might be waiting for
207 // |OnRouteMessagesReceived()| to be invoked after all observers for that 241 // |OnRouteMessagesReceived()| to be invoked after all observers for that
208 // route have been removed. 242 // route have been removed.
209 std::set<MediaRoute::Id> route_ids_listening_for_messages_; 243 std::set<MediaRoute::Id> route_ids_listening_for_messages_;
210 244
211 IssueManager issue_manager_; 245 IssueManager issue_manager_;
212 246
247 scoped_ptr<media_router::MediaRoutesObserver> routes_observer_;
248
213 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter. 249 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter.
214 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_; 250 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_;
215 251
216 // Mojo proxy object for the Media Route Provider Manager. 252 // Mojo proxy object for the Media Route Provider Manager.
217 // Set to null initially, and later set to the Provider Manager proxy object 253 // Set to null initially, and later set to the Provider Manager proxy object
218 // passed in via |RegisterMediaRouteProvider()|. 254 // passed in via |RegisterMediaRouteProvider()|.
219 // This is set to null again when the component extension is suspended 255 // This is set to null again when the component extension is suspended
220 // if or a Mojo channel error occured. 256 // if or a Mojo channel error occured.
221 interfaces::MediaRouteProviderPtr media_route_provider_; 257 interfaces::MediaRouteProviderPtr media_route_provider_;
222 258
223 // Id of the component extension. Used for managing its suspend/wake state 259 // Id of the component extension. Used for managing its suspend/wake state
224 // via event_page_tracker_. 260 // via event_page_tracker_.
225 std::string media_route_provider_extension_id_; 261 std::string media_route_provider_extension_id_;
226 262
227 // Allows the extension to be monitored for suspend, and woken. 263 // Allows the extension to be monitored for suspend, and woken.
228 // This is a reference to a BrowserContext keyed service that outlives this 264 // This is a reference to a BrowserContext keyed service that outlives this
229 // instance. 265 // instance.
230 extensions::EventPageTracker* event_page_tracker_; 266 extensions::EventPageTracker* event_page_tracker_;
231 267
232 // GUID unique to each browser run. Component extension uses this to detect 268 // GUID unique to each browser run. Component extension uses this to detect
233 // when its persisted state was written by an older browser instance, and is 269 // when its persisted state was written by an older browser instance, and is
234 // therefore stale. 270 // therefore stale.
235 std::string instance_id_; 271 std::string instance_id_;
236 272
273 bool has_local_route_;
274
237 base::ThreadChecker thread_checker_; 275 base::ThreadChecker thread_checker_;
238 276
239 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 277 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
240 }; 278 };
241 279
242 } // namespace media_router 280 } // namespace media_router
243 281
244 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 282 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_router.gypi ('k') | chrome/browser/media/router/media_router_mojo_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698