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_IMPL_H_ |
| 6 #define CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_IMPL_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/time/time.h" |
| 17 #include "content/common/content_export.h" |
| 18 #include "content/common/websocket.mojom.h" |
| 19 #include "mojo/public/cpp/bindings/binding.h" |
| 20 |
| 21 class GURL; |
| 22 |
| 23 namespace url { |
| 24 class Origin; |
| 25 } // namespace url |
| 26 |
| 27 namespace net { |
| 28 class WebSocketChannel; |
| 29 } // namespace net |
| 30 |
| 31 namespace content { |
| 32 class StoragePartition; |
| 33 |
| 34 // Host of net::WebSocketChannel. |
| 35 class CONTENT_EXPORT WebSocketImpl |
| 36 : NON_EXPORTED_BASE(public mojom::WebSocket) { |
| 37 public: |
| 38 class Delegate { |
| 39 public: |
| 40 virtual ~Delegate() {} |
| 41 virtual int GetClientProcessId() = 0; |
| 42 virtual StoragePartition* GetStoragePartition() = 0; |
| 43 virtual void OnReceivedResponseFromServer(WebSocketImpl* impl) = 0; |
| 44 virtual void OnLostConnectionToClient(WebSocketImpl* impl) = 0; |
| 45 }; |
| 46 |
| 47 WebSocketImpl(Delegate* delegate, |
| 48 mojom::WebSocketRequest request, |
| 49 int frame_id, |
| 50 base::TimeDelta delay); |
| 51 ~WebSocketImpl() override; |
| 52 |
| 53 // The renderer process is going away. |
| 54 // This function is virtual for testing. |
| 55 virtual void GoAway(); |
| 56 |
| 57 // mojom::WebSocket methods: |
| 58 void AddChannelRequest(const GURL& url, |
| 59 mojo::Array<mojo::String> requested_protocols, |
| 60 const url::Origin& origin, |
| 61 const GURL& first_party_for_cookies, |
| 62 const mojo::String& user_agent_override, |
| 63 mojom::WebSocketClientPtr client) override; |
| 64 void SendFrame(bool fin, mojom::WebSocketMessageType type, |
| 65 mojo::Array<uint8_t> data) override; |
| 66 void SendFlowControl(int64_t quota) override; |
| 67 void StartClosingHandshake(uint16_t code, |
| 68 const mojo::String& reason) override; |
| 69 |
| 70 bool handshake_succeeded() const { return handshake_succeeded_; } |
| 71 void OnHandshakeSucceeded() { handshake_succeeded_ = true; } |
| 72 |
| 73 protected: |
| 74 class WebSocketEventHandler; |
| 75 |
| 76 void OnConnectionError(); |
| 77 void AddChannel(const GURL& socket_url, |
| 78 const std::vector<std::string>& requested_protocols, |
| 79 const url::Origin& origin, |
| 80 const GURL& first_party_for_cookies, |
| 81 const std::string& user_agent_override); |
| 82 |
| 83 Delegate* delegate_; |
| 84 mojo::Binding<mojom::WebSocket> binding_; |
| 85 |
| 86 mojom::WebSocketClientPtr client_; |
| 87 |
| 88 // The channel we use to send events to the network. |
| 89 std::unique_ptr<net::WebSocketChannel> channel_; |
| 90 |
| 91 // Delay used for per-renderer WebSocket throttling. |
| 92 base::TimeDelta delay_; |
| 93 |
| 94 // SendFlowControl() is delayed when OnFlowControl() is called before |
| 95 // AddChannel() is called. |
| 96 // Zero indicates there is no pending SendFlowControl(). |
| 97 int64_t pending_flow_control_quota_; |
| 98 |
| 99 int frame_id_; |
| 100 |
| 101 // handshake_succeeded_ is set and used by WebSocketManager to manage |
| 102 // counters for per-renderer WebSocket throttling. |
| 103 bool handshake_succeeded_; |
| 104 |
| 105 base::WeakPtrFactory<WebSocketImpl> weak_ptr_factory_; |
| 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(WebSocketImpl); |
| 108 }; |
| 109 |
| 110 } // namespace content |
| 111 |
| 112 #endif // CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_IMPL_H_ |
OLD | NEW |