| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/websockets/websocket_manager.h" | 5 #include "content/browser/websockets/websocket_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, manager_); | 46 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, manager_); |
| 47 manager_ = nullptr; | 47 manager_ = nullptr; |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 WebSocketManager* manager_; | 51 WebSocketManager* manager_; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // static | 54 // static |
| 55 void WebSocketManager::CreateWebSocket(int process_id, int frame_id, | 55 void WebSocketManager::CreateWebSocket(int process_id, int frame_id, |
| 56 mojom::WebSocketRequest request) { | 56 blink::mojom::WebSocketRequest request) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 | 58 |
| 59 RenderProcessHost* host = RenderProcessHost::FromID(process_id); | 59 RenderProcessHost* host = RenderProcessHost::FromID(process_id); |
| 60 DCHECK(host); | 60 DCHECK(host); |
| 61 | 61 |
| 62 // Maintain a WebSocketManager per RenderProcessHost. While the instance of | 62 // Maintain a WebSocketManager per RenderProcessHost. While the instance of |
| 63 // WebSocketManager is allocated on the UI thread, it must only be used and | 63 // WebSocketManager is allocated on the UI thread, it must only be used and |
| 64 // deleted from the IO thread. | 64 // deleted from the IO thread. |
| 65 | 65 |
| 66 Handle* handle = | 66 Handle* handle = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 95 | 95 |
| 96 WebSocketManager::~WebSocketManager() { | 96 WebSocketManager::~WebSocketManager() { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 98 | 98 |
| 99 for (auto impl : impls_) { | 99 for (auto impl : impls_) { |
| 100 impl->GoAway(); | 100 impl->GoAway(); |
| 101 delete impl; | 101 delete impl; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 void WebSocketManager::DoCreateWebSocket(int frame_id, | 105 void WebSocketManager::DoCreateWebSocket( |
| 106 mojom::WebSocketRequest request) { | 106 int frame_id, |
| 107 blink::mojom::WebSocketRequest request) { |
| 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 108 | 109 |
| 109 if (num_pending_connections_ >= kMaxPendingWebSocketConnections) { | 110 if (num_pending_connections_ >= kMaxPendingWebSocketConnections) { |
| 110 // Too many websockets! By returning here, we let |request| die, which | 111 // Too many websockets! By returning here, we let |request| die, which |
| 111 // will be observed by the client as Mojo connection error. | 112 // will be observed by the client as Mojo connection error. |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 | 115 |
| 115 // Keep all WebSocketImpls alive until either the client drops its | 116 // Keep all WebSocketImpls alive until either the client drops its |
| 116 // connection (see OnLostConnectionToClient) or we need to shutdown. | 117 // connection (see OnLostConnectionToClient) or we need to shutdown. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 151 |
| 151 if (num_pending_connections_ == 0 && | 152 if (num_pending_connections_ == 0 && |
| 152 num_previous_failed_connections_ == 0 && | 153 num_previous_failed_connections_ == 0 && |
| 153 num_previous_succeeded_connections_ == 0) { | 154 num_previous_succeeded_connections_ == 0) { |
| 154 throttling_period_timer_.Stop(); | 155 throttling_period_timer_.Stop(); |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 | 158 |
| 158 WebSocketImpl* WebSocketManager::CreateWebSocketImpl( | 159 WebSocketImpl* WebSocketManager::CreateWebSocketImpl( |
| 159 WebSocketImpl::Delegate* delegate, | 160 WebSocketImpl::Delegate* delegate, |
| 160 mojom::WebSocketRequest request, | 161 blink::mojom::WebSocketRequest request, |
| 161 int frame_id, | 162 int frame_id, |
| 162 base::TimeDelta delay) { | 163 base::TimeDelta delay) { |
| 163 return new WebSocketImpl(delegate, std::move(request), frame_id, delay); | 164 return new WebSocketImpl(delegate, std::move(request), frame_id, delay); |
| 164 } | 165 } |
| 165 | 166 |
| 166 int WebSocketManager::GetClientProcessId() { | 167 int WebSocketManager::GetClientProcessId() { |
| 167 return process_id_; | 168 return process_id_; |
| 168 } | 169 } |
| 169 | 170 |
| 170 StoragePartition* WebSocketManager::GetStoragePartition() { | 171 StoragePartition* WebSocketManager::GetStoragePartition() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 186 --num_pending_connections_; | 187 --num_pending_connections_; |
| 187 DCHECK_GE(num_pending_connections_, 0); | 188 DCHECK_GE(num_pending_connections_, 0); |
| 188 ++num_current_failed_connections_; | 189 ++num_current_failed_connections_; |
| 189 } | 190 } |
| 190 impl->GoAway(); | 191 impl->GoAway(); |
| 191 impls_.erase(impl); | 192 impls_.erase(impl); |
| 192 delete impl; | 193 delete impl; |
| 193 } | 194 } |
| 194 | 195 |
| 195 } // namespace content | 196 } // namespace content |
| OLD | NEW |