| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/sockets_udp/sockets_udp_api.h" | 5 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/socket/udp_socket.h" | |
| 8 #include "chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.
h" | |
| 9 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" | 7 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" |
| 10 #include "content/public/common/socket_permission_request.h" | 8 #include "content/public/common/socket_permission_request.h" |
| 9 #include "extensions/browser/api/socket/udp_socket.h" |
| 10 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.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 api { | 14 namespace core_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 |
| 25 scoped_ptr<SocketResourceManagerInterface> | 25 scoped_ptr<SocketResourceManagerInterface> |
| 26 UDPSocketAsyncApiFunction::CreateSocketResourceManager() { | 26 UDPSocketAsyncApiFunction::CreateSocketResourceManager() { |
| 27 return scoped_ptr<SocketResourceManagerInterface>( | 27 return scoped_ptr<SocketResourceManagerInterface>( |
| 28 new SocketResourceManager<ResumableUDPSocket>()).Pass(); | 28 new SocketResourceManager<ResumableUDPSocket>()).Pass(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 ResumableUDPSocket* UDPSocketAsyncApiFunction::GetUdpSocket(int socket_id) { | 31 ResumableUDPSocket* UDPSocketAsyncApiFunction::GetUdpSocket(int socket_id) { |
| 32 return static_cast<ResumableUDPSocket*>(GetSocket(socket_id)); | 32 return static_cast<ResumableUDPSocket*>(GetSocket(socket_id)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 UDPSocketExtensionWithDnsLookupFunction:: | 35 UDPSocketExtensionWithDnsLookupFunction:: |
| 36 ~UDPSocketExtensionWithDnsLookupFunction() {} | 36 ~UDPSocketExtensionWithDnsLookupFunction() {} |
| 37 | 37 |
| 38 scoped_ptr<SocketResourceManagerInterface> | 38 scoped_ptr<SocketResourceManagerInterface> |
| 39 UDPSocketExtensionWithDnsLookupFunction::CreateSocketResourceManager() { | 39 UDPSocketExtensionWithDnsLookupFunction::CreateSocketResourceManager() { |
| 40 return scoped_ptr<SocketResourceManagerInterface>( | 40 return scoped_ptr<SocketResourceManagerInterface>( |
| 41 new SocketResourceManager<ResumableUDPSocket>()).Pass(); | 41 new SocketResourceManager<ResumableUDPSocket>()).Pass(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ResumableUDPSocket* UDPSocketExtensionWithDnsLookupFunction::GetUdpSocket( | 44 ResumableUDPSocket* UDPSocketExtensionWithDnsLookupFunction::GetUdpSocket( |
| 45 int socket_id) { | 45 int socket_id) { |
| 46 return static_cast<ResumableUDPSocket*>(GetSocket(socket_id)); | 46 return static_cast<ResumableUDPSocket*>(GetSocket(socket_id)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 linked_ptr<sockets_udp::SocketInfo> CreateSocketInfo( | 49 linked_ptr<sockets_udp::SocketInfo> CreateSocketInfo( |
| 50 int socket_id, | 50 int socket_id, |
| 51 ResumableUDPSocket* socket) { | 51 ResumableUDPSocket* socket) { |
| (...skipping 78 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_ = api::sockets_udp::SetPaused::Params::Create(*args_); | 140 params_ = core_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_) << "There is no socket event dispatcher. " | 144 DCHECK(socket_event_dispatcher_) |
| 145 "If this assertion is failing during a test, then it is likely that " | 145 << "There is no socket event dispatcher. " |
| 146 "TestExtensionSystem is failing to provide an instance of " | 146 "If this assertion is failing during a test, then it is likely that " |
| 147 "UDPSocketEventDispatcher."; | 147 "TestExtensionSystem is failing to provide an instance of " |
| 148 "UDPSocketEventDispatcher."; |
| 148 return socket_event_dispatcher_ != NULL; | 149 return socket_event_dispatcher_ != NULL; |
| 149 } | 150 } |
| 150 | 151 |
| 151 void SocketsUdpSetPausedFunction::Work() { | 152 void SocketsUdpSetPausedFunction::Work() { |
| 152 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 153 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 153 if (!socket) { | 154 if (!socket) { |
| 154 error_ = kSocketNotFoundError; | 155 error_ = kSocketNotFoundError; |
| 155 return; | 156 return; |
| 156 } | 157 } |
| 157 | 158 |
| 158 if (socket->paused() != params_->paused) { | 159 if (socket->paused() != params_->paused) { |
| 159 socket->set_paused(params_->paused); | 160 socket->set_paused(params_->paused); |
| 160 if (socket->IsBound() && !params_->paused) { | 161 if (socket->IsBound() && !params_->paused) { |
| 161 socket_event_dispatcher_->OnSocketResume(extension_->id(), | 162 socket_event_dispatcher_->OnSocketResume(extension_->id(), |
| 162 params_->socket_id); | 163 params_->socket_id); |
| 163 } | 164 } |
| 164 } | 165 } |
| 165 | 166 |
| 166 results_ = sockets_udp::SetPaused::Results::Create(); | 167 results_ = sockets_udp::SetPaused::Results::Create(); |
| 167 } | 168 } |
| 168 | 169 |
| 169 SocketsUdpBindFunction::SocketsUdpBindFunction() | 170 SocketsUdpBindFunction::SocketsUdpBindFunction() |
| 170 : socket_event_dispatcher_(NULL) { | 171 : socket_event_dispatcher_(NULL) {} |
| 171 } | |
| 172 | 172 |
| 173 SocketsUdpBindFunction::~SocketsUdpBindFunction() {} | 173 SocketsUdpBindFunction::~SocketsUdpBindFunction() {} |
| 174 | 174 |
| 175 bool SocketsUdpBindFunction::Prepare() { | 175 bool SocketsUdpBindFunction::Prepare() { |
| 176 params_ = sockets_udp::Bind::Params::Create(*args_); | 176 params_ = sockets_udp::Bind::Params::Create(*args_); |
| 177 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 177 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 178 | 178 |
| 179 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); | 179 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); |
| 180 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " | 180 DCHECK(socket_event_dispatcher_) |
| 181 "If this assertion is failing during a test, then it is likely that " | 181 << "There is no socket event dispatcher. " |
| 182 "TestExtensionSystem is failing to provide an instance of " | 182 "If this assertion is failing during a test, then it is likely that " |
| 183 "UDPSocketEventDispatcher."; | 183 "TestExtensionSystem is failing to provide an instance of " |
| 184 "UDPSocketEventDispatcher."; |
| 184 return socket_event_dispatcher_ != NULL; | 185 return socket_event_dispatcher_ != NULL; |
| 185 } | 186 } |
| 186 | 187 |
| 187 void SocketsUdpBindFunction::Work() { | 188 void SocketsUdpBindFunction::Work() { |
| 188 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 189 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 189 if (!socket) { | 190 if (!socket) { |
| 190 error_ = kSocketNotFoundError; | 191 error_ = kSocketNotFoundError; |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 | 194 |
| 194 content::SocketPermissionRequest param( | 195 content::SocketPermissionRequest param( |
| 195 SocketPermissionRequest::UDP_BIND, | 196 SocketPermissionRequest::UDP_BIND, params_->address, params_->port); |
| 196 params_->address, | |
| 197 params_->port); | |
| 198 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { | 197 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { |
| 199 error_ = kPermissionError; | 198 error_ = kPermissionError; |
| 200 return; | 199 return; |
| 201 } | 200 } |
| 202 | 201 |
| 203 int net_result = socket->Bind(params_->address, params_->port); | 202 int net_result = socket->Bind(params_->address, params_->port); |
| 204 if (net_result == net::OK) { | 203 if (net_result == net::OK) { |
| 205 socket_event_dispatcher_->OnSocketBind(extension_->id(), | 204 socket_event_dispatcher_->OnSocketBind(extension_->id(), |
| 206 params_->socket_id); | 205 params_->socket_id); |
| 207 } | 206 } |
| 208 | 207 |
| 209 if (net_result != net::OK) | 208 if (net_result != net::OK) |
| 210 error_ = net::ErrorToString(net_result); | 209 error_ = net::ErrorToString(net_result); |
| 211 results_ = sockets_udp::Bind::Results::Create(net_result); | 210 results_ = sockets_udp::Bind::Results::Create(net_result); |
| 212 } | 211 } |
| 213 | 212 |
| 214 SocketsUdpSendFunction::SocketsUdpSendFunction() | 213 SocketsUdpSendFunction::SocketsUdpSendFunction() : io_buffer_size_(0) {} |
| 215 : io_buffer_size_(0) {} | |
| 216 | 214 |
| 217 SocketsUdpSendFunction::~SocketsUdpSendFunction() {} | 215 SocketsUdpSendFunction::~SocketsUdpSendFunction() {} |
| 218 | 216 |
| 219 bool SocketsUdpSendFunction::Prepare() { | 217 bool SocketsUdpSendFunction::Prepare() { |
| 220 params_ = sockets_udp::Send::Params::Create(*args_); | 218 params_ = sockets_udp::Send::Params::Create(*args_); |
| 221 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 219 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 222 io_buffer_size_ = params_->data.size(); | 220 io_buffer_size_ = params_->data.size(); |
| 223 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); | 221 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); |
| 224 | 222 |
| 225 return true; | 223 return true; |
| 226 } | 224 } |
| 227 | 225 |
| 228 void SocketsUdpSendFunction::AsyncWorkStart() { | 226 void SocketsUdpSendFunction::AsyncWorkStart() { |
| 229 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 227 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 230 if (!socket) { | 228 if (!socket) { |
| 231 error_ = kSocketNotFoundError; | 229 error_ = kSocketNotFoundError; |
| 232 AsyncWorkCompleted(); | 230 AsyncWorkCompleted(); |
| 233 return; | 231 return; |
| 234 } | 232 } |
| 235 | 233 |
| 236 content::SocketPermissionRequest param( | 234 content::SocketPermissionRequest param( |
| 237 SocketPermissionRequest::UDP_SEND_TO, | 235 SocketPermissionRequest::UDP_SEND_TO, params_->address, params_->port); |
| 238 params_->address, | |
| 239 params_->port); | |
| 240 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { | 236 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { |
| 241 error_ = kPermissionError; | 237 error_ = kPermissionError; |
| 242 AsyncWorkCompleted(); | 238 AsyncWorkCompleted(); |
| 243 return; | 239 return; |
| 244 } | 240 } |
| 245 | 241 |
| 246 StartDnsLookup(params_->address); | 242 StartDnsLookup(params_->address); |
| 247 } | 243 } |
| 248 | 244 |
| 249 void SocketsUdpSendFunction::AfterDnsLookup(int lookup_result) { | 245 void SocketsUdpSendFunction::AfterDnsLookup(int lookup_result) { |
| 250 if (lookup_result == net::OK) { | 246 if (lookup_result == net::OK) { |
| 251 StartSendTo(); | 247 StartSendTo(); |
| 252 } else { | 248 } else { |
| 253 SetSendResult(lookup_result, -1); | 249 SetSendResult(lookup_result, -1); |
| 254 } | 250 } |
| 255 } | 251 } |
| 256 | 252 |
| 257 void SocketsUdpSendFunction::StartSendTo() { | 253 void SocketsUdpSendFunction::StartSendTo() { |
| 258 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 254 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 259 if (!socket) { | 255 if (!socket) { |
| 260 error_ = kSocketNotFoundError; | 256 error_ = kSocketNotFoundError; |
| 261 AsyncWorkCompleted(); | 257 AsyncWorkCompleted(); |
| 262 return; | 258 return; |
| 263 } | 259 } |
| 264 | 260 |
| 265 socket->SendTo(io_buffer_, io_buffer_size_, resolved_address_, params_->port, | 261 socket->SendTo(io_buffer_, |
| 266 base::Bind(&SocketsUdpSendFunction::OnCompleted, this)); | 262 io_buffer_size_, |
| 263 resolved_address_, |
| 264 params_->port, |
| 265 base::Bind(&SocketsUdpSendFunction::OnCompleted, this)); |
| 267 } | 266 } |
| 268 | 267 |
| 269 void SocketsUdpSendFunction::OnCompleted(int net_result) { | 268 void SocketsUdpSendFunction::OnCompleted(int net_result) { |
| 270 if (net_result >= net::OK) { | 269 if (net_result >= net::OK) { |
| 271 SetSendResult(net::OK, net_result); | 270 SetSendResult(net::OK, net_result); |
| 272 } else { | 271 } else { |
| 273 SetSendResult(net_result, -1); | 272 SetSendResult(net_result, -1); |
| 274 } | 273 } |
| 275 } | 274 } |
| 276 | 275 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 329 |
| 331 linked_ptr<sockets_udp::SocketInfo> socket_info = | 330 linked_ptr<sockets_udp::SocketInfo> socket_info = |
| 332 CreateSocketInfo(params_->socket_id, socket); | 331 CreateSocketInfo(params_->socket_id, socket); |
| 333 results_ = sockets_udp::GetInfo::Results::Create(*socket_info); | 332 results_ = sockets_udp::GetInfo::Results::Create(*socket_info); |
| 334 } | 333 } |
| 335 | 334 |
| 336 SocketsUdpGetSocketsFunction::SocketsUdpGetSocketsFunction() {} | 335 SocketsUdpGetSocketsFunction::SocketsUdpGetSocketsFunction() {} |
| 337 | 336 |
| 338 SocketsUdpGetSocketsFunction::~SocketsUdpGetSocketsFunction() {} | 337 SocketsUdpGetSocketsFunction::~SocketsUdpGetSocketsFunction() {} |
| 339 | 338 |
| 340 bool SocketsUdpGetSocketsFunction::Prepare() { | 339 bool SocketsUdpGetSocketsFunction::Prepare() { return true; } |
| 341 return true; | |
| 342 } | |
| 343 | 340 |
| 344 void SocketsUdpGetSocketsFunction::Work() { | 341 void SocketsUdpGetSocketsFunction::Work() { |
| 345 std::vector<linked_ptr<sockets_udp::SocketInfo> > socket_infos; | 342 std::vector<linked_ptr<sockets_udp::SocketInfo> > socket_infos; |
| 346 base::hash_set<int>* resource_ids = GetSocketIds(); | 343 base::hash_set<int>* resource_ids = GetSocketIds(); |
| 347 if (resource_ids != NULL) { | 344 if (resource_ids != NULL) { |
| 348 for (base::hash_set<int>::iterator it = resource_ids->begin(); | 345 for (base::hash_set<int>::iterator it = resource_ids->begin(); |
| 349 it != resource_ids->end(); ++it) { | 346 it != resource_ids->end(); |
| 347 ++it) { |
| 350 int socket_id = *it; | 348 int socket_id = *it; |
| 351 ResumableUDPSocket* socket = GetUdpSocket(socket_id); | 349 ResumableUDPSocket* socket = GetUdpSocket(socket_id); |
| 352 if (socket) { | 350 if (socket) { |
| 353 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 351 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 354 } | 352 } |
| 355 } | 353 } |
| 356 } | 354 } |
| 357 results_ = sockets_udp::GetSockets::Results::Create(socket_infos); | 355 results_ = sockets_udp::GetSockets::Results::Create(socket_infos); |
| 358 } | 356 } |
| 359 | 357 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 387 if (net_result != net::OK) | 385 if (net_result != net::OK) |
| 388 error_ = net::ErrorToString(net_result); | 386 error_ = net::ErrorToString(net_result); |
| 389 results_ = sockets_udp::JoinGroup::Results::Create(net_result); | 387 results_ = sockets_udp::JoinGroup::Results::Create(net_result); |
| 390 } | 388 } |
| 391 | 389 |
| 392 SocketsUdpLeaveGroupFunction::SocketsUdpLeaveGroupFunction() {} | 390 SocketsUdpLeaveGroupFunction::SocketsUdpLeaveGroupFunction() {} |
| 393 | 391 |
| 394 SocketsUdpLeaveGroupFunction::~SocketsUdpLeaveGroupFunction() {} | 392 SocketsUdpLeaveGroupFunction::~SocketsUdpLeaveGroupFunction() {} |
| 395 | 393 |
| 396 bool SocketsUdpLeaveGroupFunction::Prepare() { | 394 bool SocketsUdpLeaveGroupFunction::Prepare() { |
| 397 params_ = api::sockets_udp::LeaveGroup::Params::Create(*args_); | 395 params_ = core_api::sockets_udp::LeaveGroup::Params::Create(*args_); |
| 398 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 396 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 399 return true; | 397 return true; |
| 400 } | 398 } |
| 401 | 399 |
| 402 void SocketsUdpLeaveGroupFunction::Work() { | 400 void SocketsUdpLeaveGroupFunction::Work() { |
| 403 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 401 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 404 if (!socket) { | 402 if (!socket) { |
| 405 error_ = kSocketNotFoundError; | 403 error_ = kSocketNotFoundError; |
| 406 return; | 404 return; |
| 407 } | 405 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 421 results_ = sockets_udp::LeaveGroup::Results::Create(net_result); | 419 results_ = sockets_udp::LeaveGroup::Results::Create(net_result); |
| 422 } | 420 } |
| 423 | 421 |
| 424 SocketsUdpSetMulticastTimeToLiveFunction:: | 422 SocketsUdpSetMulticastTimeToLiveFunction:: |
| 425 SocketsUdpSetMulticastTimeToLiveFunction() {} | 423 SocketsUdpSetMulticastTimeToLiveFunction() {} |
| 426 | 424 |
| 427 SocketsUdpSetMulticastTimeToLiveFunction:: | 425 SocketsUdpSetMulticastTimeToLiveFunction:: |
| 428 ~SocketsUdpSetMulticastTimeToLiveFunction() {} | 426 ~SocketsUdpSetMulticastTimeToLiveFunction() {} |
| 429 | 427 |
| 430 bool SocketsUdpSetMulticastTimeToLiveFunction::Prepare() { | 428 bool SocketsUdpSetMulticastTimeToLiveFunction::Prepare() { |
| 431 params_ = api::sockets_udp::SetMulticastTimeToLive::Params::Create(*args_); | 429 params_ = |
| 430 core_api::sockets_udp::SetMulticastTimeToLive::Params::Create(*args_); |
| 432 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 431 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 433 return true; | 432 return true; |
| 434 } | 433 } |
| 435 | 434 |
| 436 void SocketsUdpSetMulticastTimeToLiveFunction::Work() { | 435 void SocketsUdpSetMulticastTimeToLiveFunction::Work() { |
| 437 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 436 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 438 if (!socket) { | 437 if (!socket) { |
| 439 error_ = kSocketNotFoundError; | 438 error_ = kSocketNotFoundError; |
| 440 return; | 439 return; |
| 441 } | 440 } |
| 442 | 441 |
| 443 int net_result = socket->SetMulticastTimeToLive(params_->ttl); | 442 int net_result = socket->SetMulticastTimeToLive(params_->ttl); |
| 444 if (net_result != net::OK) | 443 if (net_result != net::OK) |
| 445 error_ = net::ErrorToString(net_result); | 444 error_ = net::ErrorToString(net_result); |
| 446 results_ = sockets_udp::SetMulticastTimeToLive::Results::Create(net_result); | 445 results_ = sockets_udp::SetMulticastTimeToLive::Results::Create(net_result); |
| 447 } | 446 } |
| 448 | 447 |
| 449 SocketsUdpSetMulticastLoopbackModeFunction:: | 448 SocketsUdpSetMulticastLoopbackModeFunction:: |
| 450 SocketsUdpSetMulticastLoopbackModeFunction() {} | 449 SocketsUdpSetMulticastLoopbackModeFunction() {} |
| 451 | 450 |
| 452 SocketsUdpSetMulticastLoopbackModeFunction:: | 451 SocketsUdpSetMulticastLoopbackModeFunction:: |
| 453 ~SocketsUdpSetMulticastLoopbackModeFunction() {} | 452 ~SocketsUdpSetMulticastLoopbackModeFunction() {} |
| 454 | 453 |
| 455 bool SocketsUdpSetMulticastLoopbackModeFunction::Prepare() { | 454 bool SocketsUdpSetMulticastLoopbackModeFunction::Prepare() { |
| 456 params_ = api::sockets_udp::SetMulticastLoopbackMode::Params::Create(*args_); | 455 params_ = |
| 456 core_api::sockets_udp::SetMulticastLoopbackMode::Params::Create(*args_); |
| 457 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 457 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 458 return true; | 458 return true; |
| 459 } | 459 } |
| 460 | 460 |
| 461 void SocketsUdpSetMulticastLoopbackModeFunction::Work() { | 461 void SocketsUdpSetMulticastLoopbackModeFunction::Work() { |
| 462 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 462 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 463 if (!socket) { | 463 if (!socket) { |
| 464 error_ = kSocketNotFoundError; | 464 error_ = kSocketNotFoundError; |
| 465 return; | 465 return; |
| 466 } | 466 } |
| 467 | 467 |
| 468 int net_result = socket->SetMulticastLoopbackMode(params_->enabled); | 468 int net_result = socket->SetMulticastLoopbackMode(params_->enabled); |
| 469 if (net_result != net::OK) | 469 if (net_result != net::OK) |
| 470 error_ = net::ErrorToString(net_result); | 470 error_ = net::ErrorToString(net_result); |
| 471 results_ = sockets_udp::SetMulticastLoopbackMode::Results::Create(net_result); | 471 results_ = sockets_udp::SetMulticastLoopbackMode::Results::Create(net_result); |
| 472 } | 472 } |
| 473 | 473 |
| 474 SocketsUdpGetJoinedGroupsFunction::SocketsUdpGetJoinedGroupsFunction() {} | 474 SocketsUdpGetJoinedGroupsFunction::SocketsUdpGetJoinedGroupsFunction() {} |
| 475 | 475 |
| 476 SocketsUdpGetJoinedGroupsFunction::~SocketsUdpGetJoinedGroupsFunction() {} | 476 SocketsUdpGetJoinedGroupsFunction::~SocketsUdpGetJoinedGroupsFunction() {} |
| 477 | 477 |
| 478 bool SocketsUdpGetJoinedGroupsFunction::Prepare() { | 478 bool SocketsUdpGetJoinedGroupsFunction::Prepare() { |
| 479 params_ = api::sockets_udp::GetJoinedGroups::Params::Create(*args_); | 479 params_ = core_api::sockets_udp::GetJoinedGroups::Params::Create(*args_); |
| 480 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 480 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 481 return true; | 481 return true; |
| 482 } | 482 } |
| 483 | 483 |
| 484 void SocketsUdpGetJoinedGroupsFunction::Work() { | 484 void SocketsUdpGetJoinedGroupsFunction::Work() { |
| 485 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 485 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 486 if (!socket) { | 486 if (!socket) { |
| 487 error_ = kSocketNotFoundError; | 487 error_ = kSocketNotFoundError; |
| 488 return; | 488 return; |
| 489 } | 489 } |
| 490 | 490 |
| 491 content::SocketPermissionRequest param( | 491 content::SocketPermissionRequest param( |
| 492 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 492 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
| 493 kWildcardAddress, | 493 kWildcardAddress, |
| 494 kWildcardPort); | 494 kWildcardPort); |
| 495 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { | 495 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { |
| 496 error_ = kPermissionError; | 496 error_ = kPermissionError; |
| 497 return; | 497 return; |
| 498 } | 498 } |
| 499 | 499 |
| 500 const std::vector<std::string>& groups = socket->GetJoinedGroups(); | 500 const std::vector<std::string>& groups = socket->GetJoinedGroups(); |
| 501 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); | 501 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); |
| 502 } | 502 } |
| 503 | 503 |
| 504 } // namespace api | 504 } // namespace core_api |
| 505 } // namespace extensions | 505 } // namespace extensions |
| OLD | NEW |