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

Side by Side Diff: remoting/protocol/message_reader.cc

Issue 9827006: Refactor VideoStub interface to accept ownership of video packets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "remoting/protocol/message_reader.h" 5 #include "remoting/protocol/message_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 LOG(ERROR) << "Read() returned error " << result; 74 LOG(ERROR) << "Read() returned error " << result;
75 } 75 }
76 } 76 }
77 } 77 }
78 78
79 void MessageReader::OnDataReceived(net::IOBuffer* data, int data_size) { 79 void MessageReader::OnDataReceived(net::IOBuffer* data, int data_size) {
80 message_decoder_.AddData(data, data_size); 80 message_decoder_.AddData(data, data_size);
81 81
82 // Get list of all new messages first, and then call the callback 82 // Get list of all new messages first, and then call the callback
83 // for all of them. 83 // for all of them.
84 std::vector<CompoundBuffer*> new_messages; 84 std::vector<CompoundBuffer*> new_messages;
Alpha Left Google 2012/03/26 20:29:18 The ownership of CompoundBuffer is unclear here. I
Sergey Ulanov 2012/03/26 20:42:13 Yes this code gets ownership of these messages and
85 while (true) { 85 while (true) {
86 CompoundBuffer* buffer = message_decoder_.GetNextMessage(); 86 CompoundBuffer* buffer = message_decoder_.GetNextMessage();
87 if (!buffer) 87 if (!buffer)
88 break; 88 break;
89 new_messages.push_back(buffer); 89 new_messages.push_back(buffer);
90 } 90 }
91 91
92 pending_messages_ += new_messages.size(); 92 pending_messages_ += new_messages.size();
93 93
94 // TODO(lambroslambrou): MessageLoopProxy::current() will not work from the 94 // TODO(lambroslambrou): MessageLoopProxy::current() will not work from the
95 // plugin thread if this code is compiled into a separate binary. Fix this. 95 // plugin thread if this code is compiled into a separate binary. Fix this.
96 for (std::vector<CompoundBuffer*>::iterator it = new_messages.begin(); 96 for (std::vector<CompoundBuffer*>::iterator it = new_messages.begin();
97 it != new_messages.end(); ++it) { 97 it != new_messages.end(); ++it) {
98 message_received_callback_.Run(*it, base::Bind( 98 message_received_callback_.Run(
99 &MessageReader::OnMessageDone, this, 99 scoped_ptr<CompoundBuffer>(*it),
100 *it, base::MessageLoopProxy::current())); 100 base::Bind(&MessageReader::OnMessageDone, this,
101 base::MessageLoopProxy::current()));
101 } 102 }
102 } 103 }
103 104
104 void MessageReader::OnMessageDone( 105 void MessageReader::OnMessageDone(
105 CompoundBuffer* message,
106 scoped_refptr<base::MessageLoopProxy> message_loop) { 106 scoped_refptr<base::MessageLoopProxy> message_loop) {
107 if (!message_loop->BelongsToCurrentThread()) { 107 if (!message_loop->BelongsToCurrentThread()) {
108 message_loop->PostTask( 108 message_loop->PostTask(
109 FROM_HERE, 109 FROM_HERE,
110 base::Bind(&MessageReader::OnMessageDone, this, message, message_loop)); 110 base::Bind(&MessageReader::OnMessageDone, this, message_loop));
111 return; 111 return;
112 } 112 }
113 delete message;
114 ProcessDoneEvent(); 113 ProcessDoneEvent();
115 } 114 }
116 115
117 void MessageReader::ProcessDoneEvent() { 116 void MessageReader::ProcessDoneEvent() {
118 pending_messages_--; 117 pending_messages_--;
119 DCHECK_GE(pending_messages_, 0); 118 DCHECK_GE(pending_messages_, 0);
120 119
121 DoRead(); // Start next read if neccessary. 120 DoRead(); // Start next read if neccessary.
122 } 121 }
123 122
124 } // namespace protocol 123 } // namespace protocol
125 } // namespace remoting 124 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698