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

Unified Diff: blimp/net/blimp_connection.cc

Issue 1909143002: Use ConnectionErrorObserver, not callbacks, for error handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/common/BUILD.gn ('k') | blimp/net/blimp_connection_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/blimp_connection.cc
diff --git a/blimp/net/blimp_connection.cc b/blimp/net/blimp_connection.cc
index 792d0943730b7d7f2e20bf3865e1d352637a4039..7b79a5f3f9dc229258372d0fee0bea972600a23f 100644
--- a/blimp/net/blimp_connection.cc
+++ b/blimp/net/blimp_connection.cc
@@ -32,6 +32,8 @@ class BlimpMessageSender : public BlimpMessageProcessor {
}
// BlimpMessageProcessor implementation.
+ // |callback| receives net::OK on write success, or receives an error code
+ // otherwise.
void ProcessMessage(std::unique_ptr<BlimpMessage> message,
const net::CompletionCallback& callback) override;
@@ -90,10 +92,17 @@ void BlimpMessageSender::ProcessMessage(
void BlimpMessageSender::OnWritePacketComplete(int result) {
DVLOG(2) << "OnWritePacketComplete, result=" << result;
DCHECK_NE(net::ERR_IO_PENDING, result);
- base::ResetAndReturn(&pending_process_msg_callback_).Run(result);
+
+ // Create a stack-local copy of |pending_process_msg_callback_|, in case an
+ // observer deletes |this|.
+ net::CompletionCallback process_callback =
+ base::ResetAndReturn(&pending_process_msg_callback_);
+
if (result != net::OK) {
error_observer_->OnConnectionError(result);
}
+
+ process_callback.Run(result);
}
BlimpConnection::BlimpConnection(std::unique_ptr<PacketReader> reader,
@@ -103,9 +112,8 @@ BlimpConnection::BlimpConnection(std::unique_ptr<PacketReader> reader,
writer_(std::move(writer)),
outgoing_msg_processor_(new BlimpMessageSender(writer_.get())) {
DCHECK(writer_);
+ DCHECK(reader_);
- // Observe the connection errors received by any of this connection's network
- // objects.
message_pump_->set_error_observer(this);
outgoing_msg_processor_->set_error_observer(this);
}
« no previous file with comments | « blimp/common/BUILD.gn ('k') | blimp/net/blimp_connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698