Chromium Code Reviews| 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> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <unordered_map> | |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/containers/hash_tables.h" | 17 #include "base/containers/hash_tables.h" |
| 17 #include "base/containers/scoped_ptr_hash_map.h" | 18 #include "base/containers/scoped_ptr_hash_map.h" |
| 18 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
| 22 #include "base/observer_list.h" | 23 #include "base/observer_list.h" |
| 23 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 void SendRouteMessage(const MediaRoute::Id& route_id, | 94 void SendRouteMessage(const MediaRoute::Id& route_id, |
| 94 const std::string& message, | 95 const std::string& message, |
| 95 const SendRouteMessageCallback& callback) override; | 96 const SendRouteMessageCallback& callback) override; |
| 96 void SendRouteBinaryMessage( | 97 void SendRouteBinaryMessage( |
| 97 const MediaRoute::Id& route_id, | 98 const MediaRoute::Id& route_id, |
| 98 scoped_ptr<std::vector<uint8_t>> data, | 99 scoped_ptr<std::vector<uint8_t>> data, |
| 99 const SendRouteMessageCallback& callback) override; | 100 const SendRouteMessageCallback& callback) override; |
| 100 void AddIssue(const Issue& issue) override; | 101 void AddIssue(const Issue& issue) override; |
| 101 void ClearIssue(const Issue::Id& issue_id) override; | 102 void ClearIssue(const Issue::Id& issue_id) override; |
| 102 void OnUserGesture() override; | 103 void OnUserGesture() override; |
| 104 void SearchSinksAndCreateRoute( | |
| 105 const MediaSink::Id& sink_id, | |
| 106 const MediaSource::Id& source_id, | |
| 107 const std::string& search_input, | |
| 108 const std::string& domain, | |
| 109 const GURL& origin, | |
| 110 content::WebContents* web_contents, | |
| 111 const std::vector<MediaRouteResponseCallback>& route_callbacks, | |
| 112 const MediaSinkSearchResponseCallback& sink_callback, | |
| 113 base::TimeDelta timeout, | |
| 114 bool off_the_record) override; | |
| 103 | 115 |
| 104 const std::string& media_route_provider_extension_id() const { | 116 const std::string& media_route_provider_extension_id() const { |
| 105 return media_route_provider_extension_id_; | 117 return media_route_provider_extension_id_; |
| 106 } | 118 } |
| 107 | 119 |
| 108 void set_instance_id_for_test(const std::string& instance_id) { | 120 void set_instance_id_for_test(const std::string& instance_id) { |
| 109 instance_id_ = instance_id; | 121 instance_id_ = instance_id; |
| 110 } | 122 } |
| 111 | 123 |
| 112 private: | 124 private: |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 const SendRouteMessageCallback& callback); | 258 const SendRouteMessageCallback& callback); |
| 247 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id, | 259 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id, |
| 248 scoped_ptr<std::vector<uint8_t>> data, | 260 scoped_ptr<std::vector<uint8_t>> data, |
| 249 const SendRouteMessageCallback& callback); | 261 const SendRouteMessageCallback& callback); |
| 250 void DoListenForRouteMessages(const MediaRoute::Id& route_id); | 262 void DoListenForRouteMessages(const MediaRoute::Id& route_id); |
| 251 void DoStopListeningForRouteMessages(const MediaRoute::Id& route_id); | 263 void DoStopListeningForRouteMessages(const MediaRoute::Id& route_id); |
| 252 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); | 264 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); |
| 253 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); | 265 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); |
| 254 void DoStartObservingMediaRoutes(const MediaSource::Id& source_id); | 266 void DoStartObservingMediaRoutes(const MediaSource::Id& source_id); |
| 255 void DoStopObservingMediaRoutes(const MediaSource::Id& source_id); | 267 void DoStopObservingMediaRoutes(const MediaSource::Id& source_id); |
| 268 void DoSearchSinksAndCreateRoute( | |
| 269 const MediaSink::Id& sink_id, | |
| 270 const MediaSource::Id& source_id, | |
| 271 const std::string& search_input, | |
| 272 const std::string& domain, | |
| 273 const std::string& origin, | |
| 274 int tab_id, | |
| 275 const std::vector<MediaRouteResponseCallback>& route_callbacks, | |
| 276 const MediaSinkSearchResponseCallback& sink_callback, | |
| 277 base::TimeDelta timeout, | |
| 278 bool off_the_record); | |
| 256 | 279 |
| 257 // Invoked when the next batch of messages arrives. | 280 // Invoked when the next batch of messages arrives. |
| 258 // |route_id|: ID of route of the messages. | 281 // |route_id|: ID of route of the messages. |
| 259 // |messages|: A list of messages received. | 282 // |messages|: A list of messages received. |
| 260 // |error|: true if an error occurred. | 283 // |error|: true if an error occurred. |
| 261 void OnRouteMessagesReceived( | 284 void OnRouteMessagesReceived( |
| 262 const MediaRoute::Id& route_id, | 285 const MediaRoute::Id& route_id, |
| 263 mojo::Array<interfaces::RouteMessagePtr> messages, | 286 mojo::Array<interfaces::RouteMessagePtr> messages, |
| 264 bool error); | 287 bool error); |
| 265 | 288 |
| 266 // Error handler callback for |binding_| and |media_route_provider_|. | 289 // Error handler callback for |binding_| and |media_route_provider_|. |
| 267 void OnConnectionError(); | 290 void OnConnectionError(); |
| 268 | 291 |
| 269 // interfaces::MediaRouter implementation. | 292 // interfaces::MediaRouter implementation. |
| 270 void RegisterMediaRouteProvider( | 293 void RegisterMediaRouteProvider( |
| 271 interfaces::MediaRouteProviderPtr media_route_provider_ptr, | 294 interfaces::MediaRouteProviderPtr media_route_provider_ptr, |
| 272 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& | 295 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& |
| 273 callback) override; | 296 callback) override; |
| 274 void OnIssue(interfaces::IssuePtr issue) override; | 297 void OnIssue(interfaces::IssuePtr issue) override; |
| 275 void OnSinksReceived(const mojo::String& media_source, | 298 void OnSinksReceived(const mojo::String& media_source, |
| 276 mojo::Array<interfaces::MediaSinkPtr> sinks, | 299 mojo::Array<interfaces::MediaSinkPtr> sinks, |
| 277 mojo::Array<mojo::String> origins) override; | 300 mojo::Array<mojo::String> origins) override; |
| 301 void OnSearchSinkIdReceived(const mojo::String& pseudo_sink_id, | |
| 302 const mojo::String& sink_id) override; | |
| 278 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes, | 303 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes, |
| 279 const mojo::String& media_source, | 304 const mojo::String& media_source, |
| 280 mojo::Array<mojo::String> joinable_route_ids) override; | 305 mojo::Array<mojo::String> joinable_route_ids) override; |
| 281 void OnSinkAvailabilityUpdated( | 306 void OnSinkAvailabilityUpdated( |
| 282 interfaces::MediaRouter::SinkAvailability availability) override; | 307 interfaces::MediaRouter::SinkAvailability availability) override; |
| 283 void OnPresentationConnectionStateChanged( | 308 void OnPresentationConnectionStateChanged( |
| 284 const mojo::String& route_id, | 309 const mojo::String& route_id, |
| 285 interfaces::MediaRouter::PresentationConnectionState state) override; | 310 interfaces::MediaRouter::PresentationConnectionState state) override; |
| 286 void OnPresentationConnectionClosed( | 311 void OnPresentationConnectionClosed( |
| 287 const mojo::String& route_id, | 312 const mojo::String& route_id, |
| 288 interfaces::MediaRouter::PresentationConnectionCloseReason reason, | 313 interfaces::MediaRouter::PresentationConnectionCloseReason reason, |
| 289 const mojo::String& message) override; | 314 const mojo::String& message) override; |
| 290 | 315 |
| 291 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute() | 316 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute() |
| 292 // into a local callback. | 317 // into a local callback. |
| 293 void RouteResponseReceived( | 318 void RouteResponseReceived( |
| 294 const std::string& presentation_id, | 319 const std::string& presentation_id, |
| 295 bool off_the_record, | 320 bool off_the_record, |
| 296 const std::vector<MediaRouteResponseCallback>& callbacks, | 321 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 297 interfaces::MediaRoutePtr media_route, | 322 interfaces::MediaRoutePtr media_route, |
| 298 const mojo::String& error_text, | 323 const mojo::String& error_text, |
| 299 interfaces::RouteRequestResultCode result_code); | 324 interfaces::RouteRequestResultCode result_code); |
| 300 | 325 |
| 326 // Converts the callback result of calling Mojo SearchSinksAndCreateRoute() | |
| 327 // into a local callback. | |
| 328 void SearchAndCreateResponseReceived( | |
| 329 const std::string& presentation_id, | |
| 330 const std::vector<MediaRouteResponseCallback>& route_callbacks, | |
| 331 interfaces::MediaRoutePtr media_route, | |
| 332 const mojo::String& error_text, | |
| 333 interfaces::RouteRequestResultCode result_code); | |
| 334 | |
| 301 // Callback invoked by |event_page_tracker_| after an attempt to wake the | 335 // Callback invoked by |event_page_tracker_| after an attempt to wake the |
| 302 // component extension. If |success| is false, the pending request queue is | 336 // component extension. If |success| is false, the pending request queue is |
| 303 // drained. | 337 // drained. |
| 304 void EventPageWakeComplete(bool success); | 338 void EventPageWakeComplete(bool success); |
| 305 | 339 |
| 306 // Removes all requests from the pending requests queue. Called when there is | 340 // Removes all requests from the pending requests queue. Called when there is |
| 307 // a permanent error connecting to component extension. | 341 // a permanent error connecting to component extension. |
| 308 void DrainRequestQueue(); | 342 void DrainRequestQueue(); |
| 309 | 343 |
| 310 // Calls to |event_page_tracker_| to wake the component extension. | 344 // Calls to |event_page_tracker_| to wake the component extension. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 338 // Pending requests queued to be executed once component extension | 372 // Pending requests queued to be executed once component extension |
| 339 // becomes ready. | 373 // becomes ready. |
| 340 std::deque<base::Closure> pending_requests_; | 374 std::deque<base::Closure> pending_requests_; |
| 341 | 375 |
| 342 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>> | 376 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>> |
| 343 sinks_queries_; | 377 sinks_queries_; |
| 344 | 378 |
| 345 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaRoutesQuery>> | 379 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaRoutesQuery>> |
| 346 routes_queries_; | 380 routes_queries_; |
| 347 | 381 |
| 382 std::unordered_map<std::string, MediaSinkSearchResponseCallback> | |
| 383 search_callbacks_; | |
|
imcheng
2016/04/18 23:15:46
Is it possible that multiple callbacks could exist
btolsch
2016/04/19 01:39:43
One UI can't create that situation, but if two UIs
| |
| 384 | |
| 348 using PresentationSessionMessagesObserverList = | 385 using PresentationSessionMessagesObserverList = |
| 349 base::ObserverList<PresentationSessionMessagesObserver>; | 386 base::ObserverList<PresentationSessionMessagesObserver>; |
| 350 base::ScopedPtrHashMap<MediaRoute::Id, | 387 base::ScopedPtrHashMap<MediaRoute::Id, |
| 351 scoped_ptr<PresentationSessionMessagesObserverList>> | 388 scoped_ptr<PresentationSessionMessagesObserverList>> |
| 352 messages_observers_; | 389 messages_observers_; |
| 353 | 390 |
| 354 // IDs of MediaRoutes being listened for messages. Note that this is | 391 // IDs of MediaRoutes being listened for messages. Note that this is |
| 355 // different from |message_observers_| because we might be waiting for | 392 // different from |message_observers_| because we might be waiting for |
| 356 // |OnRouteMessagesReceived()| to be invoked after all observers for that | 393 // |OnRouteMessagesReceived()| to be invoked after all observers for that |
| 357 // route have been removed. | 394 // route have been removed. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 #endif | 445 #endif |
| 409 | 446 |
| 410 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; | 447 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; |
| 411 | 448 |
| 412 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); | 449 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); |
| 413 }; | 450 }; |
| 414 | 451 |
| 415 } // namespace media_router | 452 } // namespace media_router |
| 416 | 453 |
| 417 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ | 454 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ |
| OLD | NEW |