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

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: Add const to function for MediaRouterAndroid. 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
97 void UpdateHasLocalRoute(bool has_local_route);
imcheng 2015/10/02 19:54:43 ok, I see now why you had the MediaRoutesObserver
apacible 2015/10/02 20:45:48 No problem, switched back.
98
95 private: 99 private:
96 friend class MediaRouterFactory; 100 friend class MediaRouterFactory;
97 friend class MediaRouterMojoExtensionTest; 101 friend class MediaRouterMojoExtensionTest;
98 friend class MediaRouterMojoTest; 102 friend class MediaRouterMojoTest;
99 103
100 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 104 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
101 RegisterAndUnregisterMediaSinksObserver); 105 RegisterAndUnregisterMediaSinksObserver);
102 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 106 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
103 RegisterAndUnregisterMediaRoutesObserver); 107 RegisterAndUnregisterMediaRoutesObserver);
104 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue); 108 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue);
(...skipping 26 matching lines...) Expand all
131 void RegisterMediaSinksObserver(MediaSinksObserver* observer) override; 135 void RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
132 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; 136 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
133 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 137 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
134 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 138 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
135 void RegisterIssuesObserver(IssuesObserver* observer) override; 139 void RegisterIssuesObserver(IssuesObserver* observer) override;
136 void UnregisterIssuesObserver(IssuesObserver* observer) override; 140 void UnregisterIssuesObserver(IssuesObserver* observer) override;
137 void RegisterPresentationSessionMessagesObserver( 141 void RegisterPresentationSessionMessagesObserver(
138 PresentationSessionMessagesObserver* observer) override; 142 PresentationSessionMessagesObserver* observer) override;
139 void UnregisterPresentationSessionMessagesObserver( 143 void UnregisterPresentationSessionMessagesObserver(
140 PresentationSessionMessagesObserver* observer) override; 144 PresentationSessionMessagesObserver* observer) override;
145 void RegisterLocalMediaRoutesObserver(
146 LocalMediaRoutesObserver* observer) override;
147 void UnregisterLocalMediaRoutesObserver(
148 LocalMediaRoutesObserver* observer) override;
141 149
142 // These calls invoke methods in the component extension via Mojo. 150 // These calls invoke methods in the component extension via Mojo.
143 void DoCreateRoute(const MediaSource::Id& source_id, 151 void DoCreateRoute(const MediaSource::Id& source_id,
144 const MediaSink::Id& sink_id, 152 const MediaSink::Id& sink_id,
145 const std::string& origin, 153 const std::string& origin,
146 int tab_id, 154 int tab_id,
147 const std::vector<MediaRouteResponseCallback>& callbacks); 155 const std::vector<MediaRouteResponseCallback>& callbacks);
148 void DoJoinRoute(const MediaSource::Id& source_id, 156 void DoJoinRoute(const MediaSource::Id& source_id,
149 const std::string& presentation_id, 157 const std::string& presentation_id,
150 const std::string& origin, 158 const std::string& origin,
(...skipping 29 matching lines...) Expand all
180 // interfaces::MediaRouter implementation. 188 // interfaces::MediaRouter implementation.
181 void RegisterMediaRouteProvider( 189 void RegisterMediaRouteProvider(
182 interfaces::MediaRouteProviderPtr media_route_provider_ptr, 190 interfaces::MediaRouteProviderPtr media_route_provider_ptr,
183 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& 191 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback&
184 callback) override; 192 callback) override;
185 void OnIssue(interfaces::IssuePtr issue) override; 193 void OnIssue(interfaces::IssuePtr issue) override;
186 void OnSinksReceived(const mojo::String& media_source, 194 void OnSinksReceived(const mojo::String& media_source,
187 mojo::Array<interfaces::MediaSinkPtr> sinks) override; 195 mojo::Array<interfaces::MediaSinkPtr> sinks) override;
188 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override; 196 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override;
189 197
198 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute()
199 // into a local callback.
200 void RouteResponseReceived(
201 const std::string& presentation_id,
202 const std::vector<MediaRouteResponseCallback>& callbacks,
203 interfaces::MediaRoutePtr media_route,
204 const mojo::String& error_text);
205
190 // Pending requests queued to be executed once component extension 206 // Pending requests queued to be executed once component extension
191 // becomes ready. 207 // becomes ready.
192 std::vector<base::Closure> pending_requests_; 208 std::vector<base::Closure> pending_requests_;
193 209
194 base::ScopedPtrHashMap<MediaSource::Id, 210 base::ScopedPtrHashMap<MediaSource::Id,
195 scoped_ptr<base::ObserverList<MediaSinksObserver>>> 211 scoped_ptr<base::ObserverList<MediaSinksObserver>>>
196 sinks_observers_; 212 sinks_observers_;
197 213
214 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_;
215
198 base::ObserverList<MediaRoutesObserver> routes_observers_; 216 base::ObserverList<MediaRoutesObserver> routes_observers_;
199 217
200 using PresentationSessionMessagesObserverList = 218 using PresentationSessionMessagesObserverList =
201 base::ObserverList<PresentationSessionMessagesObserver>; 219 base::ObserverList<PresentationSessionMessagesObserver>;
202 base::ScopedPtrHashMap<MediaRoute::Id, 220 base::ScopedPtrHashMap<MediaRoute::Id,
203 scoped_ptr<PresentationSessionMessagesObserverList>> 221 scoped_ptr<PresentationSessionMessagesObserverList>>
204 messages_observers_; 222 messages_observers_;
205 // IDs of MediaRoutes being listened for messages. Note that this is 223 // IDs of MediaRoutes being listened for messages. Note that this is
206 // different from |message_observers_| because we might be waiting for 224 // different from |message_observers_| because we might be waiting for
207 // |OnRouteMessagesReceived()| to be invoked after all observers for that 225 // |OnRouteMessagesReceived()| to be invoked after all observers for that
208 // route have been removed. 226 // route have been removed.
209 std::set<MediaRoute::Id> route_ids_listening_for_messages_; 227 std::set<MediaRoute::Id> route_ids_listening_for_messages_;
210 228
211 IssueManager issue_manager_; 229 IssueManager issue_manager_;
212 230
231 scoped_ptr<media_router::MediaRoutesObserver> routes_observer_;
232
213 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter. 233 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter.
214 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_; 234 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_;
215 235
216 // Mojo proxy object for the Media Route Provider Manager. 236 // Mojo proxy object for the Media Route Provider Manager.
217 // Set to null initially, and later set to the Provider Manager proxy object 237 // Set to null initially, and later set to the Provider Manager proxy object
218 // passed in via |RegisterMediaRouteProvider()|. 238 // passed in via |RegisterMediaRouteProvider()|.
219 // This is set to null again when the component extension is suspended 239 // This is set to null again when the component extension is suspended
220 // if or a Mojo channel error occured. 240 // if or a Mojo channel error occured.
221 interfaces::MediaRouteProviderPtr media_route_provider_; 241 interfaces::MediaRouteProviderPtr media_route_provider_;
222 242
223 // Id of the component extension. Used for managing its suspend/wake state 243 // Id of the component extension. Used for managing its suspend/wake state
224 // via event_page_tracker_. 244 // via event_page_tracker_.
225 std::string media_route_provider_extension_id_; 245 std::string media_route_provider_extension_id_;
226 246
227 // Allows the extension to be monitored for suspend, and woken. 247 // Allows the extension to be monitored for suspend, and woken.
228 // This is a reference to a BrowserContext keyed service that outlives this 248 // This is a reference to a BrowserContext keyed service that outlives this
229 // instance. 249 // instance.
230 extensions::EventPageTracker* event_page_tracker_; 250 extensions::EventPageTracker* event_page_tracker_;
231 251
232 // GUID unique to each browser run. Component extension uses this to detect 252 // 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 253 // when its persisted state was written by an older browser instance, and is
234 // therefore stale. 254 // therefore stale.
235 std::string instance_id_; 255 std::string instance_id_;
236 256
257 bool has_local_route_;
258
237 base::ThreadChecker thread_checker_; 259 base::ThreadChecker thread_checker_;
238 260
239 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 261 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
240 }; 262 };
241 263
242 } // namespace media_router 264 } // namespace media_router
243 265
244 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 266 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698