OLD | NEW |
---|---|
(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/macros.h" | |
14 #include "base/memory/linked_ptr.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 | |
29 | |
30 namespace extensions { | |
31 class EventPageTracker; | |
32 } // namespace extensions | |
33 | |
34 namespace media_router { | |
35 | |
36 class IssuesObserver; | |
37 class MediaRouterMojoTest; | |
38 | |
39 // Implementation of the Mojo-based service which bridges the Media Router | |
40 // Provider Manager and the Media Router. | |
41 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.
| |
42 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
| |
43 public mojo::ErrorHandler, | |
44 public KeyedService { | |
45 public: | |
46 MediaRouterMojoImpl(); | |
47 | |
48 ~MediaRouterMojoImpl() override; | |
49 | |
50 // Binds the MediaRouterMojoImpl BrowserContext service to a Mojo request. | |
51 // |extension_id|: The ID of the component extension. | |
52 // 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.
| |
53 // |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.
| |
54 // |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.
| |
55 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.
| |
56 const std::string& extension_id, | |
57 content::BrowserContext* context, | |
58 mojo::InterfaceRequest<interfaces::MediaRouterObserver> request); | |
59 | |
60 // mojo::ErrorHandler | |
61 void OnConnectionError() override; | |
62 | |
63 // interfaces::MediaRouter implementation. | |
64 // 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
| |
65 void ProvideMediaRouter( | |
66 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.
| |
67 const interfaces::MediaRouterObserver::ProvideMediaRouterCallback& | |
68 callback) override; | |
69 void OnMessage(const mojo::String& route_id, | |
70 const mojo::String& message) override; | |
71 void OnIssue(interfaces::IssuePtr issue) override; | |
72 void OnSinksReceived(const mojo::String& media_source, | |
73 mojo::Array<interfaces::MediaSinkPtr> sinks) override; | |
74 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override; | |
75 | |
76 // MediaRouter implementation. | |
77 // For messages sent to the extension. | |
78 // Execution of the requests is delegated to the Do* methods, which can be | |
79 // enqueued for later use if the extension is temporarily suspended. | |
80 void CreateRoute(const MediaSourceId& source_id, | |
81 const MediaSinkId& sink_id, | |
82 const MediaRouteResponseCallback& callback) override; | |
83 void CloseRoute(const MediaRouteId& route_id) override; | |
84 void PostMessage(const MediaRouteId& route_id, | |
85 const std::string& message) override; | |
86 void ClearIssue(const Issue::IssueId& issue_id) override; | |
87 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
| |
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 MediaRouterMojoTest; | |
96 | |
97 // Used for testing. | |
98 MediaRouterMojoImpl( | |
99 const std::string& mrpm_ext_id, | |
100 extensions::EventPageTracker* event_page_tracker_for_test); | |
101 | |
102 // Binds |this| to a Mojo interface request, so that clients can acquire a | |
103 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. | |
104 void Bind(mojo::InterfaceRequest<interfaces::MediaRouterObserver> request); | |
105 | |
106 // Enqueues a closure for later execution by ExecutePendingRequests(). | |
107 void EnqueueTask(const base::Closure& closure); | |
108 | |
109 // Starts monitoring the suspend state of |extension_id|. | |
110 void MonitorExtension(const std::string& extension_id, | |
111 content::BrowserContext* context); | |
112 | |
113 // Runs a closure if the extension monitored by |extension_monitor_| is | |
114 // active, or defers it for later execution if the extension is suspended. | |
115 void RunOrDefer(const base::Closure& request_cb); | |
116 | |
117 // Runs pending requests in |pending_requests_|. | |
118 void ExecutePendingRequests(); | |
119 | |
120 // 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.
| |
121 std::vector<base::Closure> pending_requests_; | |
122 | |
123 // These calls invoke methods in the MRPM via Mojo. | |
124 void DoCreateRoute(const MediaSourceId& source_id, | |
125 const MediaSinkId& sink_id, | |
126 const MediaRouteResponseCallback& callback); | |
127 void DoCloseRoute(const MediaRouteId& route_id); | |
128 void DoPostMessage(const MediaRouteId& route_id, const std::string& message); | |
129 void DoClearIssue(const Issue::IssueId& issue_id); | |
130 void DoStartObservingMediaSinks(const std::string& source_id); | |
131 void DoStopObservingMediaSinks(const std::string& source_id); | |
132 void DoStartObservingMediaRoutes(); | |
133 void DoStopObservingMediaRoutes(); | |
134 void DoStartObservingIssues(); | |
135 void DoStopObservingIssues(); | |
136 | |
137 // Multimap of sinks observer objects, keyed by media source ID. | |
138 std::map<MediaSourceId, linked_ptr<ObserverList<MediaSinksObserver>>> | |
139 sinks_observers_; | |
140 | |
141 // List of route observer objects. | |
142 ObserverList<MediaRoutesObserver> routes_observers_; | |
143 | |
144 // Binds |this| to a Mojo MediaRouterObserver interface. | |
145 // The binding is released when binding_ is deleted. | |
146 scoped_ptr<mojo::Binding<interfaces::MediaRouterObserver>> binding_; | |
147 | |
148 // Mojo proxy object for the Provider Manager. | |
149 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.
| |
150 | |
151 // 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.
| |
152 // via event_page_tracker_. | |
153 std::string mrpm_extension_id_; | |
154 | |
155 // 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.
| |
156 // state. | |
157 extensions::EventPageTracker* event_page_tracker_; | |
158 | |
159 // GUID of this object's instance. | |
160 // 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.
| |
161 std::string instance_id_; | |
162 | |
163 base::ThreadChecker thread_checker_; | |
164 | |
165 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); | |
166 }; | |
167 | |
168 } // namespace media_router | |
169 | |
170 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ | |
OLD | NEW |