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

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

Issue 996173006: [Presentation API] Fix potential callback leaks in PSImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Anton's comments Created 5 years, 9 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
« no previous file with comments | « no previous file | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // WebContentsObserver override. 174 // WebContentsObserver override.
175 void DidNavigateAnyFrame( 175 void DidNavigateAnyFrame(
176 content::RenderFrameHost* render_frame_host, 176 content::RenderFrameHost* render_frame_host,
177 const content::LoadCommittedDetails& details, 177 const content::LoadCommittedDetails& details,
178 const content::FrameNavigateParams& params) override; 178 const content::FrameNavigateParams& params) override;
179 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; 179 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
180 180
181 // PresentationServiceDelegate::Observer 181 // PresentationServiceDelegate::Observer
182 void OnDelegateDestroyed() override; 182 void OnDelegateDestroyed() override;
183 183
184 // Finds the callback from |pending_session_cbs_| using |request_session_id|.
185 // If it exists, invoke it with |session| and |error|, then erase it from
186 // |pending_session_cbs_|.
187 void RunAndEraseNewSessionMojoCallback(
188 int request_session_id,
189 presentation::PresentationSessionInfoPtr session,
190 presentation::PresentationErrorPtr error);
191
184 // Sets |default_presentation_url_| to |presentation_url| and informs the 192 // Sets |default_presentation_url_| to |presentation_url| and informs the
185 // delegate of new default presentation URL and ID. 193 // delegate of new default presentation URL and ID.
186 void DoSetDefaultPresentationUrl( 194 void DoSetDefaultPresentationUrl(
187 const std::string& presentation_url, 195 const std::string& presentation_url,
188 const std::string& presentation_id); 196 const std::string& presentation_id);
189 197
190 // Removes all listeners and resets default presentation URL on this instance 198 // Removes all listeners and resets default presentation URL on this instance
191 // and informs the PresentationServiceDelegate of such. 199 // and informs the PresentationServiceDelegate of such.
192 void Reset(); 200 void Reset();
193 201
194 // These two functions are bound as base::Callbacks and passed to 202 // These two functions are bound as base::Callbacks and passed to
195 // embedder's implementation of PresentationServiceDelegate for later 203 // embedder's implementation of PresentationServiceDelegate for later
196 // invocation. 204 // invocation.
197 void OnStartOrJoinSessionSucceeded( 205 void OnStartOrJoinSessionSucceeded(
198 bool is_start_session, 206 bool is_start_session,
199 const NewSessionMojoCallback& callback, 207 int request_session_id,
200 const PresentationSessionInfo& session_info); 208 const PresentationSessionInfo& session_info);
201 void OnStartOrJoinSessionError( 209 void OnStartOrJoinSessionError(
202 bool is_start_session, 210 bool is_start_session,
203 const NewSessionMojoCallback& callback, 211 int request_session_id,
204 const PresentationError& error); 212 const PresentationError& error);
205 213
206 // Requests delegate to start a session. 214 // Requests delegate to start a session.
207 void DoStartSession( 215 void DoStartSession(
208 const std::string& presentation_url, 216 const std::string& presentation_url,
209 const std::string& presentation_id, 217 const std::string& presentation_id,
210 const NewSessionMojoCallback& callback); 218 const NewSessionMojoCallback& callback);
211 219
212 // Removes the head of the queue (which represents the request that has just 220 // Removes the head of the queue (which represents the request that has just
213 // been processed). 221 // been processed).
214 // Checks if there are any queued StartSession requests and if so, executes 222 // Checks if there are any queued StartSession requests and if so, executes
215 // the first one in the queue. 223 // the first one in the queue.
216 void HandleQueuedStartSessionRequests(); 224 void HandleQueuedStartSessionRequests();
217 225
226 // Associates |callback| with a unique request ID and stores it in a map.
227 int RegisterNewSessionCallback(
228 const NewSessionMojoCallback& callback);
229
230 // Invokes |callback| with an error.
231 void InvokeNewSessionMojoCallbackWithError(
232 const NewSessionMojoCallback& callback);
233
218 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one 234 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one
219 // if it does not exist. 235 // if it does not exist.
220 ScreenAvailabilityContext* GetOrCreateAvailabilityContext( 236 ScreenAvailabilityContext* GetOrCreateAvailabilityContext(
221 const std::string& presentation_url); 237 const std::string& presentation_url);
222 238
223 RenderFrameHost* render_frame_host_; 239 RenderFrameHost* render_frame_host_;
224 PresentationServiceDelegate* delegate_; 240 PresentationServiceDelegate* delegate_;
225 241
226 // Map from presentation URL to its ScreenAvailabilityContext state machine. 242 // Map from presentation URL to its ScreenAvailabilityContext state machine.
227 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>> 243 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>>
228 availability_contexts_; 244 availability_contexts_;
229 245
230 std::string default_presentation_url_; 246 std::string default_presentation_url_;
231 std::string default_presentation_id_; 247 std::string default_presentation_id_;
232 248
233 // We only allow one StartSession request to be processed at a time. 249 // We only allow one StartSession request to be processed at a time.
234 // StartSession requests are queued here. When a request has been processed, 250 // StartSession requests are queued here. When a request has been processed,
235 // it is removed from head of the queue. 251 // it is removed from head of the queue.
236 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_; 252 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_;
237 253
254 int next_request_session_id_;
255 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_;
256
238 // NOTE: Weak pointers must be invalidated before all other member variables. 257 // NOTE: Weak pointers must be invalidated before all other member variables.
239 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; 258 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_;
240 259
241 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); 260 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl);
242 }; 261 };
243 262
244 } // namespace content 263 } // namespace content
245 264
246 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 265 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698