| 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 blink::mojom::WebSocketRequest request) { | 56 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( | 105 void WebSocketManager::DoCreateWebSocket(int frame_id, |
| 106 int frame_id, | 106 mojom::WebSocketRequest request) { |
| 107 blink::mojom::WebSocketRequest request) { | |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 109 | 108 |
| 110 if (num_pending_connections_ >= kMaxPendingWebSocketConnections) { | 109 if (num_pending_connections_ >= kMaxPendingWebSocketConnections) { |
| 111 // Too many websockets! By returning here, we let |request| die, which | 110 // Too many websockets! By returning here, we let |request| die, which |
| 112 // will be observed by the client as Mojo connection error. | 111 // will be observed by the client as Mojo connection error. |
| 113 return; | 112 return; |
| 114 } | 113 } |
| 115 | 114 |
| 116 // Keep all WebSocketImpls alive until either the client drops its | 115 // Keep all WebSocketImpls alive until either the client drops its |
| 117 // connection (see OnLostConnectionToClient) or we need to shutdown. | 116 // connection (see OnLostConnectionToClient) or we need to shutdown. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 150 |
| 152 if (num_pending_connections_ == 0 && | 151 if (num_pending_connections_ == 0 && |
| 153 num_previous_failed_connections_ == 0 && | 152 num_previous_failed_connections_ == 0 && |
| 154 num_previous_succeeded_connections_ == 0) { | 153 num_previous_succeeded_connections_ == 0) { |
| 155 throttling_period_timer_.Stop(); | 154 throttling_period_timer_.Stop(); |
| 156 } | 155 } |
| 157 } | 156 } |
| 158 | 157 |
| 159 WebSocketImpl* WebSocketManager::CreateWebSocketImpl( | 158 WebSocketImpl* WebSocketManager::CreateWebSocketImpl( |
| 160 WebSocketImpl::Delegate* delegate, | 159 WebSocketImpl::Delegate* delegate, |
| 161 blink::mojom::WebSocketRequest request, | 160 mojom::WebSocketRequest request, |
| 162 int frame_id, | 161 int frame_id, |
| 163 base::TimeDelta delay) { | 162 base::TimeDelta delay) { |
| 164 return new WebSocketImpl(delegate, std::move(request), frame_id, delay); | 163 return new WebSocketImpl(delegate, std::move(request), frame_id, delay); |
| 165 } | 164 } |
| 166 | 165 |
| 167 int WebSocketManager::GetClientProcessId() { | 166 int WebSocketManager::GetClientProcessId() { |
| 168 return process_id_; | 167 return process_id_; |
| 169 } | 168 } |
| 170 | 169 |
| 171 StoragePartition* WebSocketManager::GetStoragePartition() { | 170 StoragePartition* WebSocketManager::GetStoragePartition() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 187 --num_pending_connections_; | 186 --num_pending_connections_; |
| 188 DCHECK_GE(num_pending_connections_, 0); | 187 DCHECK_GE(num_pending_connections_, 0); |
| 189 ++num_current_failed_connections_; | 188 ++num_current_failed_connections_; |
| 190 } | 189 } |
| 191 impl->GoAway(); | 190 impl->GoAway(); |
| 192 impls_.erase(impl); | 191 impls_.erase(impl); |
| 193 delete impl; | 192 delete impl; |
| 194 } | 193 } |
| 195 | 194 |
| 196 } // namespace content | 195 } // namespace content |
| OLD | NEW |