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

Side by Side Diff: webkit/plugins/ppapi/ppb_transport_impl.cc

Issue 7713021: Add SetProperty() in the PPB_Transport_Dev interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppb_transport_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_transport_impl.h" 5 #include "webkit/plugins/ppapi/ppb_transport_impl.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 12 matching lines...) Expand all
23 using webkit_glue::P2PTransport; 23 using webkit_glue::P2PTransport;
24 24
25 namespace webkit { 25 namespace webkit {
26 namespace ppapi { 26 namespace ppapi {
27 27
28 namespace { 28 namespace {
29 29
30 const char kUdpProtocolName[] = "udp"; 30 const char kUdpProtocolName[] = "udp";
31 const char kTcpProtocolName[] = "tcp"; 31 const char kTcpProtocolName[] = "tcp";
32 32
33 const int kMinBufferSize = 1024;
34 const int kMaxBufferSize = 1024 * 1024;
35
33 int MapNetError(int result) { 36 int MapNetError(int result) {
34 if (result > 0) 37 if (result > 0)
35 return result; 38 return result;
36 39
37 switch (result) { 40 switch (result) {
38 case net::OK: 41 case net::OK:
39 return PP_OK; 42 return PP_OK;
40 case net::ERR_IO_PENDING: 43 case net::ERR_IO_PENDING:
41 return PP_OK_COMPLETIONPENDING; 44 return PP_OK_COMPLETIONPENDING;
42 case net::ERR_INVALID_ARGUMENT: 45 case net::ERR_INVALID_ARGUMENT:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return p2p_transport_.get() != NULL; 97 return p2p_transport_.get() != NULL;
95 } 98 }
96 99
97 PP_Bool PPB_Transport_Impl::IsWritable() { 100 PP_Bool PPB_Transport_Impl::IsWritable() {
98 if (!p2p_transport_.get()) 101 if (!p2p_transport_.get())
99 return PP_FALSE; 102 return PP_FALSE;
100 103
101 return PP_FromBool(writable_); 104 return PP_FromBool(writable_);
102 } 105 }
103 106
107 int32_t PPB_Transport_Impl::SetProperty(PP_TransportProperty property,
108 PP_Var value) {
109 // SetProperty() may be called only before Connect().
110 if (started_)
111 return PP_ERROR_FAILED;
112
113 switch (property) {
114 case PP_TRANSPORTPROPERTY_STUN_SERVER: {
115 StringVar* value_str = StringVar::FromPPVar(value);
116 if (!value_str)
117 return PP_ERROR_BADARGUMENT;
118 config_.stun_server = value_str->value();
119 break;
120 }
121
122 case PP_TRANSPORTPROPERTY_RELAY_SERVER: {
123 StringVar* value_str = StringVar::FromPPVar(value);
124 if (!value_str)
125 return PP_ERROR_BADARGUMENT;
126 config_.relay_server = value_str->value();
127 break;
128 }
129
130 case PP_TRANSPORTPROPERTY_RELAY_TOKEN: {
131 StringVar* value_str = StringVar::FromPPVar(value);
132 if (!value_str)
133 return PP_ERROR_BADARGUMENT;
134 config_.relay_token = value_str->value();
135 break;
136 }
137
138 case PP_TRANSPORTPROPERTY_TCP_RECEIVE_WINDOW: {
139 if (!use_tcp_)
140 return PP_ERROR_BADARGUMENT;
141
142 int32_t int_value = value.value.as_int;
143 if (value.type != PP_VARTYPE_INT32 || int_value < kMinBufferSize ||
144 int_value > kMaxBufferSize) {
145 return PP_ERROR_BADARGUMENT;
146 }
147 config_.tcp_receive_window = int_value;
148 break;
149 }
150
151 case PP_TRANSPORTPROPERTY_TCP_SEND_WINDOW: {
152 if (!use_tcp_)
153 return PP_ERROR_BADARGUMENT;
154
155 int32_t int_value = value.value.as_int;
156 if (value.type != PP_VARTYPE_INT32 || int_value < kMinBufferSize ||
157 int_value > kMaxBufferSize) {
158 return PP_ERROR_BADARGUMENT;
159 }
160 config_.tcp_send_window = int_value;
161 break;
162 }
163
164 default:
165 return PP_ERROR_BADARGUMENT;
166 }
167
168 return PP_OK;
169 }
170
104 int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { 171 int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) {
105 if (!p2p_transport_.get()) 172 if (!p2p_transport_.get())
106 return PP_ERROR_FAILED; 173 return PP_ERROR_FAILED;
107 174
108 // Connect() has already been called. 175 // Connect() has already been called.
109 if (started_) 176 if (started_)
110 return PP_ERROR_INPROGRESS; 177 return PP_ERROR_INPROGRESS;
111 178
112 P2PTransport::Protocol protocol = use_tcp_ ? 179 P2PTransport::Protocol protocol = use_tcp_ ?
113 P2PTransport::PROTOCOL_TCP : P2PTransport::PROTOCOL_UDP; 180 P2PTransport::PROTOCOL_TCP : P2PTransport::PROTOCOL_UDP;
114 181
115 if (!p2p_transport_->Init(name_, protocol, "", this)) 182 if (!p2p_transport_->Init(name_, protocol, config_, this))
116 return PP_ERROR_FAILED; 183 return PP_ERROR_FAILED;
117 184
118 started_ = true; 185 started_ = true;
119 186
120 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); 187 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
121 if (!plugin_module) 188 if (!plugin_module)
122 return PP_ERROR_FAILED; 189 return PP_ERROR_FAILED;
123 190
124 connect_callback_ = new TrackedCompletionCallback( 191 connect_callback_ = new TrackedCompletionCallback(
125 plugin_module->GetCallbackTracker(), pp_resource(), callback); 192 plugin_module->GetCallbackTracker(), pp_resource(), callback);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 void PPB_Transport_Impl::OnWritten(int result) { 337 void PPB_Transport_Impl::OnWritten(int result) {
271 DCHECK(send_callback_.get() && !send_callback_->completed()); 338 DCHECK(send_callback_.get() && !send_callback_->completed());
272 339
273 scoped_refptr<TrackedCompletionCallback> callback; 340 scoped_refptr<TrackedCompletionCallback> callback;
274 callback.swap(send_callback_); 341 callback.swap(send_callback_);
275 callback->Run(MapNetError(result)); 342 callback->Run(MapNetError(result));
276 } 343 }
277 344
278 } // namespace ppapi 345 } // namespace ppapi
279 } // namespace webkit 346 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_transport_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698