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

Side by Side Diff: content/browser/presentation/presentation_service_impl.h

Issue 1406013003: [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Original patch Created 5 years, 1 month 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 CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 ReceiveSessionMessagesAfterReset); 87 ReceiveSessionMessagesAfterReset);
88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
89 MaxPendingStartSessionRequests); 89 MaxPendingStartSessionRequests);
90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
91 MaxPendingJoinSessionRequests); 91 MaxPendingJoinSessionRequests);
92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
93 ListenForSessionStateChange); 93 ListenForSessionStateChange);
94 // Maximum number of pending JoinSession requests at any given time. 94 // Maximum number of pending JoinSession requests at any given time.
95 static const int kMaxNumQueuedSessionRequests = 10; 95 static const int kMaxNumQueuedSessionRequests = 10;
96 96
97 using DefaultSessionMojoCallback = 97 using PresentationSessionMojoCallback =
98 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; 98 mojo::Callback<void(presentation::PresentationSessionInfoPtr)>;
99 using SessionStateCallback = 99 using SessionStateCallback =
100 mojo::Callback<void(presentation::PresentationSessionInfoPtr, 100 mojo::Callback<void(presentation::PresentationSessionInfoPtr,
101 presentation::PresentationConnectionState)>; 101 presentation::PresentationConnectionState)>;
102 using SessionMessagesCallback = 102 using SessionMessagesCallback =
103 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>; 103 mojo::Callback<void(mojo::Array<presentation::SessionMessagePtr>)>;
104 using SendMessageMojoCallback = mojo::Callback<void(bool)>; 104 using SendMessageMojoCallback = mojo::Callback<void(bool)>;
105 105
106 // Listener implementation owned by PresentationServiceImpl. An instance of 106 // Listener implementation owned by PresentationServiceImpl. An instance of
107 // this is created when PresentationRequest.getAvailability() is resolved. 107 // this is created when PresentationRequest.getAvailability() is resolved.
(...skipping 10 matching lines...) Expand all
118 // PresentationScreenAvailabilityListener implementation. 118 // PresentationScreenAvailabilityListener implementation.
119 std::string GetAvailabilityUrl() const override; 119 std::string GetAvailabilityUrl() const override;
120 void OnScreenAvailabilityChanged(bool available) override; 120 void OnScreenAvailabilityChanged(bool available) override;
121 void OnScreenAvailabilityNotSupported() override; 121 void OnScreenAvailabilityNotSupported() override;
122 122
123 private: 123 private:
124 const std::string availability_url_; 124 const std::string availability_url_;
125 PresentationServiceImpl* const service_; 125 PresentationServiceImpl* const service_;
126 }; 126 };
127 127
128 class CONTENT_EXPORT DefaultSessionStartContext {
129 public:
130 DefaultSessionStartContext();
131 ~DefaultSessionStartContext();
132
133 // Adds a callback. May invoke the callback immediately if |session| using
134 // default presentation URL was already started.
135 void AddCallback(const DefaultSessionMojoCallback& callback);
136
137 // Sets the session info. Maybe invoke callbacks queued with AddCallback().
138 void set_session(const PresentationSessionInfo& session);
139
140 private:
141 // Flush all queued callbacks by invoking them with null
142 // PresentationSessionInfoPtr.
143 void Reset();
144
145 ScopedVector<DefaultSessionMojoCallback> callbacks_;
146 scoped_ptr<PresentationSessionInfo> session_;
147 };
148
149 // Ensures the provided NewSessionMojoCallback is invoked exactly once 128 // Ensures the provided NewSessionMojoCallback is invoked exactly once
150 // before it goes out of scope. 129 // before it goes out of scope.
151 class NewSessionMojoCallbackWrapper { 130 class NewSessionMojoCallbackWrapper {
152 public: 131 public:
153 explicit NewSessionMojoCallbackWrapper( 132 explicit NewSessionMojoCallbackWrapper(
154 const NewSessionMojoCallback& callback); 133 const NewSessionMojoCallback& callback);
155 ~NewSessionMojoCallbackWrapper(); 134 ~NewSessionMojoCallbackWrapper();
156 135
157 void Run(presentation::PresentationSessionInfoPtr session, 136 void Run(presentation::PresentationSessionInfoPtr session,
158 presentation::PresentationErrorPtr error); 137 presentation::PresentationErrorPtr error);
(...skipping 11 matching lines...) Expand all
170 PresentationServiceImpl( 149 PresentationServiceImpl(
171 RenderFrameHost* render_frame_host, 150 RenderFrameHost* render_frame_host,
172 WebContents* web_contents, 151 WebContents* web_contents,
173 PresentationServiceDelegate* delegate); 152 PresentationServiceDelegate* delegate);
174 153
175 // PresentationService implementation. 154 // PresentationService implementation.
176 void SetDefaultPresentationURL(const mojo::String& url) override; 155 void SetDefaultPresentationURL(const mojo::String& url) override;
177 void SetClient(presentation::PresentationServiceClientPtr client) override; 156 void SetClient(presentation::PresentationServiceClientPtr client) override;
178 void ListenForScreenAvailability(const mojo::String& url) override; 157 void ListenForScreenAvailability(const mojo::String& url) override;
179 void StopListeningForScreenAvailability(const mojo::String& url) override; 158 void StopListeningForScreenAvailability(const mojo::String& url) override;
180 void ListenForDefaultSessionStart(
181 const DefaultSessionMojoCallback& callback) override;
182 void StartSession( 159 void StartSession(
183 const mojo::String& presentation_url, 160 const mojo::String& presentation_url,
184 const NewSessionMojoCallback& callback) override; 161 const NewSessionMojoCallback& callback) override;
185 void JoinSession( 162 void JoinSession(
186 const mojo::String& presentation_url, 163 const mojo::String& presentation_url,
187 const mojo::String& presentation_id, 164 const mojo::String& presentation_id,
188 const NewSessionMojoCallback& callback) override; 165 const NewSessionMojoCallback& callback) override;
189 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info, 166 void SendSessionMessage(presentation::PresentationSessionInfoPtr session_info,
190 presentation::SessionMessagePtr session_message, 167 presentation::SessionMessagePtr session_message,
191 const SendMessageMojoCallback& callback) override; 168 const SendMessageMojoCallback& callback) override;
192 void CloseSession( 169 void CloseSession(
193 const mojo::String& presentation_url, 170 const mojo::String& presentation_url,
194 const mojo::String& presentation_id) override; 171 const mojo::String& presentation_id) override;
195 void ListenForSessionStateChange() override; 172 void ListenForSessionStateChange() override;
196 void ListenForSessionMessages( 173 void ListenForSessionMessages(
197 presentation::PresentationSessionInfoPtr session) override; 174 presentation::PresentationSessionInfoPtr session) override;
198 175
199 // Creates a binding between this object and |request|. 176 // Creates a binding between this object and |request|.
200 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request); 177 void Bind(mojo::InterfaceRequest<presentation::PresentationService> request);
201 178
202 // WebContentsObserver override. 179 // WebContentsObserver override.
203 void DidNavigateAnyFrame( 180 void DidNavigateAnyFrame(
204 content::RenderFrameHost* render_frame_host, 181 content::RenderFrameHost* render_frame_host,
205 const content::LoadCommittedDetails& details, 182 const content::LoadCommittedDetails& details,
206 const content::FrameNavigateParams& params) override; 183 const content::FrameNavigateParams& params) override;
207 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; 184 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
208 185
209 // PresentationServiceDelegate::Observer 186 // PresentationServiceDelegate::Observer
210 void OnDelegateDestroyed() override; 187 void OnDelegateDestroyed() override;
211 void OnDefaultPresentationStarted(const PresentationSessionInfo& session) 188
212 override; 189 // Passed to embedder's implementation of PresentationServiceDelegate for
190 // later invocation when default presentation has started.
191 void OnDefaultPresentationStarted(
192 const PresentationSessionInfo& session_info);
213 193
214 // Finds the callback from |pending_join_session_cbs_| using 194 // Finds the callback from |pending_join_session_cbs_| using
215 // |request_session_id|. 195 // |request_session_id|.
216 // If it exists, invoke it with |session| and |error|, then erase it from 196 // If it exists, invoke it with |session| and |error|, then erase it from
217 // |pending_join_session_cbs_|. 197 // |pending_join_session_cbs_|.
218 void RunAndEraseJoinSessionMojoCallback( 198 void RunAndEraseJoinSessionMojoCallback(
219 int request_session_id, 199 int request_session_id,
220 presentation::PresentationSessionInfoPtr session, 200 presentation::PresentationSessionInfoPtr session,
221 presentation::PresentationErrorPtr error); 201 presentation::PresentationErrorPtr error);
222 202
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 257
278 // For StartSession requests. 258 // For StartSession requests.
279 // Set to a positive value when a StartSession request is being processed. 259 // Set to a positive value when a StartSession request is being processed.
280 int start_session_request_id_; 260 int start_session_request_id_;
281 scoped_ptr<NewSessionMojoCallbackWrapper> pending_start_session_cb_; 261 scoped_ptr<NewSessionMojoCallbackWrapper> pending_start_session_cb_;
282 262
283 // For JoinSession requests. 263 // For JoinSession requests.
284 base::hash_map<int, linked_ptr<NewSessionMojoCallbackWrapper>> 264 base::hash_map<int, linked_ptr<NewSessionMojoCallbackWrapper>>
285 pending_join_session_cbs_; 265 pending_join_session_cbs_;
286 266
287 scoped_ptr<DefaultSessionStartContext> default_session_start_context_;
288
289 // RAII binding of |this| to an Presentation interface request. 267 // RAII binding of |this| to an Presentation interface request.
290 // The binding is removed when binding_ is cleared or goes out of scope. 268 // The binding is removed when binding_ is cleared or goes out of scope.
291 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; 269 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_;
292 270
293 // There can be only one send message request at a time. 271 // There can be only one send message request at a time.
294 scoped_ptr<SendMessageMojoCallback> send_message_callback_; 272 scoped_ptr<SendMessageMojoCallback> send_message_callback_;
295 273
296 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_; 274 scoped_ptr<SessionMessagesCallback> on_session_messages_callback_;
297 275
298 // ID of the RenderFrameHost this object is associated with. 276 // ID of the RenderFrameHost this object is associated with.
299 int render_process_id_; 277 int render_process_id_;
300 int render_frame_id_; 278 int render_frame_id_;
301 279
302 // NOTE: Weak pointers must be invalidated before all other member variables. 280 // NOTE: Weak pointers must be invalidated before all other member variables.
303 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; 281 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_;
304 282
305 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); 283 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl);
306 }; 284 };
307 285
308 } // namespace content 286 } // namespace content
309 287
310 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 288 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698