OLD | NEW |
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_udp/sockets_udp_api.h" | 5 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h" |
6 | 6 |
7 #include "content/public/common/socket_permission_request.h" | 7 #include "content/public/common/socket_permission_request.h" |
8 #include "extensions/browser/api/socket/udp_socket.h" | 8 #include "extensions/browser/api/socket/udp_socket.h" |
9 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h" | 9 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h" |
10 #include "extensions/common/api/sockets/sockets_manifest_data.h" | 10 #include "extensions/common/api/sockets/sockets_manifest_data.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 namespace core_api { | 14 namespace api { |
15 | 15 |
16 using content::SocketPermissionRequest; | 16 using content::SocketPermissionRequest; |
17 | 17 |
18 const char kSocketNotFoundError[] = "Socket not found"; | 18 const char kSocketNotFoundError[] = "Socket not found"; |
19 const char kPermissionError[] = "App does not have permission"; | 19 const char kPermissionError[] = "App does not have permission"; |
20 const char kWildcardAddress[] = "*"; | 20 const char kWildcardAddress[] = "*"; |
21 const int kWildcardPort = 0; | 21 const int kWildcardPort = 0; |
22 | 22 |
23 UDPSocketAsyncApiFunction::~UDPSocketAsyncApiFunction() {} | 23 UDPSocketAsyncApiFunction::~UDPSocketAsyncApiFunction() {} |
24 | 24 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 SetSocketProperties(socket, ¶ms_.get()->properties); | 130 SetSocketProperties(socket, ¶ms_.get()->properties); |
131 results_ = sockets_udp::Update::Results::Create(); | 131 results_ = sockets_udp::Update::Results::Create(); |
132 } | 132 } |
133 | 133 |
134 SocketsUdpSetPausedFunction::SocketsUdpSetPausedFunction() | 134 SocketsUdpSetPausedFunction::SocketsUdpSetPausedFunction() |
135 : socket_event_dispatcher_(NULL) {} | 135 : socket_event_dispatcher_(NULL) {} |
136 | 136 |
137 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} | 137 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} |
138 | 138 |
139 bool SocketsUdpSetPausedFunction::Prepare() { | 139 bool SocketsUdpSetPausedFunction::Prepare() { |
140 params_ = core_api::sockets_udp::SetPaused::Params::Create(*args_); | 140 params_ = api::sockets_udp::SetPaused::Params::Create(*args_); |
141 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 141 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
142 | 142 |
143 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); | 143 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); |
144 DCHECK(socket_event_dispatcher_) | 144 DCHECK(socket_event_dispatcher_) |
145 << "There is no socket event dispatcher. " | 145 << "There is no socket event dispatcher. " |
146 "If this assertion is failing during a test, then it is likely that " | 146 "If this assertion is failing during a test, then it is likely that " |
147 "TestExtensionSystem is failing to provide an instance of " | 147 "TestExtensionSystem is failing to provide an instance of " |
148 "UDPSocketEventDispatcher."; | 148 "UDPSocketEventDispatcher."; |
149 return socket_event_dispatcher_ != NULL; | 149 return socket_event_dispatcher_ != NULL; |
150 } | 150 } |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 if (net_result != net::OK) | 387 if (net_result != net::OK) |
388 error_ = net::ErrorToString(net_result); | 388 error_ = net::ErrorToString(net_result); |
389 results_ = sockets_udp::JoinGroup::Results::Create(net_result); | 389 results_ = sockets_udp::JoinGroup::Results::Create(net_result); |
390 } | 390 } |
391 | 391 |
392 SocketsUdpLeaveGroupFunction::SocketsUdpLeaveGroupFunction() {} | 392 SocketsUdpLeaveGroupFunction::SocketsUdpLeaveGroupFunction() {} |
393 | 393 |
394 SocketsUdpLeaveGroupFunction::~SocketsUdpLeaveGroupFunction() {} | 394 SocketsUdpLeaveGroupFunction::~SocketsUdpLeaveGroupFunction() {} |
395 | 395 |
396 bool SocketsUdpLeaveGroupFunction::Prepare() { | 396 bool SocketsUdpLeaveGroupFunction::Prepare() { |
397 params_ = core_api::sockets_udp::LeaveGroup::Params::Create(*args_); | 397 params_ = api::sockets_udp::LeaveGroup::Params::Create(*args_); |
398 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 398 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
399 return true; | 399 return true; |
400 } | 400 } |
401 | 401 |
402 void SocketsUdpLeaveGroupFunction::Work() { | 402 void SocketsUdpLeaveGroupFunction::Work() { |
403 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 403 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
404 if (!socket) { | 404 if (!socket) { |
405 error_ = kSocketNotFoundError; | 405 error_ = kSocketNotFoundError; |
406 return; | 406 return; |
407 } | 407 } |
(...skipping 13 matching lines...) Expand all Loading... |
421 results_ = sockets_udp::LeaveGroup::Results::Create(net_result); | 421 results_ = sockets_udp::LeaveGroup::Results::Create(net_result); |
422 } | 422 } |
423 | 423 |
424 SocketsUdpSetMulticastTimeToLiveFunction:: | 424 SocketsUdpSetMulticastTimeToLiveFunction:: |
425 SocketsUdpSetMulticastTimeToLiveFunction() {} | 425 SocketsUdpSetMulticastTimeToLiveFunction() {} |
426 | 426 |
427 SocketsUdpSetMulticastTimeToLiveFunction:: | 427 SocketsUdpSetMulticastTimeToLiveFunction:: |
428 ~SocketsUdpSetMulticastTimeToLiveFunction() {} | 428 ~SocketsUdpSetMulticastTimeToLiveFunction() {} |
429 | 429 |
430 bool SocketsUdpSetMulticastTimeToLiveFunction::Prepare() { | 430 bool SocketsUdpSetMulticastTimeToLiveFunction::Prepare() { |
431 params_ = | 431 params_ = api::sockets_udp::SetMulticastTimeToLive::Params::Create(*args_); |
432 core_api::sockets_udp::SetMulticastTimeToLive::Params::Create(*args_); | |
433 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 432 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
434 return true; | 433 return true; |
435 } | 434 } |
436 | 435 |
437 void SocketsUdpSetMulticastTimeToLiveFunction::Work() { | 436 void SocketsUdpSetMulticastTimeToLiveFunction::Work() { |
438 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 437 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
439 if (!socket) { | 438 if (!socket) { |
440 error_ = kSocketNotFoundError; | 439 error_ = kSocketNotFoundError; |
441 return; | 440 return; |
442 } | 441 } |
443 | 442 |
444 int net_result = socket->SetMulticastTimeToLive(params_->ttl); | 443 int net_result = socket->SetMulticastTimeToLive(params_->ttl); |
445 if (net_result != net::OK) | 444 if (net_result != net::OK) |
446 error_ = net::ErrorToString(net_result); | 445 error_ = net::ErrorToString(net_result); |
447 results_ = sockets_udp::SetMulticastTimeToLive::Results::Create(net_result); | 446 results_ = sockets_udp::SetMulticastTimeToLive::Results::Create(net_result); |
448 } | 447 } |
449 | 448 |
450 SocketsUdpSetMulticastLoopbackModeFunction:: | 449 SocketsUdpSetMulticastLoopbackModeFunction:: |
451 SocketsUdpSetMulticastLoopbackModeFunction() {} | 450 SocketsUdpSetMulticastLoopbackModeFunction() {} |
452 | 451 |
453 SocketsUdpSetMulticastLoopbackModeFunction:: | 452 SocketsUdpSetMulticastLoopbackModeFunction:: |
454 ~SocketsUdpSetMulticastLoopbackModeFunction() {} | 453 ~SocketsUdpSetMulticastLoopbackModeFunction() {} |
455 | 454 |
456 bool SocketsUdpSetMulticastLoopbackModeFunction::Prepare() { | 455 bool SocketsUdpSetMulticastLoopbackModeFunction::Prepare() { |
457 params_ = | 456 params_ = api::sockets_udp::SetMulticastLoopbackMode::Params::Create(*args_); |
458 core_api::sockets_udp::SetMulticastLoopbackMode::Params::Create(*args_); | |
459 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 457 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
460 return true; | 458 return true; |
461 } | 459 } |
462 | 460 |
463 void SocketsUdpSetMulticastLoopbackModeFunction::Work() { | 461 void SocketsUdpSetMulticastLoopbackModeFunction::Work() { |
464 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 462 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
465 if (!socket) { | 463 if (!socket) { |
466 error_ = kSocketNotFoundError; | 464 error_ = kSocketNotFoundError; |
467 return; | 465 return; |
468 } | 466 } |
469 | 467 |
470 int net_result = socket->SetMulticastLoopbackMode(params_->enabled); | 468 int net_result = socket->SetMulticastLoopbackMode(params_->enabled); |
471 if (net_result != net::OK) | 469 if (net_result != net::OK) |
472 error_ = net::ErrorToString(net_result); | 470 error_ = net::ErrorToString(net_result); |
473 results_ = sockets_udp::SetMulticastLoopbackMode::Results::Create(net_result); | 471 results_ = sockets_udp::SetMulticastLoopbackMode::Results::Create(net_result); |
474 } | 472 } |
475 | 473 |
476 SocketsUdpGetJoinedGroupsFunction::SocketsUdpGetJoinedGroupsFunction() {} | 474 SocketsUdpGetJoinedGroupsFunction::SocketsUdpGetJoinedGroupsFunction() {} |
477 | 475 |
478 SocketsUdpGetJoinedGroupsFunction::~SocketsUdpGetJoinedGroupsFunction() {} | 476 SocketsUdpGetJoinedGroupsFunction::~SocketsUdpGetJoinedGroupsFunction() {} |
479 | 477 |
480 bool SocketsUdpGetJoinedGroupsFunction::Prepare() { | 478 bool SocketsUdpGetJoinedGroupsFunction::Prepare() { |
481 params_ = core_api::sockets_udp::GetJoinedGroups::Params::Create(*args_); | 479 params_ = api::sockets_udp::GetJoinedGroups::Params::Create(*args_); |
482 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 480 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
483 return true; | 481 return true; |
484 } | 482 } |
485 | 483 |
486 void SocketsUdpGetJoinedGroupsFunction::Work() { | 484 void SocketsUdpGetJoinedGroupsFunction::Work() { |
487 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 485 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
488 if (!socket) { | 486 if (!socket) { |
489 error_ = kSocketNotFoundError; | 487 error_ = kSocketNotFoundError; |
490 return; | 488 return; |
491 } | 489 } |
(...skipping 11 matching lines...) Expand all Loading... |
503 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); | 501 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); |
504 } | 502 } |
505 | 503 |
506 SocketsUdpSetBroadcastFunction::SocketsUdpSetBroadcastFunction() { | 504 SocketsUdpSetBroadcastFunction::SocketsUdpSetBroadcastFunction() { |
507 } | 505 } |
508 | 506 |
509 SocketsUdpSetBroadcastFunction::~SocketsUdpSetBroadcastFunction() { | 507 SocketsUdpSetBroadcastFunction::~SocketsUdpSetBroadcastFunction() { |
510 } | 508 } |
511 | 509 |
512 bool SocketsUdpSetBroadcastFunction::Prepare() { | 510 bool SocketsUdpSetBroadcastFunction::Prepare() { |
513 params_ = core_api::sockets_udp::SetBroadcast::Params::Create(*args_); | 511 params_ = api::sockets_udp::SetBroadcast::Params::Create(*args_); |
514 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 512 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
515 return true; | 513 return true; |
516 } | 514 } |
517 | 515 |
518 void SocketsUdpSetBroadcastFunction::Work() { | 516 void SocketsUdpSetBroadcastFunction::Work() { |
519 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 517 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
520 if (!socket) { | 518 if (!socket) { |
521 error_ = kSocketNotFoundError; | 519 error_ = kSocketNotFoundError; |
522 return; | 520 return; |
523 } | 521 } |
524 | 522 |
525 int net_result = socket->SetBroadcast(params_->enabled); | 523 int net_result = socket->SetBroadcast(params_->enabled); |
526 if (net_result != net::OK) { | 524 if (net_result != net::OK) { |
527 error_ = net::ErrorToString(net_result); | 525 error_ = net::ErrorToString(net_result); |
528 } | 526 } |
529 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); | 527 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); |
530 } | 528 } |
531 | 529 |
532 } // namespace core_api | 530 } // namespace api |
533 } // namespace extensions | 531 } // namespace extensions |
OLD | NEW |