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

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: 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;
Wez 2016/04/21 22:44:29 This changes the MessageSender to have different s
Kevin M 2016/04/22 22:10:41 Isn't it normal for an observer of an object to ha
Wez 2016/05/07 22:13:46 In most cases I'd expect that an observer might te
97 } 98 }
99
100 base::ResetAndReturn(&pending_process_msg_callback_).Run(result);
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_);
Wez 2016/04/21 22:44:29 Why do we only DCHECK(writer_), but not reader_?
Kevin M 2016/04/22 22:10:41 Done.
109 111
110 // Observe the connection errors received by any of this connection's network
111 // objects.
112 message_pump_->set_error_observer(this); 112 message_pump_->set_error_observer(this);
Wez 2016/04/21 22:44:29 Seems strange that this observer is set on the pum
Kevin M 2016/04/22 22:10:41 The use of observers is consistent here. The sende
Wez 2016/05/07 22:13:47 Acknowledged.
113 BlimpMessageSender* sender = 113
114 static_cast<BlimpMessageSender*>(outgoing_msg_processor_.get()); 114 std::unique_ptr<BlimpMessageSender> sender(
115 new BlimpMessageSender(writer_.get()));
115 sender->set_error_observer(this); 116 sender->set_error_observer(this);
117 outgoing_msg_processor_ = std::move(sender);
116 } 118 }
117 119
118 BlimpConnection::BlimpConnection() {} 120 BlimpConnection::BlimpConnection() {}
119 121
120 BlimpConnection::~BlimpConnection() { 122 BlimpConnection::~BlimpConnection() {
121 DVLOG(1) << "BlimpConnection destroyed."; 123 DVLOG(1) << "BlimpConnection destroyed.";
122 } 124 }
123 125
124 void BlimpConnection::AddConnectionErrorObserver( 126 void BlimpConnection::AddConnectionErrorObserver(
125 ConnectionErrorObserver* observer) { 127 ConnectionErrorObserver* observer) {
(...skipping 16 matching lines...) Expand all
142 144
143 void BlimpConnection::OnConnectionError(int error) { 145 void BlimpConnection::OnConnectionError(int error) {
144 VLOG(1) << "OnConnectionError, error=" << error; 146 VLOG(1) << "OnConnectionError, error=" << error;
145 147
146 // Propagate the error to all observers. 148 // Propagate the error to all observers.
147 FOR_EACH_OBSERVER(ConnectionErrorObserver, error_observers_, 149 FOR_EACH_OBSERVER(ConnectionErrorObserver, error_observers_,
148 OnConnectionError(error)); 150 OnConnectionError(error));
149 } 151 }
150 152
151 } // namespace blimp 153 } // namespace blimp
OLDNEW
« no previous file with comments | « no previous file | blimp/net/blimp_connection_unittest.cc » ('j') | blimp/net/blimp_connection_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698