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

Side by Side 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: wez feedback Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "blimp/net/blimp_connection.h" 5 #include "blimp/net/blimp_connection.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 writer_->WritePacket( 84 writer_->WritePacket(
85 scoped_refptr<net::DrainableIOBuffer>( 85 scoped_refptr<net::DrainableIOBuffer>(
86 new net::DrainableIOBuffer(buffer_.get(), message->ByteSize())), 86 new net::DrainableIOBuffer(buffer_.get(), message->ByteSize())),
87 base::Bind(&BlimpMessageSender::OnWritePacketComplete, 87 base::Bind(&BlimpMessageSender::OnWritePacketComplete,
88 weak_factory_.GetWeakPtr())); 88 weak_factory_.GetWeakPtr()));
89 } 89 }
90 90
91 void BlimpMessageSender::OnWritePacketComplete(int result) { 91 void BlimpMessageSender::OnWritePacketComplete(int result) {
92 DVLOG(2) << "OnWritePacketComplete, result=" << result; 92 DVLOG(2) << "OnWritePacketComplete, result=" << result;
93 DCHECK_NE(net::ERR_IO_PENDING, result); 93 DCHECK_NE(net::ERR_IO_PENDING, result);
94 base::ResetAndReturn(&pending_process_msg_callback_).Run(result); 94
95 if (result != net::OK) { 95 if (result != net::OK) {
96 error_observer_->OnConnectionError(result); 96 error_observer_->OnConnectionError(result);
97 return;
97 } 98 }
99
100 base::ResetAndReturn(&pending_process_msg_callback_).Run(result);
haibinlu 2016/05/03 21:23:05 nit. use net::OK instead to be specific. Also, ad
Kevin M 2016/05/24 20:47:04 Done.
98 } 101 }
99 102
100 } // namespace 103 } // namespace
101 104
102 BlimpConnection::BlimpConnection(std::unique_ptr<PacketReader> reader, 105 BlimpConnection::BlimpConnection(std::unique_ptr<PacketReader> reader,
103 std::unique_ptr<PacketWriter> writer) 106 std::unique_ptr<PacketWriter> writer)
104 : reader_(std::move(reader)), 107 : reader_(std::move(reader)),
105 message_pump_(new BlimpMessagePump(reader_.get())), 108 message_pump_(new BlimpMessagePump(reader_.get())),
106 writer_(std::move(writer)), 109 writer_(std::move(writer)) {
107 outgoing_msg_processor_(new BlimpMessageSender(writer_.get())) {
108 DCHECK(writer_); 110 DCHECK(writer_);
111 DCHECK(reader_);
109 112
110 // Observe the connection errors received by any of this connection's network
111 // objects.
112 message_pump_->set_error_observer(this); 113 message_pump_->set_error_observer(this);
113 BlimpMessageSender* sender = 114
114 static_cast<BlimpMessageSender*>(outgoing_msg_processor_.get()); 115 std::unique_ptr<BlimpMessageSender> sender(
116 new BlimpMessageSender(writer_.get()));
115 sender->set_error_observer(this); 117 sender->set_error_observer(this);
118 outgoing_msg_processor_ = std::move(sender);
116 } 119 }
117 120
118 BlimpConnection::BlimpConnection() {} 121 BlimpConnection::BlimpConnection() {}
119 122
120 BlimpConnection::~BlimpConnection() { 123 BlimpConnection::~BlimpConnection() {
121 DVLOG(1) << "BlimpConnection destroyed."; 124 DVLOG(1) << "BlimpConnection destroyed.";
122 } 125 }
123 126
124 void BlimpConnection::AddConnectionErrorObserver( 127 void BlimpConnection::AddConnectionErrorObserver(
125 ConnectionErrorObserver* observer) { 128 ConnectionErrorObserver* observer) {
(...skipping 16 matching lines...) Expand all
142 145
143 void BlimpConnection::OnConnectionError(int error) { 146 void BlimpConnection::OnConnectionError(int error) {
144 VLOG(1) << "OnConnectionError, error=" << error; 147 VLOG(1) << "OnConnectionError, error=" << error;
145 148
146 // Propagate the error to all observers. 149 // Propagate the error to all observers.
147 FOR_EACH_OBSERVER(ConnectionErrorObserver, error_observers_, 150 FOR_EACH_OBSERVER(ConnectionErrorObserver, error_observers_,
148 OnConnectionError(error)); 151 OnConnectionError(error));
149 } 152 }
150 153
151 } // namespace blimp 154 } // namespace blimp
OLDNEW
« no previous file with comments | « no previous file | blimp/net/blimp_connection_unittest.cc » ('j') | blimp/net/blimp_message_output_buffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698