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..febbb73c7db3054a5f37911b03d7d0829d8d7973 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/media_router_mojo_impl.h |
| @@ -0,0 +1,181 @@ |
| +// 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/containers/scoped_ptr_hash_map.h" |
| +#include "base/macros.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 extensions { |
| +class EventPageTracker; |
| +} |
| + |
| +namespace media_router { |
| + |
| +// Mojo service exposing Media Router functionality to the Media Route Provider |
| +// Manager. |
| +class MediaRouterMojoImpl : public MediaRouter, |
|
Wez
2015/05/22 00:05:38
Sorry, I meant to mention this fundamental questio
imcheng (use chromium acct)
2015/05/22 00:54:07
I think "really only intended to expose MediaRoute
Wez
2015/05/23 00:45:46
Right - thinking about this last night, I realised
imcheng (use chromium acct)
2015/05/26 17:58:31
ok, I changed the class level comments as you sugg
|
| + public interfaces::MediaRouterObserver, |
| + public mojo::ErrorHandler, |
| + public KeyedService { |
| + public: |
| + ~MediaRouterMojoImpl() override; |
| + |
| + // Binds the MediaRouterMojoImpl BrowserContext service to a Mojo request. |
| + // Called by the Mojo module registry. |
| + // |extension_id|: The ID of the component extension, used for querying |
| + // suspension state. |
| + // |context|: The BrowserContext which owns the extension process. |
| + // |request|: The Mojo connection request used for binding. |
| + static void BindToRequest( |
| + const std::string& extension_id, |
| + content::BrowserContext* context, |
| + mojo::InterfaceRequest<interfaces::MediaRouterObserver> request); |
| + |
| + // mojo::ErrorHandler implementation. |
| + void OnConnectionError() override; |
| + |
| + // interfaces::MediaRouterObserver implementation. |
| + void ProvideMediaRouter( |
| + interfaces::MediaRouterPtr media_router_ptr, |
| + 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. |
| + // 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; |
| + void RegisterMediaSinksObserver(MediaSinksObserver* observer) override; |
| + void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; |
| + void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| + void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| + void AddIssuesObserver(IssuesObserver* observer) override; |
| + void RemoveIssuesObserver(IssuesObserver* observer) override; |
| + |
| + private: |
| + friend class MediaRouterMojoImplFactory; |
| + friend class MediaRouterMojoTest; |
| + |
| + FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, |
| + DeferredBindingAndSuspension); |
| + |
| + // Standard constructor, used by |
| + // MediaRouterMojoImplFactory::GetApiForBrowserContext. |
| + MediaRouterMojoImpl(); |
| + |
| + // Constructor used only for testing. |
| + MediaRouterMojoImpl( |
| + const std::string& mojo_media_router_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); |
|
Wez
2015/05/22 00:05:39
I think you're right that there's no real value in
imcheng (use chromium acct)
2015/05/22 00:54:07
When I tried to change it I realized why it was st
Wez
2015/05/23 00:45:46
That's fine, but in that case you need to make it
imcheng (use chromium acct)
2015/05/26 17:58:31
Both are used in production code, so *ForTest isn'
|
| + |
| + // Stores the |extension_id| of the component extension in this instance. |
| + // Also obtains a reference to the extension's ProcessManager using |
| + // |context|, which is a reference to the BrowserContext that this |
| + // instance and extension are keyed on. |
|
Wez
2015/05/22 00:05:38
Does "keyed on" mean "belong to", in effect?
imcheng (use chromium acct)
2015/05/22 00:54:07
Yes
Wez
2015/05/23 00:45:46
OK - in that case I'd suggest using "belong to", s
imcheng (use chromium acct)
2015/05/26 17:58:31
Done.
|
| + void InitExtensionInfo(const std::string& extension_id, |
| + content::BrowserContext* context); |
| + |
| + // Enqueues a closure for later execution by ExecutePendingRequests(). |
| + void EnqueueTask(const base::Closure& closure); |
| + |
| + // 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); |
| + |
| + // Runs the closures queued in |pending_requests_|. |
|
Wez
2015/05/22 00:05:38
nit: Suggest "Dispatches the Mojo requests queued
imcheng (use chromium acct)
2015/05/22 00:54:07
Done.
|
| + void ExecutePendingRequests(); |
| + |
| + // 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(); |
| + |
| + // Pending requests queued to be executed once MRPM becomes ready. |
| + std::vector<base::Closure> pending_requests_; |
| + |
| + base::ScopedPtrHashMap<MediaSourceId, |
| + scoped_ptr<ObserverList<MediaSinksObserver>>> |
| + sinks_observers_; |
| + |
| + ObserverList<MediaRoutesObserver> routes_observers_; |
| + |
| + // Binds |this| to a Mojo MediaRouterObserver interface. |
| + // This binding exists so that MediaRouterObserver calls from the |
|
Wez
2015/05/22 00:05:38
That is fairly intuitive from the class names; the
imcheng (use chromium acct)
2015/05/22 00:54:07
Yes. The component extension is a MediaRouter. Jus
Wez
2015/05/23 00:45:47
See above re the class level comment :)
|
| + // component extensions are routed here. |
| + // The binding is released when binding_ is deleted. |
| + scoped_ptr<mojo::Binding<interfaces::MediaRouterObserver>> binding_; |
| + |
| + // Mojo proxy object for the Provider Manager. |
| + // Set to null initially, and set to the proxy to the component extension |
| + // on |ProvideMediaRouter()|. This is set to null again when the component |
| + // extension becomes suspended or if there is a connection error. |
|
Wez
2015/05/22 00:05:38
So this is basically the API through which we send
imcheng (use chromium acct)
2015/05/22 00:54:07
We should really get rid of any references to the
Wez
2015/05/23 00:45:46
Acknowledged.
|
| + interfaces::MediaRouterPtr mojo_media_router_; |
| + |
| + // Id of the component extension. Used for managing its suspend/wake state |
| + // via event_page_tracker_. |
| + std::string mojo_media_router_extension_id_; |
| + |
| + // Allows the extension to be monitored for suspend, and woken. |
| + // This is a reference to a BrowserContext keyed service that outlives this |
| + // instance. |
| + extensions::EventPageTracker* event_page_tracker_; |
| + |
| + // GUID unique to each browser run. Component extension uses this to detect |
| + // when its persisted state was written by an older browser instance, and is |
| + // therefore stale. |
| + 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_ |