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

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

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: resolve code review comments from Derek Created 4 years 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 #include "content/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 119 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
120 blink::mojom::PresentationError::From(PresentationError( 120 blink::mojom::PresentationError::From(PresentationError(
121 PRESENTATION_ERROR_UNKNOWN, "Internal error"))); 121 PRESENTATION_ERROR_UNKNOWN, "Internal error")));
122 } 122 }
123 123
124 } // namespace 124 } // namespace
125 125
126 PresentationServiceImpl::PresentationServiceImpl( 126 PresentationServiceImpl::PresentationServiceImpl(
127 RenderFrameHost* render_frame_host, 127 RenderFrameHost* render_frame_host,
128 WebContents* web_contents, 128 WebContents* web_contents,
129 PresentationServiceDelegate* delegate) 129 ControllerPresentationServiceDelegate* controller_delegate,
130 ReceiverPresentationServiceDelegate* receiver_delegate)
130 : WebContentsObserver(web_contents), 131 : WebContentsObserver(web_contents),
131 delegate_(delegate), 132 controller_delegate_(controller_delegate),
133 receiver_delegate_(receiver_delegate),
132 start_session_request_id_(kInvalidRequestSessionId), 134 start_session_request_id_(kInvalidRequestSessionId),
133 weak_factory_(this) { 135 weak_factory_(this) {
134 DCHECK(render_frame_host); 136 DCHECK(render_frame_host);
135 DCHECK(web_contents); 137 DCHECK(web_contents);
136 CHECK(render_frame_host->IsRenderFrameLive()); 138 CHECK(render_frame_host->IsRenderFrameLive());
137 139
138 render_process_id_ = render_frame_host->GetProcess()->GetID(); 140 render_process_id_ = render_frame_host->GetProcess()->GetID();
139 render_frame_id_ = render_frame_host->GetRoutingID(); 141 render_frame_id_ = render_frame_host->GetRoutingID();
140 DVLOG(2) << "PresentationServiceImpl: " 142 DVLOG(2) << "PresentationServiceImpl: "
141 << render_process_id_ << ", " << render_frame_id_; 143 << render_process_id_ << ", " << render_frame_id_;
142 if (delegate_) 144
143 delegate_->AddObserver(render_process_id_, render_frame_id_, this); 145 if (auto* delegate = GetPresentationServiceDelegate())
146 delegate->AddObserver(render_process_id_, render_frame_id_, this);
144 } 147 }
145 148
146 PresentationServiceImpl::~PresentationServiceImpl() { 149 PresentationServiceImpl::~PresentationServiceImpl() {
147 if (delegate_) 150 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", "
148 delegate_->RemoveObserver(render_process_id_, render_frame_id_); 151 << render_frame_id_;
152
153 if (auto* delegate = GetPresentationServiceDelegate())
154 delegate->RemoveObserver(render_process_id_, render_frame_id_);
149 } 155 }
150 156
151 // static 157 // static
152 void PresentationServiceImpl::CreateMojoService( 158 void PresentationServiceImpl::CreateMojoService(
153 RenderFrameHost* render_frame_host, 159 RenderFrameHost* render_frame_host,
154 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 160 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
155 DVLOG(2) << "CreateMojoService"; 161 DVLOG(2) << "CreateMojoService";
156 WebContents* web_contents = 162 WebContents* web_contents =
157 WebContents::FromRenderFrameHost(render_frame_host); 163 WebContents::FromRenderFrameHost(render_frame_host);
158 DCHECK(web_contents); 164 DCHECK(web_contents);
159 165
166 auto* browser = GetContentClient()->browser();
167 auto* receiver_delegate =
168 browser->GetReceiverPresentationServiceDelegate(web_contents);
169
170 // In current implementation, web contents can be controller or receiver
mark a. foltz 2016/12/02 22:09:05 nit: web_contents
zhaobin 2016/12/03 00:34:26 Done.
171 // but not both.
172 auto* controller_delegate =
173 receiver_delegate
174 ? nullptr
175 : browser->GetControllerPresentationServiceDelegate(web_contents);
176
160 // This object will be deleted when the RenderFrameHost is about to be 177 // This object will be deleted when the RenderFrameHost is about to be
161 // deleted (RenderFrameDeleted). 178 // deleted (RenderFrameDeleted).
162 PresentationServiceImpl* impl = new PresentationServiceImpl( 179 PresentationServiceImpl* impl = new PresentationServiceImpl(
163 render_frame_host, 180 render_frame_host, web_contents, controller_delegate, receiver_delegate);
164 web_contents,
165 GetContentClient()->browser()->GetPresentationServiceDelegate(
166 web_contents));
167 impl->Bind(std::move(request)); 181 impl->Bind(std::move(request));
168 } 182 }
169 183
170 void PresentationServiceImpl::Bind( 184 void PresentationServiceImpl::Bind(
171 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 185 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
172 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( 186 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>(
173 this, std::move(request))); 187 this, std::move(request)));
174 } 188 }
175 189
176 void PresentationServiceImpl::SetClient( 190 void PresentationServiceImpl::SetClient(
177 blink::mojom::PresentationServiceClientPtr client) { 191 blink::mojom::PresentationServiceClientPtr client) {
178 DCHECK(!client_.get()); 192 DCHECK(!client_.get());
179 // TODO(imcheng): Set ErrorHandler to listen for errors. 193 // TODO(imcheng): Set ErrorHandler to listen for errors.
180 client_ = std::move(client); 194 client_ = std::move(client);
195
196 if (receiver_delegate_) {
197 receiver_delegate_->RegisterReceiverConnectionAvailableCallback(
198 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable,
199 weak_factory_.GetWeakPtr()));
200 }
181 } 201 }
182 202
183 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { 203 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
184 DVLOG(2) << "ListenForScreenAvailability " << url.spec(); 204 DVLOG(2) << "ListenForScreenAvailability " << url.spec();
185 if (!delegate_) { 205 if (!controller_delegate_) {
186 client_->OnScreenAvailabilityUpdated(url, false); 206 client_->OnScreenAvailabilityUpdated(url, false);
187 return; 207 return;
188 } 208 }
189 209
190 if (screen_availability_listeners_.count(url)) 210 if (screen_availability_listeners_.count(url))
191 return; 211 return;
192 212
193 std::unique_ptr<ScreenAvailabilityListenerImpl> listener( 213 std::unique_ptr<ScreenAvailabilityListenerImpl> listener(
194 new ScreenAvailabilityListenerImpl(url, this)); 214 new ScreenAvailabilityListenerImpl(url, this));
195 if (delegate_->AddScreenAvailabilityListener( 215 if (controller_delegate_->AddScreenAvailabilityListener(
196 render_process_id_, 216 render_process_id_, render_frame_id_, listener.get())) {
197 render_frame_id_,
198 listener.get())) {
199 screen_availability_listeners_[url] = std::move(listener); 217 screen_availability_listeners_[url] = std::move(listener);
200 } else { 218 } else {
201 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request."; 219 DVLOG(1) << "AddScreenAvailabilityListener failed. Ignoring request.";
202 } 220 }
203 } 221 }
204 222
205 void PresentationServiceImpl::StopListeningForScreenAvailability( 223 void PresentationServiceImpl::StopListeningForScreenAvailability(
206 const GURL& url) { 224 const GURL& url) {
207 DVLOG(2) << "StopListeningForScreenAvailability " << url.spec(); 225 DVLOG(2) << "StopListeningForScreenAvailability " << url.spec();
208 if (!delegate_) 226 if (!controller_delegate_)
209 return; 227 return;
210 228
211 auto listener_it = screen_availability_listeners_.find(url); 229 auto listener_it = screen_availability_listeners_.find(url);
212 if (listener_it == screen_availability_listeners_.end()) 230 if (listener_it == screen_availability_listeners_.end())
213 return; 231 return;
214 232
215 delegate_->RemoveScreenAvailabilityListener( 233 controller_delegate_->RemoveScreenAvailabilityListener(
216 render_process_id_, render_frame_id_, listener_it->second.get()); 234 render_process_id_, render_frame_id_, listener_it->second.get());
217 screen_availability_listeners_.erase(listener_it); 235 screen_availability_listeners_.erase(listener_it);
218 } 236 }
219 237
220 void PresentationServiceImpl::StartSession( 238 void PresentationServiceImpl::StartSession(
221 const std::vector<GURL>& presentation_urls, 239 const std::vector<GURL>& presentation_urls,
222 const NewSessionCallback& callback) { 240 const NewSessionCallback& callback) {
223 DVLOG(2) << "StartSession"; 241 DVLOG(2) << "StartSession";
224 if (!delegate_) { 242 if (!controller_delegate_) {
225 callback.Run( 243 callback.Run(
226 blink::mojom::PresentationSessionInfoPtr(), 244 blink::mojom::PresentationSessionInfoPtr(),
227 blink::mojom::PresentationError::From(PresentationError( 245 blink::mojom::PresentationError::From(PresentationError(
228 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 246 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
229 return; 247 return;
230 } 248 }
231 249
232 // There is a StartSession request in progress. To avoid queueing up 250 // There is a StartSession request in progress. To avoid queueing up
233 // requests, the incoming request is rejected. 251 // requests, the incoming request is rejected.
234 if (start_session_request_id_ != kInvalidRequestSessionId) { 252 if (start_session_request_id_ != kInvalidRequestSessionId) {
235 InvokeNewSessionCallbackWithError(callback); 253 InvokeNewSessionCallbackWithError(callback);
236 return; 254 return;
237 } 255 }
238 256
239 start_session_request_id_ = GetNextRequestSessionId(); 257 start_session_request_id_ = GetNextRequestSessionId();
240 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); 258 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
241 delegate_->StartSession( 259 controller_delegate_->StartSession(
242 render_process_id_, render_frame_id_, presentation_urls, 260 render_process_id_, render_frame_id_, presentation_urls,
243 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 261 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
244 weak_factory_.GetWeakPtr(), start_session_request_id_), 262 weak_factory_.GetWeakPtr(), start_session_request_id_),
245 base::Bind(&PresentationServiceImpl::OnStartSessionError, 263 base::Bind(&PresentationServiceImpl::OnStartSessionError,
246 weak_factory_.GetWeakPtr(), start_session_request_id_)); 264 weak_factory_.GetWeakPtr(), start_session_request_id_));
247 } 265 }
248 266
249 void PresentationServiceImpl::JoinSession( 267 void PresentationServiceImpl::JoinSession(
250 const std::vector<GURL>& presentation_urls, 268 const std::vector<GURL>& presentation_urls,
251 const base::Optional<std::string>& presentation_id, 269 const base::Optional<std::string>& presentation_id,
252 const NewSessionCallback& callback) { 270 const NewSessionCallback& callback) {
253 DVLOG(2) << "JoinSession"; 271 DVLOG(2) << "JoinSession";
254 if (!delegate_) { 272 if (!controller_delegate_) {
255 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 273 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
256 blink::mojom::PresentationError::From(PresentationError( 274 blink::mojom::PresentationError::From(PresentationError(
257 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 275 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
258 "Error joining route: No matching route"))); 276 "Error joining route: No matching route")));
259 return; 277 return;
260 } 278 }
261 279
262 int request_session_id = RegisterJoinSessionCallback(callback); 280 int request_session_id = RegisterJoinSessionCallback(callback);
263 if (request_session_id == kInvalidRequestSessionId) { 281 if (request_session_id == kInvalidRequestSessionId) {
264 InvokeNewSessionCallbackWithError(callback); 282 InvokeNewSessionCallbackWithError(callback);
265 return; 283 return;
266 } 284 }
267 delegate_->JoinSession( 285 controller_delegate_->JoinSession(
268 render_process_id_, render_frame_id_, presentation_urls, 286 render_process_id_, render_frame_id_, presentation_urls,
269 presentation_id.value_or(std::string()), 287 presentation_id.value_or(std::string()),
270 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, 288 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded,
271 weak_factory_.GetWeakPtr(), request_session_id), 289 weak_factory_.GetWeakPtr(), request_session_id),
272 base::Bind(&PresentationServiceImpl::OnJoinSessionError, 290 base::Bind(&PresentationServiceImpl::OnJoinSessionError,
273 weak_factory_.GetWeakPtr(), request_session_id)); 291 weak_factory_.GetWeakPtr(), request_session_id));
274 } 292 }
275 293
276 int PresentationServiceImpl::RegisterJoinSessionCallback( 294 int PresentationServiceImpl::RegisterJoinSessionCallback(
277 const NewSessionCallback& callback) { 295 const NewSessionCallback& callback) {
278 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) 296 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests)
279 return kInvalidRequestSessionId; 297 return kInvalidRequestSessionId;
280 298
281 int request_id = GetNextRequestSessionId(); 299 int request_id = GetNextRequestSessionId();
282 pending_join_session_cbs_[request_id].reset( 300 pending_join_session_cbs_[request_id].reset(
283 new NewSessionCallbackWrapper(callback)); 301 new NewSessionCallbackWrapper(callback));
284 return request_id; 302 return request_id;
285 } 303 }
286 304
287 void PresentationServiceImpl::ListenForConnectionStateChangeAndChangeState( 305 void PresentationServiceImpl::ListenForConnectionStateChangeAndChangeState(
288 const PresentationSessionInfo& connection) { 306 const PresentationSessionInfo& connection) {
289 if (delegate_) { 307 if (controller_delegate_) {
290 delegate_->ListenForConnectionStateChange( 308 controller_delegate_->ListenForConnectionStateChange(
291 render_process_id_, render_frame_id_, connection, 309 render_process_id_, render_frame_id_, connection,
292 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, 310 base::Bind(&PresentationServiceImpl::OnConnectionStateChanged,
293 weak_factory_.GetWeakPtr(), connection)); 311 weak_factory_.GetWeakPtr(), connection));
294 OnConnectionStateChanged(connection, 312 OnConnectionStateChanged(connection,
295 PresentationConnectionStateChangeInfo( 313 PresentationConnectionStateChangeInfo(
296 PRESENTATION_CONNECTION_STATE_CONNECTED)); 314 PRESENTATION_CONNECTION_STATE_CONNECTED));
297 } 315 }
298 } 316 }
299 317
300 void PresentationServiceImpl::OnStartSessionSucceeded( 318 void PresentationServiceImpl::OnStartSessionSucceeded(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 372
355 DCHECK(it->second.get()); 373 DCHECK(it->second.get());
356 it->second->Run(std::move(session), std::move(error)); 374 it->second->Run(std::move(session), std::move(error));
357 pending_join_session_cbs_.erase(it); 375 pending_join_session_cbs_.erase(it);
358 return true; 376 return true;
359 } 377 }
360 378
361 void PresentationServiceImpl::SetDefaultPresentationUrls( 379 void PresentationServiceImpl::SetDefaultPresentationUrls(
362 const std::vector<GURL>& presentation_urls) { 380 const std::vector<GURL>& presentation_urls) {
363 DVLOG(2) << "SetDefaultPresentationUrls"; 381 DVLOG(2) << "SetDefaultPresentationUrls";
364 if (!delegate_) 382 if (!controller_delegate_)
365 return; 383 return;
366 384
367 if (default_presentation_urls_ == presentation_urls) 385 if (default_presentation_urls_ == presentation_urls)
368 return; 386 return;
369 387
370 default_presentation_urls_ = presentation_urls; 388 default_presentation_urls_ = presentation_urls;
371 delegate_->SetDefaultPresentationUrls( 389 controller_delegate_->SetDefaultPresentationUrls(
372 render_process_id_, render_frame_id_, presentation_urls, 390 render_process_id_, render_frame_id_, presentation_urls,
373 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 391 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
374 weak_factory_.GetWeakPtr())); 392 weak_factory_.GetWeakPtr()));
375 } 393 }
376 394
377 void PresentationServiceImpl::SendSessionMessage( 395 void PresentationServiceImpl::SendSessionMessage(
378 blink::mojom::PresentationSessionInfoPtr session, 396 blink::mojom::PresentationSessionInfoPtr session,
379 blink::mojom::SessionMessagePtr session_message, 397 blink::mojom::SessionMessagePtr session_message,
380 const SendSessionMessageCallback& callback) { 398 const SendSessionMessageCallback& callback) {
381 DVLOG(2) << "SendSessionMessage"; 399 DVLOG(2) << "SendSessionMessage"
400 << " [id]: " << session->id;
382 DCHECK(!session_message.is_null()); 401 DCHECK(!session_message.is_null());
383 // send_message_callback_ should be null by now, otherwise resetting of 402 // send_message_callback_ should be null by now, otherwise resetting of
384 // send_message_callback_ with new callback will drop the old callback. 403 // send_message_callback_ with new callback will drop the old callback.
385 if (!delegate_ || send_message_callback_) { 404 if (!controller_delegate_ || send_message_callback_) {
386 callback.Run(false); 405 callback.Run(false);
387 return; 406 return;
388 } 407 }
389 408
390 send_message_callback_.reset(new SendSessionMessageCallback(callback)); 409 send_message_callback_.reset(new SendSessionMessageCallback(callback));
391 delegate_->SendMessage( 410 controller_delegate_->SendMessage(
392 render_process_id_, render_frame_id_, 411 render_process_id_, render_frame_id_,
393 session.To<PresentationSessionInfo>(), 412 session.To<PresentationSessionInfo>(),
394 GetPresentationSessionMessage(std::move(session_message)), 413 GetPresentationSessionMessage(std::move(session_message)),
395 base::Bind(&PresentationServiceImpl::OnSendMessageCallback, 414 base::Bind(&PresentationServiceImpl::OnSendMessageCallback,
396 weak_factory_.GetWeakPtr())); 415 weak_factory_.GetWeakPtr()));
397 } 416 }
398 417
399 void PresentationServiceImpl::OnSendMessageCallback(bool sent) { 418 void PresentationServiceImpl::OnSendMessageCallback(bool sent) {
400 // It is possible that Reset() is invoked before receiving this callback. 419 // It is possible that Reset() is invoked before receiving this callback.
401 // So, always check send_message_callback_ for non-null. 420 // So, always check send_message_callback_ for non-null.
402 if (send_message_callback_) { 421 if (send_message_callback_) {
403 send_message_callback_->Run(sent); 422 send_message_callback_->Run(sent);
404 send_message_callback_.reset(); 423 send_message_callback_.reset();
405 } 424 }
406 } 425 }
407 426
408 void PresentationServiceImpl::CloseConnection( 427 void PresentationServiceImpl::CloseConnection(
409 const GURL& presentation_url, 428 const GURL& presentation_url,
410 const std::string& presentation_id) { 429 const std::string& presentation_id) {
411 DVLOG(2) << "CloseConnection " << presentation_id; 430 DVLOG(2) << "CloseConnection " << presentation_id;
412 if (delegate_) 431 if (controller_delegate_)
413 delegate_->CloseConnection(render_process_id_, render_frame_id_, 432 controller_delegate_->CloseConnection(render_process_id_, render_frame_id_,
414 presentation_id); 433 presentation_id);
415 } 434 }
416 435
417 void PresentationServiceImpl::Terminate(const GURL& presentation_url, 436 void PresentationServiceImpl::Terminate(const GURL& presentation_url,
418 const std::string& presentation_id) { 437 const std::string& presentation_id) {
419 DVLOG(2) << "Terminate " << presentation_id; 438 DVLOG(2) << "Terminate " << presentation_id;
420 if (delegate_) 439 if (controller_delegate_)
421 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id); 440 controller_delegate_->Terminate(render_process_id_, render_frame_id_,
441 presentation_id);
422 } 442 }
423 443
424 void PresentationServiceImpl::OnConnectionStateChanged( 444 void PresentationServiceImpl::OnConnectionStateChanged(
425 const PresentationSessionInfo& connection, 445 const PresentationSessionInfo& connection,
426 const PresentationConnectionStateChangeInfo& info) { 446 const PresentationConnectionStateChangeInfo& info) {
427 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged " 447 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged "
428 << "[presentation_id]: " << connection.presentation_id 448 << "[presentation_id]: " << connection.presentation_id
429 << " [state]: " << info.state; 449 << " [state]: " << info.state;
430 DCHECK(client_.get()); 450 DCHECK(client_.get());
431 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { 451 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) {
(...skipping 10 matching lines...) Expand all
442 462
443 bool PresentationServiceImpl::FrameMatches( 463 bool PresentationServiceImpl::FrameMatches(
444 content::RenderFrameHost* render_frame_host) const { 464 content::RenderFrameHost* render_frame_host) const {
445 if (!render_frame_host) 465 if (!render_frame_host)
446 return false; 466 return false;
447 467
448 return render_frame_host->GetProcess()->GetID() == render_process_id_ && 468 return render_frame_host->GetProcess()->GetID() == render_process_id_ &&
449 render_frame_host->GetRoutingID() == render_frame_id_; 469 render_frame_host->GetRoutingID() == render_frame_id_;
450 } 470 }
451 471
472 PresentationServiceDelegate*
473 PresentationServiceImpl::GetPresentationServiceDelegate() {
474 return receiver_delegate_
475 ? static_cast<PresentationServiceDelegate*>(receiver_delegate_)
mark a. foltz 2016/12/02 22:09:05 Can these casts be removed now since both receiver
476 : static_cast<PresentationServiceDelegate*>(controller_delegate_);
477 }
478
452 void PresentationServiceImpl::ListenForSessionMessages( 479 void PresentationServiceImpl::ListenForSessionMessages(
453 blink::mojom::PresentationSessionInfoPtr session) { 480 blink::mojom::PresentationSessionInfoPtr session) {
454 DVLOG(2) << "ListenForSessionMessages"; 481 DVLOG(2) << "ListenForSessionMessages";
455 if (!delegate_) 482 if (!controller_delegate_)
456 return; 483 return;
457 484
458 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 485 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
459 delegate_->ListenForSessionMessages( 486 controller_delegate_->ListenForSessionMessages(
460 render_process_id_, render_frame_id_, session_info, 487 render_process_id_, render_frame_id_, session_info,
461 base::Bind(&PresentationServiceImpl::OnSessionMessages, 488 base::Bind(&PresentationServiceImpl::OnSessionMessages,
462 weak_factory_.GetWeakPtr(), session_info)); 489 weak_factory_.GetWeakPtr(), session_info));
463 } 490 }
464 491
492 void PresentationServiceImpl::SetPresentationConnection(
493 blink::mojom::PresentationSessionInfoPtr session,
494 blink::mojom::PresentationConnectionPtr connection) {
495 DVLOG(2) << "SetPresentationConnection";
496
497 if (!controller_delegate_)
498 return;
499
500 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
501 controller_delegate_->ConnectToOffscreenPresentation(
502 render_process_id_, render_frame_id_, session_info,
503 std::move(connection));
504 }
505
465 void PresentationServiceImpl::OnSessionMessages( 506 void PresentationServiceImpl::OnSessionMessages(
466 const PresentationSessionInfo& session, 507 const PresentationSessionInfo& session,
467 const ScopedVector<PresentationSessionMessage>& messages, 508 const ScopedVector<PresentationSessionMessage>& messages,
468 bool pass_ownership) { 509 bool pass_ownership) {
469 DCHECK(client_); 510 DCHECK(client_);
470 511 DVLOG(2) << "OnSessionMessages"
471 DVLOG(2) << "OnSessionMessages"; 512 << " [id]: " << session.presentation_id;
472 std::vector<blink::mojom::SessionMessagePtr> mojo_messages(messages.size()); 513 std::vector<blink::mojom::SessionMessagePtr> mojo_messages(messages.size());
473 std::transform(messages.begin(), messages.end(), mojo_messages.begin(), 514 std::transform(messages.begin(), messages.end(), mojo_messages.begin(),
474 [pass_ownership](PresentationSessionMessage* message) { 515 [pass_ownership](PresentationSessionMessage* message) {
475 return ToMojoSessionMessage(message, pass_ownership); 516 return ToMojoSessionMessage(message, pass_ownership);
476 }); 517 });
477 518
478 client_->OnSessionMessagesReceived( 519 client_->OnSessionMessagesReceived(
479 blink::mojom::PresentationSessionInfo::From(session), 520 blink::mojom::PresentationSessionInfo::From(session),
480 std::move(mojo_messages)); 521 std::move(mojo_messages));
481 } 522 }
482 523
524 void PresentationServiceImpl::OnReceiverConnectionAvailable(
525 const content::PresentationSessionInfo& session_info,
526 PresentationConnectionPtr controller) {
527 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
528 }
529
483 void PresentationServiceImpl::DidNavigateAnyFrame( 530 void PresentationServiceImpl::DidNavigateAnyFrame(
484 content::RenderFrameHost* render_frame_host, 531 content::RenderFrameHost* render_frame_host,
485 const content::LoadCommittedDetails& details, 532 const content::LoadCommittedDetails& details,
486 const content::FrameNavigateParams& params) { 533 const content::FrameNavigateParams& params) {
487 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 534 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
488 if (!FrameMatches(render_frame_host)) 535 if (!FrameMatches(render_frame_host))
489 return; 536 return;
490 537
491 std::string prev_url_host = details.previous_url.host(); 538 std::string prev_url_host = details.previous_url.host();
492 std::string curr_url_host = params.url.host(); 539 std::string curr_url_host = params.url.host();
(...skipping 25 matching lines...) Expand all
518 void PresentationServiceImpl::WebContentsDestroyed() { 565 void PresentationServiceImpl::WebContentsDestroyed() {
519 LOG(ERROR) << "PresentationServiceImpl is being deleted in " 566 LOG(ERROR) << "PresentationServiceImpl is being deleted in "
520 << "WebContentsDestroyed()! This shouldn't happen since it " 567 << "WebContentsDestroyed()! This shouldn't happen since it "
521 << "should've been deleted during RenderFrameDeleted()."; 568 << "should've been deleted during RenderFrameDeleted().";
522 Reset(); 569 Reset();
523 delete this; 570 delete this;
524 } 571 }
525 572
526 void PresentationServiceImpl::Reset() { 573 void PresentationServiceImpl::Reset() {
527 DVLOG(2) << "PresentationServiceImpl::Reset"; 574 DVLOG(2) << "PresentationServiceImpl::Reset";
528 if (delegate_) 575
529 delegate_->Reset(render_process_id_, render_frame_id_); 576 if (auto* delegate = GetPresentationServiceDelegate())
577 delegate->Reset(render_process_id_, render_frame_id_);
530 578
531 default_presentation_urls_.clear(); 579 default_presentation_urls_.clear();
532 580
533 screen_availability_listeners_.clear(); 581 screen_availability_listeners_.clear();
534 582
535 start_session_request_id_ = kInvalidRequestSessionId; 583 start_session_request_id_ = kInvalidRequestSessionId;
536 pending_start_session_cb_.reset(); 584 pending_start_session_cb_.reset();
537 585
538 pending_join_session_cbs_.clear(); 586 pending_join_session_cbs_.clear();
539 587
540 if (on_session_messages_callback_.get()) { 588 if (on_session_messages_callback_.get()) {
541 on_session_messages_callback_->Run( 589 on_session_messages_callback_->Run(
542 mojo::Array<blink::mojom::SessionMessagePtr>()); 590 mojo::Array<blink::mojom::SessionMessagePtr>());
543 on_session_messages_callback_.reset(); 591 on_session_messages_callback_.reset();
544 } 592 }
545 593
546 if (send_message_callback_) { 594 if (send_message_callback_) {
547 // Run the callback with false, indicating the renderer to stop sending 595 // Run the callback with false, indicating the renderer to stop sending
548 // the requests and invalidate all pending requests. 596 // the requests and invalidate all pending requests.
549 send_message_callback_->Run(false); 597 send_message_callback_->Run(false);
550 send_message_callback_.reset(); 598 send_message_callback_.reset();
551 } 599 }
552 } 600 }
553 601
554 void PresentationServiceImpl::OnDelegateDestroyed() { 602 void PresentationServiceImpl::OnDelegateDestroyed() {
555 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 603 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
556 delegate_ = nullptr; 604 controller_delegate_ = nullptr;
605 receiver_delegate_ = nullptr;
557 Reset(); 606 Reset();
558 } 607 }
559 608
560 void PresentationServiceImpl::OnDefaultPresentationStarted( 609 void PresentationServiceImpl::OnDefaultPresentationStarted(
561 const PresentationSessionInfo& connection) { 610 const PresentationSessionInfo& connection) {
562 DCHECK(client_.get()); 611 DCHECK(client_.get());
563 client_->OnDefaultSessionStarted( 612 client_->OnDefaultSessionStarted(
564 blink::mojom::PresentationSessionInfo::From(connection)); 613 blink::mojom::PresentationSessionInfo::From(connection));
565 ListenForConnectionStateChangeAndChangeState(connection); 614 ListenForConnectionStateChangeAndChangeState(connection);
566 } 615 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 654
606 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 655 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
607 blink::mojom::PresentationSessionInfoPtr session, 656 blink::mojom::PresentationSessionInfoPtr session,
608 blink::mojom::PresentationErrorPtr error) { 657 blink::mojom::PresentationErrorPtr error) {
609 DCHECK(!callback_.is_null()); 658 DCHECK(!callback_.is_null());
610 callback_.Run(std::move(session), std::move(error)); 659 callback_.Run(std::move(session), std::move(error));
611 callback_.Reset(); 660 callback_.Reset();
612 } 661 }
613 662
614 } // namespace content 663 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698