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

Unified Diff: blimp/net/blimp_connection.cc

Issue 1551583003: Implementation and fixes for Blimp client/engine E2E communication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dtrainor-linux-cl1528243002
Patch Set: Created 5 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
Index: blimp/net/blimp_connection.cc
diff --git a/blimp/net/blimp_connection.cc b/blimp/net/blimp_connection.cc
index dd4002114a8f4db801dd331b78182cc0c7b6793f..7aa3a1dc2024d967ebf09b42395c5ba820057b20 100644
--- a/blimp/net/blimp_connection.cc
+++ b/blimp/net/blimp_connection.cc
@@ -7,6 +7,7 @@
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "blimp/common/proto/blimp_message.pb.h"
#include "blimp/net/blimp_message_processor.h"
@@ -38,46 +39,56 @@ class BlimpMessageSender : public BlimpMessageProcessor {
void OnWritePacketComplete(int result);
PacketWriter* writer_;
- ConnectionErrorObserver* error_observer_;
- scoped_refptr<net::DrainableIOBuffer> buffer_;
haibinlu 2015/12/29 00:51:45 can you sync to the head? The base seems out-of-da
Kevin M 2015/12/30 23:08:49 Done.
+ ConnectionErrorObserver* error_observer_ = nullptr;
+ scoped_refptr<net::IOBuffer> buffer_;
net::CompletionCallback pending_process_msg_callback_;
+ base::WeakPtrFactory<BlimpMessageSender> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(BlimpMessageSender);
};
BlimpMessageSender::BlimpMessageSender(PacketWriter* writer)
: writer_(writer),
- buffer_(new net::DrainableIOBuffer(
- new net::IOBuffer(kMaxPacketPayloadSizeBytes),
- kMaxPacketPayloadSizeBytes)) {
+ buffer_(new net::IOBuffer(kMaxPacketPayloadSizeBytes)),
+ weak_factory_(this) {
DCHECK(writer_);
}
-BlimpMessageSender::~BlimpMessageSender() {}
+BlimpMessageSender::~BlimpMessageSender() {
+ DVLOG(1) << "BlimpMessageSender destroyed.";
+}
void BlimpMessageSender::ProcessMessage(
scoped_ptr<BlimpMessage> message,
const net::CompletionCallback& callback) {
+ DCHECK(error_observer_);
+ DVLOG(2) << "ProcessMessage, size=" << message->ByteSize();
if (message->ByteSize() > static_cast<int>(kMaxPacketPayloadSizeBytes)) {
DLOG(ERROR) << "Message is too big, size=" << message->ByteSize();
callback.Run(net::ERR_MSG_TOO_BIG);
return;
}
- buffer_->SetOffset(0);
- if (!message->SerializeToArray(buffer_->data(), message->ByteSize())) {
+ scoped_refptr<net::DrainableIOBuffer> drainable_buffer(
+ new net::DrainableIOBuffer(buffer_.get(), message->ByteSize()));
+ if (!message->SerializeToArray(drainable_buffer->data(),
+ message->GetCachedSize())) {
DLOG(ERROR) << "Failed to serialize message.";
callback.Run(net::ERR_INVALID_ARGUMENT);
return;
}
+ // Check that no other message writes are in-flight at this time.
+ DCHECK(pending_process_msg_callback_.is_null());
pending_process_msg_callback_ = callback;
- writer_->WritePacket(buffer_,
+
+ writer_->WritePacket(drainable_buffer,
base::Bind(&BlimpMessageSender::OnWritePacketComplete,
- base::Unretained(this)));
+ weak_factory_.GetWeakPtr()));
}
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);
if (result != net::OK) {
@@ -98,7 +109,9 @@ BlimpConnection::BlimpConnection(scoped_ptr<PacketReader> reader,
BlimpConnection::BlimpConnection() {}
-BlimpConnection::~BlimpConnection() {}
+BlimpConnection::~BlimpConnection() {
+ DVLOG(1) << "BlimpConnection destroyed.";
+}
void BlimpConnection::SetConnectionErrorObserver(
ConnectionErrorObserver* observer) {

Powered by Google App Engine
This is Rietveld 408576698