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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 if (result != net::ERR_CONNECTION_CLOSED) { | 83 if (result != net::ERR_CONNECTION_CLOSED) { |
84 LOG(ERROR) << "Read() returned error " << result; | 84 LOG(ERROR) << "Read() returned error " << result; |
85 } | 85 } |
86 // Stop reading after any error. | 86 // Stop reading after any error. |
87 closed_ = true; | 87 closed_ = true; |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 void MessageReader::OnDataReceived(net::IOBuffer* data, int data_size) { | 91 void MessageReader::OnDataReceived(net::IOBuffer* data, int data_size) { |
92 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
93 | |
94 base::TimeTicks now = base::TimeTicks::Now(); | |
95 | |
96 if (message_decoder_.is_buffer_empty()) | |
97 last_message_started_time_ = now; | |
Wez
2015/01/21 01:35:40
nit: Blank line after this?
This logic doesn't se
Sergey Ulanov
2015/01/29 01:33:29
Yes, I noticed it myself too. Fixed now and update
| |
93 message_decoder_.AddData(data, data_size); | 98 message_decoder_.AddData(data, data_size); |
94 | 99 |
95 // Get list of all new messages first, and then call the callback | 100 // Get list of all new messages first, and then call the callback |
96 // for all of them. | 101 // for all of them. |
97 while (true) { | 102 while (true) { |
98 CompoundBuffer* buffer = message_decoder_.GetNextMessage(); | 103 CompoundBuffer* buffer = message_decoder_.GetNextMessage(); |
99 if (!buffer) | 104 if (!buffer) |
100 break; | 105 break; |
101 pending_messages_++; | 106 pending_messages_++; |
107 base::TimeDelta read_delay = now - last_message_started_time_; | |
102 base::ThreadTaskRunnerHandle::Get()->PostTask( | 108 base::ThreadTaskRunnerHandle::Get()->PostTask( |
103 FROM_HERE, | 109 FROM_HERE, |
104 base::Bind(&MessageReader::RunCallback, | 110 base::Bind(&MessageReader::RunCallback, weak_factory_.GetWeakPtr(), |
105 weak_factory_.GetWeakPtr(), | 111 base::Passed(make_scoped_ptr(buffer)), read_delay)); |
106 base::Passed(make_scoped_ptr(buffer)))); | |
107 } | 112 } |
108 } | 113 } |
109 | 114 |
110 void MessageReader::RunCallback(scoped_ptr<CompoundBuffer> message) { | 115 void MessageReader::RunCallback(scoped_ptr<CompoundBuffer> message, |
111 if (!message_received_callback_.is_null()){ | 116 base::TimeDelta read_delay) { |
117 last_message_read_delay_ = read_delay; | |
118 if (!message_received_callback_.is_null()) { | |
112 message_received_callback_.Run( | 119 message_received_callback_.Run( |
113 message.Pass(), | 120 message.Pass(), |
114 base::Bind(&MessageReader::OnMessageDone, weak_factory_.GetWeakPtr())); | 121 base::Bind(&MessageReader::OnMessageDone, weak_factory_.GetWeakPtr())); |
115 } | 122 } |
116 } | 123 } |
117 | 124 |
118 void MessageReader::OnMessageDone() { | 125 void MessageReader::OnMessageDone() { |
119 DCHECK(CalledOnValidThread()); | 126 DCHECK(CalledOnValidThread()); |
120 pending_messages_--; | 127 pending_messages_--; |
121 DCHECK_GE(pending_messages_, 0); | 128 DCHECK_GE(pending_messages_, 0); |
122 | 129 |
123 // Start next read if necessary. | 130 // Start next read if necessary. |
124 DoRead(); | 131 DoRead(); |
125 } | 132 } |
126 | 133 |
127 } // namespace protocol | 134 } // namespace protocol |
128 } // namespace remoting | 135 } // namespace remoting |
OLD | NEW |