Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: content/browser/websockets/websocket_impl.cc

Issue 2267233002: Change WebSocketChannel to pass data via IOBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/websockets/websocket_channel.h » ('j') | net/websockets/websocket_channel.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_impl.h" 5 #include "content/browser/websockets/websocket_impl.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "content/browser/bad_message.h" 21 #include "content/browser/bad_message.h"
22 #include "content/browser/child_process_security_policy_impl.h" 22 #include "content/browser/child_process_security_policy_impl.h"
23 #include "content/browser/ssl/ssl_error_handler.h" 23 #include "content/browser/ssl/ssl_error_handler.h"
24 #include "content/browser/ssl/ssl_manager.h" 24 #include "content/browser/ssl/ssl_manager.h"
25 #include "content/public/browser/storage_partition.h" 25 #include "content/public/browser/storage_partition.h"
26 #include "ipc/ipc_message.h" 26 #include "ipc/ipc_message.h"
27 #include "net/base/io_buffer.h"
27 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
28 #include "net/http/http_request_headers.h" 29 #include "net/http/http_request_headers.h"
29 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
30 #include "net/http/http_util.h" 31 #include "net/http/http_util.h"
31 #include "net/ssl/ssl_info.h" 32 #include "net/ssl/ssl_info.h"
32 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
33 #include "net/websockets/websocket_channel.h" 34 #include "net/websockets/websocket_channel.h"
34 #include "net/websockets/websocket_errors.h" 35 #include "net/websockets/websocket_errors.h"
35 #include "net/websockets/websocket_event_interface.h" 36 #include "net/websockets/websocket_event_interface.h"
36 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode 37 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 public: 87 public:
87 explicit WebSocketEventHandler(WebSocketImpl* impl); 88 explicit WebSocketEventHandler(WebSocketImpl* impl);
88 ~WebSocketEventHandler() override; 89 ~WebSocketEventHandler() override;
89 90
90 // net::WebSocketEventInterface implementation 91 // net::WebSocketEventInterface implementation
91 92
92 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, 93 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol,
93 const std::string& extensions) override; 94 const std::string& extensions) override;
94 ChannelState OnDataFrame(bool fin, 95 ChannelState OnDataFrame(bool fin,
95 WebSocketMessageType type, 96 WebSocketMessageType type,
96 const std::vector<char>& data) override; 97 scoped_refptr<net::IOBuffer> buffer,
98 size_t buffer_size) override;
97 ChannelState OnClosingHandshake() override; 99 ChannelState OnClosingHandshake() override;
98 ChannelState OnFlowControl(int64_t quota) override; 100 ChannelState OnFlowControl(int64_t quota) override;
99 ChannelState OnDropChannel(bool was_clean, 101 ChannelState OnDropChannel(bool was_clean,
100 uint16_t code, 102 uint16_t code,
101 const std::string& reason) override; 103 const std::string& reason) override;
102 ChannelState OnFailChannel(const std::string& message) override; 104 ChannelState OnFailChannel(const std::string& message) override;
103 ChannelState OnStartOpeningHandshake( 105 ChannelState OnStartOpeningHandshake(
104 std::unique_ptr<net::WebSocketHandshakeRequestInfo> request) override; 106 std::unique_ptr<net::WebSocketHandshakeRequestInfo> request) override;
105 ChannelState OnFinishOpeningHandshake( 107 ChannelState OnFinishOpeningHandshake(
106 std::unique_ptr<net::WebSocketHandshakeResponseInfo> response) override; 108 std::unique_ptr<net::WebSocketHandshakeResponseInfo> response) override;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 impl_->delegate_->OnReceivedResponseFromServer(impl_); 162 impl_->delegate_->OnReceivedResponseFromServer(impl_);
161 163
162 impl_->client_->OnAddChannelResponse(selected_protocol, extensions); 164 impl_->client_->OnAddChannelResponse(selected_protocol, extensions);
163 165
164 return net::WebSocketEventInterface::CHANNEL_ALIVE; 166 return net::WebSocketEventInterface::CHANNEL_ALIVE;
165 } 167 }
166 168
167 ChannelState WebSocketImpl::WebSocketEventHandler::OnDataFrame( 169 ChannelState WebSocketImpl::WebSocketEventHandler::OnDataFrame(
168 bool fin, 170 bool fin,
169 net::WebSocketFrameHeader::OpCode type, 171 net::WebSocketFrameHeader::OpCode type,
170 const std::vector<char>& data) { 172 scoped_refptr<net::IOBuffer> buffer,
173 size_t buffer_size) {
171 DVLOG(3) << "WebSocketEventHandler::OnDataFrame @" 174 DVLOG(3) << "WebSocketEventHandler::OnDataFrame @"
172 << reinterpret_cast<void*>(this) 175 << reinterpret_cast<void*>(this)
173 << " fin=" << fin 176 << " fin=" << fin
174 << " type=" << type << " data is " << data.size() << " bytes"; 177 << " type=" << type << " data is " << buffer_size << " bytes";
175 178
176 // TODO(darin): Avoid this copy. 179 // TODO(darin): Avoid this copy.
177 std::vector<uint8_t> data_to_pass(data.size()); 180 std::vector<uint8_t> data_to_pass(buffer_size);
178 std::copy(data.begin(), data.end(), data_to_pass.begin()); 181 if (buffer_size > 0) {
182 std::copy(buffer->data(), buffer->data() + buffer_size,
183 data_to_pass.begin());
184 }
179 185
180 impl_->client_->OnDataFrame(fin, OpCodeToMessageType(type), data_to_pass); 186 impl_->client_->OnDataFrame(fin, OpCodeToMessageType(type), data_to_pass);
181 187
182 return net::WebSocketEventInterface::CHANNEL_ALIVE; 188 return net::WebSocketEventInterface::CHANNEL_ALIVE;
183 } 189 }
184 190
185 ChannelState WebSocketImpl::WebSocketEventHandler::OnClosingHandshake() { 191 ChannelState WebSocketImpl::WebSocketEventHandler::OnClosingHandshake() {
186 DVLOG(3) << "WebSocketEventHandler::OnClosingHandshake @" 192 DVLOG(3) << "WebSocketEventHandler::OnClosingHandshake @"
187 << reinterpret_cast<void*>(this); 193 << reinterpret_cast<void*>(this);
188 194
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (handshake_succeeded_) { 433 if (handshake_succeeded_) {
428 DVLOG(1) << "Dropping frame sent to closed websocket"; 434 DVLOG(1) << "Dropping frame sent to closed websocket";
429 } else { 435 } else {
430 bad_message::ReceivedBadMessage( 436 bad_message::ReceivedBadMessage(
431 delegate_->GetClientProcessId(), 437 delegate_->GetClientProcessId(),
432 bad_message::WSI_UNEXPECTED_SEND_FRAME); 438 bad_message::WSI_UNEXPECTED_SEND_FRAME);
433 } 439 }
434 return; 440 return;
435 } 441 }
436 442
437 // TODO(darin): Avoid this copy. 443 scoped_refptr<net::IOBuffer> data_to_pass(new net::IOBuffer(data.size()));
yhirano 2016/09/06 12:19:48 "Avoid this copy" missing?
438 std::vector<char> data_to_pass(data.size()); 444 std::copy(data.begin(), data.end(), data_to_pass->data());
439 std::copy(data.begin(), data.end(), data_to_pass.begin());
440 445
441 channel_->SendFrame(fin, MessageTypeToOpCode(type), data_to_pass); 446 channel_->SendFrame(fin, MessageTypeToOpCode(type), std::move(data_to_pass),
447 data.size());
442 } 448 }
443 449
444 void WebSocketImpl::SendFlowControl(int64_t quota) { 450 void WebSocketImpl::SendFlowControl(int64_t quota) {
445 DVLOG(3) << "WebSocketImpl::OnFlowControl @" 451 DVLOG(3) << "WebSocketImpl::OnFlowControl @"
446 << reinterpret_cast<void*>(this) << " quota=" << quota; 452 << reinterpret_cast<void*>(this) << " quota=" << quota;
447 453
448 if (!channel_) { 454 if (!channel_) {
449 // WebSocketChannel is not yet created due to the delay introduced by 455 // WebSocketChannel is not yet created due to the delay introduced by
450 // per-renderer WebSocket throttling. 456 // per-renderer WebSocket throttling.
451 // SendFlowControl() is called after WebSocketChannel is created. 457 // SendFlowControl() is called after WebSocketChannel is created.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 net::HttpRequestHeaders::kUserAgent, 528 net::HttpRequestHeaders::kUserAgent,
523 user_agent_override.c_str()); 529 user_agent_override.c_str());
524 } 530 }
525 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin, 531 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin,
526 first_party_for_cookies, additional_headers); 532 first_party_for_cookies, additional_headers);
527 if (quota > 0) 533 if (quota > 0)
528 SendFlowControl(quota); 534 SendFlowControl(quota);
529 } 535 }
530 536
531 } // namespace content 537 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | net/websockets/websocket_channel.h » ('j') | net/websockets/websocket_channel.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698