OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_MANAGER_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/timer/timer.h" |
| 13 #include "content/browser/websockets/websocket_impl.h" |
| 14 #include "content/common/content_export.h" |
| 15 |
| 16 namespace shell { |
| 17 class InterfaceRegistry; |
| 18 } // namespace shell |
| 19 |
| 20 namespace content { |
| 21 class StoragePartition; |
| 22 |
| 23 // The WebSocketManager is a per child process instance that manages the |
| 24 // lifecycle of WebSocketImpl objects. It is responsible for creating |
| 25 // WebSocketImpl objects for each WebSocketRequest and throttling the number of |
| 26 // WebSocketImpl objects in use. |
| 27 class CONTENT_EXPORT WebSocketManager |
| 28 : NON_EXPORTED_BASE(public WebSocketImpl::Delegate) { |
| 29 public: |
| 30 // Called on the UI thread: |
| 31 static void CreateWebSocket(int process_id, int frame_id, |
| 32 mojom::WebSocketRequest request); |
| 33 |
| 34 protected: |
| 35 class Handle; |
| 36 friend class base::DeleteHelper<WebSocketManager>; |
| 37 |
| 38 // Called on the UI thread: |
| 39 WebSocketManager(int process_id, StoragePartition* storage_partition); |
| 40 |
| 41 // All other methods must run on the IO thread. |
| 42 |
| 43 ~WebSocketManager() override; |
| 44 void DoCreateWebSocket(int frame_id, mojom::WebSocketRequest request); |
| 45 base::TimeDelta CalculateDelay() const; |
| 46 void ThrottlingPeriodTimerCallback(); |
| 47 |
| 48 // This is virtual to support testing. |
| 49 virtual WebSocketImpl* CreateWebSocketImpl(WebSocketImpl::Delegate* delegate, |
| 50 mojom::WebSocketRequest request, |
| 51 int frame_id, |
| 52 base::TimeDelta delay); |
| 53 |
| 54 // WebSocketImpl::Delegate methods: |
| 55 int GetClientProcessId() override; |
| 56 StoragePartition* GetStoragePartition() override; |
| 57 void OnReceivedResponseFromServer(WebSocketImpl* impl) override; |
| 58 void OnLostConnectionToClient(WebSocketImpl* impl) override; |
| 59 |
| 60 int process_id_; |
| 61 StoragePartition* storage_partition_; |
| 62 |
| 63 std::set<WebSocketImpl*> impls_; |
| 64 |
| 65 // Timer and counters for per-renderer WebSocket throttling. |
| 66 base::RepeatingTimer throttling_period_timer_; |
| 67 |
| 68 // The current number of pending connections. |
| 69 int num_pending_connections_; |
| 70 |
| 71 // The number of handshakes that failed in the current and previous time |
| 72 // period. |
| 73 int64_t num_current_succeeded_connections_; |
| 74 int64_t num_previous_succeeded_connections_; |
| 75 |
| 76 // The number of handshakes that succeeded in the current and previous time |
| 77 // period. |
| 78 int64_t num_current_failed_connections_; |
| 79 int64_t num_previous_failed_connections_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(WebSocketManager); |
| 82 }; |
| 83 |
| 84 } // namespace content |
| 85 |
| 86 #endif // CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_MANAGER_H_ |
OLD | NEW |