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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/browser/media/router/media_router_base.h" | 27 #include "chrome/browser/media/router/media_router_base.h" |
| 28 #include "chrome/browser/media/router/media_routes_observer.h" | 28 #include "chrome/browser/media/router/media_routes_observer.h" |
| 29 #include "mojo/public/cpp/bindings/binding.h" | 29 #include "mojo/public/cpp/bindings/binding.h" |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 class BrowserContext; | 32 class BrowserContext; |
| 33 } | 33 } |
| 34 | 34 |
| 35 namespace extensions { | 35 namespace extensions { |
| 36 class EventPageTracker; | 36 class EventPageTracker; |
| 37 class Extension; | |
| 37 } | 38 } |
| 38 | 39 |
| 39 namespace media_router { | 40 namespace media_router { |
| 40 | 41 |
| 41 enum class MediaRouteProviderWakeReason; | 42 enum class MediaRouteProviderWakeReason; |
| 42 | 43 |
| 43 // MediaRouter implementation that delegates calls to the component extension. | 44 // MediaRouter implementation that delegates calls to the component extension. |
| 44 // Also handles the suspension and wakeup of the component extension. | 45 // Also handles the suspension and wakeup of the component extension. |
| 45 class MediaRouterMojoImpl : public MediaRouterBase, | 46 class MediaRouterMojoImpl : public MediaRouterBase, |
| 46 public interfaces::MediaRouter { | 47 public interfaces::MediaRouter { |
| 47 public: | 48 public: |
| 48 ~MediaRouterMojoImpl() override; | 49 ~MediaRouterMojoImpl() override; |
| 49 | 50 |
| 50 // Sets up the MediaRouterMojoImpl instance owned by |context| to handle | 51 // Sets up the MediaRouterMojoImpl instance owned by |context| to handle |
| 51 // MediaRouterObserver requests from the component extension given by | 52 // MediaRouterObserver requests from the component extension given by |
| 52 // |extension_id|. Creates the MediaRouterMojoImpl instance if it does not | 53 // |extension|. Creates the MediaRouterMojoImpl instance if it does not |
| 53 // exist. | 54 // exist. |
| 54 // Called by the Mojo module registry. | 55 // Called by the Mojo module registry. |
| 55 // |extension_id|: The ID of the component extension, used for querying | 56 // |extension|: The component extension, used for querying |
| 56 // suspension state. | 57 // suspension state. |
| 57 // |context|: The BrowserContext which owns the extension process. | 58 // |context|: The BrowserContext which owns the extension process. |
| 58 // |request|: The Mojo connection request used for binding. | 59 // |request|: The Mojo connection request used for binding. |
| 59 static void BindToRequest( | 60 static void BindToRequest( |
| 60 const std::string& extension_id, | 61 const extensions::Extension* extension, |
| 61 content::BrowserContext* context, | 62 content::BrowserContext* context, |
| 62 mojo::InterfaceRequest<interfaces::MediaRouter> request); | 63 mojo::InterfaceRequest<interfaces::MediaRouter> request); |
| 63 | 64 |
| 64 // MediaRouter implementation. | 65 // MediaRouter implementation. |
| 65 // Execution of the requests is delegated to the Do* methods, which can be | 66 // Execution of the requests is delegated to the Do* methods, which can be |
| 66 // enqueued for later use if the extension is temporarily suspended. | 67 // enqueued for later use if the extension is temporarily suspended. |
| 67 void CreateRoute(const MediaSource::Id& source_id, | 68 void CreateRoute(const MediaSource::Id& source_id, |
| 68 const MediaSink::Id& sink_id, | 69 const MediaSink::Id& sink_id, |
| 69 const GURL& origin, | 70 const GURL& origin, |
| 70 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery); | 175 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery); |
| 175 }; | 176 }; |
| 176 | 177 |
| 177 // Standard constructor, used by | 178 // Standard constructor, used by |
| 178 // MediaRouterMojoImplFactory::GetApiForBrowserContext. | 179 // MediaRouterMojoImplFactory::GetApiForBrowserContext. |
| 179 explicit MediaRouterMojoImpl( | 180 explicit MediaRouterMojoImpl( |
| 180 extensions::EventPageTracker* event_page_tracker); | 181 extensions::EventPageTracker* event_page_tracker); |
| 181 | 182 |
| 182 // Binds |this| to a Mojo interface request, so that clients can acquire a | 183 // Binds |this| to a Mojo interface request, so that clients can acquire a |
| 183 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. | 184 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. |
| 184 // Stores the |extension_id| of the component extension. | 185 // Stores the ID of |extension| in |media_route_provider_extension_id_|. |
| 185 void BindToMojoRequest( | 186 void BindToMojoRequest( |
| 186 mojo::InterfaceRequest<interfaces::MediaRouter> request, | 187 mojo::InterfaceRequest<interfaces::MediaRouter> request, |
| 187 const std::string& extension_id); | 188 const extensions::Extension& extension); |
| 188 | 189 |
| 189 // Enqueues a closure for later execution by ExecutePendingRequests(). | 190 // Enqueues a closure for later execution by ExecutePendingRequests(). |
| 190 void EnqueueTask(const base::Closure& closure); | 191 void EnqueueTask(const base::Closure& closure); |
| 191 | 192 |
| 192 // Runs a closure if the extension monitored by |extension_monitor_| is | 193 // Runs a closure if the extension monitored by |extension_monitor_| is |
| 193 // active, or defers it for later execution if the extension is suspended. | 194 // active, or defers it for later execution if the extension is suspended. |
| 194 void RunOrDefer(const base::Closure& request); | 195 void RunOrDefer(const base::Closure& request); |
| 195 | 196 |
| 196 // Dispatches the Mojo requests queued in |pending_requests_|. | 197 // Dispatches the Mojo requests queued in |pending_requests_|. |
| 197 void ExecutePendingRequests(); | 198 void ExecutePendingRequests(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 | 367 |
| 367 // The last reported sink availability from the media route provider manager. | 368 // The last reported sink availability from the media route provider manager. |
| 368 interfaces::MediaRouter::SinkAvailability availability_; | 369 interfaces::MediaRouter::SinkAvailability availability_; |
| 369 | 370 |
| 370 int wakeup_attempt_count_; | 371 int wakeup_attempt_count_; |
| 371 | 372 |
| 372 // Records the current reason the extension is being woken up. Is set to | 373 // Records the current reason the extension is being woken up. Is set to |
| 373 // MediaRouteProviderWakeReason::TOTAL_COUNT if there is no pending reason. | 374 // MediaRouteProviderWakeReason::TOTAL_COUNT if there is no pending reason. |
| 374 MediaRouteProviderWakeReason current_wake_reason_; | 375 MediaRouteProviderWakeReason current_wake_reason_; |
| 375 | 376 |
| 377 // A flag to ensure that we record the provider version once, during the | |
| 378 // initial event page wakeup attempt. | |
| 379 bool provider_version_recorded_; | |
|
Wez
2016/03/18 18:35:43
nit: Suggest was_provider_version_recorded_ or hav
mark a. foltz
2016/03/18 20:11:00
Done.
| |
| 380 | |
| 376 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; | 381 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; |
| 377 | 382 |
| 378 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); | 383 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); |
| 379 }; | 384 }; |
| 380 | 385 |
| 381 } // namespace media_router | 386 } // namespace media_router |
| 382 | 387 |
| 383 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ | 388 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ |
| OLD | NEW |