diff options
22 files changed, 138 insertions, 60 deletions
diff --git a/chrome/common/service_process_util.cc b/chrome/common/service_process_util.cc index 489610a..81899b6 100644 --- a/chrome/common/service_process_util.cc +++ b/chrome/common/service_process_util.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/path_service.h" #include "base/process_util.h" +#include "base/singleton.h" #include "base/string16.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -156,6 +157,11 @@ ServiceProcessState::~ServiceProcessState() { TearDownState(); } +// static +ServiceProcessState* ServiceProcessState::GetInstance() { + return Singleton<ServiceProcessState>::get(); +} + bool ServiceProcessState::Initialize() { if (!TakeSingletonLock()) { return false; diff --git a/chrome/common/service_process_util.h b/chrome/common/service_process_util.h index 28304e1..6f2685e 100644 --- a/chrome/common/service_process_util.h +++ b/chrome/common/service_process_util.h @@ -12,6 +12,8 @@ #include "base/shared_memory.h" #include "base/task.h" +template <typename T> struct DefaultSingletonTraits; + // Return the IPC channel to connect to the service process. // std::string GetServiceProcessChannelName(); @@ -48,11 +50,11 @@ bool ForceServiceProcessShutdown(const std::string& version); // and this class are shared. class ServiceProcessState { public: - ServiceProcessState(); - ~ServiceProcessState(); + // Returns the singleton instance. + static ServiceProcessState* GetInstance(); // Tries to become the sole service process for the current user data dir. - // Returns false is another service process is already running. + // Returns false if another service process is already running. bool Initialize(); // Signal that the service process is ready. @@ -69,7 +71,10 @@ class ServiceProcessState { // Unregister the service process to run on startup. bool RemoveFromAutoRun(); + private: + ServiceProcessState(); + ~ServiceProcessState(); // Create the shared memory data for the service process. bool CreateSharedData(); @@ -95,6 +100,8 @@ class ServiceProcessState { struct StateData; StateData* state_; scoped_ptr<base::SharedMemory> shared_mem_service_data_; + + friend struct DefaultSingletonTraits<ServiceProcessState>; }; #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ diff --git a/chrome/common/service_process_util_unittest.cc b/chrome/common/service_process_util_unittest.cc index 6000b5c..58b68e1 100644 --- a/chrome/common/service_process_util_unittest.cc +++ b/chrome/common/service_process_util_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/at_exit.h" #include "base/process_util.h" #include "base/string_util.h" #include "chrome/common/chrome_version_info.h" @@ -18,18 +19,28 @@ TEST(ServiceProcessUtilTest, ScopedVersionedName) { EXPECT_NE(std::string::npos, scoped_name.find(version_info.Version())); } +class ServiceProcessStateTest : public testing::Test { + private: + // This is used to release the ServiceProcessState singleton after each test. + base::ShadowingAtExitManager at_exit_manager_; +}; + #if defined(OS_WIN) // Singleton-ness is only implemented on Windows. -TEST(ServiceProcessStateTest, Singleton) { +// TODO(sanjeev): Rewrite this test to spawn a new process and test using the +// ServiceProcessState singleton across processes. +/* +TEST_F(ServiceProcessStateTest, Singleton) { ServiceProcessState state; EXPECT_TRUE(state.Initialize()); // The second instance should fail to Initialize. ServiceProcessState another_state; EXPECT_FALSE(another_state.Initialize()); } +*/ #endif // defined(OS_WIN) -TEST(ServiceProcessStateTest, ReadyState) { +TEST_F(ServiceProcessStateTest, ReadyState) { #if defined(OS_WIN) // On Posix, we use a lock file on disk to signal readiness. This lock file // could be lying around from previous crashes which could cause @@ -38,15 +49,15 @@ TEST(ServiceProcessStateTest, ReadyState) { // Posix, this check will only execute on Windows. EXPECT_FALSE(CheckServiceProcessReady()); #endif // defined(OS_WIN) - ServiceProcessState state; - EXPECT_TRUE(state.Initialize()); - state.SignalReady(NULL); + ServiceProcessState* state = ServiceProcessState::GetInstance(); + EXPECT_TRUE(state->Initialize()); + state->SignalReady(NULL); EXPECT_TRUE(CheckServiceProcessReady()); - state.SignalStopped(); + state->SignalStopped(); EXPECT_FALSE(CheckServiceProcessReady()); } -TEST(ServiceProcessStateTest, SharedMem) { +TEST_F(ServiceProcessStateTest, SharedMem) { #if defined(OS_WIN) // On Posix, named shared memory uses a file on disk. This file // could be lying around from previous crashes which could cause @@ -55,8 +66,8 @@ TEST(ServiceProcessStateTest, SharedMem) { // implementation on Posix, this check will only execute on Windows. EXPECT_EQ(0, GetServiceProcessPid()); #endif // defined(OS_WIN) - ServiceProcessState state; - EXPECT_TRUE(state.Initialize()); + ServiceProcessState* state = ServiceProcessState::GetInstance(); + EXPECT_TRUE(state->Initialize()); EXPECT_EQ(base::GetCurrentProcId(), GetServiceProcessPid()); } diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc index 96e7ea6..366021b 100644 --- a/chrome/service/service_main.cc +++ b/chrome/service/service_main.cc @@ -17,7 +17,7 @@ // Mainline routine for running as the service process. int ServiceProcessMain(const MainFunctionParams& parameters) { // If there is already a service process running, quit now. - if (!Singleton<ServiceProcessState>::get()->Initialize()) + if (!ServiceProcessState::GetInstance()->Initialize()) return 0; MessageLoopForUI main_message_loop; diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index 3699555..e826c1f 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -136,7 +136,7 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop, // After the IPC server has started we signal that the service process is // ready. - Singleton<ServiceProcessState>::get()->SignalReady( + ServiceProcessState::GetInstance()->SignalReady( NewRunnableMethod(this, &ServiceProcess::Shutdown)); // See if we need to stay running. @@ -162,7 +162,7 @@ bool ServiceProcess::Teardown() { // might use it have been shut down. network_change_notifier_.reset(); - Singleton<ServiceProcessState>::get()->SignalStopped(); + ServiceProcessState::GetInstance()->SignalStopped(); return true; } @@ -207,7 +207,7 @@ void ServiceProcess::OnCloudPrintProxyDisabled() { void ServiceProcess::OnServiceEnabled() { enabled_services_++; if (1 == enabled_services_) { - Singleton<ServiceProcessState>::get()->AddToAutoRun(); + ServiceProcessState::GetInstance()->AddToAutoRun(); } } @@ -215,7 +215,7 @@ void ServiceProcess::OnServiceDisabled() { DCHECK_NE(enabled_services_, 0); enabled_services_--; if (0 == enabled_services_) { - Singleton<ServiceProcessState>::get()->RemoveFromAutoRun(); + ServiceProcessState::GetInstance()->RemoveFromAutoRun(); // We will wait for some time to respond to IPCs before shutting down. ScheduleShutdownCheck(); } diff --git a/net/base/bandwidth_metrics.cc b/net/base/bandwidth_metrics.cc new file mode 100644 index 0000000..eaaa3c0 --- /dev/null +++ b/net/base/bandwidth_metrics.cc @@ -0,0 +1,15 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/singleton.h" +#include "net/base/bandwidth_metrics.h" + +namespace net { + +ScopedBandwidthMetrics::ScopedBandwidthMetrics() + : metrics_(Singleton<BandwidthMetrics>::get()), + started_(false) { +} + +} // namespace net diff --git a/net/base/bandwidth_metrics.h b/net/base/bandwidth_metrics.h index 80fa005..aef366d 100644 --- a/net/base/bandwidth_metrics.h +++ b/net/base/bandwidth_metrics.h @@ -121,9 +121,7 @@ class BandwidthMetrics { // ensure we always stop them. class ScopedBandwidthMetrics { public: - explicit ScopedBandwidthMetrics(BandwidthMetrics* metrics) - : metrics_(metrics), started_(false) { - } + ScopedBandwidthMetrics(); ~ScopedBandwidthMetrics() { if (started_) diff --git a/net/net.gyp b/net/net.gyp index 447c4f6..82359ab 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -29,6 +29,8 @@ 'base/address_list_net_log_param.h', 'base/auth.cc', 'base/auth.h', + 'base/bandwidth_metrics.cc', + 'base/bandwidth_metrics.h', 'base/cache_type.h', 'base/capturing_net_log.cc', 'base/capturing_net_log.h', diff --git a/net/socket_stream/socket_stream_job.cc b/net/socket_stream/socket_stream_job.cc index 8d1da73..6636233 100644 --- a/net/socket_stream/socket_stream_job.cc +++ b/net/socket_stream/socket_stream_job.cc @@ -9,20 +9,17 @@ namespace net { -static SocketStreamJobManager* GetJobManager() { - return Singleton<SocketStreamJobManager>::get(); -} - // static SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory( const std::string& scheme, ProtocolFactory* factory) { - return GetJobManager()->RegisterProtocolFactory(scheme, factory); + return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory( + scheme, factory); } // static SocketStreamJob* SocketStreamJob::CreateSocketStreamJob( const GURL& url, SocketStream::Delegate* delegate) { - return GetJobManager()->CreateJob(url, delegate); + return SocketStreamJobManager::GetInstance()->CreateJob(url, delegate); } SocketStreamJob::SocketStreamJob() {} diff --git a/net/socket_stream/socket_stream_job_manager.cc b/net/socket_stream/socket_stream_job_manager.cc index 7dd0d6b..de2f0a8 100644 --- a/net/socket_stream/socket_stream_job_manager.cc +++ b/net/socket_stream/socket_stream_job_manager.cc @@ -4,6 +4,8 @@ #include "net/socket_stream/socket_stream_job_manager.h" +#include "base/singleton.h" + namespace net { SocketStreamJobManager::SocketStreamJobManager() { @@ -12,6 +14,11 @@ SocketStreamJobManager::SocketStreamJobManager() { SocketStreamJobManager::~SocketStreamJobManager() { } +// static +SocketStreamJobManager* SocketStreamJobManager::GetInstance() { + return Singleton<SocketStreamJobManager>::get(); +} + SocketStreamJob* SocketStreamJobManager::CreateJob( const GURL& url, SocketStream::Delegate* delegate) const { // If url is invalid, create plain SocketStreamJob, which will close diff --git a/net/socket_stream/socket_stream_job_manager.h b/net/socket_stream/socket_stream_job_manager.h index 1150058..fbd572d 100644 --- a/net/socket_stream/socket_stream_job_manager.h +++ b/net/socket_stream/socket_stream_job_manager.h @@ -12,14 +12,15 @@ #include "net/socket_stream/socket_stream.h" #include "net/socket_stream/socket_stream_job.h" +template <typename T> struct DefaultSingletonTraits; class GURL; namespace net { class SocketStreamJobManager { public: - SocketStreamJobManager(); - ~SocketStreamJobManager(); + // Returns the singleton instance. + static SocketStreamJobManager* GetInstance(); SocketStreamJob* CreateJob( const GURL& url, SocketStream::Delegate* delegate) const; @@ -28,8 +29,12 @@ class SocketStreamJobManager { const std::string& scheme, SocketStreamJob::ProtocolFactory* factory); private: + friend struct DefaultSingletonTraits<SocketStreamJobManager>; typedef std::map<std::string, SocketStreamJob::ProtocolFactory*> FactoryMap; + SocketStreamJobManager(); + ~SocketStreamJobManager(); + mutable Lock lock_; FactoryMap factories_; diff --git a/net/spdy/spdy_stream.cc b/net/spdy/spdy_stream.cc index 8a5d4a4..3900993 100644 --- a/net/spdy/spdy_stream.cc +++ b/net/spdy/spdy_stream.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "base/message_loop.h" -#include "base/singleton.h" #include "base/values.h" #include "net/spdy/spdy_session.h" @@ -47,7 +46,6 @@ SpdyStream::SpdyStream(SpdySession* session, send_window_size_(spdy::kSpdyStreamInitialWindowSize), recv_window_size_(spdy::kSpdyStreamInitialWindowSize), pushed_(pushed), - metrics_(Singleton<BandwidthMetrics>::get()), response_received_(false), session_(session), delegate_(NULL), diff --git a/net/url_request/https_prober.cc b/net/url_request/https_prober.cc index 4388294..bdafcf6 100644 --- a/net/url_request/https_prober.cc +++ b/net/url_request/https_prober.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/singleton.h" #include "net/url_request/https_prober.h" #include "net/url_request/url_request.h" @@ -15,6 +16,11 @@ HTTPSProber::HTTPSProber() { HTTPSProber::~HTTPSProber() { } +// static +HTTPSProber* HTTPSProber::GetInstance() { + return Singleton<HTTPSProber>::get(); +} + bool HTTPSProber::HaveProbed(const std::string& host) const { return probed_.find(host) != probed_.end(); } diff --git a/net/url_request/https_prober.h b/net/url_request/https_prober.h index 1667911..5d1a6222 100644 --- a/net/url_request/https_prober.h +++ b/net/url_request/https_prober.h @@ -10,10 +10,10 @@ #include <set> #include <string> -#include "base/singleton.h" #include "base/task.h" #include "net/url_request/url_request.h" +template <typename T> struct DefaultSingletonTraits; class URLRequestContext; namespace net { @@ -33,8 +33,8 @@ class HTTPSProberDelegate { // transparently upgrading from HTTP to HTTPS (for example, for SPDY). class HTTPSProber : public net::URLRequest::Delegate { public: - HTTPSProber(); - ~HTTPSProber(); + // Returns the singleton instance. + static HTTPSProber* GetInstance(); // HaveProbed returns true if the given host is known to have been probed // since the browser was last started. @@ -62,6 +62,9 @@ class HTTPSProber : public net::URLRequest::Delegate { virtual void OnReadCompleted(net::URLRequest* request, int bytes_read); private: + HTTPSProber(); + ~HTTPSProber(); + void Success(net::URLRequest* request); void Failure(net::URLRequest* request); void DoCallback(net::URLRequest* request, bool result); diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index b71e764..26a9da2 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -29,10 +29,6 @@ namespace { // Max number of http redirects to follow. Same number as gecko. const int kMaxRedirects = 20; -URLRequestJobManager* GetJobManager() { - return Singleton<URLRequestJobManager>::get(); -} - // Discard headers which have meaning in POST (Content-Length, Content-Type, // Origin). void StripPostSpecificHeaders(net::HttpRequestHeaders* headers) { @@ -130,17 +126,19 @@ URLRequest::~URLRequest() { // static URLRequest::ProtocolFactory* URLRequest::RegisterProtocolFactory( const string& scheme, ProtocolFactory* factory) { - return GetJobManager()->RegisterProtocolFactory(scheme, factory); + return URLRequestJobManager::GetInstance()->RegisterProtocolFactory(scheme, + factory); } // static void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { - GetJobManager()->RegisterRequestInterceptor(interceptor); + URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); } // static void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { - GetJobManager()->UnregisterRequestInterceptor(interceptor); + URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( + interceptor); } void URLRequest::AppendBytesToUpload(const char* bytes, int bytes_len) { @@ -264,7 +262,7 @@ int URLRequest::GetResponseCode() { // static bool URLRequest::IsHandledProtocol(const std::string& scheme) { - return GetJobManager()->SupportsScheme(scheme); + return URLRequestJobManager::GetInstance()->SupportsScheme(scheme); } // static @@ -279,12 +277,12 @@ bool URLRequest::IsHandledURL(const GURL& url) { // static void URLRequest::AllowFileAccess() { - GetJobManager()->set_enable_file_access(true); + URLRequestJobManager::GetInstance()->set_enable_file_access(true); } // static bool URLRequest::IsFileAccessAllowed() { - return GetJobManager()->enable_file_access(); + return URLRequestJobManager::GetInstance()->enable_file_access(); } @@ -318,7 +316,7 @@ GURL URLRequest::GetSanitizedReferrer() const { } void URLRequest::Start() { - StartJob(GetJobManager()->CreateJob(this)); + StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); } /////////////////////////////////////////////////////////////////////////////// @@ -353,7 +351,7 @@ void URLRequest::StartJob(URLRequestJob* job) { void URLRequest::Restart() { // Should only be called if the original job didn't make any progress. DCHECK(job_ && !job_->has_response_started()); - RestartWithJob(GetJobManager()->CreateJob(this)); + RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob(this)); } void URLRequest::RestartWithJob(URLRequestJob *job) { @@ -427,7 +425,9 @@ void URLRequest::StopCaching() { } void URLRequest::ReceivedRedirect(const GURL& location, bool* defer_redirect) { - URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location); + URLRequestJob* job = + URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(this, + location); if (job) { RestartWithJob(job); } else if (delegate_) { @@ -441,7 +441,8 @@ void URLRequest::ResponseStarted() { params = new net::NetLogIntegerParameter("net_error", status_.os_error()); net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START_JOB, params); - URLRequestJob* job = GetJobManager()->MaybeInterceptResponse(this); + URLRequestJob* job = + URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this); if (job) { RestartWithJob(job); } else if (delegate_) { diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index c951088..f2b1b4f 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -937,7 +937,7 @@ void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { // At this point, we have a request for opportunistic encryption over HTTP. // In this case we need to probe to check that we can make HTTPS // connections to that host. - net::HTTPSProber* const prober = Singleton<net::HTTPSProber>::get(); + net::HTTPSProber* const prober = net::HTTPSProber::GetInstance(); if (prober->HaveProbed(request_info_.url.host()) || prober->InFlight(request_info_.url.host())) { continue; diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc index 1bc0be1..117c15a 100644 --- a/net/url_request/url_request_job_manager.cc +++ b/net/url_request/url_request_job_manager.cc @@ -7,6 +7,7 @@ #include <algorithm> #include "build/build_config.h" +#include "base/singleton.h" #include "base/string_util.h" #include "net/base/load_flags.h" #include "net/base/net_errors.h" @@ -45,6 +46,11 @@ URLRequestJobManager::URLRequestJobManager() : enable_file_access_(false) { URLRequestJobManager::~URLRequestJobManager() {} +// static +URLRequestJobManager* URLRequestJobManager::GetInstance() { + return Singleton<URLRequestJobManager>::get(); +} + URLRequestJob* URLRequestJobManager::CreateJob(net::URLRequest* request) const { #ifndef NDEBUG DCHECK(IsAllowedThread()); diff --git a/net/url_request/url_request_job_manager.h b/net/url_request/url_request_job_manager.h index 6d2421a..1e56b12 100644 --- a/net/url_request/url_request_job_manager.h +++ b/net/url_request/url_request_job_manager.h @@ -14,6 +14,8 @@ #include "base/platform_thread.h" #include "net/url_request/url_request.h" +template <typename T> struct DefaultSingletonTraits; + // This class is responsible for managing the set of protocol factories and // request interceptors that determine how an URLRequestJob gets created to // handle an net::URLRequest. @@ -27,8 +29,8 @@ // class URLRequestJobManager { public: - URLRequestJobManager(); - ~URLRequestJobManager(); + // Returns the singleton instance. + static URLRequestJobManager* GetInstance(); // Instantiate an URLRequestJob implementation based on the registered // interceptors and protocol factories. This will always succeed in @@ -67,6 +69,10 @@ class URLRequestJobManager { private: typedef std::map<std::string, net::URLRequest::ProtocolFactory*> FactoryMap; typedef std::vector<net::URLRequest::Interceptor*> InterceptorList; + friend struct DefaultSingletonTraits<URLRequestJobManager>; + + URLRequestJobManager(); + ~URLRequestJobManager(); mutable Lock lock_; FactoryMap factories_; 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. |