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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 // exceeds this number, the oldest request will be dropped. | 130 // exceeds this number, the oldest request will be dropped. |
| 125 static const int kMaxPendingRequests = 30; | 131 static const int kMaxPendingRequests = 30; |
| 126 | 132 |
| 127 // Max consecutive attempts to wake up the component extension before | 133 // Max consecutive attempts to wake up the component extension before |
| 128 // giving up and draining the pending request queue. | 134 // giving up and draining the pending request queue. |
| 129 static const int kMaxWakeupAttemptCount = 3; | 135 static const int kMaxWakeupAttemptCount = 3; |
| 130 | 136 |
| 131 class MediaRouterMediaRoutesObserver : | 137 class MediaRouterMediaRoutesObserver : |
| 132 public media_router::MediaRoutesObserver { | 138 public media_router::MediaRoutesObserver { |
| 133 public: | 139 public: |
| 134 explicit MediaRouterMediaRoutesObserver(MediaRouterMojoImpl* router); | 140 explicit MediaRouterMediaRoutesObserver(MediaRouterMojoImpl* router, |
| 141 const MediaSource::Id source_id = std::string("")); | |
|
imcheng
2015/11/19 18:55:08
|source_id| is not needed?
matt.boetger
2015/11/24 19:45:23
Done.
| |
| 135 ~MediaRouterMediaRoutesObserver() override; | 142 ~MediaRouterMediaRoutesObserver() override; |
| 136 | 143 |
| 137 // media_router::MediaRoutesObserver: | 144 // media_router::MediaRoutesObserver: |
| 138 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes) | 145 void OnRoutesUpdated(const MediaSource::Id source_id, |
| 146 const std::vector<media_router::MediaRoute>& routes, | |
| 147 const std::vector<media_router::MediaRoute>& joinable_routes) | |
| 139 override; | 148 override; |
| 140 | 149 |
| 141 private: | 150 private: |
| 142 MediaRouterMojoImpl* const router_; | 151 MediaRouterMojoImpl* const router_; |
| 143 | 152 |
| 144 DISALLOW_COPY_AND_ASSIGN(MediaRouterMediaRoutesObserver); | 153 DISALLOW_COPY_AND_ASSIGN(MediaRouterMediaRoutesObserver); |
| 145 }; | 154 }; |
| 146 | 155 |
| 147 // 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 |
| 148 // query. | 157 // query. |
| 149 struct MediaSinksQuery { | 158 struct MediaSinksQuery { |
| 150 public: | 159 public: |
| 151 MediaSinksQuery(); | 160 MediaSinksQuery(); |
| 152 ~MediaSinksQuery(); | 161 ~MediaSinksQuery(); |
| 153 | 162 |
| 154 // 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. |
| 155 bool is_active = false; | 164 bool is_active = false; |
| 156 base::ObserverList<MediaSinksObserver> observers; | 165 base::ObserverList<MediaSinksObserver> observers; |
| 157 | 166 |
| 158 DISALLOW_COPY_AND_ASSIGN(MediaSinksQuery); | 167 DISALLOW_COPY_AND_ASSIGN(MediaSinksQuery); |
| 159 }; | 168 }; |
| 160 | 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 | |
| 161 // Standard constructor, used by | 182 // Standard constructor, used by |
| 162 // MediaRouterMojoImplFactory::GetApiForBrowserContext. | 183 // MediaRouterMojoImplFactory::GetApiForBrowserContext. |
| 163 explicit MediaRouterMojoImpl( | 184 explicit MediaRouterMojoImpl( |
| 164 extensions::EventPageTracker* event_page_tracker); | 185 extensions::EventPageTracker* event_page_tracker); |
| 165 | 186 |
| 166 // 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 |
| 167 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. | 188 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. |
| 168 // Stores the |extension_id| of the component extension. | 189 // Stores the |extension_id| of the component extension. |
| 169 void BindToMojoRequest( | 190 void BindToMojoRequest( |
| 170 mojo::InterfaceRequest<interfaces::MediaRouter> request, | 191 mojo::InterfaceRequest<interfaces::MediaRouter> request, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 const std::string& message, | 237 const std::string& message, |
| 217 const SendRouteMessageCallback& callback); | 238 const SendRouteMessageCallback& callback); |
| 218 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id, | 239 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id, |
| 219 scoped_ptr<std::vector<uint8>> data, | 240 scoped_ptr<std::vector<uint8>> data, |
| 220 const SendRouteMessageCallback& callback); | 241 const SendRouteMessageCallback& callback); |
| 221 void DoListenForRouteMessages(const MediaRoute::Id& route_id); | 242 void DoListenForRouteMessages(const MediaRoute::Id& route_id); |
| 222 void DoStopListeningForRouteMessages(const MediaRoute::Id& route_id); | 243 void DoStopListeningForRouteMessages(const MediaRoute::Id& route_id); |
| 223 void DoOnPresentationSessionDetached(const MediaRoute::Id& route_id); | 244 void DoOnPresentationSessionDetached(const MediaRoute::Id& route_id); |
| 224 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); | 245 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); |
| 225 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); | 246 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); |
| 226 void DoStartObservingMediaRoutes(); | 247 void DoStartObservingMediaRoutes(const MediaSource::Id& source_id); |
| 227 void DoStopObservingMediaRoutes(); | 248 void DoStopObservingMediaRoutes(const MediaSource::Id& source_id); |
| 228 | 249 |
| 229 // Invoked when the next batch of messages arrives. | 250 // Invoked when the next batch of messages arrives. |
| 230 // |route_id|: ID of route of the messages. | 251 // |route_id|: ID of route of the messages. |
| 231 // |messages|: A list of messages received. | 252 // |messages|: A list of messages received. |
| 232 // |error|: true if an error occurred. | 253 // |error|: true if an error occurred. |
| 233 void OnRouteMessagesReceived( | 254 void OnRouteMessagesReceived( |
| 234 const MediaRoute::Id& route_id, | 255 const MediaRoute::Id& route_id, |
| 235 mojo::Array<interfaces::RouteMessagePtr> messages, | 256 mojo::Array<interfaces::RouteMessagePtr> messages, |
| 236 bool error); | 257 bool error); |
| 237 | 258 |
| 238 // Error handler callback for |binding_| and |media_route_provider_|. | 259 // Error handler callback for |binding_| and |media_route_provider_|. |
| 239 void OnConnectionError(); | 260 void OnConnectionError(); |
| 240 | 261 |
| 241 // interfaces::MediaRouter implementation. | 262 // interfaces::MediaRouter implementation. |
| 242 void RegisterMediaRouteProvider( | 263 void RegisterMediaRouteProvider( |
| 243 interfaces::MediaRouteProviderPtr media_route_provider_ptr, | 264 interfaces::MediaRouteProviderPtr media_route_provider_ptr, |
| 244 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& | 265 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& |
| 245 callback) override; | 266 callback) override; |
| 246 void OnIssue(interfaces::IssuePtr issue) override; | 267 void OnIssue(interfaces::IssuePtr issue) override; |
| 247 void OnSinksReceived(const mojo::String& media_source, | 268 void OnSinksReceived(const mojo::String& media_source, |
| 248 mojo::Array<interfaces::MediaSinkPtr> sinks) override; | 269 mojo::Array<interfaces::MediaSinkPtr> sinks) override; |
| 249 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<interfaces::MediaRoutePtr> joinable_routes) override; | |
| 250 void OnSinkAvailabilityUpdated( | 273 void OnSinkAvailabilityUpdated( |
| 251 interfaces::MediaRouter::SinkAvailability availability) override; | 274 interfaces::MediaRouter::SinkAvailability availability) override; |
| 252 | 275 |
| 253 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute() | 276 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute() |
| 254 // into a local callback. | 277 // into a local callback. |
| 255 void RouteResponseReceived( | 278 void RouteResponseReceived( |
| 256 const std::string& presentation_id, | 279 const std::string& presentation_id, |
| 257 const std::vector<MediaRouteResponseCallback>& callbacks, | 280 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 258 interfaces::MediaRoutePtr media_route, | 281 interfaces::MediaRoutePtr media_route, |
| 259 const mojo::String& error_text); | 282 const mojo::String& error_text); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 276 // the pending request queue. | 299 // the pending request queue. |
| 277 void AttemptWakeEventPage(); | 300 void AttemptWakeEventPage(); |
| 278 | 301 |
| 279 // Pending requests queued to be executed once component extension | 302 // Pending requests queued to be executed once component extension |
| 280 // becomes ready. | 303 // becomes ready. |
| 281 std::deque<base::Closure> pending_requests_; | 304 std::deque<base::Closure> pending_requests_; |
| 282 | 305 |
| 283 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>> | 306 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>> |
| 284 sinks_queries_; | 307 sinks_queries_; |
| 285 | 308 |
| 309 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaRoutesQuery>> | |
| 310 routes_queries_; | |
| 311 | |
| 286 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_; | 312 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_; |
| 287 | 313 |
| 288 base::ObserverList<MediaRoutesObserver> routes_observers_; | |
| 289 | |
| 290 using PresentationSessionMessagesObserverList = | 314 using PresentationSessionMessagesObserverList = |
| 291 base::ObserverList<PresentationSessionMessagesObserver>; | 315 base::ObserverList<PresentationSessionMessagesObserver>; |
| 292 base::ScopedPtrHashMap<MediaRoute::Id, | 316 base::ScopedPtrHashMap<MediaRoute::Id, |
| 293 scoped_ptr<PresentationSessionMessagesObserverList>> | 317 scoped_ptr<PresentationSessionMessagesObserverList>> |
| 294 messages_observers_; | 318 messages_observers_; |
| 295 // IDs of MediaRoutes being listened for messages. Note that this is | 319 // IDs of MediaRoutes being listened for messages. Note that this is |
| 296 // different from |message_observers_| because we might be waiting for | 320 // different from |message_observers_| because we might be waiting for |
| 297 // |OnRouteMessagesReceived()| to be invoked after all observers for that | 321 // |OnRouteMessagesReceived()| to be invoked after all observers for that |
| 298 // route have been removed. | 322 // route have been removed. |
| 299 std::set<MediaRoute::Id> route_ids_listening_for_messages_; | 323 std::set<MediaRoute::Id> route_ids_listening_for_messages_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 base::ThreadChecker thread_checker_; | 363 base::ThreadChecker thread_checker_; |
| 340 | 364 |
| 341 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; | 365 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; |
| 342 | 366 |
| 343 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); | 367 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); |
| 344 }; | 368 }; |
| 345 | 369 |
| 346 } // namespace media_router | 370 } // namespace media_router |
| 347 | 371 |
| 348 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ | 372 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ |
| OLD | NEW |