Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2118)

Unified Diff: chrome/browser/media/router/media_router_mojo_impl.h

Issue 1126923002: Add Media Router Mojo impl code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redundant forward decl removed. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..54cced934ae4e81fc3183fd3e5f1176b16479e77
--- /dev/null
+++ b/chrome/browser/media/router/media_router_mojo_impl.h
@@ -0,0 +1,180 @@
+// 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 content
Wez 2015/05/20 23:37:49 nit: This namespace is sufficiently short that you
imcheng (use chromium acct) 2015/05/21 19:28:51 Done.
+
+namespace extensions {
+class EventPageTracker;
+} // namespace extensions
+
+namespace media_router {
+
+class MediaRouterMojoTest;
+
+// Implementation of the Mojo-based service which bridges the Media Router
+// Provider Manager and the Media Router.
Wez 2015/05/20 23:37:49 Would it be clearer to describe this as the Mojo s
imcheng (use chromium acct) 2015/05/21 19:28:51 Done.
+class MediaRouterMojoImpl : public MediaRouter,
+ 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
Wez 2015/05/20 23:37:49 You mean "mojo::ErrorHandler interface."?
imcheng (use chromium acct) 2015/05/21 19:28:52 Changed to "mojo::ErrorHandler implementation."
+ void OnConnectionError() override;
+
+ // interfaces::MediaRouter implementation.
Wez 2015/05/20 23:37:48 This class doesn't seem to inherit from interfaces
imcheng (use chromium acct) 2015/05/21 19:28:51 Done.
+ // Registers a Mojo MediaRouter proxy object from the extension.
Wez 2015/05/20 23:37:49 Why does this method deserve a comment, but none o
imcheng (use chromium acct) 2015/05/21 19:28:52 removed.
+ 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.
+ // For messages sent to the extension.
Wez 2015/05/20 23:37:48 ?
imcheng (use chromium acct) 2015/05/21 19:28:52 Removed.
+ // 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;
+ // These methods send messages to the extension upon first registration
+ // and last unregistration.
Wez 2015/05/20 23:37:49 nit: Blank line above this comment, to make it mor
imcheng (use chromium acct) 2015/05/21 19:28:52 Removed since it is no longer true.
+ bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
+ 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 MediaRouterMojoImplFactory;
+ friend class MediaRouterMojoTest;
+
+ FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
+ DeferredBindingAndSuspension);
Wez 2015/05/20 23:37:49 What's the DeferredBindingAndSuspension thing abou
imcheng (use chromium acct) 2015/05/21 19:28:51 It's a test that's disabled until "issues with ext
+
+ // New instances should be constructed through
+ // MediaRouterMojoImplFactory::GetApiForBrowserContext.
Wez 2015/05/20 23:37:49 Suggest "Standard constructor, used by ..."
imcheng (use chromium acct) 2015/05/21 19:28:51 Done.
+ MediaRouterMojoImpl();
+
+ // Used for testing.
Wez 2015/05/20 23:37:48 Suggest "Constructor used only for testing." Cons
imcheng (use chromium acct) 2015/05/21 19:28:52 Changed comment. The MediaRouterMojoTest setup cod
+ 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);
+
+ // 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);
Wez 2015/05/20 23:37:48 Clarify the role of |context| in this API; I assum
imcheng (use chromium acct) 2015/05/21 19:28:52 Done.
+
+ // 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_|.
Wez 2015/05/20 23:37:49 Suggest "Runs the closures queued in |pending_requ
imcheng (use chromium acct) 2015/05/21 19:28:52 Done.
+ inline void ExecutePendingRequests();
Wez 2015/05/20 23:37:48 Remove inline from here.
imcheng (use chromium acct) 2015/05/21 19:28:51 Done.
+
+ // 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_;
+
+ // Multimap of sinks observer objects, keyed by media source ID.
Wez 2015/05/20 23:37:49 nit: This comment doesn't scan; you mean it's a Mu
imcheng (use chromium acct) 2015/05/21 19:28:52 Removed comment.
+ base::ScopedPtrHashMap<MediaSourceId,
+ scoped_ptr<ObserverList<MediaSinksObserver>>>
+ sinks_observers_;
+
+ // List of route observer objects.
Wez 2015/05/20 23:37:49 Similarly, this comment doesn't tell me what this
imcheng (use chromium acct) 2015/05/21 19:28:52 Done.
+ ObserverList<MediaRoutesObserver> routes_observers_;
+
+ // Binds |this| to a Mojo MediaRouterObserver interface.
+ // The binding is released when binding_ is deleted.
Wez 2015/05/20 23:37:49 Again, this comment doesn't describe _why_ this me
imcheng (use chromium acct) 2015/05/21 19:28:52 Done.
+ scoped_ptr<mojo::Binding<interfaces::MediaRouterObserver>> binding_;
+
+ // Mojo proxy object for the Provider Manager.
Wez 2015/05/20 23:37:49 Is there a possibility that this may be "null" if
imcheng (use chromium acct) 2015/05/21 19:28:52 Yes. Clarified in comments.
+ interfaces::MediaRouterPtr mojo_media_router_;
Wez 2015/05/20 23:37:49 I'm confused... why is the interface to the Provid
imcheng (use chromium acct) 2015/05/21 19:28:51 There was a discussion with Kevin and xhwang@ on t
Wez 2015/05/21 23:32:47 That doesn't sound right. The MediaRouter is the c
imcheng (use chromium acct) 2015/05/22 00:54:08 Hmm. I think it makes sense to me. From Chrome's p
+
+ // ID of the component extension. Used for managing its suspend/wake state
Wez 2015/05/20 23:37:49 nit: ID->Id.
imcheng (use chromium acct) 2015/05/21 19:28:51 Done.
+ // via event_page_tracker_.
+ std::string mojo_media_router_extension_id_;
+
+ // Provides querying and waking functionality for the component extension's
+ // suspend state.
Wez 2015/05/20 23:37:49 Suggest: "Allows the extension to be monitor for s
imcheng (use chromium acct) 2015/05/21 19:28:51 Done.
+ extensions::EventPageTracker* event_page_tracker_;
+
+ // GUID of this object's instance.
+ // Used by the component extension to determine if its persistent cache
+ // is stale.
Wez 2015/05/20 23:37:49 Probably needs elaborating upon; suggest something
imcheng (use chromium acct) 2015/05/21 19:28:52 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_

Powered by Google App Engine
This is Rietveld 408576698