summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/socket/socket_api.cc
diff options
context:
space:
mode:
authorrpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 02:05:26 +0000
committerrpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 02:05:26 +0000
commit64a3996dc779333627f34e4e46be2a23b9539551 (patch)
tree8e1e0829056207efdea2c70258f33d2d92bc0e2e /chrome/browser/extensions/api/socket/socket_api.cc
parent6a078da35f5fcf238013a837ab33e4a16e00d0a8 (diff)
downloadchromium_src-64a3996dc779333627f34e4e46be2a23b9539551.zip
chromium_src-64a3996dc779333627f34e4e46be2a23b9539551.tar.gz
chromium_src-64a3996dc779333627f34e4e46be2a23b9539551.tar.bz2
Implement v2 API of udp socket.
(Note this issue is a replacement for issue #19260002 that will not accept additional patch sets due to a corruption bug: https://code.google.com/p/chromium/issues/detail?id=107101). One notable change vs socket v1 is the use of event handlers for receiving data instead of using callbacks with the "recvFrom" function. This allow server apps to go to "suspend" mode when inactive (see https://docs.google.com/document/d/1qGytoYz6K0xYnOR6oM2tpxC0ET8bbb8XdTFMq4K9jTU/edit?usp=sharing), as well as improve performance (#packets/sec) (see https://docs.google.com/spreadsheet/ccc?key=0Ar6WDZ-sS7b5dEp1ckJGQjZEVGlFN3A1U1BVQUdQb2c&usp=sharing). Also implement the "close_on_suspend" behavior wrt to lifetime: By default, sockets are closed when the packaged app process dies (unload or suspend). When "close_on_suspend" is 'false', sockets survive "suspend" events, and thus can be re-used across process re-activation. This is useful for background server type apps. BUG=165273 BUG=173241 Review URL: https://chromiumcodereview.appspot.com/22650003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217912 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/socket/socket_api.cc')
-rw-r--r--chrome/browser/extensions/api/socket/socket_api.cc29
1 files changed, 19 insertions, 10 deletions
diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
index 83f1e4e..8c1a55b 100644
--- a/chrome/browser/extensions/api/socket/socket_api.cc
+++ b/chrome/browser/extensions/api/socket/socket_api.cc
@@ -47,30 +47,39 @@ const char kMulticastSocketTypeError[] =
const char kWildcardAddress[] = "*";
const int kWildcardPort = 0;
-SocketAsyncApiFunction::SocketAsyncApiFunction()
- : manager_(NULL) {
+SocketAsyncApiFunction::SocketAsyncApiFunction() {
}
SocketAsyncApiFunction::~SocketAsyncApiFunction() {
}
bool SocketAsyncApiFunction::PrePrepare() {
- manager_ = ApiResourceManager<Socket>::Get(profile());
- DCHECK(manager_) << "There is no socket manager. "
- "If this assertion is failing during a test, then it is likely that "
- "TestExtensionSystem is failing to provide an instance of "
- "ApiResourceManager<Socket>.";
- return manager_ != NULL;
+ manager_ = CreateSocketResourceManager();
+ return manager_->SetProfile(profile());
}
bool SocketAsyncApiFunction::Respond() {
return error_.empty();
}
+scoped_ptr<SocketResourceManagerInterface>
+ SocketAsyncApiFunction::CreateSocketResourceManager() {
+ return scoped_ptr<SocketResourceManagerInterface>(
+ new SocketResourceManager<Socket>()).Pass();
+}
+
+int SocketAsyncApiFunction::AddSocket(Socket* socket) {
+ return manager_->Add(socket);
+}
+
Socket* SocketAsyncApiFunction::GetSocket(int api_resource_id) {
return manager_->Get(extension_->id(), api_resource_id);
}
+base::hash_set<int>* SocketAsyncApiFunction::GetSocketIds() {
+ return manager_->GetResourceIds(extension_->id());
+}
+
void SocketAsyncApiFunction::RemoveSocket(int api_resource_id) {
manager_->Remove(extension_->id(), api_resource_id);
}
@@ -152,7 +161,7 @@ void SocketCreateFunction::Work() {
DCHECK(socket);
base::DictionaryValue* result = new base::DictionaryValue();
- result->SetInteger(kSocketIdKey, manager_->Add(socket));
+ result->SetInteger(kSocketIdKey, AddSocket(socket));
SetResult(result);
}
@@ -352,7 +361,7 @@ void SocketAcceptFunction::OnAccept(int result_code,
result->SetInteger(kResultCodeKey, result_code);
if (socket) {
Socket *client_socket = new TCPSocket(socket, extension_id(), true);
- result->SetInteger(kSocketIdKey, manager_->Add(client_socket));
+ result->SetInteger(kSocketIdKey, AddSocket(client_socket));
}
SetResult(result);