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

Unified Diff: content/browser/renderer_host/p2p/socket_host_test_utils.h

Issue 8801005: base::Bind: Convert Socket::Read. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/web_socket_proxy.cc ('k') | jingle/glue/channel_socket_adapter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/p2p/socket_host_test_utils.h
diff --git a/content/browser/renderer_host/p2p/socket_host_test_utils.h b/content/browser/renderer_host/p2p/socket_host_test_utils.h
index bb05a30146a6f5f03a641b235bd1c6a12b965008..0f1aeb4ce86583f562e46c5f3f636c510fb3838c 100644
--- a/content/browser/renderer_host/p2p/socket_host_test_utils.h
+++ b/content/browser/renderer_host/p2p/socket_host_test_utils.h
@@ -55,9 +55,11 @@ class FakeSocket : public net::StreamSocket {
void SetPeerAddress(const net::IPEndPoint& peer_address);
void SetLocalAddress(const net::IPEndPoint& local_address);
- // net::Socket interface.
+ // net::Socket implementation.
virtual int Read(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE;
+ net::OldCompletionCallback* callback) OVERRIDE;
+ virtual int Read(net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
net::OldCompletionCallback* callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
@@ -81,7 +83,8 @@ class FakeSocket : public net::StreamSocket {
bool read_pending_;
scoped_refptr<net::IOBuffer> read_buffer_;
int read_buffer_size_;
- net::OldCompletionCallback* read_callback_;
+ net::OldCompletionCallback* old_read_callback_;
+ net::CompletionCallback read_callback_;
std::string* written_data_;
std::string input_data_;
@@ -112,9 +115,15 @@ void FakeSocket::AppendInputData(const char* data, int data_size) {
memcpy(read_buffer_->data(), &input_data_[0] + input_pos_, result);
input_pos_ += result;
read_buffer_ = NULL;
- net::OldCompletionCallback* cb = read_callback_;
- read_callback_ = NULL;
- cb->Run(result);
+ if (old_read_callback_) {
+ net::OldCompletionCallback* cb = old_read_callback_;
+ old_read_callback_ = NULL;
+ cb->Run(result);
+ } else {
+ net::CompletionCallback cb = read_callback_;
+ read_callback_.Reset();
+ cb.Run(result);
+ }
}
}
@@ -139,6 +148,23 @@ int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
read_pending_ = true;
read_buffer_ = buf;
read_buffer_size_ = buf_len;
+ old_read_callback_ = callback;
+ return net::ERR_IO_PENDING;
+ }
+}
+int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
+ DCHECK(buf);
+ if (input_pos_ < static_cast<int>(input_data_.size())){
+ int result = std::min(buf_len,
+ static_cast<int>(input_data_.size()) - input_pos_);
+ memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result);
+ input_pos_ += result;
+ return result;
+ } else {
+ read_pending_ = true;
+ read_buffer_ = buf;
+ read_buffer_size_ = buf_len;
read_callback_ = callback;
return net::ERR_IO_PENDING;
}
« no previous file with comments | « chrome/browser/chromeos/web_socket_proxy.cc ('k') | jingle/glue/channel_socket_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698