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 "extensions/browser/api/socket/socket.h" | 5 #include "extensions/browser/api/socket/socket.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "extensions/browser/api/api_resource_manager.h" | 9 #include "extensions/browser/api/api_resource_manager.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 int result = | 57 int result = |
58 WriteImpl(io_buffer_write_.get(), | 58 WriteImpl(io_buffer_write_.get(), |
59 request.byte_count - request.bytes_written, | 59 request.byte_count - request.bytes_written, |
60 base::Bind(&Socket::OnWriteComplete, base::Unretained(this))); | 60 base::Bind(&Socket::OnWriteComplete, base::Unretained(this))); |
61 | 61 |
62 if (result != net::ERR_IO_PENDING) | 62 if (result != net::ERR_IO_PENDING) |
63 OnWriteComplete(result); | 63 OnWriteComplete(result); |
64 } | 64 } |
65 | 65 |
66 void Socket::OnWriteComplete(int result) { | 66 void Socket::OnWriteComplete(int result) { |
67 io_buffer_write_ = NULL; | 67 io_buffer_write_ = nullptr; |
68 | 68 |
69 WriteRequest& request = write_queue_.front(); | 69 WriteRequest& request = write_queue_.front(); |
70 | 70 |
71 if (result >= 0) { | 71 if (result >= 0) { |
72 request.bytes_written += result; | 72 request.bytes_written += result; |
73 if (request.bytes_written < request.byte_count) { | 73 if (request.bytes_written < request.byte_count) { |
74 WriteData(); | 74 WriteData(); |
75 return; | 75 return; |
76 } | 76 } |
77 DCHECK(request.bytes_written == request.byte_count); | 77 DCHECK(request.bytes_written == request.byte_count); |
(...skipping 13 matching lines...) Expand all Loading... |
91 | 91 |
92 int Socket::Listen(const std::string& address, | 92 int Socket::Listen(const std::string& address, |
93 int port, | 93 int port, |
94 int backlog, | 94 int backlog, |
95 std::string* error_msg) { | 95 std::string* error_msg) { |
96 *error_msg = kSocketTypeNotSupported; | 96 *error_msg = kSocketTypeNotSupported; |
97 return net::ERR_FAILED; | 97 return net::ERR_FAILED; |
98 } | 98 } |
99 | 99 |
100 void Socket::Accept(const AcceptCompletionCallback& callback) { | 100 void Socket::Accept(const AcceptCompletionCallback& callback) { |
101 callback.Run(net::ERR_FAILED, NULL); | 101 callback.Run(net::ERR_FAILED, nullptr); |
102 } | 102 } |
103 | 103 |
104 // static | 104 // static |
105 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str, | 105 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str, |
106 int port, | 106 int port, |
107 net::IPEndPoint* ip_end_point) { | 107 net::IPEndPoint* ip_end_point) { |
108 DCHECK(ip_end_point); | 108 DCHECK(ip_end_point); |
109 net::IPAddressNumber ip_number; | 109 net::IPAddressNumber ip_number; |
110 if (!net::ParseIPLiteralToNumber(ip_address_str, &ip_number)) | 110 if (!net::ParseIPLiteralToNumber(ip_address_str, &ip_number)) |
111 return false; | 111 return false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 int byte_count, | 143 int byte_count, |
144 const CompletionCallback& callback) | 144 const CompletionCallback& callback) |
145 : io_buffer(io_buffer), | 145 : io_buffer(io_buffer), |
146 byte_count(byte_count), | 146 byte_count(byte_count), |
147 callback(callback), | 147 callback(callback), |
148 bytes_written(0) {} | 148 bytes_written(0) {} |
149 | 149 |
150 Socket::WriteRequest::~WriteRequest() {} | 150 Socket::WriteRequest::~WriteRequest() {} |
151 | 151 |
152 } // namespace extensions | 152 } // namespace extensions |
OLD | NEW |