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

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

Issue 2174693004: [Presentation API] Add support to content/ for multiple URLs per PresentationRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing TODO Created 4 years, 4 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
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 <string>
11 #include <utility> 10 #include <utility>
12 #include <vector>
13 11
14 #include "base/logging.h" 12 #include "base/logging.h"
15 #include "base/stl_util.h" 13 #include "base/stl_util.h"
16 #include "content/browser/presentation/presentation_type_converters.h" 14 #include "content/browser/presentation/presentation_type_converters.h"
17 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
18 #include "content/public/browser/navigation_details.h" 16 #include "content/public/browser/navigation_details.h"
19 #include "content/public/browser/presentation_session_message.h" 17 #include "content/public/browser/presentation_session_message.h"
20 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 211
214 auto listener_it = screen_availability_listeners_.find(url); 212 auto listener_it = screen_availability_listeners_.find(url);
215 if (listener_it == screen_availability_listeners_.end()) 213 if (listener_it == screen_availability_listeners_.end())
216 return; 214 return;
217 215
218 delegate_->RemoveScreenAvailabilityListener( 216 delegate_->RemoveScreenAvailabilityListener(
219 render_process_id_, render_frame_id_, listener_it->second.get()); 217 render_process_id_, render_frame_id_, listener_it->second.get());
220 screen_availability_listeners_.erase(listener_it); 218 screen_availability_listeners_.erase(listener_it);
221 } 219 }
222 220
223 void PresentationServiceImpl::StartSession(const std::string& presentation_url, 221 void PresentationServiceImpl::StartSession(
224 const NewSessionCallback& callback) { 222 const std::vector<std::string>& presentation_urls,
223 const NewSessionCallback& callback) {
225 DVLOG(2) << "StartSession"; 224 DVLOG(2) << "StartSession";
226 if (!delegate_) { 225 if (!delegate_) {
227 callback.Run( 226 callback.Run(
228 blink::mojom::PresentationSessionInfoPtr(), 227 blink::mojom::PresentationSessionInfoPtr(),
229 blink::mojom::PresentationError::From(PresentationError( 228 blink::mojom::PresentationError::From(PresentationError(
230 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 229 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
231 return; 230 return;
232 } 231 }
233 232
234 // There is a StartSession request in progress. To avoid queueing up 233 // There is a StartSession request in progress. To avoid queueing up
235 // requests, the incoming request is rejected. 234 // requests, the incoming request is rejected.
236 if (start_session_request_id_ != kInvalidRequestSessionId) { 235 if (start_session_request_id_ != kInvalidRequestSessionId) {
237 InvokeNewSessionCallbackWithError(callback); 236 InvokeNewSessionCallbackWithError(callback);
238 return; 237 return;
239 } 238 }
240 239
241 start_session_request_id_ = GetNextRequestSessionId(); 240 start_session_request_id_ = GetNextRequestSessionId();
242 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); 241 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
243 delegate_->StartSession( 242 delegate_->StartSession(
244 render_process_id_, render_frame_id_, presentation_url, 243 render_process_id_, render_frame_id_, presentation_urls,
245 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 244 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
246 weak_factory_.GetWeakPtr(), start_session_request_id_), 245 weak_factory_.GetWeakPtr(), start_session_request_id_),
247 base::Bind(&PresentationServiceImpl::OnStartSessionError, 246 base::Bind(&PresentationServiceImpl::OnStartSessionError,
248 weak_factory_.GetWeakPtr(), start_session_request_id_)); 247 weak_factory_.GetWeakPtr(), start_session_request_id_));
249 } 248 }
250 249
251 void PresentationServiceImpl::JoinSession( 250 void PresentationServiceImpl::JoinSession(
252 const std::string& presentation_url, 251 const std::vector<std::string>& presentation_urls,
253 const base::Optional<std::string>& presentation_id, 252 const base::Optional<std::string>& presentation_id,
254 const NewSessionCallback& callback) { 253 const NewSessionCallback& callback) {
255 DVLOG(2) << "JoinSession"; 254 DVLOG(2) << "JoinSession";
256 if (!delegate_) { 255 if (!delegate_) {
257 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 256 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
258 blink::mojom::PresentationError::From(PresentationError( 257 blink::mojom::PresentationError::From(PresentationError(
259 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 258 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
260 "Error joining route: No matching route"))); 259 "Error joining route: No matching route")));
261 return; 260 return;
262 } 261 }
263 262
264 int request_session_id = RegisterJoinSessionCallback(callback); 263 int request_session_id = RegisterJoinSessionCallback(callback);
265 if (request_session_id == kInvalidRequestSessionId) { 264 if (request_session_id == kInvalidRequestSessionId) {
266 InvokeNewSessionCallbackWithError(callback); 265 InvokeNewSessionCallbackWithError(callback);
267 return; 266 return;
268 } 267 }
269 delegate_->JoinSession( 268 delegate_->JoinSession(
270 render_process_id_, render_frame_id_, presentation_url, 269 render_process_id_, render_frame_id_, presentation_urls,
271 presentation_id.value_or(std::string()), 270 presentation_id.value_or(std::string()),
272 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, 271 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded,
273 weak_factory_.GetWeakPtr(), request_session_id), 272 weak_factory_.GetWeakPtr(), request_session_id),
274 base::Bind(&PresentationServiceImpl::OnJoinSessionError, 273 base::Bind(&PresentationServiceImpl::OnJoinSessionError,
275 weak_factory_.GetWeakPtr(), request_session_id)); 274 weak_factory_.GetWeakPtr(), request_session_id));
276 } 275 }
277 276
278 int PresentationServiceImpl::RegisterJoinSessionCallback( 277 int PresentationServiceImpl::RegisterJoinSessionCallback(
279 const NewSessionCallback& callback) { 278 const NewSessionCallback& callback) {
280 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) 279 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 auto it = pending_join_session_cbs_.find(request_session_id); 349 auto it = pending_join_session_cbs_.find(request_session_id);
351 if (it == pending_join_session_cbs_.end()) 350 if (it == pending_join_session_cbs_.end())
352 return false; 351 return false;
353 352
354 DCHECK(it->second.get()); 353 DCHECK(it->second.get());
355 it->second->Run(std::move(session), std::move(error)); 354 it->second->Run(std::move(session), std::move(error));
356 pending_join_session_cbs_.erase(it); 355 pending_join_session_cbs_.erase(it);
357 return true; 356 return true;
358 } 357 }
359 358
360 void PresentationServiceImpl::SetDefaultPresentationURL( 359 void PresentationServiceImpl::SetDefaultPresentationUrls(
361 const std::string& url) { 360 const std::vector<std::string>& presentation_urls) {
362 DVLOG(2) << "SetDefaultPresentationURL"; 361 DVLOG(2) << "SetDefaultPresentationUrls";
363 if (!delegate_) 362 if (!delegate_)
364 return; 363 return;
365 364
366 if (default_presentation_url_ == url) 365 if (default_presentation_urls_ == presentation_urls)
367 return; 366 return;
368 367
369 default_presentation_url_ = url; 368 default_presentation_urls_ = presentation_urls;
370 delegate_->SetDefaultPresentationUrl( 369 delegate_->SetDefaultPresentationUrls(
371 render_process_id_, render_frame_id_, url, 370 render_process_id_, render_frame_id_, presentation_urls,
372 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 371 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
373 weak_factory_.GetWeakPtr())); 372 weak_factory_.GetWeakPtr()));
374 } 373 }
375 374
376 void PresentationServiceImpl::SendSessionMessage( 375 void PresentationServiceImpl::SendSessionMessage(
377 blink::mojom::PresentationSessionInfoPtr session, 376 blink::mojom::PresentationSessionInfoPtr session,
378 blink::mojom::SessionMessagePtr session_message, 377 blink::mojom::SessionMessagePtr session_message,
379 const SendSessionMessageCallback& callback) { 378 const SendSessionMessageCallback& callback) {
380 DVLOG(2) << "SendSessionMessage"; 379 DVLOG(2) << "SendSessionMessage";
381 DCHECK(!session_message.is_null()); 380 DCHECK(!session_message.is_null());
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 << "should've been deleted during RenderFrameDeleted()."; 516 << "should've been deleted during RenderFrameDeleted().";
518 Reset(); 517 Reset();
519 delete this; 518 delete this;
520 } 519 }
521 520
522 void PresentationServiceImpl::Reset() { 521 void PresentationServiceImpl::Reset() {
523 DVLOG(2) << "PresentationServiceImpl::Reset"; 522 DVLOG(2) << "PresentationServiceImpl::Reset";
524 if (delegate_) 523 if (delegate_)
525 delegate_->Reset(render_process_id_, render_frame_id_); 524 delegate_->Reset(render_process_id_, render_frame_id_);
526 525
527 default_presentation_url_.clear(); 526 default_presentation_urls_.clear();
528 527
529 screen_availability_listeners_.clear(); 528 screen_availability_listeners_.clear();
530 529
531 start_session_request_id_ = kInvalidRequestSessionId; 530 start_session_request_id_ = kInvalidRequestSessionId;
532 pending_start_session_cb_.reset(); 531 pending_start_session_cb_.reset();
533 532
534 pending_join_session_cbs_.clear(); 533 pending_join_session_cbs_.clear();
535 534
536 if (on_session_messages_callback_.get()) { 535 if (on_session_messages_callback_.get()) {
537 on_session_messages_callback_->Run( 536 on_session_messages_callback_->Run(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 602
604 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 603 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
605 blink::mojom::PresentationSessionInfoPtr session, 604 blink::mojom::PresentationSessionInfoPtr session,
606 blink::mojom::PresentationErrorPtr error) { 605 blink::mojom::PresentationErrorPtr error) {
607 DCHECK(!callback_.is_null()); 606 DCHECK(!callback_.is_null());
608 callback_.Run(std::move(session), std::move(error)); 607 callback_.Run(std::move(session), std::move(error));
609 callback_.Reset(); 608 callback_.Reset();
610 } 609 }
611 610
612 } // namespace content 611 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698