| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 server_socket_ = delegate_->CreateSocketForTethering(this, &channel_name); | 54 server_socket_ = delegate_->CreateSocketForTethering(this, &channel_name); |
| 55 if (!server_socket_.get() || channel_name.empty()) | 55 if (!server_socket_.get() || channel_name.empty()) |
| 56 SelfDestruct(); | 56 SelfDestruct(); |
| 57 return channel_name; | 57 return channel_name; |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual ~SocketPump() { } | 60 virtual ~SocketPump() { } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 virtual void DidAccept(net::StreamListenSocket* server, | 63 virtual void DidAccept(net::StreamListenSocket* server, |
| 64 net::StreamListenSocket* socket) OVERRIDE { | 64 scoped_ptr<net::StreamListenSocket> socket) OVERRIDE { |
| 65 if (accepted_socket_.get()) | 65 if (accepted_socket_.get()) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 buffer_ = new net::IOBuffer(kBufferSize); | 68 buffer_ = new net::IOBuffer(kBufferSize); |
| 69 wire_buffer_ = new net::GrowableIOBuffer(); | 69 wire_buffer_ = new net::GrowableIOBuffer(); |
| 70 wire_buffer_->SetCapacity(kBufferSize); | 70 wire_buffer_->SetCapacity(kBufferSize); |
| 71 | 71 |
| 72 accepted_socket_ = socket; | 72 accepted_socket_ = socket.Pass(); |
| 73 int result = client_socket_->Read( | 73 int result = client_socket_->Read( |
| 74 buffer_.get(), | 74 buffer_.get(), |
| 75 kBufferSize, | 75 kBufferSize, |
| 76 base::Bind(&SocketPump::OnClientRead, base::Unretained(this))); | 76 base::Bind(&SocketPump::OnClientRead, base::Unretained(this))); |
| 77 if (result != net::ERR_IO_PENDING) | 77 if (result != net::ERR_IO_PENDING) |
| 78 OnClientRead(result); | 78 OnClientRead(result); |
| 79 } | 79 } |
| 80 | 80 |
| 81 virtual void DidRead(net::StreamListenSocket* socket, | 81 virtual void DidRead(net::StreamListenSocket* socket, |
| 82 const char* data, | 82 const char* data, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 void SelfDestruct() { | 151 void SelfDestruct() { |
| 152 if (wire_buffer_->offset() != wire_buffer_size_) { | 152 if (wire_buffer_->offset() != wire_buffer_size_) { |
| 153 pending_destruction_ = true; | 153 pending_destruction_ = true; |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 delete this; | 156 delete this; |
| 157 } | 157 } |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 scoped_ptr<net::StreamSocket> client_socket_; | 160 scoped_ptr<net::StreamSocket> client_socket_; |
| 161 scoped_refptr<net::StreamListenSocket> server_socket_; | 161 scoped_ptr<net::StreamListenSocket> server_socket_; |
| 162 scoped_refptr<net::StreamListenSocket> accepted_socket_; | 162 scoped_ptr<net::StreamListenSocket> accepted_socket_; |
| 163 scoped_refptr<net::IOBuffer> buffer_; | 163 scoped_refptr<net::IOBuffer> buffer_; |
| 164 scoped_refptr<net::GrowableIOBuffer> wire_buffer_; | 164 scoped_refptr<net::GrowableIOBuffer> wire_buffer_; |
| 165 DevToolsHttpHandlerDelegate* delegate_; | 165 DevToolsHttpHandlerDelegate* delegate_; |
| 166 int wire_buffer_size_; | 166 int wire_buffer_size_; |
| 167 bool pending_destruction_; | 167 bool pending_destruction_; |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 } // namespace | 170 } // namespace |
| 171 | 171 |
| 172 const char TetheringHandler::kDomain[] = "Tethering"; | 172 const char TetheringHandler::kDomain[] = "Tethering"; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 BoundSockets::iterator it = bound_sockets_.find(port); | 299 BoundSockets::iterator it = bound_sockets_.find(port); |
| 300 if (it == bound_sockets_.end()) | 300 if (it == bound_sockets_.end()) |
| 301 return command->InternalErrorResponse("Port is not bound"); | 301 return command->InternalErrorResponse("Port is not bound"); |
| 302 | 302 |
| 303 delete it->second; | 303 delete it->second; |
| 304 bound_sockets_.erase(it); | 304 bound_sockets_.erase(it); |
| 305 return command->SuccessResponse(NULL); | 305 return command->SuccessResponse(NULL); |
| 306 } | 306 } |
| 307 | 307 |
| 308 } // namespace content | 308 } // namespace content |
| OLD | NEW |