| 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" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 if (!socket) { | 125 if (!socket) { |
| 126 error_ = kSocketNotFoundError; | 126 error_ = kSocketNotFoundError; |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 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_(nullptr) { |
| 136 } |
| 136 | 137 |
| 137 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} | 138 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} |
| 138 | 139 |
| 139 bool SocketsUdpSetPausedFunction::Prepare() { | 140 bool SocketsUdpSetPausedFunction::Prepare() { |
| 140 params_ = core_api::sockets_udp::SetPaused::Params::Create(*args_); | 141 params_ = core_api::sockets_udp::SetPaused::Params::Create(*args_); |
| 141 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 142 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 142 | 143 |
| 143 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); | 144 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); |
| 144 DCHECK(socket_event_dispatcher_) | 145 DCHECK(socket_event_dispatcher_) |
| 145 << "There is no socket event dispatcher. " | 146 << "There is no socket event dispatcher. " |
| 146 "If this assertion is failing during a test, then it is likely that " | 147 "If this assertion is failing during a test, then it is likely that " |
| 147 "TestExtensionSystem is failing to provide an instance of " | 148 "TestExtensionSystem is failing to provide an instance of " |
| 148 "UDPSocketEventDispatcher."; | 149 "UDPSocketEventDispatcher."; |
| 149 return socket_event_dispatcher_ != NULL; | 150 return socket_event_dispatcher_ != nullptr; |
| 150 } | 151 } |
| 151 | 152 |
| 152 void SocketsUdpSetPausedFunction::Work() { | 153 void SocketsUdpSetPausedFunction::Work() { |
| 153 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 154 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 154 if (!socket) { | 155 if (!socket) { |
| 155 error_ = kSocketNotFoundError; | 156 error_ = kSocketNotFoundError; |
| 156 return; | 157 return; |
| 157 } | 158 } |
| 158 | 159 |
| 159 if (socket->paused() != params_->paused) { | 160 if (socket->paused() != params_->paused) { |
| 160 socket->set_paused(params_->paused); | 161 socket->set_paused(params_->paused); |
| 161 if (socket->IsBound() && !params_->paused) { | 162 if (socket->IsBound() && !params_->paused) { |
| 162 socket_event_dispatcher_->OnSocketResume(extension_->id(), | 163 socket_event_dispatcher_->OnSocketResume(extension_->id(), |
| 163 params_->socket_id); | 164 params_->socket_id); |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 | 167 |
| 167 results_ = sockets_udp::SetPaused::Results::Create(); | 168 results_ = sockets_udp::SetPaused::Results::Create(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 SocketsUdpBindFunction::SocketsUdpBindFunction() | 171 SocketsUdpBindFunction::SocketsUdpBindFunction() |
| 171 : socket_event_dispatcher_(NULL) {} | 172 : socket_event_dispatcher_(nullptr) { |
| 173 } |
| 172 | 174 |
| 173 SocketsUdpBindFunction::~SocketsUdpBindFunction() {} | 175 SocketsUdpBindFunction::~SocketsUdpBindFunction() {} |
| 174 | 176 |
| 175 bool SocketsUdpBindFunction::Prepare() { | 177 bool SocketsUdpBindFunction::Prepare() { |
| 176 params_ = sockets_udp::Bind::Params::Create(*args_); | 178 params_ = sockets_udp::Bind::Params::Create(*args_); |
| 177 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 179 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 178 | 180 |
| 179 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); | 181 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); |
| 180 DCHECK(socket_event_dispatcher_) | 182 DCHECK(socket_event_dispatcher_) |
| 181 << "There is no socket event dispatcher. " | 183 << "There is no socket event dispatcher. " |
| 182 "If this assertion is failing during a test, then it is likely that " | 184 "If this assertion is failing during a test, then it is likely that " |
| 183 "TestExtensionSystem is failing to provide an instance of " | 185 "TestExtensionSystem is failing to provide an instance of " |
| 184 "UDPSocketEventDispatcher."; | 186 "UDPSocketEventDispatcher."; |
| 185 return socket_event_dispatcher_ != NULL; | 187 return socket_event_dispatcher_ != nullptr; |
| 186 } | 188 } |
| 187 | 189 |
| 188 void SocketsUdpBindFunction::Work() { | 190 void SocketsUdpBindFunction::Work() { |
| 189 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 191 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 190 if (!socket) { | 192 if (!socket) { |
| 191 error_ = kSocketNotFoundError; | 193 error_ = kSocketNotFoundError; |
| 192 return; | 194 return; |
| 193 } | 195 } |
| 194 | 196 |
| 195 content::SocketPermissionRequest param( | 197 content::SocketPermissionRequest param( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 336 |
| 335 SocketsUdpGetSocketsFunction::SocketsUdpGetSocketsFunction() {} | 337 SocketsUdpGetSocketsFunction::SocketsUdpGetSocketsFunction() {} |
| 336 | 338 |
| 337 SocketsUdpGetSocketsFunction::~SocketsUdpGetSocketsFunction() {} | 339 SocketsUdpGetSocketsFunction::~SocketsUdpGetSocketsFunction() {} |
| 338 | 340 |
| 339 bool SocketsUdpGetSocketsFunction::Prepare() { return true; } | 341 bool SocketsUdpGetSocketsFunction::Prepare() { return true; } |
| 340 | 342 |
| 341 void SocketsUdpGetSocketsFunction::Work() { | 343 void SocketsUdpGetSocketsFunction::Work() { |
| 342 std::vector<linked_ptr<sockets_udp::SocketInfo> > socket_infos; | 344 std::vector<linked_ptr<sockets_udp::SocketInfo> > socket_infos; |
| 343 base::hash_set<int>* resource_ids = GetSocketIds(); | 345 base::hash_set<int>* resource_ids = GetSocketIds(); |
| 344 if (resource_ids != NULL) { | 346 if (resource_ids != nullptr) { |
| 345 for (base::hash_set<int>::iterator it = resource_ids->begin(); | 347 for (base::hash_set<int>::iterator it = resource_ids->begin(); |
| 346 it != resource_ids->end(); | 348 it != resource_ids->end(); |
| 347 ++it) { | 349 ++it) { |
| 348 int socket_id = *it; | 350 int socket_id = *it; |
| 349 ResumableUDPSocket* socket = GetUdpSocket(socket_id); | 351 ResumableUDPSocket* socket = GetUdpSocket(socket_id); |
| 350 if (socket) { | 352 if (socket) { |
| 351 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 353 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 352 } | 354 } |
| 353 } | 355 } |
| 354 } | 356 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 error_ = kPermissionError; | 498 error_ = kPermissionError; |
| 497 return; | 499 return; |
| 498 } | 500 } |
| 499 | 501 |
| 500 const std::vector<std::string>& groups = socket->GetJoinedGroups(); | 502 const std::vector<std::string>& groups = socket->GetJoinedGroups(); |
| 501 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); | 503 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); |
| 502 } | 504 } |
| 503 | 505 |
| 504 } // namespace core_api | 506 } // namespace core_api |
| 505 } // namespace extensions | 507 } // namespace extensions |
| OLD | NEW |