Skip to content

Commit

Permalink
sockets.tcpServer API implementation.
Browse files Browse the repository at this point in the history
Implement a new API for TCP *server* sockets. This CL is similar to
sockets.tcp (see https://codereview.chromium.org/24684002) and follows
the same design pattern.


BUG=165273
BUG=173241

Review URL: https://codereview.chromium.org/27076004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229304 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rpaquay@chromium.org committed Oct 18, 2013
1 parent b1d1ea0 commit 96a0c06
Show file tree
Hide file tree
Showing 23 changed files with 1,474 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/extensions/api/api_resource_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace extensions {
namespace api {
class TCPServerSocketEventDispatcher;
class TCPSocketEventDispatcher;
class UDPSocketEventDispatcher;
}
Expand Down Expand Up @@ -153,6 +154,7 @@ class ApiResourceManager : public ProfileKeyedAPI,
}

private:
friend class api::TCPServerSocketEventDispatcher;
friend class api::TCPSocketEventDispatcher;
friend class api::UDPSocketEventDispatcher;
friend class ProfileKeyedAPIFactory<ApiResourceManager<T> >;
Expand Down
31 changes: 31 additions & 0 deletions chrome/browser/extensions/api/socket/tcp_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance() {
return &g_factory.Get();
}

static base::LazyInstance<ProfileKeyedAPIFactory<
ApiResourceManager<ResumableTCPServerSocket> > >
g_server_factory = LAZY_INSTANCE_INITIALIZER;

// static
template <>
ProfileKeyedAPIFactory<ApiResourceManager<ResumableTCPServerSocket> >*
ApiResourceManager<ResumableTCPServerSocket>::GetFactoryInstance() {
return &g_server_factory.Get();
}

TCPSocket::TCPSocket(const std::string& owner_extension_id)
: Socket(owner_extension_id),
socket_mode_(UNKNOWN) {
Expand Down Expand Up @@ -304,8 +315,28 @@ ResumableTCPSocket::ResumableTCPSocket(const std::string& owner_extension_id)
paused_(false) {
}

ResumableTCPSocket::ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket,
const std::string& owner_extension_id,
bool is_connected)
: TCPSocket(tcp_client_socket, owner_extension_id, is_connected),
persistent_(false),
buffer_size_(0),
paused_(false) {
}

bool ResumableTCPSocket::persistent() const {
return persistent_;
}

ResumableTCPServerSocket::ResumableTCPServerSocket(
const std::string& owner_extension_id)
: TCPSocket(owner_extension_id),
persistent_(false),
paused_(false) {
}

bool ResumableTCPServerSocket::persistent() const {
return persistent_;
}

} // namespace extensions
36 changes: 36 additions & 0 deletions chrome/browser/extensions/api/socket/tcp_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ class TCPSocket : public Socket {
class ResumableTCPSocket : public TCPSocket {
public:
explicit ResumableTCPSocket(const std::string& owner_extension_id);
explicit ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket,
const std::string& owner_extension_id,
bool is_connected);

const std::string& name() const { return name_; }
void set_name(const std::string& name) { name_ = name; }

// Overriden from ApiResource
virtual bool persistent() const OVERRIDE;
void set_persistent(bool persistent) { persistent_ = persistent; }

Expand Down Expand Up @@ -133,6 +137,38 @@ class ResumableTCPSocket : public TCPSocket {
bool paused_;
};

// TCP Socket instances from the "sockets.tcpServer" namespace. These are
// regular socket objects with additional properties related to the behavior
// defined in the "sockets.tcpServer" namespace.
class ResumableTCPServerSocket : public TCPSocket {
public:
explicit ResumableTCPServerSocket(const std::string& owner_extension_id);

const std::string& name() const { return name_; }
void set_name(const std::string& name) { name_ = name; }

virtual bool persistent() const OVERRIDE;
void set_persistent(bool persistent) { persistent_ = persistent; }

bool paused() const { return paused_; }
void set_paused(bool paused) { paused_ = paused; }

private:
friend class ApiResourceManager<ResumableTCPServerSocket>;
static const char* service_name() {
return "ResumableTCPServerSocketManager";
}

// Application-defined string - see sockets_tcp_server.idl.
std::string name_;
// Flag indicating whether the socket is left open when the application is
// suspended - see sockets_tcp_server.idl.
bool persistent_;
// Flag indicating whether a connected socket blocks its peer from sending
// more data - see sockets_tcp_server.idl.
bool paused_;
};

} // namespace extensions

#endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
Loading

0 comments on commit 96a0c06

Please sign in to comment.