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

Side by Side Diff: chrome/browser/extensions/api/socket/tcp_socket.cc

Issue 10790137: Adds socket.getInfo to the socket API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Check for NULL TCPSocket, updated test Created 8 years, 4 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
OLDNEW
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 "chrome/browser/extensions/api/socket/tcp_socket.h" 5 #include "chrome/browser/extensions/api/socket/tcp_socket.h"
6 6
7 #include "chrome/browser/extensions/api/api_resource.h" 7 #include "chrome/browser/extensions/api/api_resource.h"
8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" 8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h"
9 #include "net/base/address_list.h" 9 #include "net/base/address_list.h"
10 #include "net/base/ip_endpoint.h" 10 #include "net/base/ip_endpoint.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return false; 133 return false;
134 return socket_->SetKeepAlive(enable, delay); 134 return socket_->SetKeepAlive(enable, delay);
135 } 135 }
136 136
137 bool TCPSocket::SetNoDelay(bool no_delay) { 137 bool TCPSocket::SetNoDelay(bool no_delay) {
138 if (!socket_.get()) 138 if (!socket_.get())
139 return false; 139 return false;
140 return socket_->SetNoDelay(no_delay); 140 return socket_->SetNoDelay(no_delay);
141 } 141 }
142 142
143 bool TCPSocket::IsTCPSocket() {
144 return true;
145 }
146
147 bool TCPSocket::GetPeerAddress(net::IPEndPoint* address) {
148 if (!socket_.get())
149 return false;
150 return !socket_->GetPeerAddress(address);
151 }
152
153 bool TCPSocket::GetLocalAddress(net::IPEndPoint* address) {
154 if (!socket_.get())
155 return false;
156 return !socket_->GetLocalAddress(address);
157 }
158
159
143 int TCPSocket::WriteImpl(net::IOBuffer* io_buffer, 160 int TCPSocket::WriteImpl(net::IOBuffer* io_buffer,
144 int io_buffer_size, 161 int io_buffer_size,
145 const net::CompletionCallback& callback) { 162 const net::CompletionCallback& callback) {
146 if (!socket_.get() || !socket_->IsConnected()) 163 if (!socket_.get() || !socket_->IsConnected())
147 return net::ERR_SOCKET_NOT_CONNECTED; 164 return net::ERR_SOCKET_NOT_CONNECTED;
148 else 165 else
149 return socket_->Write(io_buffer, io_buffer_size, callback); 166 return socket_->Write(io_buffer, io_buffer_size, callback);
150 } 167 }
151 168
152 void TCPSocket::OnConnectComplete(int result) { 169 void TCPSocket::OnConnectComplete(int result) {
153 DCHECK(!connect_callback_.is_null()); 170 DCHECK(!connect_callback_.is_null());
154 DCHECK(!is_connected_); 171 DCHECK(!is_connected_);
155 is_connected_ = result == net::OK; 172 is_connected_ = result == net::OK;
156 connect_callback_.Run(result); 173 connect_callback_.Run(result);
157 connect_callback_.Reset(); 174 connect_callback_.Reset();
158 } 175 }
159 176
160 void TCPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, 177 void TCPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
161 int result) { 178 int result) {
162 DCHECK(!read_callback_.is_null()); 179 DCHECK(!read_callback_.is_null());
163 read_callback_.Run(result, io_buffer); 180 read_callback_.Run(result, io_buffer);
164 read_callback_.Reset(); 181 read_callback_.Reset();
165 } 182 }
166 183
167 } // namespace extensions 184 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698