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

Side by Side Diff: chrome/browser/media/router/mojo/media_router_mojo_impl.h

Issue 2728543009: [Media Router] Custom Controls 2 - add MediaRouter::GetRouteController() (Closed)
Patch Set: Combine CreateMRController and SetMRStatusObserver Created 3 years, 8 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_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 void ClearIssue(const Issue::Id& issue_id) override; 104 void ClearIssue(const Issue::Id& issue_id) override;
105 void OnUserGesture() override; 105 void OnUserGesture() override;
106 void SearchSinks( 106 void SearchSinks(
107 const MediaSink::Id& sink_id, 107 const MediaSink::Id& sink_id,
108 const MediaSource::Id& source_id, 108 const MediaSource::Id& source_id,
109 const std::string& search_input, 109 const std::string& search_input,
110 const std::string& domain, 110 const std::string& domain,
111 const MediaSinkSearchResponseCallback& sink_callback) override; 111 const MediaSinkSearchResponseCallback& sink_callback) override;
112 void ProvideSinks(const std::string& provider_name, 112 void ProvideSinks(const std::string& provider_name,
113 const std::vector<MediaSinkInternal>& sinks) override; 113 const std::vector<MediaSinkInternal>& sinks) override;
114 scoped_refptr<MediaRouteController> GetRouteController(
115 const MediaRoute::Id& route_id) override;
114 116
115 const std::string& media_route_provider_extension_id() const { 117 const std::string& media_route_provider_extension_id() const {
116 return media_route_provider_extension_id_; 118 return media_route_provider_extension_id_;
117 } 119 }
118 120
119 void set_instance_id_for_test(const std::string& instance_id) { 121 void set_instance_id_for_test(const std::string& instance_id) {
120 instance_id_ = instance_id; 122 instance_id_ = instance_id;
121 } 123 }
122 124
123 private: 125 private:
(...skipping 13 matching lines...) Expand all
137 FRIEND_TEST_ALL_PREFIXES( 139 FRIEND_TEST_ALL_PREFIXES(
138 MediaRouterMojoImplTest, 140 MediaRouterMojoImplTest,
139 RegisterAndUnregisterMediaSinksObserverWithAvailabilityChange); 141 RegisterAndUnregisterMediaSinksObserverWithAvailabilityChange);
140 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 142 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
141 RegisterAndUnregisterMediaRoutesObserver); 143 RegisterAndUnregisterMediaRoutesObserver);
142 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 144 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
143 RouteMessagesSingleObserver); 145 RouteMessagesSingleObserver);
144 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 146 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
145 RouteMessagesMultipleObservers); 147 RouteMessagesMultipleObservers);
146 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue); 148 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue);
149 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, GetRouteController);
150 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
151 GetRouteControllerMultipleTimes);
152 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
153 GetRouteControllerAfterInvalidation);
154 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
155 GetRouteControllerAfterRouteInvalidation);
156 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
157 FailToCreateRouteController);
147 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 158 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
148 DeferredBindingAndSuspension); 159 DeferredBindingAndSuspension);
149 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 160 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
150 DrainPendingRequestQueue); 161 DrainPendingRequestQueue);
151 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 162 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
152 DropOldestPendingRequest); 163 DropOldestPendingRequest);
153 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 164 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
154 AttemptedWakeupTooManyTimes); 165 AttemptedWakeupTooManyTimes);
155 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 166 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
156 WakeupFailedDrainsQueue); 167 WakeupFailedDrainsQueue);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 extensions::EventPageTracker* event_page_tracker); 218 extensions::EventPageTracker* event_page_tracker);
208 219
209 // Binds |this| to a Mojo interface request, so that clients can acquire a 220 // Binds |this| to a Mojo interface request, so that clients can acquire a
210 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. 221 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
211 // Stores the ID of |extension| in |media_route_provider_extension_id_|. 222 // Stores the ID of |extension| in |media_route_provider_extension_id_|.
212 void BindToMojoRequest( 223 void BindToMojoRequest(
213 mojo::InterfaceRequest<mojom::MediaRouter> request, 224 mojo::InterfaceRequest<mojom::MediaRouter> request,
214 const extensions::Extension& extension); 225 const extensions::Extension& extension);
215 226
216 // Enqueues a closure for later execution by ExecutePendingRequests(). 227 // Enqueues a closure for later execution by ExecutePendingRequests().
217 void EnqueueTask(const base::Closure& closure); 228 void EnqueueTask(base::OnceClosure closure);
218 229
219 // Runs a closure if the extension monitored by |extension_monitor_| is 230 // Runs a closure if the extension monitored by |extension_monitor_| is
220 // active, or defers it for later execution if the extension is suspended. 231 // active, or defers it for later execution if the extension is suspended.
221 void RunOrDefer(const base::Closure& request); 232 void RunOrDefer(base::OnceClosure request);
222 233
223 // Dispatches the Mojo requests queued in |pending_requests_|. 234 // Dispatches the Mojo requests queued in |pending_requests_|.
224 void ExecutePendingRequests(); 235 void ExecutePendingRequests();
225 236
226 // Drops all pending requests. Called when we have a connection error to 237 // Drops all pending requests. Called when we have a connection error to
227 // component extension and further reattempts are unlikely to help. 238 // component extension and further reattempts are unlikely to help.
228 void DrainPendingRequests(); 239 void DrainPendingRequests();
229 240
230 // MediaRouter implementation. 241 // MediaRouter implementation.
231 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override; 242 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
232 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; 243 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
233 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 244 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
234 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 245 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
235 void RegisterIssuesObserver(IssuesObserver* observer) override; 246 void RegisterIssuesObserver(IssuesObserver* observer) override;
236 void UnregisterIssuesObserver(IssuesObserver* observer) override; 247 void UnregisterIssuesObserver(IssuesObserver* observer) override;
237 void RegisterRouteMessageObserver(RouteMessageObserver* observer) override; 248 void RegisterRouteMessageObserver(RouteMessageObserver* observer) override;
238 void UnregisterRouteMessageObserver(RouteMessageObserver* observer) override; 249 void UnregisterRouteMessageObserver(RouteMessageObserver* observer) override;
250 void DetachRouteController(const MediaRoute::Id& route_id,
251 MediaRouteController* controller) override;
239 252
240 // Notifies |observer| of any existing cached routes, if it is still 253 // Notifies |observer| of any existing cached routes, if it is still
241 // registered. 254 // registered.
242 void NotifyOfExistingRoutesIfRegistered(const MediaSource::Id& source_id, 255 void NotifyOfExistingRoutesIfRegistered(const MediaSource::Id& source_id,
243 MediaRoutesObserver* observer) const; 256 MediaRoutesObserver* observer) const;
244 257
245 // These calls invoke methods in the component extension via Mojo. 258 // These calls invoke methods in the component extension via Mojo.
246 void DoCreateRoute(const MediaSource::Id& source_id, 259 void DoCreateRoute(const MediaSource::Id& source_id,
247 const MediaSink::Id& sink_id, 260 const MediaSink::Id& sink_id,
248 const url::Origin& origin, 261 const url::Origin& origin,
(...skipping 29 matching lines...) Expand all
278 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); 291 void DoStartObservingMediaSinks(const MediaSource::Id& source_id);
279 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); 292 void DoStopObservingMediaSinks(const MediaSource::Id& source_id);
280 void DoStartObservingMediaRoutes(const MediaSource::Id& source_id); 293 void DoStartObservingMediaRoutes(const MediaSource::Id& source_id);
281 void DoStopObservingMediaRoutes(const MediaSource::Id& source_id); 294 void DoStopObservingMediaRoutes(const MediaSource::Id& source_id);
282 void DoSearchSinks( 295 void DoSearchSinks(
283 const MediaSink::Id& sink_id, 296 const MediaSink::Id& sink_id,
284 const MediaSource::Id& source_id, 297 const MediaSource::Id& source_id,
285 const std::string& search_input, 298 const std::string& search_input,
286 const std::string& domain, 299 const std::string& domain,
287 const MediaSinkSearchResponseCallback& sink_callback); 300 const MediaSinkSearchResponseCallback& sink_callback);
301 void DoCreateMediaRouteController(
302 const MediaRoute::Id& route_id,
303 mojom::MediaControllerRequest mojo_media_controller_request,
304 mojom::MediaStatusObserverPtr mojo_observer);
288 305
289 void DoProvideSinks(const std::string& provider_name, 306 void DoProvideSinks(const std::string& provider_name,
290 const std::vector<MediaSinkInternal>& sinks); 307 const std::vector<MediaSinkInternal>& sinks);
291 308
292 // Error handler callback for |binding_| and |media_route_provider_|. 309 // Error handler callback for |binding_| and |media_route_provider_|.
293 void OnConnectionError(); 310 void OnConnectionError();
294 311
295 // mojom::MediaRouter implementation. 312 // mojom::MediaRouter implementation.
296 void RegisterMediaRouteProvider( 313 void RegisterMediaRouteProvider(
297 mojom::MediaRouteProviderPtr media_route_provider_ptr, 314 mojom::MediaRouteProviderPtr media_route_provider_ptr,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // happen until the user is clearly interacting with MR. 388 // happen until the user is clearly interacting with MR.
372 void OnFirewallCheckComplete(bool firewall_can_use_local_ports); 389 void OnFirewallCheckComplete(bool firewall_can_use_local_ports);
373 #endif 390 #endif
374 391
375 // Requests MRPM to update media sinks. This allows MRPs that only do 392 // Requests MRPM to update media sinks. This allows MRPs that only do
376 // discovery on sink queries an opportunity to update discovery results 393 // discovery on sink queries an opportunity to update discovery results
377 // even if the MRP SinkAvailability is marked UNAVAILABLE. 394 // even if the MRP SinkAvailability is marked UNAVAILABLE.
378 void UpdateMediaSinks(const MediaSource::Id& source_id); 395 void UpdateMediaSinks(const MediaSource::Id& source_id);
379 void DoUpdateMediaSinks(const MediaSource::Id& source_id); 396 void DoUpdateMediaSinks(const MediaSource::Id& source_id);
380 397
398 // Invalidates and removes controllers from |route_controllers_| whose media
399 // routes do not appear in |routes|.
400 void RemoveInvalidRouteControllers(const std::vector<MediaRoute>& routes);
401
402 // Callback called by MRP's CreateMediaRouteController().
403 void OnMediaControllerCreated(const MediaRoute::Id& route_id, bool success);
404
381 // Pending requests queued to be executed once component extension 405 // Pending requests queued to be executed once component extension
382 // becomes ready. 406 // becomes ready.
383 std::deque<base::Closure> pending_requests_; 407 std::deque<base::OnceClosure> pending_requests_;
384 408
385 std::unordered_map<MediaSource::Id, std::unique_ptr<MediaSinksQuery>> 409 std::unordered_map<MediaSource::Id, std::unique_ptr<MediaSinksQuery>>
386 sinks_queries_; 410 sinks_queries_;
387 411
388 std::unordered_map<MediaSource::Id, std::unique_ptr<MediaRoutesQuery>> 412 std::unordered_map<MediaSource::Id, std::unique_ptr<MediaRoutesQuery>>
389 routes_queries_; 413 routes_queries_;
390 414
391 std::unordered_map<MediaRoute::Id, 415 std::unordered_map<MediaRoute::Id,
392 std::unique_ptr<base::ObserverList<RouteMessageObserver>>> 416 std::unique_ptr<base::ObserverList<RouteMessageObserver>>>
393 message_observers_; 417 message_observers_;
(...skipping 30 matching lines...) Expand all
424 int wakeup_attempt_count_ = 0; 448 int wakeup_attempt_count_ = 0;
425 449
426 // Records the current reason the extension is being woken up. Is set to 450 // Records the current reason the extension is being woken up. Is set to
427 // MediaRouteProviderWakeReason::TOTAL_COUNT if there is no pending reason. 451 // MediaRouteProviderWakeReason::TOTAL_COUNT if there is no pending reason.
428 MediaRouteProviderWakeReason current_wake_reason_; 452 MediaRouteProviderWakeReason current_wake_reason_;
429 453
430 // A flag to ensure that we record the provider version once, during the 454 // A flag to ensure that we record the provider version once, during the
431 // initial event page wakeup attempt. 455 // initial event page wakeup attempt.
432 bool provider_version_was_recorded_ = false; 456 bool provider_version_was_recorded_ = false;
433 457
458 // Stores route controllers that can be used to send media commands to the
459 // extension.
460 std::unordered_map<MediaRoute::Id, MediaRouteController*> route_controllers_;
461
434 #if defined(OS_WIN) 462 #if defined(OS_WIN)
435 // A pair of flags to ensure that mDNS discovery is only enabled on Windows 463 // A pair of flags to ensure that mDNS discovery is only enabled on Windows
436 // when there will be appropriate context for the user to associate a firewall 464 // when there will be appropriate context for the user to associate a firewall
437 // prompt with Media Router. |should_enable_mdns_discovery_| can only go from 465 // prompt with Media Router. |should_enable_mdns_discovery_| can only go from
438 // |false| to |true|. On Windows, |is_mdns_enabled_| is set to |false| in 466 // |false| to |true|. On Windows, |is_mdns_enabled_| is set to |false| in
439 // RegisterMediaRouteProvider and only set to |true| when we successfully call 467 // RegisterMediaRouteProvider and only set to |true| when we successfully call
440 // the extension to enable mDNS. 468 // the extension to enable mDNS.
441 bool is_mdns_enabled_ = false; 469 bool is_mdns_enabled_ = false;
442 bool should_enable_mdns_discovery_ = false; 470 bool should_enable_mdns_discovery_ = false;
443 #endif 471 #endif
444 472
445 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; 473 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_;
446 474
447 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 475 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
448 }; 476 };
449 477
450 } // namespace media_router 478 } // namespace media_router
451 479
452 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ 480 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/router/mojo/media_router.mojom ('k') | chrome/browser/media/router/mojo/media_router_mojo_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698