OLD | NEW |
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 #include "content/browser/presentation/presentation_service_impl.h" | 5 #include "content/browser/presentation/presentation_service_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/browser/presentation/presentation_type_converters.h" | 10 #include "content/browser/presentation/presentation_type_converters.h" |
11 #include "content/public/browser/content_browser_client.h" | 11 #include "content/public/browser/content_browser_client.h" |
12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
17 #include "content/public/common/frame_navigate_params.h" | 17 #include "content/public/common/frame_navigate_params.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 PresentationServiceImpl::PresentationServiceImpl( | 21 PresentationServiceImpl::PresentationServiceImpl( |
22 RenderFrameHost* render_frame_host, | 22 RenderFrameHost* render_frame_host, |
23 WebContents* web_contents, | 23 WebContents* web_contents, |
24 PresentationServiceDelegate* delegate) | 24 PresentationServiceDelegate* delegate) |
25 : WebContentsObserver(web_contents), | 25 : WebContentsObserver(web_contents), |
| 26 render_frame_host_(render_frame_host), |
26 delegate_(delegate), | 27 delegate_(delegate), |
27 is_start_session_pending_(false), | 28 is_start_session_pending_(false), |
28 next_request_session_id_(0), | 29 next_request_session_id_(0), |
29 weak_factory_(this) { | 30 weak_factory_(this) { |
30 DCHECK(render_frame_host); | 31 DCHECK(render_frame_host_); |
31 DCHECK(web_contents); | 32 DCHECK(web_contents); |
32 | |
33 render_process_id_ = render_frame_host->GetProcess()->GetID(); | |
34 render_frame_id_ = render_frame_host->GetRoutingID(); | |
35 DVLOG(2) << "PresentationServiceImpl: " | 33 DVLOG(2) << "PresentationServiceImpl: " |
36 << render_process_id_ << ", " << render_frame_id_; | 34 << render_frame_host_->GetProcess()->GetID() << ", " |
| 35 << render_frame_host_->GetRoutingID(); |
37 if (delegate_) | 36 if (delegate_) |
38 delegate_->AddObserver(render_process_id_, render_frame_id_, this); | 37 delegate_->AddObserver(this); |
39 } | 38 } |
40 | 39 |
41 PresentationServiceImpl::~PresentationServiceImpl() { | 40 PresentationServiceImpl::~PresentationServiceImpl() { |
42 if (delegate_) | 41 if (delegate_) |
43 delegate_->RemoveObserver(render_process_id_, render_frame_id_); | 42 delegate_->RemoveObserver(this); |
44 FlushNewSessionCallbacks(); | 43 FlushNewSessionCallbacks(); |
45 } | 44 } |
46 | 45 |
47 // static | 46 // static |
48 void PresentationServiceImpl::CreateMojoService( | 47 void PresentationServiceImpl::CreateMojoService( |
49 RenderFrameHost* render_frame_host, | 48 RenderFrameHost* render_frame_host, |
50 mojo::InterfaceRequest<presentation::PresentationService> request) { | 49 mojo::InterfaceRequest<presentation::PresentationService> request) { |
51 DVLOG(2) << "CreateMojoService"; | 50 DVLOG(2) << "CreateMojoService"; |
52 WebContents* web_contents = | 51 WebContents* web_contents = |
53 WebContents::FromRenderFrameHost(render_frame_host); | 52 WebContents::FromRenderFrameHost(render_frame_host); |
(...skipping 23 matching lines...) Expand all Loading... |
77 } | 76 } |
78 | 77 |
79 PresentationServiceImpl::ScreenAvailabilityContext* | 78 PresentationServiceImpl::ScreenAvailabilityContext* |
80 PresentationServiceImpl::GetOrCreateAvailabilityContext( | 79 PresentationServiceImpl::GetOrCreateAvailabilityContext( |
81 const std::string& presentation_url) { | 80 const std::string& presentation_url) { |
82 auto it = availability_contexts_.find(presentation_url); | 81 auto it = availability_contexts_.find(presentation_url); |
83 if (it == availability_contexts_.end()) { | 82 if (it == availability_contexts_.end()) { |
84 linked_ptr<ScreenAvailabilityContext> context( | 83 linked_ptr<ScreenAvailabilityContext> context( |
85 new ScreenAvailabilityContext(presentation_url)); | 84 new ScreenAvailabilityContext(presentation_url)); |
86 if (!delegate_->AddScreenAvailabilityListener( | 85 if (!delegate_->AddScreenAvailabilityListener( |
87 render_process_id_, render_frame_id_, context.get())) { | 86 render_frame_host_->GetProcess()->GetID(), |
| 87 render_frame_host_->GetRoutingID(), |
| 88 context.get())) { |
88 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request."; | 89 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request."; |
89 return nullptr; | 90 return nullptr; |
90 } | 91 } |
91 it = availability_contexts_.insert( | 92 it = availability_contexts_.insert( |
92 std::make_pair(context->GetPresentationUrl(), context)).first; | 93 std::make_pair(context->GetPresentationUrl(), context)).first; |
93 } | 94 } |
94 return it->second.get(); | 95 return it->second.get(); |
95 } | 96 } |
96 | 97 |
97 void PresentationServiceImpl::ListenForScreenAvailability( | 98 void PresentationServiceImpl::ListenForScreenAvailability( |
(...skipping 19 matching lines...) Expand all Loading... |
117 DVLOG(2) << "RemoveScreenAvailabilityListener"; | 118 DVLOG(2) << "RemoveScreenAvailabilityListener"; |
118 if (!delegate_) | 119 if (!delegate_) |
119 return; | 120 return; |
120 | 121 |
121 const std::string& presentation_url_str = presentation_url.get(); | 122 const std::string& presentation_url_str = presentation_url.get(); |
122 auto it = availability_contexts_.find(presentation_url_str); | 123 auto it = availability_contexts_.find(presentation_url_str); |
123 if (it == availability_contexts_.end()) | 124 if (it == availability_contexts_.end()) |
124 return; | 125 return; |
125 | 126 |
126 delegate_->RemoveScreenAvailabilityListener( | 127 delegate_->RemoveScreenAvailabilityListener( |
127 render_process_id_, render_frame_id_, it->second.get()); | 128 render_frame_host_->GetProcess()->GetID(), |
| 129 render_frame_host_->GetRoutingID(), |
| 130 it->second.get()); |
128 // Resolve the context's pending callbacks before removing it. | 131 // Resolve the context's pending callbacks before removing it. |
129 it->second->OnScreenAvailabilityChanged(false); | 132 it->second->OnScreenAvailabilityChanged(false); |
130 availability_contexts_.erase(it); | 133 availability_contexts_.erase(it); |
131 } | 134 } |
132 | 135 |
133 void PresentationServiceImpl::ListenForDefaultSessionStart( | 136 void PresentationServiceImpl::ListenForDefaultSessionStart( |
134 const DefaultSessionMojoCallback& callback) { | 137 const DefaultSessionMojoCallback& callback) { |
135 if (!default_session_start_context_.get()) | 138 NOTIMPLEMENTED(); |
136 default_session_start_context_.reset(new DefaultSessionStartContext); | |
137 default_session_start_context_->AddCallback(callback); | |
138 } | 139 } |
139 | 140 |
140 void PresentationServiceImpl::StartSession( | 141 void PresentationServiceImpl::StartSession( |
141 const mojo::String& presentation_url, | 142 const mojo::String& presentation_url, |
142 const mojo::String& presentation_id, | 143 const mojo::String& presentation_id, |
143 const NewSessionMojoCallback& callback) { | 144 const NewSessionMojoCallback& callback) { |
144 DVLOG(2) << "StartSession"; | 145 DVLOG(2) << "StartSession"; |
145 if (!delegate_) { | 146 if (!delegate_) { |
146 InvokeNewSessionMojoCallbackWithError(callback); | 147 InvokeNewSessionMojoCallbackWithError(callback); |
147 return; | 148 return; |
(...skipping 13 matching lines...) Expand all Loading... |
161 const mojo::String& presentation_id, | 162 const mojo::String& presentation_id, |
162 const NewSessionMojoCallback& callback) { | 163 const NewSessionMojoCallback& callback) { |
163 DVLOG(2) << "JoinSession"; | 164 DVLOG(2) << "JoinSession"; |
164 if (!delegate_) { | 165 if (!delegate_) { |
165 InvokeNewSessionMojoCallbackWithError(callback); | 166 InvokeNewSessionMojoCallbackWithError(callback); |
166 return; | 167 return; |
167 } | 168 } |
168 | 169 |
169 int request_session_id = RegisterNewSessionCallback(callback); | 170 int request_session_id = RegisterNewSessionCallback(callback); |
170 delegate_->JoinSession( | 171 delegate_->JoinSession( |
171 render_process_id_, | 172 render_frame_host_->GetProcess()->GetID(), |
172 render_frame_id_, | 173 render_frame_host_->GetRoutingID(), |
173 presentation_url, | 174 presentation_url, |
174 presentation_id, | 175 presentation_id, |
175 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 176 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, |
176 weak_factory_.GetWeakPtr(), false, request_session_id), | 177 weak_factory_.GetWeakPtr(), false, request_session_id), |
177 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 178 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, |
178 weak_factory_.GetWeakPtr(), false, request_session_id)); | 179 weak_factory_.GetWeakPtr(), false, request_session_id)); |
179 } | 180 } |
180 | 181 |
181 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { | 182 void PresentationServiceImpl::HandleQueuedStartSessionRequests() { |
182 if (queued_start_session_requests_.empty()) { | 183 if (queued_start_session_requests_.empty()) { |
(...skipping 23 matching lines...) Expand all Loading... |
206 pending_session_cbs_.clear(); | 207 pending_session_cbs_.clear(); |
207 } | 208 } |
208 | 209 |
209 void PresentationServiceImpl::DoStartSession( | 210 void PresentationServiceImpl::DoStartSession( |
210 const std::string& presentation_url, | 211 const std::string& presentation_url, |
211 const std::string& presentation_id, | 212 const std::string& presentation_id, |
212 const NewSessionMojoCallback& callback) { | 213 const NewSessionMojoCallback& callback) { |
213 int request_session_id = RegisterNewSessionCallback(callback); | 214 int request_session_id = RegisterNewSessionCallback(callback); |
214 is_start_session_pending_ = true; | 215 is_start_session_pending_ = true; |
215 delegate_->StartSession( | 216 delegate_->StartSession( |
216 render_process_id_, | 217 render_frame_host_->GetProcess()->GetID(), |
217 render_frame_id_, | 218 render_frame_host_->GetRoutingID(), |
218 presentation_url, | 219 presentation_url, |
219 presentation_id, | 220 presentation_id, |
220 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, | 221 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionSucceeded, |
221 weak_factory_.GetWeakPtr(), true, request_session_id), | 222 weak_factory_.GetWeakPtr(), true, request_session_id), |
222 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, | 223 base::Bind(&PresentationServiceImpl::OnStartOrJoinSessionError, |
223 weak_factory_.GetWeakPtr(), true, request_session_id)); | 224 weak_factory_.GetWeakPtr(), true, request_session_id)); |
224 } | 225 } |
225 | 226 |
226 void PresentationServiceImpl::OnStartOrJoinSessionSucceeded( | 227 void PresentationServiceImpl::OnStartOrJoinSessionSucceeded( |
227 bool is_start_session, | 228 bool is_start_session, |
(...skipping 30 matching lines...) Expand all Loading... |
258 DCHECK(it->second.get()); | 259 DCHECK(it->second.get()); |
259 it->second->Run(session.Pass(), error.Pass()); | 260 it->second->Run(session.Pass(), error.Pass()); |
260 pending_session_cbs_.erase(it); | 261 pending_session_cbs_.erase(it); |
261 } | 262 } |
262 | 263 |
263 void PresentationServiceImpl::DoSetDefaultPresentationUrl( | 264 void PresentationServiceImpl::DoSetDefaultPresentationUrl( |
264 const std::string& default_presentation_url, | 265 const std::string& default_presentation_url, |
265 const std::string& default_presentation_id) { | 266 const std::string& default_presentation_id) { |
266 DCHECK(delegate_); | 267 DCHECK(delegate_); |
267 delegate_->SetDefaultPresentationUrl( | 268 delegate_->SetDefaultPresentationUrl( |
268 render_process_id_, | 269 render_frame_host_->GetProcess()->GetID(), |
269 render_frame_id_, | 270 render_frame_host_->GetRoutingID(), |
270 default_presentation_url, | 271 default_presentation_url, |
271 default_presentation_id); | 272 default_presentation_id); |
272 default_presentation_url_ = default_presentation_url; | 273 default_presentation_url_ = default_presentation_url; |
273 default_presentation_id_ = default_presentation_id; | 274 default_presentation_id_ = default_presentation_id; |
274 } | 275 } |
275 | 276 |
276 void PresentationServiceImpl::SetDefaultPresentationURL( | 277 void PresentationServiceImpl::SetDefaultPresentationURL( |
277 const mojo::String& default_presentation_url, | 278 const mojo::String& default_presentation_url, |
278 const mojo::String& default_presentation_id) { | 279 const mojo::String& default_presentation_id) { |
279 DVLOG(2) << "SetDefaultPresentationURL"; | 280 DVLOG(2) << "SetDefaultPresentationURL"; |
(...skipping 19 matching lines...) Expand all Loading... |
299 // Have already started listening. Create a listener for the new URL and | 300 // Have already started listening. Create a listener for the new URL and |
300 // transfer the callbacks from the old listener, if any. | 301 // transfer the callbacks from the old listener, if any. |
301 // This is done so that a listener added before default URL is changed | 302 // This is done so that a listener added before default URL is changed |
302 // will continue to work. | 303 // will continue to work. |
303 ScreenAvailabilityContext* context = | 304 ScreenAvailabilityContext* context = |
304 GetOrCreateAvailabilityContext(new_default_url); | 305 GetOrCreateAvailabilityContext(new_default_url); |
305 old_it->second->PassPendingCallbacks(context); | 306 old_it->second->PassPendingCallbacks(context); |
306 | 307 |
307 // Remove listener for old default presentation URL. | 308 // Remove listener for old default presentation URL. |
308 delegate_->RemoveScreenAvailabilityListener( | 309 delegate_->RemoveScreenAvailabilityListener( |
309 render_process_id_, | 310 render_frame_host_->GetProcess()->GetID(), |
310 render_frame_id_, | 311 render_frame_host_->GetRoutingID(), |
311 old_it->second.get()); | 312 old_it->second.get()); |
312 availability_contexts_.erase(old_it); | 313 availability_contexts_.erase(old_it); |
313 DoSetDefaultPresentationUrl(new_default_url, default_presentation_id); | 314 DoSetDefaultPresentationUrl(new_default_url, default_presentation_id); |
314 } | 315 } |
315 | 316 |
316 void PresentationServiceImpl::CloseSession( | 317 void PresentationServiceImpl::CloseSession( |
317 const mojo::String& presentation_url, | 318 const mojo::String& presentation_url, |
318 const mojo::String& presentation_id) { | 319 const mojo::String& presentation_id) { |
319 NOTIMPLEMENTED(); | 320 NOTIMPLEMENTED(); |
320 } | 321 } |
321 | 322 |
322 void PresentationServiceImpl::ListenForSessionStateChange( | 323 void PresentationServiceImpl::ListenForSessionStateChange( |
323 const SessionStateCallback& callback) { | 324 const SessionStateCallback& callback) { |
324 NOTIMPLEMENTED(); | 325 NOTIMPLEMENTED(); |
325 } | 326 } |
326 | 327 |
327 bool PresentationServiceImpl::FrameMatches( | |
328 content::RenderFrameHost* render_frame_host) const { | |
329 if (!render_frame_host) | |
330 return false; | |
331 | |
332 return render_frame_host->GetProcess()->GetID() == render_process_id_ && | |
333 render_frame_host->GetRoutingID() == render_frame_id_; | |
334 } | |
335 | |
336 void PresentationServiceImpl::DidNavigateAnyFrame( | 328 void PresentationServiceImpl::DidNavigateAnyFrame( |
337 content::RenderFrameHost* render_frame_host, | 329 content::RenderFrameHost* render_frame_host, |
338 const content::LoadCommittedDetails& details, | 330 const content::LoadCommittedDetails& details, |
339 const content::FrameNavigateParams& params) { | 331 const content::FrameNavigateParams& params) { |
340 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; | 332 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; |
341 if (!FrameMatches(render_frame_host)) | 333 if (render_frame_host_ != render_frame_host) |
342 return; | 334 return; |
343 | 335 |
344 std::string prev_url_host = details.previous_url.host(); | 336 std::string prev_url_host = details.previous_url.host(); |
345 std::string curr_url_host = params.url.host(); | 337 std::string curr_url_host = params.url.host(); |
346 | 338 |
347 // If a frame navigation is in-page (e.g. navigating to a fragment in | 339 // If a frame navigation is in-page (e.g. navigating to a fragment in |
348 // same page) then we do not unregister listeners. | 340 // same page) then we do not unregister listeners. |
349 bool in_page_navigation = details.is_in_page || | 341 bool in_page_navigation = details.is_in_page || |
350 details.type == content::NAVIGATION_TYPE_IN_PAGE; | 342 details.type == content::NAVIGATION_TYPE_IN_PAGE; |
351 | 343 |
352 DVLOG(2) << "DidNavigateAnyFrame: " | 344 DVLOG(2) << "DidNavigateAnyFrame: " |
353 << "prev host: " << prev_url_host << ", curr host: " << curr_url_host | 345 << "prev host: " << prev_url_host << ", curr host: " << curr_url_host |
354 << ", in_page_navigation: " << in_page_navigation; | 346 << ", in_page_navigation: " << in_page_navigation; |
355 | 347 |
356 if (in_page_navigation) | 348 if (in_page_navigation) |
357 return; | 349 return; |
358 | 350 |
359 // Reset if the frame actually navigated. | 351 // Reset if the frame actually navigated. |
360 Reset(); | 352 Reset(); |
361 } | 353 } |
362 | 354 |
363 void PresentationServiceImpl::RenderFrameDeleted( | 355 void PresentationServiceImpl::RenderFrameDeleted( |
364 content::RenderFrameHost* render_frame_host) { | 356 content::RenderFrameHost* render_frame_host) { |
365 DVLOG(2) << "PresentationServiceImpl::RenderFrameDeleted"; | 357 DVLOG(2) << "PresentationServiceImpl::RenderFrameDeleted"; |
366 if (!FrameMatches(render_frame_host)) | 358 if (render_frame_host_ != render_frame_host) |
367 return; | 359 return; |
368 | 360 |
369 // RenderFrameDeleted means the associated RFH is going to be deleted soon. | 361 // RenderFrameDeleted means |render_frame_host_| is going to be deleted soon. |
370 // This object should also be deleted. | 362 // This object should also be deleted. |
371 Reset(); | 363 Reset(); |
| 364 render_frame_host_ = nullptr; |
372 delete this; | 365 delete this; |
373 } | 366 } |
374 | 367 |
375 void PresentationServiceImpl::Reset() { | 368 void PresentationServiceImpl::Reset() { |
376 DVLOG(2) << "PresentationServiceImpl::Reset"; | 369 DVLOG(2) << "PresentationServiceImpl::Reset"; |
377 if (delegate_) | 370 if (delegate_) { |
378 delegate_->Reset(render_process_id_, render_frame_id_); | 371 delegate_->Reset( |
| 372 render_frame_host_->GetProcess()->GetID(), |
| 373 render_frame_host_->GetRoutingID()); |
| 374 } |
379 | 375 |
380 default_presentation_url_.clear(); | 376 default_presentation_url_.clear(); |
381 default_presentation_id_.clear(); | 377 default_presentation_id_.clear(); |
382 availability_contexts_.clear(); | 378 availability_contexts_.clear(); |
383 queued_start_session_requests_.clear(); | 379 queued_start_session_requests_.clear(); |
384 FlushNewSessionCallbacks(); | 380 FlushNewSessionCallbacks(); |
385 default_session_start_context_.reset(); | |
386 } | 381 } |
387 | 382 |
388 // static | 383 // static |
389 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( | 384 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( |
390 const NewSessionMojoCallback& callback) { | 385 const NewSessionMojoCallback& callback) { |
391 callback.Run( | 386 callback.Run( |
392 presentation::PresentationSessionInfoPtr(), | 387 presentation::PresentationSessionInfoPtr(), |
393 presentation::PresentationError::From( | 388 presentation::PresentationError::From( |
394 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); | 389 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); |
395 } | 390 } |
396 | 391 |
397 void PresentationServiceImpl::OnDelegateDestroyed() { | 392 void PresentationServiceImpl::OnDelegateDestroyed() { |
398 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 393 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
399 delegate_ = nullptr; | 394 delegate_ = nullptr; |
400 Reset(); | 395 Reset(); |
401 } | 396 } |
402 | 397 |
403 void PresentationServiceImpl::OnDefaultPresentationStarted( | |
404 const PresentationSessionInfo& session) { | |
405 if (default_session_start_context_.get()) | |
406 default_session_start_context_->set_session(session); | |
407 } | |
408 | |
409 PresentationServiceImpl::ScreenAvailabilityContext::ScreenAvailabilityContext( | 398 PresentationServiceImpl::ScreenAvailabilityContext::ScreenAvailabilityContext( |
410 const std::string& presentation_url) | 399 const std::string& presentation_url) |
411 : presentation_url_(presentation_url) { | 400 : presentation_url_(presentation_url) { |
412 } | 401 } |
413 | 402 |
414 PresentationServiceImpl::ScreenAvailabilityContext:: | 403 PresentationServiceImpl::ScreenAvailabilityContext:: |
415 ~ScreenAvailabilityContext() { | 404 ~ScreenAvailabilityContext() { |
416 // Ensure that pending callbacks are flushed. | 405 // Ensure that pending callbacks are flushed. |
417 OnScreenAvailabilityChanged(false); | 406 OnScreenAvailabilityChanged(false); |
418 } | 407 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 InvokeNewSessionMojoCallbackWithError(callback_); | 471 InvokeNewSessionMojoCallbackWithError(callback_); |
483 } | 472 } |
484 | 473 |
485 PresentationServiceImpl::NewSessionMojoCallback | 474 PresentationServiceImpl::NewSessionMojoCallback |
486 PresentationServiceImpl::StartSessionRequest::PassCallback() { | 475 PresentationServiceImpl::StartSessionRequest::PassCallback() { |
487 NewSessionMojoCallback callback = callback_; | 476 NewSessionMojoCallback callback = callback_; |
488 callback_.reset(); | 477 callback_.reset(); |
489 return callback; | 478 return callback; |
490 } | 479 } |
491 | 480 |
492 PresentationServiceImpl::DefaultSessionStartContext | |
493 ::DefaultSessionStartContext() { | |
494 } | |
495 | |
496 PresentationServiceImpl::DefaultSessionStartContext | |
497 ::~DefaultSessionStartContext() { | |
498 Reset(); | |
499 } | |
500 | |
501 void PresentationServiceImpl::DefaultSessionStartContext::AddCallback( | |
502 const DefaultSessionMojoCallback& callback) { | |
503 if (session_.get()) { | |
504 DCHECK(callbacks_.empty()); | |
505 callback.Run(presentation::PresentationSessionInfo::From(*session_)); | |
506 session_.reset(); | |
507 } else { | |
508 callbacks_.push_back(new DefaultSessionMojoCallback(callback)); | |
509 } | |
510 } | |
511 | |
512 void PresentationServiceImpl::DefaultSessionStartContext::set_session( | |
513 const PresentationSessionInfo& session) { | |
514 if (callbacks_.empty()) { | |
515 session_.reset(new PresentationSessionInfo(session)); | |
516 } else { | |
517 DCHECK(!session_.get()); | |
518 ScopedVector<DefaultSessionMojoCallback> callbacks; | |
519 callbacks.swap(callbacks_); | |
520 for (const auto& callback : callbacks) | |
521 callback->Run(presentation::PresentationSessionInfo::From(session)); | |
522 } | |
523 } | |
524 | |
525 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | |
526 ScopedVector<DefaultSessionMojoCallback> callbacks; | |
527 callbacks.swap(callbacks_); | |
528 for (const auto& callback : callbacks) | |
529 callback->Run(presentation::PresentationSessionInfoPtr()); | |
530 session_.reset(); | |
531 } | |
532 | |
533 } // namespace content | 481 } // namespace content |
534 | 482 |
OLD | NEW |