Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(830)

Unified Diff: chrome/browser/extensions/api/socket/socket_api_controller.cc

Issue 8857004: Delete UDPClientSocket on same thread as creation. Also refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to fix hunk failure. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/socket/socket_api_controller.cc
diff --git a/chrome/browser/extensions/api/socket/socket_api_controller.cc b/chrome/browser/extensions/api/socket/socket_api_controller.cc
index 21952973ef560f3f3809fcf7a86e1cbf79b163db..8758719458442af53305e5f6c9b2019b253a093d 100644
--- a/chrome/browser/extensions/api/socket/socket_api_controller.cc
+++ b/chrome/browser/extensions/api/socket/socket_api_controller.cc
@@ -22,8 +22,8 @@ namespace extensions {
// we need to manage it in the context of an extension.
class Socket {
public:
- explicit Socket(const Profile* profile, const std::string& src_extension_id,
- const GURL& src_url);
+ Socket(const Profile* profile, const std::string& src_extension_id,
+ const GURL& src_url);
~Socket();
bool Connect(const net::IPEndPoint& ip_end_point);
@@ -38,7 +38,7 @@ class Socket {
std::string src_extension_id_;
GURL src_url_;
- net::UDPClientSocket* udp_client_socket_;
+ scoped_ptr<net::UDPClientSocket> udp_client_socket_;
bool is_connected_;
net::OldCompletionCallbackImpl<Socket> io_callback_;
@@ -101,30 +101,25 @@ int Socket::Write(const std::string message) {
return bytes_sent;
}
-SocketController* SocketController::GetInstance() {
- return Singleton<SocketController>::get();
+SocketController::SocketController() : next_socket_id_(1) {
}
-SocketController::SocketController() : next_socket_id_(1) {}
-
-SocketController::~SocketController() {
- STLDeleteValues(&socket_map_);
-}
+SocketController::~SocketController() {}
Socket* SocketController::GetSocket(int socket_id) {
// TODO(miket): we should verify that the extension asking for the
// socket is the same one that created it.
SocketMap::iterator i = socket_map_.find(socket_id);
if (i != socket_map_.end())
- return i->second;
+ return i->second.get();
return NULL;
}
int SocketController::CreateUdp(const Profile* profile,
const std::string& extension_id,
const GURL& src_url) {
- Socket* socket = new Socket(profile, extension_id, src_url);
- CHECK(socket);
+ linked_ptr<Socket> socket(new Socket(profile, extension_id, src_url));
+ CHECK(socket.get());
socket_map_[next_socket_id_] = socket;
return next_socket_id_++;
}

Powered by Google App Engine
This is Rietveld 408576698