summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/socket/udp_socket.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/udp_socket.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/udp_socket.cc')
-rw-r--r--chrome/browser/extensions/api/socket/udp_socket.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/socket/udp_socket.cc b/chrome/browser/extensions/api/socket/udp_socket.cc
index 4a77aea..7d36ffc 100644
--- a/chrome/browser/extensions/api/socket/udp_socket.cc
+++ b/chrome/browser/extensions/api/socket/udp_socket.cc
@@ -14,6 +14,17 @@
namespace extensions {
+static base::LazyInstance<ProfileKeyedAPIFactory<
+ ApiResourceManager<ResumableUDPSocket> > >
+ g_factory = LAZY_INSTANCE_INITIALIZER;
+
+// static
+template <>
+ProfileKeyedAPIFactory<ApiResourceManager<ResumableUDPSocket> >*
+ApiResourceManager<ResumableUDPSocket>::GetFactoryInstance() {
+ return &g_factory.Get();
+}
+
UDPSocket::UDPSocket(const std::string& owner_extension_id)
: Socket(owner_extension_id),
socket_(net::DatagramSocket::DEFAULT_BIND,
@@ -278,4 +289,34 @@ const std::vector<std::string>& UDPSocket::GetJoinedGroups() const {
return multicast_groups_;
}
+ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id)
+ : UDPSocket(owner_extension_id),
+ persistent_(false),
+ buffer_size_(0) {
+}
+
+const std::string& ResumableUDPSocket::name() const {
+ return name_;
+}
+
+void ResumableUDPSocket::set_name(const std::string& name) {
+ name_ = name;
+}
+
+bool ResumableUDPSocket::persistent() const {
+ return persistent_;
+}
+
+void ResumableUDPSocket::set_persistent(bool persistent) {
+ persistent_ = persistent;
+}
+
+int ResumableUDPSocket::buffer_size() const {
+ return buffer_size_;
+}
+
+void ResumableUDPSocket::set_buffer_size(int buffer_size) {
+ buffer_size_ = buffer_size;
+}
+
} // namespace extensions