diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 08:14:10 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 08:14:10 +0000 |
commit | ee16679f293ca27ce3d822a97efad7d3fa8a049e (patch) | |
tree | 4d531d3ecd47038f476a405372acfbdd20c493f3 /net/websockets | |
parent | dce3a57799f52dc3edc0bee78c5e74fed362c365 (diff) | |
download | chromium_src-ee16679f293ca27ce3d822a97efad7d3fa8a049e.zip chromium_src-ee16679f293ca27ce3d822a97efad7d3fa8a049e.tar.gz chromium_src-ee16679f293ca27ce3d822a97efad7d3fa8a049e.tar.bz2 |
Add a new GetInstance() method for singleton classes under chrome/service and /net.
This is a small step towards making all singleton classes use the Singleton<T> pattern within their code and not expect the callers to know about it.
This CL includes files under chrome/service and /net with related files elsewhere.
Suggested files to focus for reviewers:
- @sanjeevr for chrome/common and chrome/service
- @ukai for net/websockets
- @agl for rest of net
BUG=65298
TEST=all existing tests should continue to pass.
Review URL: http://codereview.chromium.org/5634005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r-- | net/websockets/websocket_job.cc | 15 | ||||
-rw-r--r-- | net/websockets/websocket_job_unittest.cc | 4 | ||||
-rw-r--r-- | net/websockets/websocket_throttle.cc | 5 | ||||
-rw-r--r-- | net/websockets/websocket_throttle.h | 6 |
4 files changed, 20 insertions, 10 deletions
diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index a1e2dde..9adbaa3 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "base/singleton.h" #include "base/string_tokenizer.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" @@ -144,8 +145,8 @@ void WebSocketJob::RestartWithAuth( void WebSocketJob::DetachDelegate() { state_ = CLOSED; - Singleton<WebSocketThrottle>::get()->RemoveFromQueue(this); - Singleton<WebSocketThrottle>::get()->WakeupSocketIfNecessary(); + WebSocketThrottle::GetInstance()->RemoveFromQueue(this); + WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary(); scoped_refptr<WebSocketJob> protect(this); @@ -165,7 +166,7 @@ int WebSocketJob::OnStartOpenConnection( DCHECK(!callback_); state_ = CONNECTING; addresses_.Copy(socket->address_list().head(), true); - Singleton<WebSocketThrottle>::get()->PutInQueue(this); + WebSocketThrottle::GetInstance()->PutInQueue(this); if (!waiting_) return OK; callback_ = callback; @@ -237,8 +238,8 @@ void WebSocketJob::OnReceivedData( void WebSocketJob::OnClose(SocketStream* socket) { state_ = CLOSED; - Singleton<WebSocketThrottle>::get()->RemoveFromQueue(this); - Singleton<WebSocketThrottle>::get()->WakeupSocketIfNecessary(); + WebSocketThrottle::GetInstance()->RemoveFromQueue(this); + WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary(); scoped_refptr<WebSocketJob> protect(this); @@ -405,8 +406,8 @@ void WebSocketJob::SaveNextCookie() { handshake_response_.reset(); - Singleton<WebSocketThrottle>::get()->RemoveFromQueue(this); - Singleton<WebSocketThrottle>::get()->WakeupSocketIfNecessary(); + WebSocketThrottle::GetInstance()->RemoveFromQueue(this); + WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary(); return; } diff --git a/net/websockets/websocket_job_unittest.cc b/net/websockets/websocket_job_unittest.cc index 53d4a625..43d8509 100644 --- a/net/websockets/websocket_job_unittest.cc +++ b/net/websockets/websocket_job_unittest.cc @@ -222,7 +222,7 @@ class WebSocketJobTest : public PlatformTest { addr.ai_addr = reinterpret_cast<sockaddr*>(&sa_in); addr.ai_next = NULL; websocket_->addresses_.Copy(&addr, true); - Singleton<WebSocketThrottle>::get()->PutInQueue(websocket_); + WebSocketThrottle::GetInstance()->PutInQueue(websocket_); } WebSocketJob::State GetWebSocketJobState() { return websocket_->state_; @@ -230,7 +230,7 @@ class WebSocketJobTest : public PlatformTest { void CloseWebSocketJob() { if (websocket_->socket_) { websocket_->socket_->DetachDelegate(); - Singleton<WebSocketThrottle>::get()->RemoveFromQueue(websocket_); + WebSocketThrottle::GetInstance()->RemoveFromQueue(websocket_); } websocket_->state_ = WebSocketJob::CLOSED; websocket_->delegate_ = NULL; diff --git a/net/websockets/websocket_throttle.cc b/net/websockets/websocket_throttle.cc index 2d62815..c714de6 100644 --- a/net/websockets/websocket_throttle.cc +++ b/net/websockets/websocket_throttle.cc @@ -54,6 +54,11 @@ WebSocketThrottle::~WebSocketThrottle() { DCHECK(addr_map_.empty()); } +// static +WebSocketThrottle* WebSocketThrottle::GetInstance() { + return Singleton<WebSocketThrottle>::get(); +} + void WebSocketThrottle::PutInQueue(WebSocketJob* job) { queue_.push_back(job); const AddressList& address_list = job->address_list(); diff --git a/net/websockets/websocket_throttle.h b/net/websockets/websocket_throttle.h index 0849834..9becc62 100644 --- a/net/websockets/websocket_throttle.h +++ b/net/websockets/websocket_throttle.h @@ -10,7 +10,8 @@ #include <string> #include "base/hash_tables.h" -#include "base/singleton.h" + +template <typename T> struct DefaultSingletonTraits; namespace net { @@ -27,6 +28,9 @@ class WebSocketJob; // for that connection to have failed. class WebSocketThrottle { public: + // Returns the singleton instance. + static WebSocketThrottle* GetInstance(); + // Puts |job| in |queue_| and queues for the destination addresses // of |job|. // If other job is using the same destination address, set |job| waiting. |