Chromium Code Reviews| Index: chrome/browser/media/router/media_router_mojo_impl.h |
| diff --git a/chrome/browser/media/router/media_router_mojo_impl.h b/chrome/browser/media/router/media_router_mojo_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b8d1f886e32a5aae5c61285143295cab23d1c4b1 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/media_router_mojo_impl.h |
| @@ -0,0 +1,170 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ |
| +#define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/containers/hash_tables.h" |
| +#include "base/macros.h" |
| +#include "base/memory/linked_ptr.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| +#include "base/observer_list.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "chrome/browser/media/router/issue.h" |
| +#include "chrome/browser/media/router/media_router.h" |
| +#include "chrome/browser/media/router/media_router.mojom.h" |
| +#include "components/keyed_service/core/keyed_service.h" |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} // namespace content |
| + |
| +namespace extensions { |
| +class EventPageTracker; |
| +} // namespace extensions |
| + |
| +namespace media_router { |
| + |
| +class IssuesObserver; |
| +class MediaRouterMojoTest; |
| + |
| +// Implementation of the Mojo-based service which bridges the Media Router |
| +// Provider Manager and the Media Router. |
| +class MediaRouterMojoImpl : public MediaRouter, |
|
mark a. foltz
2015/05/08 00:58:38
What is the relationship between this class and Me
Kevin M
2015/05/12 23:56:10
Please revisit.
|
| + public interfaces::MediaRouterObserver, |
|
mark a. foltz
2015/05/08 00:58:38
It seems odd for a class to both implement an inte
Kevin M
2015/05/12 23:56:10
This reflects a choice made during the upstreaming
|
| + public mojo::ErrorHandler, |
| + public KeyedService { |
| + public: |
| + MediaRouterMojoImpl(); |
| + |
| + ~MediaRouterMojoImpl() override; |
| + |
| + // Binds the MediaRouterMojoImpl BrowserContext service to a Mojo request. |
| + // |extension_id|: The ID of the component extension. |
| + // Used for querying suspension state. |
|
mark a. foltz
2015/05/08 00:58:38
Wrap to previous line and use a four space continu
Kevin M
2015/05/12 23:56:10
Done.
|
| + // |context|: The BrowserContext which owns the extension process. |
|
mark a. foltz
2015/05/08 00:58:38
extra whitespace
Kevin M
2015/05/12 23:56:10
Done.
|
| + // |request|: The Mojo connection request used for binding. |
|
mark a. foltz
2015/05/08 00:58:38
ditto
Kevin M
2015/05/12 23:56:09
Done.
|
| + static void BindToRequest( |
|
mark a. foltz
2015/05/08 00:58:38
When would a caller invoke this method? Is this a
Kevin M
2015/05/12 23:56:09
Correct - it's called by the Mojo module registry.
|
| + const std::string& extension_id, |
| + content::BrowserContext* context, |
| + mojo::InterfaceRequest<interfaces::MediaRouterObserver> request); |
| + |
| + // mojo::ErrorHandler |
| + void OnConnectionError() override; |
| + |
| + // interfaces::MediaRouter implementation. |
| + // For incoming messages from the extension. |
|
mark a. foltz
2015/05/08 00:58:38
It seems like ProvideMediaRouter is injecting an i
Kevin M
2015/05/12 23:56:10
It's registering a the extension's Mojo "MediaRout
|
| + void ProvideMediaRouter( |
| + interfaces::MediaRouterPtr mrpm, |
|
mark a. foltz
2015/05/08 00:58:38
|mrpm| is too short- expand into a hacker_style pa
Kevin M
2015/05/12 23:56:10
Done.
|
| + const interfaces::MediaRouterObserver::ProvideMediaRouterCallback& |
| + callback) override; |
| + void OnMessage(const mojo::String& route_id, |
| + const mojo::String& message) override; |
| + void OnIssue(interfaces::IssuePtr issue) override; |
| + void OnSinksReceived(const mojo::String& media_source, |
| + mojo::Array<interfaces::MediaSinkPtr> sinks) override; |
| + void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override; |
| + |
| + // MediaRouter implementation. |
| + // For messages sent to the extension. |
| + // Execution of the requests is delegated to the Do* methods, which can be |
| + // enqueued for later use if the extension is temporarily suspended. |
| + void CreateRoute(const MediaSourceId& source_id, |
| + const MediaSinkId& sink_id, |
| + const MediaRouteResponseCallback& callback) override; |
| + void CloseRoute(const MediaRouteId& route_id) override; |
| + void PostMessage(const MediaRouteId& route_id, |
| + const std::string& message) override; |
| + void ClearIssue(const Issue::IssueId& issue_id) override; |
| + bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override; |
|
mark a. foltz
2015/05/08 00:58:38
Are the methods from here on below also resulting
Kevin M
2015/05/12 23:56:10
Yes, upon first registration and last unregistrati
|
| + void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; |
| + bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| + void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| + void AddIssuesObserver(IssuesObserver* observer) override; |
| + void RemoveIssuesObserver(IssuesObserver* observer) override; |
| + |
| + private: |
| + friend class MediaRouterMojoTest; |
| + |
| + // Used for testing. |
| + MediaRouterMojoImpl( |
| + const std::string& mrpm_ext_id, |
| + extensions::EventPageTracker* event_page_tracker_for_test); |
| + |
| + // Binds |this| to a Mojo interface request, so that clients can acquire a |
| + // handle to a MediaRouterMojoImpl instance via the Mojo service connector. |
| + void Bind(mojo::InterfaceRequest<interfaces::MediaRouterObserver> request); |
| + |
| + // Enqueues a closure for later execution by ExecutePendingRequests(). |
| + void EnqueueTask(const base::Closure& closure); |
| + |
| + // Starts monitoring the suspend state of |extension_id|. |
| + void MonitorExtension(const std::string& extension_id, |
| + content::BrowserContext* context); |
| + |
| + // Runs a closure if the extension monitored by |extension_monitor_| is |
| + // active, or defers it for later execution if the extension is suspended. |
| + void RunOrDefer(const base::Closure& request_cb); |
| + |
| + // Runs pending requests in |pending_requests_|. |
| + void ExecutePendingRequests(); |
| + |
| + // Pending requests queued to be executed once MRPM becomes ready. |
|
mark a. foltz
2015/05/08 00:58:38
Member variables need to go after method declarati
Kevin M
2015/05/12 23:56:09
Done.
|
| + std::vector<base::Closure> pending_requests_; |
| + |
| + // These calls invoke methods in the MRPM via Mojo. |
| + void DoCreateRoute(const MediaSourceId& source_id, |
| + const MediaSinkId& sink_id, |
| + const MediaRouteResponseCallback& callback); |
| + void DoCloseRoute(const MediaRouteId& route_id); |
| + void DoPostMessage(const MediaRouteId& route_id, const std::string& message); |
| + void DoClearIssue(const Issue::IssueId& issue_id); |
| + void DoStartObservingMediaSinks(const std::string& source_id); |
| + void DoStopObservingMediaSinks(const std::string& source_id); |
| + void DoStartObservingMediaRoutes(); |
| + void DoStopObservingMediaRoutes(); |
| + void DoStartObservingIssues(); |
| + void DoStopObservingIssues(); |
| + |
| + // Multimap of sinks observer objects, keyed by media source ID. |
| + std::map<MediaSourceId, linked_ptr<ObserverList<MediaSinksObserver>>> |
| + sinks_observers_; |
| + |
| + // List of route observer objects. |
| + ObserverList<MediaRoutesObserver> routes_observers_; |
| + |
| + // Binds |this| to a Mojo MediaRouterObserver interface. |
| + // The binding is released when binding_ is deleted. |
| + scoped_ptr<mojo::Binding<interfaces::MediaRouterObserver>> binding_; |
| + |
| + // Mojo proxy object for the Provider Manager. |
| + interfaces::MediaRouterPtr mrpm_; |
|
mark a. foltz
2015/05/08 00:58:38
Please expand into a proper variable name.
Kevin M
2015/05/12 23:56:10
Done.
|
| + |
| + // ID of the MRPM extension. Used for managing its suspend/wake state |
|
mark a. foltz
2015/05/08 00:58:38
s/MRPM/component/ ?
Kevin M
2015/05/12 23:56:10
Done.
|
| + // via event_page_tracker_. |
| + std::string mrpm_extension_id_; |
| + |
| + // Provides querying and waking functionality for an extension's suspend |
|
mark a. foltz
2015/05/08 00:58:38
...for the component extension's...
Kevin M
2015/05/12 23:56:09
Done.
|
| + // state. |
| + extensions::EventPageTracker* event_page_tracker_; |
| + |
| + // GUID of this object's instance. |
| + // Used by the MRPM to determine if its persistent cache is stale. |
|
mark a. foltz
2015/05/08 00:58:38
... the component extension ...
Kevin M
2015/05/12 23:56:09
Done.
|
| + std::string instance_id_; |
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ |