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