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

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

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Fix compile error after rebase 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>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "content/public/browser/content_browser_client.h" 14 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/navigation_handle.h" 15 #include "content/public/browser/navigation_handle.h"
16 #include "content/public/browser/render_frame_host.h" 16 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
20 #include "content/public/common/frame_navigate_params.h" 20 #include "content/public/common/frame_navigate_params.h"
21 #include "content/public/common/presentation_connection_message.h" 21 #include "content/public/common/presentation_connection_message.h"
22 #include "content/public/common/presentation_constants.h"
23 22
24 namespace content { 23 namespace content {
25 24
26 namespace { 25 namespace {
27 26
28 const int kInvalidRequestSessionId = -1; 27 const int kInvalidRequestSessionId = -1;
29 28
30 int GetNextRequestSessionId() { 29 int GetNextRequestSessionId() {
31 static int next_request_session_id = 0; 30 static int next_request_session_id = 0;
32 return ++next_request_session_id; 31 return ++next_request_session_id;
33 } 32 }
34 33
35 // Converts a PresentationConnectionMessage |input| to a ConnectionMessage.
36 // |input|: The message to convert.
37 // |pass_ownership|: If true, function may reuse strings or buffers from
38 // |input| without copying. |input| can be freely modified.
39 blink::mojom::ConnectionMessagePtr ToMojoConnectionMessage(
40 content::PresentationConnectionMessage* input,
41 bool pass_ownership) {
42 DCHECK(input);
43 blink::mojom::ConnectionMessagePtr output(
44 blink::mojom::ConnectionMessage::New());
45 if (input->is_binary()) {
46 // binary data
47 DCHECK(input->data);
48 output->type = blink::mojom::PresentationMessageType::BINARY;
49 if (pass_ownership) {
50 output->data = std::move(*(input->data));
51 } else {
52 output->data = *(input->data);
53 }
54 } else {
55 // string message
56 output->type = blink::mojom::PresentationMessageType::TEXT;
57 if (pass_ownership) {
58 output->message = std::move(input->message);
59 } else {
60 output->message = input->message;
61 }
62 }
63 return output;
64 }
65
66 void InvokeNewSessionCallbackWithError( 34 void InvokeNewSessionCallbackWithError(
67 const PresentationServiceImpl::NewSessionCallback& callback) { 35 const PresentationServiceImpl::NewSessionCallback& callback) {
68 callback.Run(base::nullopt, 36 callback.Run(base::nullopt,
69 PresentationError( 37 PresentationError(
70 PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS, 38 PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS,
71 "There is already an unsettled Promise from a previous call " 39 "There is already an unsettled Promise from a previous call "
72 "to start.")); 40 "to start."));
73 } 41 }
74 42
75 } // namespace 43 } // namespace
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 return; 370 return;
403 371
404 controller_delegate_->ConnectToPresentation( 372 controller_delegate_->ConnectToPresentation(
405 render_process_id_, render_frame_id_, session_info, 373 render_process_id_, render_frame_id_, session_info,
406 std::move(controller_connection_ptr), 374 std::move(controller_connection_ptr),
407 std::move(receiver_connection_request)); 375 std::move(receiver_connection_request));
408 } 376 }
409 377
410 void PresentationServiceImpl::OnConnectionMessages( 378 void PresentationServiceImpl::OnConnectionMessages(
411 const PresentationSessionInfo& session_info, 379 const PresentationSessionInfo& session_info,
412 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages, 380 std::vector<PresentationConnectionMessage> messages) {
413 bool pass_ownership) {
414 DCHECK(client_); 381 DCHECK(client_);
415 382
416 DVLOG(2) << "OnConnectionMessages [id]: " << session_info.presentation_id; 383 DVLOG(2) << "OnConnectionMessages [id]: " << session_info.presentation_id;
417 std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages( 384 client_->OnConnectionMessagesReceived(session_info, std::move(messages));
418 messages.size());
419 std::transform(
420 messages.begin(), messages.end(), mojo_messages.begin(),
421 [pass_ownership](
422 const std::unique_ptr<PresentationConnectionMessage>& message) {
423 return ToMojoConnectionMessage(message.get(), pass_ownership);
424 });
425
426 client_->OnConnectionMessagesReceived(session_info, std::move(mojo_messages));
427 } 385 }
428 386
429 void PresentationServiceImpl::OnReceiverConnectionAvailable( 387 void PresentationServiceImpl::OnReceiverConnectionAvailable(
430 const content::PresentationSessionInfo& session_info, 388 const content::PresentationSessionInfo& session_info,
431 PresentationConnectionPtr controller_connection_ptr, 389 PresentationConnectionPtr controller_connection_ptr,
432 PresentationConnectionRequest receiver_connection_request) { 390 PresentationConnectionRequest receiver_connection_request) {
433 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; 391 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
434 392
435 client_->OnReceiverConnectionAvailable( 393 client_->OnReceiverConnectionAvailable(
436 session_info, std::move(controller_connection_ptr), 394 session_info, std::move(controller_connection_ptr),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 508
551 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 509 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
552 const base::Optional<PresentationSessionInfo>& session_info, 510 const base::Optional<PresentationSessionInfo>& session_info,
553 const base::Optional<PresentationError>& error) { 511 const base::Optional<PresentationError>& error) {
554 DCHECK(!callback_.is_null()); 512 DCHECK(!callback_.is_null());
555 callback_.Run(session_info, error); 513 callback_.Run(session_info, error);
556 callback_.Reset(); 514 callback_.Reset();
557 } 515 }
558 516
559 } // namespace content 517 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698