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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/browser/presentation/presentation_type_converters.h" | 10 #include "content/browser/presentation/presentation_type_converters.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; | 46 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; |
47 output->message.Swap(input->message.get()); | 47 output->message.Swap(input->message.get()); |
48 } | 48 } |
49 return output.Pass(); | 49 return output.Pass(); |
50 } | 50 } |
51 | 51 |
52 scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage( | 52 scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage( |
53 presentation::SessionMessagePtr input) { | 53 presentation::SessionMessagePtr input) { |
54 DCHECK(!input.is_null()); | 54 DCHECK(!input.is_null()); |
55 scoped_ptr<content::PresentationSessionMessage> output; | 55 scoped_ptr<content::PresentationSessionMessage> output; |
56 if (input->type == presentation::PresentationMessageType:: | 56 switch (input->type) { |
57 PRESENTATION_MESSAGE_TYPE_TEXT) { | 57 case presentation::PresentationMessageType:: |
mark a. foltz
2015/06/05 22:40:55
Consider a using presentation::PresentationMessage
USE s.singapati at gmail.com
2015/06/08 13:04:19
Done.
| |
58 DCHECK(!input->message.is_null()); | 58 PRESENTATION_MESSAGE_TYPE_TEXT: { |
59 DCHECK(input->data.is_null()); | 59 DCHECK(!input->message.is_null()); |
60 // Return null PresentationSessionMessage if size exceeds. | 60 DCHECK(input->data.is_null()); |
61 if (input->message.size() > content::kMaxPresentationSessionMessageSize) | 61 // Return null PresentationSessionMessage if size exceeds. |
62 if (input->message.size() > content::kMaxPresentationSessionMessageSize) | |
63 return output.Pass(); | |
64 | |
65 output = content::PresentationSessionMessage::CreateStringMessage( | |
66 input->presentation_url, input->presentation_id, | |
67 make_scoped_ptr(new std::string)); | |
68 input->message.Swap(output->message.get()); | |
62 return output.Pass(); | 69 return output.Pass(); |
70 } | |
71 case presentation::PresentationMessageType:: | |
72 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: { | |
73 DCHECK(!input->data.is_null()); | |
74 DCHECK(input->message.is_null()); | |
75 if (input->data.size() > content::kMaxPresentationSessionMessageSize) | |
76 return output.Pass(); | |
63 | 77 |
64 output = content::PresentationSessionMessage::CreateStringMessage( | 78 output = content::PresentationSessionMessage::CreateArrayBufferMessage( |
65 input->presentation_url, | 79 input->presentation_url, input->presentation_id, |
66 input->presentation_id, | 80 make_scoped_ptr(new std::vector<uint8_t>)); |
67 make_scoped_ptr(new std::string)); | 81 input->data.Swap(output->data.get()); |
68 input->message.Swap(output->message.get()); | 82 return output.Pass(); |
83 } | |
84 case presentation::PresentationMessageType:: | |
85 PRESENTATION_MESSAGE_TYPE_BLOB: { | |
86 DCHECK(!input->data.is_null()); | |
87 DCHECK(input->message.is_null()); | |
88 if (input->data.size() > content::kMaxPresentationSessionMessageSize) | |
89 return output.Pass(); | |
69 | 90 |
70 } else if (input->type == presentation::PresentationMessageType:: | 91 output = content::PresentationSessionMessage::CreateBlobMessage( |
71 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER) { | 92 input->presentation_url, input->presentation_id, |
72 DCHECK(!input->data.is_null()); | 93 make_scoped_ptr(new std::vector<uint8_t>)); |
73 DCHECK(input->message.is_null()); | 94 input->data.Swap(output->data.get()); |
74 // Return null PresentationSessionMessage if size exceeds. | |
75 if (input->data.size() > content::kMaxPresentationSessionMessageSize) | |
76 return output.Pass(); | 95 return output.Pass(); |
77 | 96 } |
78 output = content::PresentationSessionMessage::CreateBinaryMessage( | |
79 input->presentation_url, | |
80 input->presentation_id, | |
81 make_scoped_ptr(new std::vector<uint8_t>)); | |
82 input->data.Swap(output->data.get()); | |
83 } | 97 } |
84 | 98 |
99 NOTREACHED() << "Invalid presentation message type " << input->type; | |
85 return output.Pass(); | 100 return output.Pass(); |
86 } | 101 } |
87 | 102 |
88 void InvokeNewSessionMojoCallbackWithError( | 103 void InvokeNewSessionMojoCallbackWithError( |
89 const NewSessionMojoCallback& callback) { | 104 const NewSessionMojoCallback& callback) { |
90 callback.Run( | 105 callback.Run( |
91 presentation::PresentationSessionInfoPtr(), | 106 presentation::PresentationSessionInfoPtr(), |
92 presentation::PresentationError::From( | 107 presentation::PresentationError::From( |
93 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); | 108 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); |
94 } | 109 } |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 680 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
666 ScopedVector<DefaultSessionMojoCallback> callbacks; | 681 ScopedVector<DefaultSessionMojoCallback> callbacks; |
667 callbacks.swap(callbacks_); | 682 callbacks.swap(callbacks_); |
668 for (const auto& callback : callbacks) | 683 for (const auto& callback : callbacks) |
669 callback->Run(presentation::PresentationSessionInfoPtr()); | 684 callback->Run(presentation::PresentationSessionInfoPtr()); |
670 session_.reset(); | 685 session_.reset(); |
671 } | 686 } |
672 | 687 |
673 } // namespace content | 688 } // namespace content |
674 | 689 |
OLD | NEW |