| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/server/web_socket_encoder.h" | 5 #include "net/server/web_socket_encoder.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 212 } |
| 213 | 213 |
| 214 WebSocketDeflateParameters response = offer; | 214 WebSocketDeflateParameters response = offer; |
| 215 if (offer.is_client_max_window_bits_specified() && | 215 if (offer.is_client_max_window_bits_specified() && |
| 216 !offer.has_client_max_window_bits_value()) { | 216 !offer.has_client_max_window_bits_value()) { |
| 217 // We need to choose one value for the response. | 217 // We need to choose one value for the response. |
| 218 response.SetClientMaxWindowBits(15); | 218 response.SetClientMaxWindowBits(15); |
| 219 } | 219 } |
| 220 DCHECK(response.IsValidAsResponse()); | 220 DCHECK(response.IsValidAsResponse()); |
| 221 DCHECK(offer.IsCompatibleWith(response)); | 221 DCHECK(offer.IsCompatibleWith(response)); |
| 222 auto deflater = base::WrapUnique( | 222 auto deflater = base::MakeUnique<WebSocketDeflater>( |
| 223 new WebSocketDeflater(response.server_context_take_over_mode())); | 223 response.server_context_take_over_mode()); |
| 224 auto inflater = base::WrapUnique( | 224 auto inflater = base::MakeUnique<WebSocketInflater>(kInflaterChunkSize, |
| 225 new WebSocketInflater(kInflaterChunkSize, kInflaterChunkSize)); | 225 kInflaterChunkSize); |
| 226 if (!deflater->Initialize(response.PermissiveServerMaxWindowBits()) || | 226 if (!deflater->Initialize(response.PermissiveServerMaxWindowBits()) || |
| 227 !inflater->Initialize(response.PermissiveClientMaxWindowBits())) { | 227 !inflater->Initialize(response.PermissiveClientMaxWindowBits())) { |
| 228 // For some reason we cannot accept the parameters. | 228 // For some reason we cannot accept the parameters. |
| 229 continue; | 229 continue; |
| 230 } | 230 } |
| 231 *deflate_parameters = response; | 231 *deflate_parameters = response; |
| 232 return base::WrapUnique(new WebSocketEncoder( | 232 return base::WrapUnique(new WebSocketEncoder( |
| 233 FOR_SERVER, std::move(deflater), std::move(inflater))); | 233 FOR_SERVER, std::move(deflater), std::move(inflater))); |
| 234 } | 234 } |
| 235 | 235 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 258 } | 258 } |
| 259 const auto& extension = parser.extensions()[0]; | 259 const auto& extension = parser.extensions()[0]; |
| 260 WebSocketDeflateParameters params; | 260 WebSocketDeflateParameters params; |
| 261 std::string failure_message; | 261 std::string failure_message; |
| 262 if (!params.Initialize(extension, &failure_message) || | 262 if (!params.Initialize(extension, &failure_message) || |
| 263 !params.IsValidAsResponse(&failure_message)) { | 263 !params.IsValidAsResponse(&failure_message)) { |
| 264 // TODO (yhirano): Fail the connection. | 264 // TODO (yhirano): Fail the connection. |
| 265 return base::WrapUnique(new WebSocketEncoder(FOR_CLIENT, nullptr, nullptr)); | 265 return base::WrapUnique(new WebSocketEncoder(FOR_CLIENT, nullptr, nullptr)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 auto deflater = base::WrapUnique( | 268 auto deflater = base::MakeUnique<WebSocketDeflater>( |
| 269 new WebSocketDeflater(params.client_context_take_over_mode())); | 269 params.client_context_take_over_mode()); |
| 270 auto inflater = base::WrapUnique( | 270 auto inflater = base::MakeUnique<WebSocketInflater>(kInflaterChunkSize, |
| 271 new WebSocketInflater(kInflaterChunkSize, kInflaterChunkSize)); | 271 kInflaterChunkSize); |
| 272 if (!deflater->Initialize(params.PermissiveClientMaxWindowBits()) || | 272 if (!deflater->Initialize(params.PermissiveClientMaxWindowBits()) || |
| 273 !inflater->Initialize(params.PermissiveServerMaxWindowBits())) { | 273 !inflater->Initialize(params.PermissiveServerMaxWindowBits())) { |
| 274 // TODO (yhirano): Fail the connection. | 274 // TODO (yhirano): Fail the connection. |
| 275 return base::WrapUnique(new WebSocketEncoder(FOR_CLIENT, nullptr, nullptr)); | 275 return base::WrapUnique(new WebSocketEncoder(FOR_CLIENT, nullptr, nullptr)); |
| 276 } | 276 } |
| 277 | 277 |
| 278 return base::WrapUnique(new WebSocketEncoder(FOR_CLIENT, std::move(deflater), | 278 return base::WrapUnique(new WebSocketEncoder(FOR_CLIENT, std::move(deflater), |
| 279 std::move(inflater))); | 279 std::move(inflater))); |
| 280 } | 280 } |
| 281 | 281 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 return false; | 346 return false; |
| 347 scoped_refptr<IOBufferWithSize> buffer = | 347 scoped_refptr<IOBufferWithSize> buffer = |
| 348 deflater_->GetOutput(deflater_->CurrentOutputSize()); | 348 deflater_->GetOutput(deflater_->CurrentOutputSize()); |
| 349 if (!buffer.get()) | 349 if (!buffer.get()) |
| 350 return false; | 350 return false; |
| 351 *output = std::string(buffer->data(), buffer->size()); | 351 *output = std::string(buffer->data(), buffer->size()); |
| 352 return true; | 352 return true; |
| 353 } | 353 } |
| 354 | 354 |
| 355 } // namespace net | 355 } // namespace net |
| OLD | NEW |