Index: net/socket/websocket_endpoint_lock_manager.h |
diff --git a/net/socket/websocket_endpoint_lock_manager.h b/net/socket/websocket_endpoint_lock_manager.h |
index d5cad508d6ad8622807a8b0f988ba771fae020db..7bdd7358204f5cbbf8a243bbe228d12d8e67d386 100644 |
--- a/net/socket/websocket_endpoint_lock_manager.h |
+++ b/net/socket/websocket_endpoint_lock_manager.h |
@@ -11,6 +11,7 @@ |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/memory/singleton.h" |
+#include "base/time/time.h" |
#include "net/base/ip_endpoint.h" |
#include "net/base/net_export.h" |
#include "net/socket/websocket_transport_client_socket_pool.h" |
@@ -45,22 +46,28 @@ class NET_EXPORT_PRIVATE WebSocketEndpointLockManager { |
// UnlockSocket(). |
void RememberSocket(StreamSocket* socket, const IPEndPoint& endpoint); |
- // Releases the lock on the endpoint that was associated with |socket| by |
- // RememberSocket(). If appropriate, triggers the next socket connection. |
- // Should be called exactly once for each |socket| that was passed to |
- // RememberSocket(). Does nothing if UnlockEndpoint() has been called since |
+ // Removes the socket association that was recorded by RememberSocket(), then |
+ // asynchronously releases the lock on the endpoint after a delay. If |
+ // appropriate, calls |waiter->GetEndpointLock()| when the lock is |
+ // released. Should be called exactly once for each |socket| that was passed |
+ // to RememberSocket(). Does nothing if UnlockEndpoint() has been called since |
// the call to RememberSocket(). |
void UnlockSocket(StreamSocket* socket); |
- // Releases the lock on |endpoint|. Does nothing if |endpoint| is not locked. |
- // Removes any socket association that was recorded with RememberSocket(). If |
- // appropriate, calls |waiter->GotEndpointLock()|. |
+ // Asynchronously releases the lock on |endpoint| after a delay. Does nothing |
+ // if |endpoint| is not locked. Removes any socket association that was |
+ // recorded with RememberSocket(). If appropriate, calls |
+ // |waiter->GotEndpointLock()| when the lock is released. |
void UnlockEndpoint(const IPEndPoint& endpoint); |
// Checks that |lock_info_map_| and |socket_lock_info_map_| are empty. For |
// tests. |
bool IsEmpty() const; |
+ // Changes the value of the unlock delay. Returns the previous value of the |
+ // delay. |
+ base::TimeDelta SetUnlockDelayForTesting(base::TimeDelta new_delay); |
+ |
private: |
struct LockInfo { |
typedef base::LinkedList<Waiter> WaiterQueue; |
@@ -97,7 +104,8 @@ class NET_EXPORT_PRIVATE WebSocketEndpointLockManager { |
WebSocketEndpointLockManager(); |
~WebSocketEndpointLockManager(); |
- void UnlockEndpointByIterator(LockInfoMap::iterator lock_info_it); |
+ void UnlockEndpointAfterDelay(const IPEndPoint& endpoint); |
+ void DelayedUnlockEndpoint(const IPEndPoint& endpoint); |
void EraseSocket(LockInfoMap::iterator lock_info_it); |
// If an entry is present in the map for a particular endpoint, then that |
@@ -111,6 +119,16 @@ class NET_EXPORT_PRIVATE WebSocketEndpointLockManager { |
// is non-NULL if and only if there is an entry in this map for the socket. |
SocketLockInfoMap socket_lock_info_map_; |
+ // Time to wait between a call to Unlock* and actually unlocking the socket. |
+ base::TimeDelta unlock_delay_; |
+ |
+ // Number of sockets currently pending unlock. |
+ size_t pending_unlock_count_; |
+ |
+ // The messsage loop holding the unlock delay callback may outlive this |
+ // object. |
+ base::WeakPtrFactory<WebSocketEndpointLockManager> weak_factory_; |
+ |
friend struct DefaultSingletonTraits<WebSocketEndpointLockManager>; |
DISALLOW_COPY_AND_ASSIGN(WebSocketEndpointLockManager); |