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

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

Issue 2710703006: Remove unused PresentationServiceImpl message code (Closed)
Patch Set: Remove unused PresentationDispatcher test code Created 3 years, 9 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 <utility> 10 #include <utility>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 output->type = blink::mojom::PresentationMessageType::TEXT; 56 output->type = blink::mojom::PresentationMessageType::TEXT;
57 if (pass_ownership) { 57 if (pass_ownership) {
58 output->message = std::move(input->message); 58 output->message = std::move(input->message);
59 } else { 59 } else {
60 output->message = input->message; 60 output->message = input->message;
61 } 61 }
62 } 62 }
63 return output; 63 return output;
64 } 64 }
65 65
66 std::unique_ptr<PresentationConnectionMessage> GetPresentationConnectionMessage(
67 blink::mojom::ConnectionMessagePtr input) {
68 std::unique_ptr<content::PresentationConnectionMessage> output;
69 if (input.is_null())
70 return output;
71
72 switch (input->type) {
73 case blink::mojom::PresentationMessageType::TEXT: {
74 // Return nullptr PresentationConnectionMessage if invalid (unset
75 // |message|,
76 // set |data|, or size too large).
77 if (input->data || !input->message ||
78 input->message->size() >
79 content::kMaxPresentationConnectionMessageSize)
80 return output;
81
82 output.reset(
83 new PresentationConnectionMessage(PresentationMessageType::TEXT));
84 output->message = std::move(input->message.value());
85 return output;
86 }
87 case blink::mojom::PresentationMessageType::BINARY: {
88 // Return nullptr PresentationConnectionMessage if invalid (unset |data|,
89 // set
90 // |message|, or size too large).
91 if (!input->data || input->message ||
92 input->data->size() > content::kMaxPresentationConnectionMessageSize)
93 return output;
94
95 output.reset(
96 new PresentationConnectionMessage(PresentationMessageType::BINARY));
97 output->data.reset(
98 new std::vector<uint8_t>(std::move(input->data.value())));
99 return output;
100 }
101 }
102
103 NOTREACHED() << "Invalid presentation message type " << input->type;
104 return output;
105 }
106
107 void InvokeNewSessionCallbackWithError( 66 void InvokeNewSessionCallbackWithError(
108 const PresentationServiceImpl::NewSessionCallback& callback) { 67 const PresentationServiceImpl::NewSessionCallback& callback) {
109 callback.Run(base::nullopt, 68 callback.Run(base::nullopt,
110 PresentationError( 69 PresentationError(
111 PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS, 70 PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS,
112 "There is already an unsettled Promise from a previous call " 71 "There is already an unsettled Promise from a previous call "
113 "to start.")); 72 "to start."));
114 } 73 }
115 74
116 } // namespace 75 } // namespace
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 if (default_presentation_urls_ == presentation_urls) 326 if (default_presentation_urls_ == presentation_urls)
368 return; 327 return;
369 328
370 default_presentation_urls_ = presentation_urls; 329 default_presentation_urls_ = presentation_urls;
371 controller_delegate_->SetDefaultPresentationUrls( 330 controller_delegate_->SetDefaultPresentationUrls(
372 render_process_id_, render_frame_id_, presentation_urls, 331 render_process_id_, render_frame_id_, presentation_urls,
373 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 332 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
374 weak_factory_.GetWeakPtr())); 333 weak_factory_.GetWeakPtr()));
375 } 334 }
376 335
377 void PresentationServiceImpl::SendConnectionMessage(
378 const PresentationSessionInfo& session_info,
379 blink::mojom::ConnectionMessagePtr connection_message,
380 const SendConnectionMessageCallback& callback) {
381 DVLOG(2) << "SendConnectionMessage [id]: " << session_info.presentation_id;
382 DCHECK(!connection_message.is_null());
383 // send_message_callback_ should be null by now, otherwise resetting of
384 // send_message_callback_ with new callback will drop the old callback.
385 if (!controller_delegate_ || send_message_callback_) {
386 callback.Run(false);
387 return;
388 }
389
390 send_message_callback_.reset(new SendConnectionMessageCallback(callback));
391 controller_delegate_->SendMessage(
392 render_process_id_, render_frame_id_, session_info,
393 GetPresentationConnectionMessage(std::move(connection_message)),
394 base::Bind(&PresentationServiceImpl::OnSendMessageCallback,
395 weak_factory_.GetWeakPtr()));
396 }
397
398 void PresentationServiceImpl::OnSendMessageCallback(bool sent) {
399 // It is possible that Reset() is invoked before receiving this callback.
400 // So, always check send_message_callback_ for non-null.
401 if (send_message_callback_) {
402 send_message_callback_->Run(sent);
403 send_message_callback_.reset();
404 }
405 }
406
407 void PresentationServiceImpl::CloseConnection( 336 void PresentationServiceImpl::CloseConnection(
408 const GURL& presentation_url, 337 const GURL& presentation_url,
409 const std::string& presentation_id) { 338 const std::string& presentation_id) {
410 DVLOG(2) << "CloseConnection " << presentation_id; 339 DVLOG(2) << "CloseConnection " << presentation_id;
411 if (controller_delegate_) 340 if (controller_delegate_)
412 controller_delegate_->CloseConnection(render_process_id_, render_frame_id_, 341 controller_delegate_->CloseConnection(render_process_id_, render_frame_id_,
413 presentation_id); 342 presentation_id);
414 } 343 }
415 344
416 void PresentationServiceImpl::Terminate(const GURL& presentation_url, 345 void PresentationServiceImpl::Terminate(const GURL& presentation_url,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 delegate->Reset(render_process_id_, render_frame_id_); 487 delegate->Reset(render_process_id_, render_frame_id_);
559 488
560 default_presentation_urls_.clear(); 489 default_presentation_urls_.clear();
561 490
562 screen_availability_listeners_.clear(); 491 screen_availability_listeners_.clear();
563 492
564 start_session_request_id_ = kInvalidRequestSessionId; 493 start_session_request_id_ = kInvalidRequestSessionId;
565 pending_start_session_cb_.reset(); 494 pending_start_session_cb_.reset();
566 495
567 pending_join_session_cbs_.clear(); 496 pending_join_session_cbs_.clear();
568
569 if (on_connection_messages_callback_.get()) {
570 on_connection_messages_callback_->Run(
571 std::vector<blink::mojom::ConnectionMessagePtr>());
572 on_connection_messages_callback_.reset();
573 }
574
575 if (send_message_callback_) {
576 // Run the callback with false, indicating the renderer to stop sending
577 // the requests and invalidate all pending requests.
578 send_message_callback_->Run(false);
579 send_message_callback_.reset();
580 }
581 } 497 }
582 498
583 void PresentationServiceImpl::OnDelegateDestroyed() { 499 void PresentationServiceImpl::OnDelegateDestroyed() {
584 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 500 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
585 controller_delegate_ = nullptr; 501 controller_delegate_ = nullptr;
586 receiver_delegate_ = nullptr; 502 receiver_delegate_ = nullptr;
587 Reset(); 503 Reset();
588 } 504 }
589 505
590 void PresentationServiceImpl::OnDefaultPresentationStarted( 506 void PresentationServiceImpl::OnDefaultPresentationStarted(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 550
635 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 551 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
636 const base::Optional<PresentationSessionInfo>& session_info, 552 const base::Optional<PresentationSessionInfo>& session_info,
637 const base::Optional<PresentationError>& error) { 553 const base::Optional<PresentationError>& error) {
638 DCHECK(!callback_.is_null()); 554 DCHECK(!callback_.is_null());
639 callback_.Run(session_info, error); 555 callback_.Run(session_info, error);
640 callback_.Reset(); 556 callback_.Reset();
641 } 557 }
642 558
643 } // namespace content 559 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698