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