| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/thread_task_runner_handle.h" |
| 10 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 12 #include "net/socket/socket.h" | 13 #include "net/socket/socket.h" |
| 13 #include "remoting/base/compound_buffer.h" | 14 #include "remoting/base/compound_buffer.h" |
| 14 #include "remoting/proto/internal.pb.h" | 15 #include "remoting/proto/internal.pb.h" |
| 15 | 16 |
| 16 namespace remoting { | 17 namespace remoting { |
| 17 namespace protocol { | 18 namespace protocol { |
| 18 | 19 |
| 19 static const int kReadBufferSize = 4096; | 20 static const int kReadBufferSize = 4096; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 std::vector<CompoundBuffer*> new_messages; | 85 std::vector<CompoundBuffer*> new_messages; |
| 85 while (true) { | 86 while (true) { |
| 86 CompoundBuffer* buffer = message_decoder_.GetNextMessage(); | 87 CompoundBuffer* buffer = message_decoder_.GetNextMessage(); |
| 87 if (!buffer) | 88 if (!buffer) |
| 88 break; | 89 break; |
| 89 new_messages.push_back(buffer); | 90 new_messages.push_back(buffer); |
| 90 } | 91 } |
| 91 | 92 |
| 92 pending_messages_ += new_messages.size(); | 93 pending_messages_ += new_messages.size(); |
| 93 | 94 |
| 94 // TODO(lambroslambrou): MessageLoopProxy::current() will not work from the | |
| 95 // plugin thread if this code is compiled into a separate binary. Fix this. | |
| 96 for (std::vector<CompoundBuffer*>::iterator it = new_messages.begin(); | 95 for (std::vector<CompoundBuffer*>::iterator it = new_messages.begin(); |
| 97 it != new_messages.end(); ++it) { | 96 it != new_messages.end(); ++it) { |
| 98 message_received_callback_.Run( | 97 message_received_callback_.Run( |
| 99 scoped_ptr<CompoundBuffer>(*it), | 98 scoped_ptr<CompoundBuffer>(*it), |
| 100 base::Bind(&MessageReader::OnMessageDone, this, | 99 base::Bind(&MessageReader::OnMessageDone, this, |
| 101 base::MessageLoopProxy::current())); | 100 base::ThreadTaskRunnerHandle::Get())); |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 | 103 |
| 105 void MessageReader::OnMessageDone( | 104 void MessageReader::OnMessageDone( |
| 106 scoped_refptr<base::MessageLoopProxy> message_loop) { | 105 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 107 if (!message_loop->BelongsToCurrentThread()) { | 106 if (task_runner->BelongsToCurrentThread()) { |
| 108 message_loop->PostTask( | 107 ProcessDoneEvent(); |
| 109 FROM_HERE, | 108 } else { |
| 110 base::Bind(&MessageReader::OnMessageDone, this, message_loop)); | 109 task_runner->PostTask( |
| 111 return; | 110 FROM_HERE, base::Bind(&MessageReader::ProcessDoneEvent, this)); |
| 112 } | 111 } |
| 113 ProcessDoneEvent(); | |
| 114 } | 112 } |
| 115 | 113 |
| 116 void MessageReader::ProcessDoneEvent() { | 114 void MessageReader::ProcessDoneEvent() { |
| 117 pending_messages_--; | 115 pending_messages_--; |
| 118 DCHECK_GE(pending_messages_, 0); | 116 DCHECK_GE(pending_messages_, 0); |
| 119 | 117 |
| 120 DoRead(); // Start next read if neccessary. | 118 DoRead(); // Start next read if neccessary. |
| 121 } | 119 } |
| 122 | 120 |
| 123 } // namespace protocol | 121 } // namespace protocol |
| 124 } // namespace remoting | 122 } // namespace remoting |
| OLD | NEW |