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_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 <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 const MediaSink::Id& sink_id, | 67 const MediaSink::Id& sink_id, |
| 68 const GURL& origin, | 68 const GURL& origin, |
| 69 content::WebContents* web_contents, | 69 content::WebContents* web_contents, |
| 70 const std::vector<MediaRouteResponseCallback>& callbacks) override; | 70 const std::vector<MediaRouteResponseCallback>& callbacks) override; |
| 71 void JoinRoute( | 71 void JoinRoute( |
| 72 const MediaSource::Id& source_id, | 72 const MediaSource::Id& source_id, |
| 73 const std::string& presentation_id, | 73 const std::string& presentation_id, |
| 74 const GURL& origin, | 74 const GURL& origin, |
| 75 content::WebContents* web_contents, | 75 content::WebContents* web_contents, |
| 76 const std::vector<MediaRouteResponseCallback>& callbacks) override; | 76 const std::vector<MediaRouteResponseCallback>& callbacks) override; |
| 77 void JoinRouteByRouteId( | |
| 78 const MediaSource::Id& source, | |
| 79 const MediaRoute::Id& route_id, | |
| 80 const GURL& origin, | |
| 81 content::WebContents* web_contents, | |
| 82 const std::vector<MediaRouteResponseCallback>& callbacks) override; | |
| 77 void CloseRoute(const MediaRoute::Id& route_id) override; | 83 void CloseRoute(const MediaRoute::Id& route_id) override; |
| 78 void SendRouteMessage(const MediaRoute::Id& route_id, | 84 void SendRouteMessage(const MediaRoute::Id& route_id, |
| 79 const std::string& message, | 85 const std::string& message, |
| 80 const SendRouteMessageCallback& callback) override; | 86 const SendRouteMessageCallback& callback) override; |
| 81 void SendRouteBinaryMessage( | 87 void SendRouteBinaryMessage( |
| 82 const MediaRoute::Id& route_id, | 88 const MediaRoute::Id& route_id, |
| 83 scoped_ptr<std::vector<uint8>> data, | 89 scoped_ptr<std::vector<uint8>> data, |
| 84 const SendRouteMessageCallback& callback) override; | 90 const SendRouteMessageCallback& callback) override; |
| 85 void AddIssue(const Issue& issue) override; | 91 void AddIssue(const Issue& issue) override; |
| 86 void ClearIssue(const Issue::Id& issue_id) override; | 92 void ClearIssue(const Issue::Id& issue_id) override; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 // giving up and draining the pending request queue. | 135 // giving up and draining the pending request queue. |
| 130 static const int kMaxWakeupAttemptCount = 3; | 136 static const int kMaxWakeupAttemptCount = 3; |
| 131 | 137 |
| 132 class MediaRouterMediaRoutesObserver : | 138 class MediaRouterMediaRoutesObserver : |
| 133 public media_router::MediaRoutesObserver { | 139 public media_router::MediaRoutesObserver { |
| 134 public: | 140 public: |
| 135 explicit MediaRouterMediaRoutesObserver(MediaRouterMojoImpl* router); | 141 explicit MediaRouterMediaRoutesObserver(MediaRouterMojoImpl* router); |
| 136 ~MediaRouterMediaRoutesObserver() override; | 142 ~MediaRouterMediaRoutesObserver() override; |
| 137 | 143 |
| 138 // media_router::MediaRoutesObserver: | 144 // media_router::MediaRoutesObserver: |
| 139 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes) | 145 void OnRoutesUpdated( |
| 146 const std::vector<media_router::MediaRoute>& routes, | |
| 147 const std::vector<media_router::MediaRoute::Id>& joinable_route_ids) | |
| 140 override; | 148 override; |
| 141 | 149 |
| 142 private: | 150 private: |
| 143 MediaRouterMojoImpl* const router_; | 151 MediaRouterMojoImpl* const router_; |
| 144 | 152 |
| 145 DISALLOW_COPY_AND_ASSIGN(MediaRouterMediaRoutesObserver); | 153 DISALLOW_COPY_AND_ASSIGN(MediaRouterMediaRoutesObserver); |
| 146 }; | 154 }; |
| 147 | 155 |
| 148 // Represents a query to the MRPM for media sinks and holds observers for the | 156 // Represents a query to the MRPM for media sinks and holds observers for the |
| 149 // query. | 157 // query. |
| 150 struct MediaSinksQuery { | 158 struct MediaSinksQuery { |
| 151 public: | 159 public: |
| 152 MediaSinksQuery(); | 160 MediaSinksQuery(); |
| 153 ~MediaSinksQuery(); | 161 ~MediaSinksQuery(); |
| 154 | 162 |
| 155 // True if the query has been sent to the MRPM. False otherwise. | 163 // True if the query has been sent to the MRPM. False otherwise. |
| 156 bool is_active = false; | 164 bool is_active = false; |
| 157 base::ObserverList<MediaSinksObserver> observers; | 165 base::ObserverList<MediaSinksObserver> observers; |
| 158 | 166 |
| 159 DISALLOW_COPY_AND_ASSIGN(MediaSinksQuery); | 167 DISALLOW_COPY_AND_ASSIGN(MediaSinksQuery); |
| 160 }; | 168 }; |
| 161 | 169 |
| 170 struct MediaRoutesQuery { | |
| 171 public: | |
| 172 MediaRoutesQuery(); | |
| 173 ~MediaRoutesQuery(); | |
| 174 | |
| 175 // True if the query has been sent to the MRPM. False otherwise. | |
| 176 bool is_active = false; | |
| 177 base::ObserverList<MediaRoutesObserver> observers; | |
| 178 | |
| 179 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery); | |
| 180 }; | |
| 181 | |
| 162 // Standard constructor, used by | 182 // Standard constructor, used by |
| 163 // MediaRouterMojoImplFactory::GetApiForBrowserContext. | 183 // MediaRouterMojoImplFactory::GetApiForBrowserContext. |
| 164 explicit MediaRouterMojoImpl( | 184 explicit MediaRouterMojoImpl( |
| 165 extensions::EventPageTracker* event_page_tracker); | 185 extensions::EventPageTracker* event_page_tracker); |
| 166 | 186 |
| 167 // Binds |this| to a Mojo interface request, so that clients can acquire a | 187 // Binds |this| to a Mojo interface request, so that clients can acquire a |
| 168 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. | 188 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. |
| 169 // Stores the |extension_id| of the component extension. | 189 // Stores the |extension_id| of the component extension. |
| 170 void BindToMojoRequest( | 190 void BindToMojoRequest( |
| 171 mojo::InterfaceRequest<interfaces::MediaRouter> request, | 191 mojo::InterfaceRequest<interfaces::MediaRouter> request, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 const std::string& message, | 237 const std::string& message, |
| 218 const SendRouteMessageCallback& callback); | 238 const SendRouteMessageCallback& callback); |
| 219 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id, | 239 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id, |
| 220 scoped_ptr<std::vector<uint8>> data, | 240 scoped_ptr<std::vector<uint8>> data, |
| 221 const SendRouteMessageCallback& callback); | 241 const SendRouteMessageCallback& callback); |
| 222 void DoListenForRouteMessages(const MediaRoute::Id& route_id); | 242 void DoListenForRouteMessages(const MediaRoute::Id& route_id); |
| 223 void DoStopListeningForRouteMessages(const MediaRoute::Id& route_id); | 243 void DoStopListeningForRouteMessages(const MediaRoute::Id& route_id); |
| 224 void DoOnPresentationSessionDetached(const MediaRoute::Id& route_id); | 244 void DoOnPresentationSessionDetached(const MediaRoute::Id& route_id); |
| 225 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); | 245 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); |
| 226 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); | 246 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); |
| 227 void DoStartObservingMediaRoutes(); | 247 void DoStartObservingMediaRoutes(const MediaSource::Id& source_id); |
| 228 void DoStopObservingMediaRoutes(); | 248 void DoStopObservingMediaRoutes(const MediaSource::Id& source_id); |
| 229 | 249 |
| 230 // Invoked when the next batch of messages arrives. | 250 // Invoked when the next batch of messages arrives. |
| 231 // |route_id|: ID of route of the messages. | 251 // |route_id|: ID of route of the messages. |
| 232 // |messages|: A list of messages received. | 252 // |messages|: A list of messages received. |
| 233 // |error|: true if an error occurred. | 253 // |error|: true if an error occurred. |
| 234 void OnRouteMessagesReceived( | 254 void OnRouteMessagesReceived( |
| 235 const MediaRoute::Id& route_id, | 255 const MediaRoute::Id& route_id, |
| 236 mojo::Array<interfaces::RouteMessagePtr> messages, | 256 mojo::Array<interfaces::RouteMessagePtr> messages, |
| 237 bool error); | 257 bool error); |
| 238 | 258 |
| 239 // Error handler callback for |binding_| and |media_route_provider_|. | 259 // Error handler callback for |binding_| and |media_route_provider_|. |
| 240 void OnConnectionError(); | 260 void OnConnectionError(); |
| 241 | 261 |
| 242 // interfaces::MediaRouter implementation. | 262 // interfaces::MediaRouter implementation. |
| 243 void RegisterMediaRouteProvider( | 263 void RegisterMediaRouteProvider( |
| 244 interfaces::MediaRouteProviderPtr media_route_provider_ptr, | 264 interfaces::MediaRouteProviderPtr media_route_provider_ptr, |
| 245 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& | 265 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& |
| 246 callback) override; | 266 callback) override; |
| 247 void OnIssue(interfaces::IssuePtr issue) override; | 267 void OnIssue(interfaces::IssuePtr issue) override; |
| 248 void OnSinksReceived(const mojo::String& media_source, | 268 void OnSinksReceived(const mojo::String& media_source, |
| 249 mojo::Array<interfaces::MediaSinkPtr> sinks) override; | 269 mojo::Array<interfaces::MediaSinkPtr> sinks) override; |
| 250 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override; | 270 void OnRoutesUpdated(const mojo::String& media_source, |
| 271 mojo::Array<interfaces::MediaRoutePtr> routes, | |
| 272 mojo::Array<mojo::String> joinable_route_ids) override; | |
| 251 void OnSinkAvailabilityUpdated( | 273 void OnSinkAvailabilityUpdated( |
| 252 interfaces::MediaRouter::SinkAvailability availability) override; | 274 interfaces::MediaRouter::SinkAvailability availability) override; |
| 253 void OnPresentationConnectionStateChanged( | 275 void OnPresentationConnectionStateChanged( |
| 254 const mojo::String& route_id, | 276 const mojo::String& route_id, |
| 255 interfaces::MediaRouter::PresentationConnectionState state) override; | 277 interfaces::MediaRouter::PresentationConnectionState state) override; |
| 256 | 278 |
| 257 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute() | 279 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute() |
| 258 // into a local callback. | 280 // into a local callback. |
| 259 void RouteResponseReceived( | 281 void RouteResponseReceived( |
| 260 const std::string& presentation_id, | 282 const std::string& presentation_id, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 288 // Clears the wake reason after the extension has been awoken. | 310 // Clears the wake reason after the extension has been awoken. |
| 289 void ClearWakeReason(); | 311 void ClearWakeReason(); |
| 290 | 312 |
| 291 // Pending requests queued to be executed once component extension | 313 // Pending requests queued to be executed once component extension |
| 292 // becomes ready. | 314 // becomes ready. |
| 293 std::deque<base::Closure> pending_requests_; | 315 std::deque<base::Closure> pending_requests_; |
| 294 | 316 |
| 295 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>> | 317 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>> |
| 296 sinks_queries_; | 318 sinks_queries_; |
| 297 | 319 |
| 320 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaRoutesQuery>> | |
|
mark a. foltz
2015/12/03 19:24:23
Why do we need this map and |local_routes_observer
matt.boetger
2015/12/15 19:21:20
|local_routes_observers| only deals with local, di
| |
| 321 routes_queries_; | |
| 322 | |
| 298 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_; | 323 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_; |
| 299 | 324 |
| 300 base::ObserverList<MediaRoutesObserver> routes_observers_; | |
| 301 | |
| 302 using PresentationSessionMessagesObserverList = | 325 using PresentationSessionMessagesObserverList = |
| 303 base::ObserverList<PresentationSessionMessagesObserver>; | 326 base::ObserverList<PresentationSessionMessagesObserver>; |
| 304 base::ScopedPtrHashMap<MediaRoute::Id, | 327 base::ScopedPtrHashMap<MediaRoute::Id, |
| 305 scoped_ptr<PresentationSessionMessagesObserverList>> | 328 scoped_ptr<PresentationSessionMessagesObserverList>> |
| 306 messages_observers_; | 329 messages_observers_; |
| 307 | 330 |
| 308 // IDs of MediaRoutes being listened for messages. Note that this is | 331 // IDs of MediaRoutes being listened for messages. Note that this is |
| 309 // different from |message_observers_| because we might be waiting for | 332 // different from |message_observers_| because we might be waiting for |
| 310 // |OnRouteMessagesReceived()| to be invoked after all observers for that | 333 // |OnRouteMessagesReceived()| to be invoked after all observers for that |
| 311 // route have been removed. | 334 // route have been removed. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 MediaRouteProviderWakeReason current_wake_reason_; | 377 MediaRouteProviderWakeReason current_wake_reason_; |
| 355 | 378 |
| 356 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; | 379 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; |
| 357 | 380 |
| 358 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); | 381 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); |
| 359 }; | 382 }; |
| 360 | 383 |
| 361 } // namespace media_router | 384 } // namespace media_router |
| 362 | 385 |
| 363 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ | 386 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ |
| OLD | NEW |