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

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: Updated unittests. Created 4 years, 5 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const std::string& availability_url = url.get(); 209 const std::string& availability_url = url.get();
212 auto listener_it = screen_availability_listeners_.find(availability_url); 210 auto listener_it = screen_availability_listeners_.find(availability_url);
213 if (listener_it == screen_availability_listeners_.end()) 211 if (listener_it == screen_availability_listeners_.end())
214 return; 212 return;
215 213
216 delegate_->RemoveScreenAvailabilityListener( 214 delegate_->RemoveScreenAvailabilityListener(
217 render_process_id_, render_frame_id_, listener_it->second.get()); 215 render_process_id_, render_frame_id_, listener_it->second.get());
218 screen_availability_listeners_.erase(listener_it); 216 screen_availability_listeners_.erase(listener_it);
219 } 217 }
220 218
221 void PresentationServiceImpl::StartSession(const mojo::String& presentation_url, 219 void PresentationServiceImpl::StartSession(
222 const NewSessionCallback& callback) { 220 mojo::Array<mojo::String> presentation_urls,
221 const NewSessionCallback& callback) {
223 DVLOG(2) << "StartSession"; 222 DVLOG(2) << "StartSession";
224 if (!delegate_) { 223 if (!delegate_) {
225 callback.Run( 224 callback.Run(
226 blink::mojom::PresentationSessionInfoPtr(), 225 blink::mojom::PresentationSessionInfoPtr(),
227 blink::mojom::PresentationError::From(PresentationError( 226 blink::mojom::PresentationError::From(PresentationError(
228 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 227 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
229 return; 228 return;
230 } 229 }
231 230
232 // There is a StartSession request in progress. To avoid queueing up 231 // There is a StartSession request in progress. To avoid queueing up
233 // requests, the incoming request is rejected. 232 // requests, the incoming request is rejected.
234 if (start_session_request_id_ != kInvalidRequestSessionId) { 233 if (start_session_request_id_ != kInvalidRequestSessionId) {
235 InvokeNewSessionCallbackWithError(callback); 234 InvokeNewSessionCallbackWithError(callback);
236 return; 235 return;
237 } 236 }
238 237
238 std::vector<std::string> urls(presentation_urls.size());
239 std::transform(presentation_urls.begin(), presentation_urls.end(),
240 urls.begin(),
241 [](const mojo::String& url) { return url.get(); });
242
239 start_session_request_id_ = GetNextRequestSessionId(); 243 start_session_request_id_ = GetNextRequestSessionId();
240 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); 244 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
241 delegate_->StartSession( 245 delegate_->StartSession(
242 render_process_id_, render_frame_id_, presentation_url, 246 render_process_id_, render_frame_id_, urls,
243 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 247 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
244 weak_factory_.GetWeakPtr(), start_session_request_id_), 248 weak_factory_.GetWeakPtr(), start_session_request_id_),
245 base::Bind(&PresentationServiceImpl::OnStartSessionError, 249 base::Bind(&PresentationServiceImpl::OnStartSessionError,
246 weak_factory_.GetWeakPtr(), start_session_request_id_)); 250 weak_factory_.GetWeakPtr(), start_session_request_id_));
247 } 251 }
248 252
249 void PresentationServiceImpl::JoinSession( 253 void PresentationServiceImpl::JoinSession(
250 const mojo::String& presentation_url, 254 mojo::Array<mojo::String> presentation_urls,
251 const mojo::String& presentation_id, 255 const mojo::String& presentation_id,
252 const NewSessionCallback& callback) { 256 const NewSessionCallback& callback) {
253 DVLOG(2) << "JoinSession"; 257 DVLOG(2) << "JoinSession";
254 if (!delegate_) { 258 if (!delegate_) {
255 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 259 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
256 blink::mojom::PresentationError::From(PresentationError( 260 blink::mojom::PresentationError::From(PresentationError(
257 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 261 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
258 "Error joining route: No matching route"))); 262 "Error joining route: No matching route")));
259 return; 263 return;
260 } 264 }
261 265
262 int request_session_id = RegisterJoinSessionCallback(callback); 266 int request_session_id = RegisterJoinSessionCallback(callback);
263 if (request_session_id == kInvalidRequestSessionId) { 267 if (request_session_id == kInvalidRequestSessionId) {
264 InvokeNewSessionCallbackWithError(callback); 268 InvokeNewSessionCallbackWithError(callback);
265 return; 269 return;
266 } 270 }
271 std::vector<std::string> urls(presentation_urls.size());
272 std::transform(presentation_urls.begin(), presentation_urls.end(),
273 urls.begin(),
274 [](const mojo::String& url) { return url.get(); });
275
267 delegate_->JoinSession( 276 delegate_->JoinSession(
268 render_process_id_, 277 render_process_id_, render_frame_id_, urls, presentation_id,
269 render_frame_id_,
270 presentation_url,
271 presentation_id,
272 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded, 278 base::Bind(&PresentationServiceImpl::OnJoinSessionSucceeded,
273 weak_factory_.GetWeakPtr(), request_session_id), 279 weak_factory_.GetWeakPtr(), request_session_id),
274 base::Bind(&PresentationServiceImpl::OnJoinSessionError, 280 base::Bind(&PresentationServiceImpl::OnJoinSessionError,
275 weak_factory_.GetWeakPtr(), request_session_id)); 281 weak_factory_.GetWeakPtr(), request_session_id));
276 } 282 }
277 283
278 int PresentationServiceImpl::RegisterJoinSessionCallback( 284 int PresentationServiceImpl::RegisterJoinSessionCallback(
279 const NewSessionCallback& callback) { 285 const NewSessionCallback& callback) {
280 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests) 286 if (pending_join_session_cbs_.size() >= kMaxNumQueuedSessionRequests)
281 return kInvalidRequestSessionId; 287 return kInvalidRequestSessionId;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 auto it = pending_join_session_cbs_.find(request_session_id); 356 auto it = pending_join_session_cbs_.find(request_session_id);
351 if (it == pending_join_session_cbs_.end()) 357 if (it == pending_join_session_cbs_.end())
352 return false; 358 return false;
353 359
354 DCHECK(it->second.get()); 360 DCHECK(it->second.get());
355 it->second->Run(std::move(session), std::move(error)); 361 it->second->Run(std::move(session), std::move(error));
356 pending_join_session_cbs_.erase(it); 362 pending_join_session_cbs_.erase(it);
357 return true; 363 return true;
358 } 364 }
359 365
360 void PresentationServiceImpl::SetDefaultPresentationURL( 366 void PresentationServiceImpl::SetDefaultPresentationUrls(
361 const mojo::String& url) { 367 mojo::Array<mojo::String> presentation_urls) {
362 DVLOG(2) << "SetDefaultPresentationURL"; 368 DVLOG(2) << "SetDefaultPresentationUrls";
363 if (!delegate_) 369 if (!delegate_)
364 return; 370 return;
365 371
366 const std::string& new_default_url = url.get(); 372 std::vector<std::string> new_default_urls(presentation_urls.size());
367 if (default_presentation_url_ == new_default_url) 373 std::transform(presentation_urls.begin(), presentation_urls.end(),
374 new_default_urls.begin(),
375 [](const mojo::String& url) { return url.get(); });
376
377 if (default_presentation_urls_ == new_default_urls)
368 return; 378 return;
369 379
370 default_presentation_url_ = new_default_url; 380 default_presentation_urls_ = new_default_urls;
371 delegate_->SetDefaultPresentationUrl( 381 delegate_->SetDefaultPresentationUrls(
372 render_process_id_, render_frame_id_, new_default_url, 382 render_process_id_, render_frame_id_, new_default_urls,
373 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 383 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
374 weak_factory_.GetWeakPtr())); 384 weak_factory_.GetWeakPtr()));
375 } 385 }
376 386
377 void PresentationServiceImpl::SendSessionMessage( 387 void PresentationServiceImpl::SendSessionMessage(
378 blink::mojom::PresentationSessionInfoPtr session, 388 blink::mojom::PresentationSessionInfoPtr session,
379 blink::mojom::SessionMessagePtr session_message, 389 blink::mojom::SessionMessagePtr session_message,
380 const SendSessionMessageCallback& callback) { 390 const SendSessionMessageCallback& callback) {
381 DVLOG(2) << "SendSessionMessage"; 391 DVLOG(2) << "SendSessionMessage";
382 DCHECK(!session_message.is_null()); 392 DCHECK(!session_message.is_null());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 << "should've been deleted during RenderFrameDeleted()."; 526 << "should've been deleted during RenderFrameDeleted().";
517 Reset(); 527 Reset();
518 delete this; 528 delete this;
519 } 529 }
520 530
521 void PresentationServiceImpl::Reset() { 531 void PresentationServiceImpl::Reset() {
522 DVLOG(2) << "PresentationServiceImpl::Reset"; 532 DVLOG(2) << "PresentationServiceImpl::Reset";
523 if (delegate_) 533 if (delegate_)
524 delegate_->Reset(render_process_id_, render_frame_id_); 534 delegate_->Reset(render_process_id_, render_frame_id_);
525 535
526 default_presentation_url_.clear(); 536 default_presentation_urls_.clear();
527 537
528 screen_availability_listeners_.clear(); 538 screen_availability_listeners_.clear();
529 539
530 start_session_request_id_ = kInvalidRequestSessionId; 540 start_session_request_id_ = kInvalidRequestSessionId;
531 pending_start_session_cb_.reset(); 541 pending_start_session_cb_.reset();
532 542
533 pending_join_session_cbs_.clear(); 543 pending_join_session_cbs_.clear();
534 544
535 if (on_session_messages_callback_.get()) { 545 if (on_session_messages_callback_.get()) {
536 on_session_messages_callback_->Run( 546 on_session_messages_callback_->Run(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 612
603 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 613 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
604 blink::mojom::PresentationSessionInfoPtr session, 614 blink::mojom::PresentationSessionInfoPtr session,
605 blink::mojom::PresentationErrorPtr error) { 615 blink::mojom::PresentationErrorPtr error) {
606 DCHECK(!callback_.is_null()); 616 DCHECK(!callback_.is_null());
607 callback_.Run(std::move(session), std::move(error)); 617 callback_.Run(std::move(session), std::move(error));
608 callback_.Reset(); 618 callback_.Reset();
609 } 619 }
610 620
611 } // namespace content 621 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698