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

Side by Side Diff: chrome/browser/media/router/media_router_mojo_impl.h

Issue 1259073004: [Presentation API] Change ListenForSessionMessages API to client-style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comments Created 5 years, 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
13 #include "base/containers/scoped_ptr_hash_map.h" 14 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
18 #include "base/observer_list.h" 19 #include "base/observer_list.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 int tab_id, 71 int tab_id,
71 const std::vector<MediaRouteResponseCallback>& callbacks) override; 72 const std::vector<MediaRouteResponseCallback>& callbacks) override;
72 void CloseRoute(const MediaRoute::Id& route_id) override; 73 void CloseRoute(const MediaRoute::Id& route_id) override;
73 void SendRouteMessage(const MediaRoute::Id& route_id, 74 void SendRouteMessage(const MediaRoute::Id& route_id,
74 const std::string& message, 75 const std::string& message,
75 const SendRouteMessageCallback& callback) override; 76 const SendRouteMessageCallback& callback) override;
76 void SendRouteBinaryMessage( 77 void SendRouteBinaryMessage(
77 const MediaRoute::Id& route_id, 78 const MediaRoute::Id& route_id,
78 scoped_ptr<std::vector<uint8>> data, 79 scoped_ptr<std::vector<uint8>> data,
79 const SendRouteMessageCallback& callback) override; 80 const SendRouteMessageCallback& callback) override;
80 void ListenForRouteMessages(
81 const std::vector<MediaRoute::Id>& route_ids,
82 const PresentationSessionMessageCallback& message_cb) override;
83 void ClearIssue(const Issue::Id& issue_id) override; 81 void ClearIssue(const Issue::Id& issue_id) override;
84 void RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
85 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
86 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
87 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
88 void RegisterIssuesObserver(IssuesObserver* observer) override;
89 void UnregisterIssuesObserver(IssuesObserver* observer) override;
90 82
91 const std::string& media_route_provider_extension_id() const { 83 const std::string& media_route_provider_extension_id() const {
92 return media_route_provider_extension_id_; 84 return media_route_provider_extension_id_;
93 } 85 }
94 86
95 void set_instance_id_for_test(const std::string& instance_id) { 87 void set_instance_id_for_test(const std::string& instance_id) {
96 instance_id_ = instance_id; 88 instance_id_ = instance_id;
97 } 89 }
98 90
99 private: 91 private:
100 friend class MediaRouterFactory; 92 friend class MediaRouterFactory;
101 friend class MediaRouterMojoTest; 93 friend class MediaRouterMojoTest;
102 94
95 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
96 RegisterAndUnregisterMediaSinksObserver);
97 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
98 RegisterAndUnregisterMediaRoutesObserver);
99 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue);
103 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 100 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
104 DeferredBindingAndSuspension); 101 DeferredBindingAndSuspension);
105 102
106 // Standard constructor, used by 103 // Standard constructor, used by
107 // MediaRouterMojoImplFactory::GetApiForBrowserContext. 104 // MediaRouterMojoImplFactory::GetApiForBrowserContext.
108 explicit MediaRouterMojoImpl( 105 explicit MediaRouterMojoImpl(
109 extensions::EventPageTracker* event_page_tracker); 106 extensions::EventPageTracker* event_page_tracker);
110 107
111 // Binds |this| to a Mojo interface request, so that clients can acquire a 108 // Binds |this| to a Mojo interface request, so that clients can acquire a
112 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. 109 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
113 // Stores the |extension_id| of the component extension. 110 // Stores the |extension_id| of the component extension.
114 void BindToMojoRequest( 111 void BindToMojoRequest(
115 mojo::InterfaceRequest<interfaces::MediaRouter> request, 112 mojo::InterfaceRequest<interfaces::MediaRouter> request,
116 const std::string& extension_id); 113 const std::string& extension_id);
117 114
118 // Enqueues a closure for later execution by ExecutePendingRequests(). 115 // Enqueues a closure for later execution by ExecutePendingRequests().
119 void EnqueueTask(const base::Closure& closure); 116 void EnqueueTask(const base::Closure& closure);
120 117
121 // Runs a closure if the extension monitored by |extension_monitor_| is 118 // Runs a closure if the extension monitored by |extension_monitor_| is
122 // active, or defers it for later execution if the extension is suspended. 119 // active, or defers it for later execution if the extension is suspended.
123 void RunOrDefer(const base::Closure& request); 120 void RunOrDefer(const base::Closure& request);
124 121
125 // Dispatches the Mojo requests queued in |pending_requests_|. 122 // Dispatches the Mojo requests queued in |pending_requests_|.
126 void ExecutePendingRequests(); 123 void ExecutePendingRequests();
127 124
125 // MediaRouter implementation.
126 void RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
127 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
128 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
129 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
130 void RegisterIssuesObserver(IssuesObserver* observer) override;
131 void UnregisterIssuesObserver(IssuesObserver* observer) override;
132 void RegisterPresentationSessionMessagesObserver(
133 PresentationSessionMessagesObserver* observer) override;
134 void UnregisterPresentationSessionMessagesObserver(
135 PresentationSessionMessagesObserver* observer) override;
136
128 // These calls invoke methods in the component extension via Mojo. 137 // These calls invoke methods in the component extension via Mojo.
129 void DoCreateRoute(const MediaSource::Id& source_id, 138 void DoCreateRoute(const MediaSource::Id& source_id,
130 const MediaSink::Id& sink_id, 139 const MediaSink::Id& sink_id,
131 const std::string& origin, 140 const std::string& origin,
132 int tab_id, 141 int tab_id,
133 const std::vector<MediaRouteResponseCallback>& callbacks); 142 const std::vector<MediaRouteResponseCallback>& callbacks);
134 void DoJoinRoute(const MediaSource::Id& source_id, 143 void DoJoinRoute(const MediaSource::Id& source_id,
135 const std::string& presentation_id, 144 const std::string& presentation_id,
136 const std::string& origin, 145 const std::string& origin,
137 int tab_id, 146 int tab_id,
138 const std::vector<MediaRouteResponseCallback>& callbacks); 147 const std::vector<MediaRouteResponseCallback>& callbacks);
139 void DoCloseRoute(const MediaRoute::Id& route_id); 148 void DoCloseRoute(const MediaRoute::Id& route_id);
140 void DoSendSessionMessage(const MediaRoute::Id& route_id, 149 void DoSendSessionMessage(const MediaRoute::Id& route_id,
141 const std::string& message, 150 const std::string& message,
142 const SendRouteMessageCallback& callback); 151 const SendRouteMessageCallback& callback);
143 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id, 152 void DoSendSessionBinaryMessage(const MediaRoute::Id& route_id,
144 scoped_ptr<std::vector<uint8>> data, 153 scoped_ptr<std::vector<uint8>> data,
145 const SendRouteMessageCallback& callback); 154 const SendRouteMessageCallback& callback);
146 void DoListenForRouteMessages( 155 void DoListenForRouteMessages(const MediaRoute::Id& route_id);
147 const std::vector<MediaRoute::Id>& route_ids,
148 const PresentationSessionMessageCallback& message_cb);
149 void DoClearIssue(const Issue::Id& issue_id); 156 void DoClearIssue(const Issue::Id& issue_id);
150 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); 157 void DoStartObservingMediaSinks(const MediaSource::Id& source_id);
151 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); 158 void DoStopObservingMediaSinks(const MediaSource::Id& source_id);
152 void DoStartObservingMediaRoutes(); 159 void DoStartObservingMediaRoutes();
153 void DoStopObservingMediaRoutes(); 160 void DoStopObservingMediaRoutes();
154 161
155 // Invoked when the next batch of messages arrives. 162 // Invoked when the next batch of messages arrives.
163 // |route_id|: ID of route of the messages.
156 // |messages|: A list of messages received. 164 // |messages|: A list of messages received.
157 // |message_cb|: The callback to invoke to pass on the messages received. 165 void OnRouteMessagesReceived(
158 void OnRouteMessageReceived( 166 const MediaRoute::Id& route_id,
159 const PresentationSessionMessageCallback& message_cb,
160 mojo::Array<interfaces::RouteMessagePtr> messages); 167 mojo::Array<interfaces::RouteMessagePtr> messages);
161 168
162 // Error handler callback for |binding_| and |media_route_provider_|. 169 // Error handler callback for |binding_| and |media_route_provider_|.
163 void OnConnectionError(); 170 void OnConnectionError();
164 171
165 // interfaces::MediaRouter implementation. 172 // interfaces::MediaRouter implementation.
166 void RegisterMediaRouteProvider( 173 void RegisterMediaRouteProvider(
167 interfaces::MediaRouteProviderPtr media_route_provider_ptr, 174 interfaces::MediaRouteProviderPtr media_route_provider_ptr,
168 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& 175 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback&
169 callback) override; 176 callback) override;
170 void OnIssue(interfaces::IssuePtr issue) override; 177 void OnIssue(interfaces::IssuePtr issue) override;
171 void OnSinksReceived(const mojo::String& media_source, 178 void OnSinksReceived(const mojo::String& media_source,
172 mojo::Array<interfaces::MediaSinkPtr> sinks) override; 179 mojo::Array<interfaces::MediaSinkPtr> sinks) override;
173 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override; 180 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override;
174 181
175 // Pending requests queued to be executed once component extension 182 // Pending requests queued to be executed once component extension
176 // becomes ready. 183 // becomes ready.
177 std::vector<base::Closure> pending_requests_; 184 std::vector<base::Closure> pending_requests_;
178 185
179 base::ScopedPtrHashMap<MediaSource::Id, 186 base::ScopedPtrHashMap<MediaSource::Id,
180 scoped_ptr<base::ObserverList<MediaSinksObserver>>> 187 scoped_ptr<base::ObserverList<MediaSinksObserver>>>
181 sinks_observers_; 188 sinks_observers_;
182 189
183 base::ObserverList<MediaRoutesObserver> routes_observers_; 190 base::ObserverList<MediaRoutesObserver> routes_observers_;
184 191
192 using PresentationSessionMessagesObserverList =
193 base::ObserverList<PresentationSessionMessagesObserver>;
194 base::ScopedPtrHashMap<MediaRoute::Id,
195 scoped_ptr<PresentationSessionMessagesObserverList>>
196 messages_observers_;
197 // IDs of MediaRoutes being listened for messages. Note that this is
198 // different from |message_observers_| because we might be waiting for
199 // |OnRouteMessagesReceived()| to be invoked after all observers for that
200 // route have been removed.
201 std::set<MediaRoute::Id> route_ids_listening_for_messages_;
202
185 IssueManager issue_manager_; 203 IssueManager issue_manager_;
186 204
187 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter. 205 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter.
188 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_; 206 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_;
189 207
190 // Mojo proxy object for the Media Route Provider Manager. 208 // Mojo proxy object for the Media Route Provider Manager.
191 // Set to null initially, and later set to the Provider Manager proxy object 209 // Set to null initially, and later set to the Provider Manager proxy object
192 // passed in via |RegisterMediaRouteProvider()|. 210 // passed in via |RegisterMediaRouteProvider()|.
193 // This is set to null again when the component extension is suspended 211 // This is set to null again when the component extension is suspended
194 // if or a Mojo channel error occured. 212 // if or a Mojo channel error occured.
(...skipping 14 matching lines...) Expand all
209 std::string instance_id_; 227 std::string instance_id_;
210 228
211 base::ThreadChecker thread_checker_; 229 base::ThreadChecker thread_checker_;
212 230
213 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 231 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
214 }; 232 };
215 233
216 } // namespace media_router 234 } // namespace media_router
217 235
218 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 236 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_router.mojom ('k') | chrome/browser/media/router/media_router_mojo_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698