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

Side by Side Diff: extensions/browser/api/sockets_tcp/sockets_tcp_api.cc

Issue 1226353004: Generate all extension schema namespaces as "api" and instead vary the generated bundle names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" 5 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h"
6 6
7 #include "content/public/browser/browser_context.h" 7 #include "content/public/browser/browser_context.h"
8 #include "content/public/common/socket_permission_request.h" 8 #include "content/public/common/socket_permission_request.h"
9 #include "extensions/browser/api/socket/tcp_socket.h" 9 #include "extensions/browser/api/socket/tcp_socket.h"
10 #include "extensions/browser/api/socket/tls_socket.h" 10 #include "extensions/browser/api/socket/tls_socket.h"
11 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h" 11 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h"
12 #include "extensions/common/api/sockets/sockets_manifest_data.h" 12 #include "extensions/common/api/sockets/sockets_manifest_data.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/url_request/url_request_context.h" 14 #include "net/url_request/url_request_context.h"
15 #include "net/url_request/url_request_context_getter.h" 15 #include "net/url_request/url_request_context_getter.h"
16 16
17 using extensions::ResumableTCPSocket; 17 using extensions::ResumableTCPSocket;
18 using extensions::core_api::sockets_tcp::SocketInfo; 18 using extensions::api::sockets_tcp::SocketInfo;
19 using extensions::core_api::sockets_tcp::SocketProperties; 19 using extensions::api::sockets_tcp::SocketProperties;
20 20
21 namespace { 21 namespace {
22 22
23 const char kSocketNotFoundError[] = "Socket not found"; 23 const char kSocketNotFoundError[] = "Socket not found";
24 const char kPermissionError[] = "Does not have permission"; 24 const char kPermissionError[] = "Does not have permission";
25 const char kInvalidSocketStateError[] = 25 const char kInvalidSocketStateError[] =
26 "Socket must be a connected client TCP socket."; 26 "Socket must be a connected client TCP socket.";
27 const char kSocketNotConnectedError[] = "Socket not connected"; 27 const char kSocketNotConnectedError[] = "Socket not connected";
28 28
29 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, 29 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (properties->buffer_size.get()) { 75 if (properties->buffer_size.get()) {
76 // buffer size is validated when issuing the actual Recv operation 76 // buffer size is validated when issuing the actual Recv operation
77 // on the socket. 77 // on the socket.
78 socket->set_buffer_size(*properties->buffer_size.get()); 78 socket->set_buffer_size(*properties->buffer_size.get());
79 } 79 }
80 } 80 }
81 81
82 } // namespace 82 } // namespace
83 83
84 namespace extensions { 84 namespace extensions {
85 namespace core_api { 85 namespace api {
86 86
87 using content::SocketPermissionRequest; 87 using content::SocketPermissionRequest;
88 88
89 TCPSocketAsyncApiFunction::~TCPSocketAsyncApiFunction() {} 89 TCPSocketAsyncApiFunction::~TCPSocketAsyncApiFunction() {}
90 90
91 scoped_ptr<SocketResourceManagerInterface> 91 scoped_ptr<SocketResourceManagerInterface>
92 TCPSocketAsyncApiFunction::CreateSocketResourceManager() { 92 TCPSocketAsyncApiFunction::CreateSocketResourceManager() {
93 return scoped_ptr<SocketResourceManagerInterface>( 93 return scoped_ptr<SocketResourceManagerInterface>(
94 new SocketResourceManager<ResumableTCPSocket>()).Pass(); 94 new SocketResourceManager<ResumableTCPSocket>()).Pass();
95 } 95 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 SetSocketProperties(socket, &params_.get()->properties); 155 SetSocketProperties(socket, &params_.get()->properties);
156 results_ = sockets_tcp::Update::Results::Create(); 156 results_ = sockets_tcp::Update::Results::Create();
157 } 157 }
158 158
159 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() 159 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction()
160 : socket_event_dispatcher_(NULL) {} 160 : socket_event_dispatcher_(NULL) {}
161 161
162 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} 162 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {}
163 163
164 bool SocketsTcpSetPausedFunction::Prepare() { 164 bool SocketsTcpSetPausedFunction::Prepare() {
165 params_ = core_api::sockets_tcp::SetPaused::Params::Create(*args_); 165 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_);
166 EXTENSION_FUNCTION_VALIDATE(params_.get()); 166 EXTENSION_FUNCTION_VALIDATE(params_.get());
167 167
168 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); 168 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context());
169 DCHECK(socket_event_dispatcher_) 169 DCHECK(socket_event_dispatcher_)
170 << "There is no socket event dispatcher. " 170 << "There is no socket event dispatcher. "
171 "If this assertion is failing during a test, then it is likely that " 171 "If this assertion is failing during a test, then it is likely that "
172 "TestExtensionSystem is failing to provide an instance of " 172 "TestExtensionSystem is failing to provide an instance of "
173 "TCPSocketEventDispatcher."; 173 "TCPSocketEventDispatcher.";
174 return socket_event_dispatcher_ != NULL; 174 return socket_event_dispatcher_ != NULL;
175 } 175 }
(...skipping 14 matching lines...) Expand all
190 } 190 }
191 191
192 results_ = sockets_tcp::SetPaused::Results::Create(); 192 results_ = sockets_tcp::SetPaused::Results::Create();
193 } 193 }
194 194
195 SocketsTcpSetKeepAliveFunction::SocketsTcpSetKeepAliveFunction() {} 195 SocketsTcpSetKeepAliveFunction::SocketsTcpSetKeepAliveFunction() {}
196 196
197 SocketsTcpSetKeepAliveFunction::~SocketsTcpSetKeepAliveFunction() {} 197 SocketsTcpSetKeepAliveFunction::~SocketsTcpSetKeepAliveFunction() {}
198 198
199 bool SocketsTcpSetKeepAliveFunction::Prepare() { 199 bool SocketsTcpSetKeepAliveFunction::Prepare() {
200 params_ = core_api::sockets_tcp::SetKeepAlive::Params::Create(*args_); 200 params_ = api::sockets_tcp::SetKeepAlive::Params::Create(*args_);
201 EXTENSION_FUNCTION_VALIDATE(params_.get()); 201 EXTENSION_FUNCTION_VALIDATE(params_.get());
202 return true; 202 return true;
203 } 203 }
204 204
205 void SocketsTcpSetKeepAliveFunction::Work() { 205 void SocketsTcpSetKeepAliveFunction::Work() {
206 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); 206 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id);
207 if (!socket) { 207 if (!socket) {
208 error_ = kSocketNotFoundError; 208 error_ = kSocketNotFoundError;
209 return; 209 return;
210 } 210 }
211 211
212 int delay = params_->delay ? *params_->delay.get() : 0; 212 int delay = params_->delay ? *params_->delay.get() : 0;
213 213
214 bool success = socket->SetKeepAlive(params_->enable, delay); 214 bool success = socket->SetKeepAlive(params_->enable, delay);
215 int net_result = (success ? net::OK : net::ERR_FAILED); 215 int net_result = (success ? net::OK : net::ERR_FAILED);
216 if (net_result != net::OK) 216 if (net_result != net::OK)
217 error_ = net::ErrorToString(net_result); 217 error_ = net::ErrorToString(net_result);
218 results_ = sockets_tcp::SetKeepAlive::Results::Create(net_result); 218 results_ = sockets_tcp::SetKeepAlive::Results::Create(net_result);
219 } 219 }
220 220
221 SocketsTcpSetNoDelayFunction::SocketsTcpSetNoDelayFunction() {} 221 SocketsTcpSetNoDelayFunction::SocketsTcpSetNoDelayFunction() {}
222 222
223 SocketsTcpSetNoDelayFunction::~SocketsTcpSetNoDelayFunction() {} 223 SocketsTcpSetNoDelayFunction::~SocketsTcpSetNoDelayFunction() {}
224 224
225 bool SocketsTcpSetNoDelayFunction::Prepare() { 225 bool SocketsTcpSetNoDelayFunction::Prepare() {
226 params_ = core_api::sockets_tcp::SetNoDelay::Params::Create(*args_); 226 params_ = api::sockets_tcp::SetNoDelay::Params::Create(*args_);
227 EXTENSION_FUNCTION_VALIDATE(params_.get()); 227 EXTENSION_FUNCTION_VALIDATE(params_.get());
228 return true; 228 return true;
229 } 229 }
230 230
231 void SocketsTcpSetNoDelayFunction::Work() { 231 void SocketsTcpSetNoDelayFunction::Work() {
232 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); 232 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id);
233 if (!socket) { 233 if (!socket) {
234 error_ = kSocketNotFoundError; 234 error_ = kSocketNotFoundError;
235 return; 235 return;
236 } 236 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 450 }
451 451
452 SocketsTcpSecureFunction::SocketsTcpSecureFunction() { 452 SocketsTcpSecureFunction::SocketsTcpSecureFunction() {
453 } 453 }
454 454
455 SocketsTcpSecureFunction::~SocketsTcpSecureFunction() { 455 SocketsTcpSecureFunction::~SocketsTcpSecureFunction() {
456 } 456 }
457 457
458 bool SocketsTcpSecureFunction::Prepare() { 458 bool SocketsTcpSecureFunction::Prepare() {
459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
460 params_ = core_api::sockets_tcp::Secure::Params::Create(*args_); 460 params_ = api::sockets_tcp::Secure::Params::Create(*args_);
461 EXTENSION_FUNCTION_VALIDATE(params_.get()); 461 EXTENSION_FUNCTION_VALIDATE(params_.get());
462 url_request_getter_ = browser_context()->GetRequestContext(); 462 url_request_getter_ = browser_context()->GetRequestContext();
463 return true; 463 return true;
464 } 464 }
465 465
466 // Override the regular implementation, which would call AsyncWorkCompleted 466 // Override the regular implementation, which would call AsyncWorkCompleted
467 // immediately after Work(). 467 // immediately after Work().
468 void SocketsTcpSecureFunction::AsyncWorkStart() { 468 void SocketsTcpSecureFunction::AsyncWorkStart() {
469 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 469 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
470 470
(...skipping 23 matching lines...) Expand all
494 error_ = kSocketNotConnectedError; 494 error_ = kSocketNotConnectedError;
495 AsyncWorkCompleted(); 495 AsyncWorkCompleted();
496 return; 496 return;
497 } 497 }
498 498
499 net::URLRequestContext* url_request_context = 499 net::URLRequestContext* url_request_context =
500 url_request_getter_->GetURLRequestContext(); 500 url_request_getter_->GetURLRequestContext();
501 501
502 // UpgradeSocketToTLS() uses the older API's SecureOptions. Copy over the 502 // UpgradeSocketToTLS() uses the older API's SecureOptions. Copy over the
503 // only values inside -- TLSVersionConstraints's |min| and |max|, 503 // only values inside -- TLSVersionConstraints's |min| and |max|,
504 core_api::socket::SecureOptions legacy_params; 504 api::socket::SecureOptions legacy_params;
505 if (params_->options.get() && params_->options->tls_version.get()) { 505 if (params_->options.get() && params_->options->tls_version.get()) {
506 legacy_params.tls_version.reset( 506 legacy_params.tls_version.reset(new api::socket::TLSVersionConstraints);
507 new core_api::socket::TLSVersionConstraints);
508 if (params_->options->tls_version->min.get()) { 507 if (params_->options->tls_version->min.get()) {
509 legacy_params.tls_version->min.reset( 508 legacy_params.tls_version->min.reset(
510 new std::string(*params_->options->tls_version->min.get())); 509 new std::string(*params_->options->tls_version->min.get()));
511 } 510 }
512 if (params_->options->tls_version->max.get()) { 511 if (params_->options->tls_version->max.get()) {
513 legacy_params.tls_version->max.reset( 512 legacy_params.tls_version->max.reset(
514 new std::string(*params_->options->tls_version->max.get())); 513 new std::string(*params_->options->tls_version->max.get()));
515 } 514 }
516 } 515 }
517 516
(...skipping 14 matching lines...) Expand all
532 531
533 if (socket && result == net::OK) { 532 if (socket && result == net::OK) {
534 socket->set_persistent(persistent_); 533 socket->set_persistent(persistent_);
535 socket->set_paused(paused_); 534 socket->set_paused(paused_);
536 ReplaceSocket(params_->socket_id, socket.release()); 535 ReplaceSocket(params_->socket_id, socket.release());
537 } else { 536 } else {
538 RemoveSocket(params_->socket_id); 537 RemoveSocket(params_->socket_id);
539 error_ = net::ErrorToString(result); 538 error_ = net::ErrorToString(result);
540 } 539 }
541 540
542 results_ = core_api::sockets_tcp::Secure::Results::Create(result); 541 results_ = api::sockets_tcp::Secure::Results::Create(result);
543 AsyncWorkCompleted(); 542 AsyncWorkCompleted();
544 } 543 }
545 544
546 } // namespace api 545 } // namespace api
547 } // namespace extensions 546 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/sockets_tcp/sockets_tcp_api.h ('k') | extensions/browser/api/sockets_tcp/sockets_tcp_api_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698