| OLD | NEW |
| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |