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

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: Compile fix 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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 void JoinRoute( 65 void JoinRoute(
66 const MediaSource::Id& source_id, 66 const MediaSource::Id& source_id,
67 const std::string& presentation_id, 67 const std::string& presentation_id,
68 const GURL& origin, 68 const GURL& origin,
69 int tab_id, 69 int tab_id,
70 const std::vector<MediaRouteResponseCallback>& callbacks) override; 70 const std::vector<MediaRouteResponseCallback>& callbacks) override;
71 void CloseRoute(const MediaRoute::Id& route_id) override; 71 void CloseRoute(const MediaRoute::Id& route_id) override;
72 void SendRouteMessage(const MediaRoute::Id& route_id, 72 void SendRouteMessage(const MediaRoute::Id& route_id,
73 const std::string& message, 73 const std::string& message,
74 const SendRouteMessageCallback& callback) override; 74 const SendRouteMessageCallback& callback) override;
75 void ListenForRouteMessages(
76 const std::vector<MediaRoute::Id>& route_ids,
77 const PresentationSessionMessageCallback& message_cb) override;
78 void ClearIssue(const Issue::Id& issue_id) override; 75 void ClearIssue(const Issue::Id& issue_id) override;
79 void RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
80 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
81 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
82 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
83 void RegisterIssuesObserver(IssuesObserver* observer) override;
84 void UnregisterIssuesObserver(IssuesObserver* observer) override;
85 76
86 const std::string& media_route_provider_extension_id() const { 77 const std::string& media_route_provider_extension_id() const {
87 return media_route_provider_extension_id_; 78 return media_route_provider_extension_id_;
88 } 79 }
89 80
90 void set_instance_id_for_test(const std::string& instance_id) { 81 void set_instance_id_for_test(const std::string& instance_id) {
91 instance_id_ = instance_id; 82 instance_id_ = instance_id;
92 } 83 }
93 84
94 private: 85 private:
95 friend class MediaRouterFactory; 86 friend class MediaRouterFactory;
96 friend class MediaRouterMojoTest; 87 friend class MediaRouterMojoTest;
97 88
89 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
90 RegisterAndUnregisterMediaSinksObserver);
91 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
92 RegisterAndUnregisterMediaRoutesObserver);
98 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 93 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
99 DeferredBindingAndSuspension); 94 DeferredBindingAndSuspension);
100 95
101 // Standard constructor, used by 96 // Standard constructor, used by
102 // MediaRouterMojoImplFactory::GetApiForBrowserContext. 97 // MediaRouterMojoImplFactory::GetApiForBrowserContext.
103 explicit MediaRouterMojoImpl( 98 explicit MediaRouterMojoImpl(
104 extensions::EventPageTracker* event_page_tracker); 99 extensions::EventPageTracker* event_page_tracker);
105 100
106 // Binds |this| to a Mojo interface request, so that clients can acquire a 101 // Binds |this| to a Mojo interface request, so that clients can acquire a
107 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. 102 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
108 // Stores the |extension_id| of the component extension. 103 // Stores the |extension_id| of the component extension.
109 void BindToMojoRequest( 104 void BindToMojoRequest(
110 mojo::InterfaceRequest<interfaces::MediaRouter> request, 105 mojo::InterfaceRequest<interfaces::MediaRouter> request,
111 const std::string& extension_id); 106 const std::string& extension_id);
112 107
113 // Enqueues a closure for later execution by ExecutePendingRequests(). 108 // Enqueues a closure for later execution by ExecutePendingRequests().
114 void EnqueueTask(const base::Closure& closure); 109 void EnqueueTask(const base::Closure& closure);
115 110
116 // Runs a closure if the extension monitored by |extension_monitor_| is 111 // Runs a closure if the extension monitored by |extension_monitor_| is
117 // active, or defers it for later execution if the extension is suspended. 112 // active, or defers it for later execution if the extension is suspended.
118 void RunOrDefer(const base::Closure& request); 113 void RunOrDefer(const base::Closure& request);
119 114
120 // Dispatches the Mojo requests queued in |pending_requests_|. 115 // Dispatches the Mojo requests queued in |pending_requests_|.
121 void ExecutePendingRequests(); 116 void ExecutePendingRequests();
122 117
118 // MediaRouter implementation.
119 void RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
120 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
121 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
122 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
123 void RegisterIssuesObserver(IssuesObserver* observer) override;
124 void UnregisterIssuesObserver(IssuesObserver* observer) override;
125 void RegisterPresentationSessionMessagesObserver(
126 PresentationSessionMessagesObserver* observer) override;
127 void UnregisterPresentationSessionMessagesObserver(
128 PresentationSessionMessagesObserver* observer) override;
129
123 // These calls invoke methods in the component extension via Mojo. 130 // These calls invoke methods in the component extension via Mojo.
124 void DoCreateRoute(const MediaSource::Id& source_id, 131 void DoCreateRoute(const MediaSource::Id& source_id,
125 const MediaSink::Id& sink_id, 132 const MediaSink::Id& sink_id,
126 const std::string& origin, 133 const std::string& origin,
127 int tab_id, 134 int tab_id,
128 const std::vector<MediaRouteResponseCallback>& callbacks); 135 const std::vector<MediaRouteResponseCallback>& callbacks);
129 void DoJoinRoute(const MediaSource::Id& source_id, 136 void DoJoinRoute(const MediaSource::Id& source_id,
130 const std::string& presentation_id, 137 const std::string& presentation_id,
131 const std::string& origin, 138 const std::string& origin,
132 int tab_id, 139 int tab_id,
133 const std::vector<MediaRouteResponseCallback>& callbacks); 140 const std::vector<MediaRouteResponseCallback>& callbacks);
134 void DoCloseRoute(const MediaRoute::Id& route_id); 141 void DoCloseRoute(const MediaRoute::Id& route_id);
135 void DoSendSessionMessage(const MediaRoute::Id& route_id, 142 void DoSendSessionMessage(const MediaRoute::Id& route_id,
136 const std::string& message, 143 const std::string& message,
137 const SendRouteMessageCallback& callback); 144 const SendRouteMessageCallback& callback);
138 void DoListenForRouteMessages( 145 void DoListenForRouteMessages(const MediaRoute::Id& route_id);
139 const std::vector<MediaRoute::Id>& route_ids,
140 const PresentationSessionMessageCallback& message_cb);
141 void DoClearIssue(const Issue::Id& issue_id); 146 void DoClearIssue(const Issue::Id& issue_id);
142 void DoStartObservingMediaSinks(const MediaSource::Id& source_id); 147 void DoStartObservingMediaSinks(const MediaSource::Id& source_id);
143 void DoStopObservingMediaSinks(const MediaSource::Id& source_id); 148 void DoStopObservingMediaSinks(const MediaSource::Id& source_id);
144 void DoStartObservingMediaRoutes(); 149 void DoStartObservingMediaRoutes();
145 void DoStopObservingMediaRoutes(); 150 void DoStopObservingMediaRoutes();
146 void DoStartObservingIssues(); 151 void DoStartObservingIssues();
147 void DoStopObservingIssues(); 152 void DoStopObservingIssues();
148 153
149 // Invoked when the next batch of messages arrives. 154 // Invoked when the next batch of messages arrives.
155 // |route_id|: ID of route of the messages.
150 // |messages|: A list of messages received. 156 // |messages|: A list of messages received.
151 // |message_cb|: The callback to invoke to pass on the messages received. 157 void OnRouteMessagesReceived(
152 void OnRouteMessageReceived( 158 const MediaRoute::Id& route_id,
153 const PresentationSessionMessageCallback& message_cb,
154 mojo::Array<interfaces::RouteMessagePtr> messages); 159 mojo::Array<interfaces::RouteMessagePtr> messages);
155 160
156 // Error handler callback for |binding_| and |media_route_provider_|. 161 // Error handler callback for |binding_| and |media_route_provider_|.
157 void OnConnectionError(); 162 void OnConnectionError();
158 163
159 // interfaces::MediaRouter implementation. 164 // interfaces::MediaRouter implementation.
160 void RegisterMediaRouteProvider( 165 void RegisterMediaRouteProvider(
161 interfaces::MediaRouteProviderPtr media_route_provider_ptr, 166 interfaces::MediaRouteProviderPtr media_route_provider_ptr,
162 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& 167 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback&
163 callback) override; 168 callback) override;
164 void OnIssue(interfaces::IssuePtr issue) override; 169 void OnIssue(interfaces::IssuePtr issue) override;
165 void OnSinksReceived(const mojo::String& media_source, 170 void OnSinksReceived(const mojo::String& media_source,
166 mojo::Array<interfaces::MediaSinkPtr> sinks) override; 171 mojo::Array<interfaces::MediaSinkPtr> sinks) override;
167 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override; 172 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override;
168 173
169 // Pending requests queued to be executed once component extension 174 // Pending requests queued to be executed once component extension
170 // becomes ready. 175 // becomes ready.
171 std::vector<base::Closure> pending_requests_; 176 std::vector<base::Closure> pending_requests_;
172 177
173 base::ScopedPtrHashMap<MediaSource::Id, 178 base::ScopedPtrHashMap<MediaSource::Id,
174 scoped_ptr<base::ObserverList<MediaSinksObserver>>> 179 scoped_ptr<base::ObserverList<MediaSinksObserver>>>
175 sinks_observers_; 180 sinks_observers_;
176 181
177 base::ObserverList<MediaRoutesObserver> routes_observers_; 182 base::ObserverList<MediaRoutesObserver> routes_observers_;
178 183
184 base::ScopedPtrHashMap<
185 MediaRoute::Id,
186 scoped_ptr<base::ObserverList<PresentationSessionMessagesObserver>>>
187 messages_observers_;
188 // IDs of MediaRoutes being listened for messages. Note that this is
189 // different from |message_observers_| because we might be waiting for
190 // |OnRouteMessagesReceived()| to be invoked after all observers for that
haibinlu 2015/07/30 23:59:11 if all observers for the route message have been r
imcheng 2015/08/03 18:56:33 Currently we stop listening when we see there are
191 // route have been removed.
192 base::hash_set<MediaRoute::Id> listening_messages_for_routes_;
193
179 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter. 194 // Binds |this| to a Mojo connection stub for interfaces::MediaRouter.
180 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_; 195 scoped_ptr<mojo::Binding<interfaces::MediaRouter>> binding_;
181 196
182 // Mojo proxy object for the Media Route Provider Manager. 197 // Mojo proxy object for the Media Route Provider Manager.
183 // Set to null initially, and later set to the Provider Manager proxy object 198 // Set to null initially, and later set to the Provider Manager proxy object
184 // passed in via |RegisterMediaRouteProvider()|. 199 // passed in via |RegisterMediaRouteProvider()|.
185 // This is set to null again when the component extension is suspended 200 // This is set to null again when the component extension is suspended
186 // if or a Mojo channel error occured. 201 // if or a Mojo channel error occured.
187 interfaces::MediaRouteProviderPtr media_route_provider_; 202 interfaces::MediaRouteProviderPtr media_route_provider_;
188 203
(...skipping 12 matching lines...) Expand all
201 std::string instance_id_; 216 std::string instance_id_;
202 217
203 base::ThreadChecker thread_checker_; 218 base::ThreadChecker thread_checker_;
204 219
205 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 220 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
206 }; 221 };
207 222
208 } // namespace media_router 223 } // namespace media_router
209 224
210 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 225 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698