| Index: content/browser/renderer_host/websocket_host.h
|
| diff --git a/content/browser/renderer_host/websocket_host.h b/content/browser/renderer_host/websocket_host.h
|
| index efdc9d1bd000ef1e56abd46f2808fb62724092ad..cca9cdb76a7bb3e4e05235531bea57a02743b55c 100644
|
| --- a/content/browser/renderer_host/websocket_host.h
|
| +++ b/content/browser/renderer_host/websocket_host.h
|
| @@ -60,6 +60,49 @@ class CONTENT_EXPORT WebSocketHost {
|
| void OnHandshakeSucceeded() { handshake_succeeded_ = true; }
|
|
|
| private:
|
| + using ReceiveQuotaProvider = int64_t;
|
| + using ReceiveQuotaConsumer = int64_t;
|
| +
|
| + // This class provides an abstraction for when there are multiple active
|
| + // providers of receive quota, but only one can actual consume receive quota
|
| + // (ie. receive messages) at any one time.
|
| + class ReceiveQuotaMultiplexer {
|
| + public:
|
| + ReceiveQuotaMultiplexer();
|
| +
|
| + // set_channel must be called before any other methods.
|
| + void set_channel(net::WebSocketChannel* channel) { channel_ = channel; }
|
| +
|
| + // Adds quota for ReceiveQuotaProvider |provider|. The amount is actually
|
| + // updated by this method. If |provider| is also the current quota consumer,
|
| + // returns true. May provide |channel_| with more quota.
|
| + bool AddQuota(ReceiveQuotaProvider* provider, int64_t quota);
|
| +
|
| + // Returns the quota available from the currently active quota consumer. In
|
| + // other words, how many bytes of data may be sent to the consumer right
|
| + // now.
|
| + int64_t AvailableQuota() const;
|
| +
|
| + // Marks some quota as consumed. To be called this after sending some data
|
| + // to the current consumer.
|
| + void ConsumedQuota(int64_t quota);
|
| +
|
| + // Set the current consumer. The pointer remains owned by the caller, and
|
| + // must remain valid until this method is called again, or the class is
|
| + // destroyed.
|
| + void SetConsumer(ReceiveQuotaConsumer* consumer);
|
| +
|
| + private:
|
| + // Calls channel_->SendFlowControl() if appropriate.
|
| + void PublishMoreQuotaIfNeeded();
|
| +
|
| + net::WebSocketChannel* channel_;
|
| + int64_t published_quota_;
|
| + ReceiveQuotaConsumer* current_consumer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ReceiveQuotaMultiplexer);
|
| + };
|
| +
|
| // Handlers for each message type, dispatched by OnMessageReceived(), as
|
| // defined in content/common/websocket_messages.h
|
|
|
| @@ -105,6 +148,8 @@ class CONTENT_EXPORT WebSocketHost {
|
| // to manage counters for per-renderer WebSocket throttling.
|
| bool handshake_succeeded_;
|
|
|
| + ReceiveQuotaMultiplexer receive_quota_multiplexer_;
|
| +
|
| base::WeakPtrFactory<WebSocketHost> weak_ptr_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(WebSocketHost);
|
|
|