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 "chrome/browser/extensions/api/sockets_udp/sockets_udp_api.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/socket/udp_socket.h" | 7 #include "chrome/browser/extensions/api/socket/udp_socket.h" |
8 #include "chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.
h" | 8 #include "chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.
h" |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" | 9 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" |
11 #include "content/public/common/socket_permission_request.h" | 10 #include "content/public/common/socket_permission_request.h" |
12 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
13 | 12 |
14 namespace extensions { | 13 namespace extensions { |
15 namespace api { | 14 namespace api { |
16 | 15 |
17 using content::SocketPermissionRequest; | 16 using content::SocketPermissionRequest; |
18 | 17 |
19 const char kSocketNotFoundError[] = "Socket not found"; | 18 const char kSocketNotFoundError[] = "Socket not found"; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 133 |
135 SocketsUdpSetPausedFunction::SocketsUdpSetPausedFunction() | 134 SocketsUdpSetPausedFunction::SocketsUdpSetPausedFunction() |
136 : socket_event_dispatcher_(NULL) {} | 135 : socket_event_dispatcher_(NULL) {} |
137 | 136 |
138 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} | 137 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} |
139 | 138 |
140 bool SocketsUdpSetPausedFunction::Prepare() { | 139 bool SocketsUdpSetPausedFunction::Prepare() { |
141 params_ = api::sockets_udp::SetPaused::Params::Create(*args_); | 140 params_ = api::sockets_udp::SetPaused::Params::Create(*args_); |
142 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 141 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
143 | 142 |
144 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(GetProfile()); | 143 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); |
145 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " | 144 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " |
146 "If this assertion is failing during a test, then it is likely that " | 145 "If this assertion is failing during a test, then it is likely that " |
147 "TestExtensionSystem is failing to provide an instance of " | 146 "TestExtensionSystem is failing to provide an instance of " |
148 "UDPSocketEventDispatcher."; | 147 "UDPSocketEventDispatcher."; |
149 return socket_event_dispatcher_ != NULL; | 148 return socket_event_dispatcher_ != NULL; |
150 } | 149 } |
151 | 150 |
152 void SocketsUdpSetPausedFunction::Work() { | 151 void SocketsUdpSetPausedFunction::Work() { |
153 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 152 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
154 if (!socket) { | 153 if (!socket) { |
(...skipping 15 matching lines...) Expand all Loading... |
170 SocketsUdpBindFunction::SocketsUdpBindFunction() | 169 SocketsUdpBindFunction::SocketsUdpBindFunction() |
171 : socket_event_dispatcher_(NULL) { | 170 : socket_event_dispatcher_(NULL) { |
172 } | 171 } |
173 | 172 |
174 SocketsUdpBindFunction::~SocketsUdpBindFunction() {} | 173 SocketsUdpBindFunction::~SocketsUdpBindFunction() {} |
175 | 174 |
176 bool SocketsUdpBindFunction::Prepare() { | 175 bool SocketsUdpBindFunction::Prepare() { |
177 params_ = sockets_udp::Bind::Params::Create(*args_); | 176 params_ = sockets_udp::Bind::Params::Create(*args_); |
178 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 177 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
179 | 178 |
180 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(GetProfile()); | 179 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); |
181 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " | 180 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " |
182 "If this assertion is failing during a test, then it is likely that " | 181 "If this assertion is failing during a test, then it is likely that " |
183 "TestExtensionSystem is failing to provide an instance of " | 182 "TestExtensionSystem is failing to provide an instance of " |
184 "UDPSocketEventDispatcher."; | 183 "UDPSocketEventDispatcher."; |
185 return socket_event_dispatcher_ != NULL; | 184 return socket_event_dispatcher_ != NULL; |
186 } | 185 } |
187 | 186 |
188 void SocketsUdpBindFunction::Work() { | 187 void SocketsUdpBindFunction::Work() { |
189 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 188 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
190 if (!socket) { | 189 if (!socket) { |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 error_ = kPermissionError; | 496 error_ = kPermissionError; |
498 return; | 497 return; |
499 } | 498 } |
500 | 499 |
501 const std::vector<std::string>& groups = socket->GetJoinedGroups(); | 500 const std::vector<std::string>& groups = socket->GetJoinedGroups(); |
502 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); | 501 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); |
503 } | 502 } |
504 | 503 |
505 } // namespace api | 504 } // namespace api |
506 } // namespace extensions | 505 } // namespace extensions |
OLD | NEW |