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

Unified Diff: blimp/net/blimp_message_pump.cc

Issue 1452823011: Make PacketReader/PacketWriter interfaces async-only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address wez,haibin feedback Created 5 years, 1 month 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
Index: blimp/net/blimp_message_pump.cc
diff --git a/blimp/net/blimp_message_pump.cc b/blimp/net/blimp_message_pump.cc
index 14d8d2eec875d712d06741ff198a333ac99d4460..b6d0724c3eb04621573214cce61cf4a5b7212995 100644
--- a/blimp/net/blimp_message_pump.cc
+++ b/blimp/net/blimp_message_pump.cc
@@ -40,36 +40,32 @@ void BlimpMessagePump::ReadNextPacket() {
buffer_->set_offset(0);
read_packet_callback_.Reset(base::Bind(
&BlimpMessagePump::OnReadPacketComplete, base::Unretained(this)));
- int result =
- reader_->ReadPacket(buffer_.get(), read_packet_callback_.callback());
- if (result != net::ERR_IO_PENDING) {
- // Read completed synchronously.
- OnReadPacketComplete(result);
- }
+ reader_->ReadPacket(buffer_.get(), read_packet_callback_.callback());
Wez 2015/11/30 21:33:24 See my other comment re cancellable callbacks.
Kevin M 2015/12/01 01:50:27 Done.
}
void BlimpMessagePump::OnReadPacketComplete(int result) {
- if (result > 0) {
- // The result is the size of the packet in bytes.
+ if (result == net::OK) {
scoped_ptr<BlimpMessage> message(new BlimpMessage);
- bool parse_result =
- message->ParseFromArray(buffer_->StartOfBuffer(), result);
- if (parse_result) {
+ if (message->ParseFromArray(buffer_->StartOfBuffer(), buffer_->offset())) {
process_msg_callback_.Reset(base::Bind(
&BlimpMessagePump::OnProcessMessageComplete, base::Unretained(this)));
processor_->ProcessMessage(message.Pass(),
process_msg_callback_.callback());
return;
+ } else {
Wez 2015/11/30 21:33:24 Never use constructs of the form if (condition) {
Kevin M 2015/12/01 01:50:27 Done.
+ result = net::ERR_FAILED;
}
- result = net::ERR_FAILED;
}
+
+ // Error reporting.
+ DCHECK_NE(net::OK, result);
if (error_observer_)
error_observer_->OnConnectionError(result);
}
void BlimpMessagePump::OnProcessMessageComplete(int result) {
// No error is expected from the message receiver.
- DCHECK_EQ(result, net::OK);
+ DCHECK_EQ(net::OK, result);
ReadNextPacket();
}

Powered by Google App Engine
This is Rietveld 408576698