| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/devtools/tethering_handler.h" | 5 #include "content/browser/devtools/tethering_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 server_socket_ = delegate_->CreateSocketForTethering(this, &channel_name); | 47 server_socket_ = delegate_->CreateSocketForTethering(this, &channel_name); |
| 48 if (!server_socket_.get() || channel_name.empty()) | 48 if (!server_socket_.get() || channel_name.empty()) |
| 49 SelfDestruct(); | 49 SelfDestruct(); |
| 50 return channel_name; | 50 return channel_name; |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual ~SocketPump() { } | 53 virtual ~SocketPump() { } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 virtual void DidAccept(net::StreamListenSocket* server, | 56 virtual void DidAccept(net::StreamListenSocket* server, |
| 57 scoped_ptr<net::StreamListenSocket> socket) OVERRIDE { | 57 scoped_ptr<net::StreamListenSocket> socket) override { |
| 58 if (accepted_socket_.get()) | 58 if (accepted_socket_.get()) |
| 59 return; | 59 return; |
| 60 | 60 |
| 61 buffer_ = new net::IOBuffer(kBufferSize); | 61 buffer_ = new net::IOBuffer(kBufferSize); |
| 62 wire_buffer_ = new net::GrowableIOBuffer(); | 62 wire_buffer_ = new net::GrowableIOBuffer(); |
| 63 wire_buffer_->SetCapacity(kBufferSize); | 63 wire_buffer_->SetCapacity(kBufferSize); |
| 64 | 64 |
| 65 accepted_socket_ = socket.Pass(); | 65 accepted_socket_ = socket.Pass(); |
| 66 int result = client_socket_->Read( | 66 int result = client_socket_->Read( |
| 67 buffer_.get(), | 67 buffer_.get(), |
| 68 kBufferSize, | 68 kBufferSize, |
| 69 base::Bind(&SocketPump::OnClientRead, base::Unretained(this))); | 69 base::Bind(&SocketPump::OnClientRead, base::Unretained(this))); |
| 70 if (result != net::ERR_IO_PENDING) | 70 if (result != net::ERR_IO_PENDING) |
| 71 OnClientRead(result); | 71 OnClientRead(result); |
| 72 } | 72 } |
| 73 | 73 |
| 74 virtual void DidRead(net::StreamListenSocket* socket, | 74 virtual void DidRead(net::StreamListenSocket* socket, |
| 75 const char* data, | 75 const char* data, |
| 76 int len) OVERRIDE { | 76 int len) override { |
| 77 int old_size = wire_buffer_size_; | 77 int old_size = wire_buffer_size_; |
| 78 wire_buffer_size_ += len; | 78 wire_buffer_size_ += len; |
| 79 while (wire_buffer_->capacity() < wire_buffer_size_) | 79 while (wire_buffer_->capacity() < wire_buffer_size_) |
| 80 wire_buffer_->SetCapacity(wire_buffer_->capacity() * 2); | 80 wire_buffer_->SetCapacity(wire_buffer_->capacity() * 2); |
| 81 memcpy(wire_buffer_->StartOfBuffer() + old_size, data, len); | 81 memcpy(wire_buffer_->StartOfBuffer() + old_size, data, len); |
| 82 if (old_size != wire_buffer_->offset()) | 82 if (old_size != wire_buffer_->offset()) |
| 83 return; | 83 return; |
| 84 OnClientWrite(0); | 84 OnClientWrite(0); |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual void DidClose(net::StreamListenSocket* socket) OVERRIDE { | 87 virtual void DidClose(net::StreamListenSocket* socket) override { |
| 88 SelfDestruct(); | 88 SelfDestruct(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void OnClientRead(int result) { | 91 void OnClientRead(int result) { |
| 92 if (result <= 0) { | 92 if (result <= 0) { |
| 93 SelfDestruct(); | 93 SelfDestruct(); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 accepted_socket_->Send(buffer_->data(), result); | 97 accepted_socket_->Send(buffer_->data(), result); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 "Tethering is used by another connection"); | 409 "Tethering is used by another connection"); |
| 410 } | 410 } |
| 411 DCHECK(impl_); | 411 DCHECK(impl_); |
| 412 message_loop_proxy_->PostTask( | 412 message_loop_proxy_->PostTask( |
| 413 FROM_HERE, | 413 FROM_HERE, |
| 414 base::Bind(&TetheringImpl::Unbind, base::Unretained(impl_), command)); | 414 base::Bind(&TetheringImpl::Unbind, base::Unretained(impl_), command)); |
| 415 return command->AsyncResponsePromise(); | 415 return command->AsyncResponsePromise(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 } // namespace content | 418 } // namespace content |
| OLD | NEW |