OLD | NEW |
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> | 10 #include <string> |
(...skipping 29 matching lines...) Expand all Loading... |
40 // |pass_ownership|: If true, function may reuse strings or buffers from | 40 // |pass_ownership|: If true, function may reuse strings or buffers from |
41 // |input| without copying. |input| can be freely modified. | 41 // |input| without copying. |input| can be freely modified. |
42 presentation::SessionMessagePtr ToMojoSessionMessage( | 42 presentation::SessionMessagePtr ToMojoSessionMessage( |
43 content::PresentationSessionMessage* input, | 43 content::PresentationSessionMessage* input, |
44 bool pass_ownership) { | 44 bool pass_ownership) { |
45 DCHECK(input); | 45 DCHECK(input); |
46 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); | 46 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); |
47 if (input->is_binary()) { | 47 if (input->is_binary()) { |
48 // binary data | 48 // binary data |
49 DCHECK(input->data); | 49 DCHECK(input->data); |
50 output->type = presentation::PresentationMessageType:: | 50 output->type = presentation::PresentationMessageType::ARRAY_BUFFER; |
51 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | |
52 if (pass_ownership) { | 51 if (pass_ownership) { |
53 output->data.Swap(input->data.get()); | 52 output->data.Swap(input->data.get()); |
54 } else { | 53 } else { |
55 output->data = mojo::Array<uint8_t>::From(*input->data); | 54 output->data = mojo::Array<uint8_t>::From(*input->data); |
56 } | 55 } |
57 } else { | 56 } else { |
58 // string message | 57 // string message |
59 output->type = | 58 output->type = presentation::PresentationMessageType::TEXT; |
60 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; | |
61 if (pass_ownership) { | 59 if (pass_ownership) { |
62 output->message.Swap(&input->message); | 60 output->message.Swap(&input->message); |
63 } else { | 61 } else { |
64 output->message = input->message; | 62 output->message = input->message; |
65 } | 63 } |
66 } | 64 } |
67 return output; | 65 return output; |
68 } | 66 } |
69 | 67 |
70 scoped_ptr<PresentationSessionMessage> GetPresentationSessionMessage( | 68 scoped_ptr<PresentationSessionMessage> GetPresentationSessionMessage( |
71 presentation::SessionMessagePtr input) { | 69 presentation::SessionMessagePtr input) { |
72 DCHECK(!input.is_null()); | 70 DCHECK(!input.is_null()); |
73 scoped_ptr<content::PresentationSessionMessage> output; | 71 scoped_ptr<content::PresentationSessionMessage> output; |
74 switch (input->type) { | 72 switch (input->type) { |
75 case presentation::PRESENTATION_MESSAGE_TYPE_TEXT: { | 73 case presentation::PresentationMessageType::TEXT: { |
76 DCHECK(!input->message.is_null()); | 74 DCHECK(!input->message.is_null()); |
77 DCHECK(input->data.is_null()); | 75 DCHECK(input->data.is_null()); |
78 // Return null PresentationSessionMessage if size exceeds. | 76 // Return null PresentationSessionMessage if size exceeds. |
79 if (input->message.size() > content::kMaxPresentationSessionMessageSize) | 77 if (input->message.size() > content::kMaxPresentationSessionMessageSize) |
80 return output; | 78 return output; |
81 | 79 |
82 output.reset( | 80 output.reset( |
83 new PresentationSessionMessage(PresentationMessageType::TEXT)); | 81 new PresentationSessionMessage(PresentationMessageType::TEXT)); |
84 input->message.Swap(&output->message); | 82 input->message.Swap(&output->message); |
85 return output; | 83 return output; |
86 } | 84 } |
87 case presentation::PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: { | 85 case presentation::PresentationMessageType::ARRAY_BUFFER: { |
88 DCHECK(!input->data.is_null()); | 86 DCHECK(!input->data.is_null()); |
89 DCHECK(input->message.is_null()); | 87 DCHECK(input->message.is_null()); |
90 if (input->data.size() > content::kMaxPresentationSessionMessageSize) | 88 if (input->data.size() > content::kMaxPresentationSessionMessageSize) |
91 return output; | 89 return output; |
92 | 90 |
93 output.reset(new PresentationSessionMessage( | 91 output.reset(new PresentationSessionMessage( |
94 PresentationMessageType::ARRAY_BUFFER)); | 92 PresentationMessageType::ARRAY_BUFFER)); |
95 output->data.reset(new std::vector<uint8_t>); | 93 output->data.reset(new std::vector<uint8_t>); |
96 input->data.Swap(output->data.get()); | 94 input->data.Swap(output->data.get()); |
97 return output; | 95 return output; |
98 } | 96 } |
99 case presentation::PRESENTATION_MESSAGE_TYPE_BLOB: { | 97 case presentation::PresentationMessageType::BLOB: { |
100 DCHECK(!input->data.is_null()); | 98 DCHECK(!input->data.is_null()); |
101 DCHECK(input->message.is_null()); | 99 DCHECK(input->message.is_null()); |
102 if (input->data.size() > content::kMaxPresentationSessionMessageSize) | 100 if (input->data.size() > content::kMaxPresentationSessionMessageSize) |
103 return output; | 101 return output; |
104 | 102 |
105 output.reset( | 103 output.reset( |
106 new PresentationSessionMessage(PresentationMessageType::BLOB)); | 104 new PresentationSessionMessage(PresentationMessageType::BLOB)); |
107 output->data.reset(new std::vector<uint8_t>); | 105 output->data.reset(new std::vector<uint8_t>); |
108 input->data.Swap(output->data.get()); | 106 input->data.Swap(output->data.get()); |
109 return output; | 107 return output; |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 596 |
599 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( | 597 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( |
600 presentation::PresentationSessionInfoPtr session, | 598 presentation::PresentationSessionInfoPtr session, |
601 presentation::PresentationErrorPtr error) { | 599 presentation::PresentationErrorPtr error) { |
602 DCHECK(!callback_.is_null()); | 600 DCHECK(!callback_.is_null()); |
603 callback_.Run(std::move(session), std::move(error)); | 601 callback_.Run(std::move(session), std::move(error)); |
604 callback_.reset(); | 602 callback_.reset(); |
605 } | 603 } |
606 | 604 |
607 } // namespace content | 605 } // namespace content |
OLD | NEW |