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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/containers/hash_tables.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/message_loop/message_loop_proxy.h"
19 #include "base/observer_list.h"
20 #include "base/threading/thread_checker.h"
21 #include "chrome/browser/media/router/issue.h"
22 #include "chrome/browser/media/router/media_router.h"
23 #include "chrome/browser/media/router/media_router.mojom.h"
24 #include "components/keyed_service/core/keyed_service.h"
25
26 namespace content {
27 class BrowserContext;
28 } // 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.
29
30 namespace extensions {
31 class EventPageTracker;
32 } // namespace extensions
33
34 namespace media_router {
35
36 class MediaRouterMojoTest;
37
38 // Implementation of the Mojo-based service which bridges the Media Router
39 // 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.
40 class MediaRouterMojoImpl : public MediaRouter,
41 public interfaces::MediaRouterObserver,
42 public mojo::ErrorHandler,
43 public KeyedService {
44 public:
45 ~MediaRouterMojoImpl() override;
46
47 // Binds the MediaRouterMojoImpl BrowserContext service to a Mojo request.
48 // Called by the Mojo module registry.
49 // |extension_id|: The ID of the component extension, used for querying
50 // suspension state.
51 // |context|: The BrowserContext which owns the extension process.
52 // |request|: The Mojo connection request used for binding.
53 static void BindToRequest(
54 const std::string& extension_id,
55 content::BrowserContext* context,
56 mojo::InterfaceRequest<interfaces::MediaRouterObserver> request);
57
58 // 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."
59 void OnConnectionError() override;
60
61 // 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.
62 // 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.
63 void ProvideMediaRouter(
64 interfaces::MediaRouterPtr media_router_ptr,
65 const interfaces::MediaRouterObserver::ProvideMediaRouterCallback&
66 callback) override;
67 void OnMessage(const mojo::String& route_id,
68 const mojo::String& message) override;
69 void OnIssue(interfaces::IssuePtr issue) override;
70 void OnSinksReceived(const mojo::String& media_source,
71 mojo::Array<interfaces::MediaSinkPtr> sinks) override;
72 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override;
73
74 // MediaRouter implementation.
75 // For messages sent to the extension.
Wez 2015/05/20 23:37:48 ?
imcheng (use chromium acct) 2015/05/21 19:28:52 Removed.
76 // Execution of the requests is delegated to the Do* methods, which can be
77 // enqueued for later use if the extension is temporarily suspended.
78 void CreateRoute(const MediaSourceId& source_id,
79 const MediaSinkId& sink_id,
80 const MediaRouteResponseCallback& callback) override;
81 void CloseRoute(const MediaRouteId& route_id) override;
82 void PostMessage(const MediaRouteId& route_id,
83 const std::string& message) override;
84 void ClearIssue(const Issue::IssueId& issue_id) override;
85 // These methods send messages to the extension upon first registration
86 // 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.
87 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
88 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
89 bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
90 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
91 void AddIssuesObserver(IssuesObserver* observer) override;
92 void RemoveIssuesObserver(IssuesObserver* observer) override;
93
94 private:
95 friend class MediaRouterMojoImplFactory;
96 friend class MediaRouterMojoTest;
97
98 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
99 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
100
101 // New instances should be constructed through
102 // 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.
103 MediaRouterMojoImpl();
104
105 // 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
106 MediaRouterMojoImpl(
107 const std::string& mojo_media_router_ext_id,
108 extensions::EventPageTracker* event_page_tracker_for_test);
109
110 // Binds |this| to a Mojo interface request, so that clients can acquire a
111 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
112 void Bind(mojo::InterfaceRequest<interfaces::MediaRouterObserver> request);
113
114 // Enqueues a closure for later execution by ExecutePendingRequests().
115 void EnqueueTask(const base::Closure& closure);
116
117 // Starts monitoring the suspend state of |extension_id|.
118 void MonitorExtension(const std::string& extension_id,
119 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.
120
121 // Runs a closure if the extension monitored by |extension_monitor_| is
122 // active, or defers it for later execution if the extension is suspended.
123 void RunOrDefer(const base::Closure& request_cb);
124
125 // 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.
126 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.
127
128 // These calls invoke methods in the MRPM via Mojo.
129 void DoCreateRoute(const MediaSourceId& source_id,
130 const MediaSinkId& sink_id,
131 const MediaRouteResponseCallback& callback);
132 void DoCloseRoute(const MediaRouteId& route_id);
133 void DoPostMessage(const MediaRouteId& route_id, const std::string& message);
134 void DoClearIssue(const Issue::IssueId& issue_id);
135 void DoStartObservingMediaSinks(const std::string& source_id);
136 void DoStopObservingMediaSinks(const std::string& source_id);
137 void DoStartObservingMediaRoutes();
138 void DoStopObservingMediaRoutes();
139 void DoStartObservingIssues();
140 void DoStopObservingIssues();
141
142 // Pending requests queued to be executed once MRPM becomes ready.
143 std::vector<base::Closure> pending_requests_;
144
145 // 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.
146 base::ScopedPtrHashMap<MediaSourceId,
147 scoped_ptr<ObserverList<MediaSinksObserver>>>
148 sinks_observers_;
149
150 // 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.
151 ObserverList<MediaRoutesObserver> routes_observers_;
152
153 // Binds |this| to a Mojo MediaRouterObserver interface.
154 // 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.
155 scoped_ptr<mojo::Binding<interfaces::MediaRouterObserver>> binding_;
156
157 // 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.
158 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
159
160 // 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.
161 // via event_page_tracker_.
162 std::string mojo_media_router_extension_id_;
163
164 // Provides querying and waking functionality for the component extension's
165 // 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.
166 extensions::EventPageTracker* event_page_tracker_;
167
168 // GUID of this object's instance.
169 // Used by the component extension to determine if its persistent cache
170 // 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.
171 std::string instance_id_;
172
173 base::ThreadChecker thread_checker_;
174
175 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
176 };
177
178 } // namespace media_router
179
180 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698