| 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 "content/renderer/media/rtc_data_channel_handler.h" | 5 #include "content/renderer/media/rtc_data_channel_handler.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 DVLOG(3) << "setClient " << client; | 170 DVLOG(3) << "setClient " << client; |
| 171 webkit_client_ = client; | 171 webkit_client_ = client; |
| 172 if (!client && observer_.get()) { | 172 if (!client && observer_.get()) { |
| 173 observer_->Unregister(); | 173 observer_->Unregister(); |
| 174 observer_ = nullptr; | 174 observer_ = nullptr; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 blink::WebString RtcDataChannelHandler::label() { | 178 blink::WebString RtcDataChannelHandler::label() { |
| 179 DCHECK(thread_checker_.CalledOnValidThread()); | 179 DCHECK(thread_checker_.CalledOnValidThread()); |
| 180 return base::UTF8ToUTF16(channel()->label()); | 180 return blink::WebString::fromUTF8(channel()->label()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool RtcDataChannelHandler::isReliable() { | 183 bool RtcDataChannelHandler::isReliable() { |
| 184 DCHECK(thread_checker_.CalledOnValidThread()); | 184 DCHECK(thread_checker_.CalledOnValidThread()); |
| 185 return channel()->reliable(); | 185 return channel()->reliable(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool RtcDataChannelHandler::ordered() const { | 188 bool RtcDataChannelHandler::ordered() const { |
| 189 DCHECK(thread_checker_.CalledOnValidThread()); | 189 DCHECK(thread_checker_.CalledOnValidThread()); |
| 190 return channel()->ordered(); | 190 return channel()->ordered(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 unsigned short RtcDataChannelHandler::maxRetransmitTime() const { | 193 unsigned short RtcDataChannelHandler::maxRetransmitTime() const { |
| 194 DCHECK(thread_checker_.CalledOnValidThread()); | 194 DCHECK(thread_checker_.CalledOnValidThread()); |
| 195 return channel()->maxRetransmitTime(); | 195 return channel()->maxRetransmitTime(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 unsigned short RtcDataChannelHandler::maxRetransmits() const { | 198 unsigned short RtcDataChannelHandler::maxRetransmits() const { |
| 199 DCHECK(thread_checker_.CalledOnValidThread()); | 199 DCHECK(thread_checker_.CalledOnValidThread()); |
| 200 return channel()->maxRetransmits(); | 200 return channel()->maxRetransmits(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 blink::WebString RtcDataChannelHandler::protocol() const { | 203 blink::WebString RtcDataChannelHandler::protocol() const { |
| 204 DCHECK(thread_checker_.CalledOnValidThread()); | 204 DCHECK(thread_checker_.CalledOnValidThread()); |
| 205 return base::UTF8ToUTF16(channel()->protocol()); | 205 return blink::WebString::fromUTF8(channel()->protocol()); |
| 206 } | 206 } |
| 207 | 207 |
| 208 bool RtcDataChannelHandler::negotiated() const { | 208 bool RtcDataChannelHandler::negotiated() const { |
| 209 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
| 210 return channel()->negotiated(); | 210 return channel()->negotiated(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 unsigned short RtcDataChannelHandler::id() const { | 213 unsigned short RtcDataChannelHandler::id() const { |
| 214 DCHECK(thread_checker_.CalledOnValidThread()); | 214 DCHECK(thread_checker_.CalledOnValidThread()); |
| 215 return channel()->id(); | 215 return channel()->id(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 unsigned long RtcDataChannelHandler::bufferedAmount() { | 250 unsigned long RtcDataChannelHandler::bufferedAmount() { |
| 251 DCHECK(thread_checker_.CalledOnValidThread()); | 251 DCHECK(thread_checker_.CalledOnValidThread()); |
| 252 return channel()->buffered_amount(); | 252 return channel()->buffered_amount(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 bool RtcDataChannelHandler::sendStringData(const blink::WebString& data) { | 255 bool RtcDataChannelHandler::sendStringData(const blink::WebString& data) { |
| 256 DCHECK(thread_checker_.CalledOnValidThread()); | 256 DCHECK(thread_checker_.CalledOnValidThread()); |
| 257 std::string utf8_buffer = base::UTF16ToUTF8(base::StringPiece16(data)); | 257 std::string utf8_buffer = data.utf8(); |
| 258 webrtc::DataBuffer data_buffer(utf8_buffer); | 258 webrtc::DataBuffer data_buffer(utf8_buffer); |
| 259 RecordMessageSent(data_buffer.size()); | 259 RecordMessageSent(data_buffer.size()); |
| 260 return channel()->Send(data_buffer); | 260 return channel()->Send(data_buffer); |
| 261 } | 261 } |
| 262 | 262 |
| 263 bool RtcDataChannelHandler::sendRawData(const char* data, size_t length) { | 263 bool RtcDataChannelHandler::sendRawData(const char* data, size_t length) { |
| 264 DCHECK(thread_checker_.CalledOnValidThread()); | 264 DCHECK(thread_checker_.CalledOnValidThread()); |
| 265 rtc::CopyOnWriteBuffer buffer(data, length); | 265 rtc::CopyOnWriteBuffer buffer(data, length); |
| 266 webrtc::DataBuffer data_buffer(buffer, true); | 266 webrtc::DataBuffer data_buffer(buffer, true); |
| 267 RecordMessageSent(data_buffer.size()); | 267 RecordMessageSent(data_buffer.size()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 if (buffer->binary) { | 328 if (buffer->binary) { |
| 329 webkit_client_->didReceiveRawData(buffer->data.data<char>(), | 329 webkit_client_->didReceiveRawData(buffer->data.data<char>(), |
| 330 buffer->data.size()); | 330 buffer->data.size()); |
| 331 } else { | 331 } else { |
| 332 base::string16 utf16; | 332 base::string16 utf16; |
| 333 if (!base::UTF8ToUTF16(buffer->data.data<char>(), buffer->data.size(), | 333 if (!base::UTF8ToUTF16(buffer->data.data<char>(), buffer->data.size(), |
| 334 &utf16)) { | 334 &utf16)) { |
| 335 LOG(ERROR) << "Failed convert received data to UTF16"; | 335 LOG(ERROR) << "Failed convert received data to UTF16"; |
| 336 return; | 336 return; |
| 337 } | 337 } |
| 338 webkit_client_->didReceiveStringData(utf16); | 338 webkit_client_->didReceiveStringData(blink::WebString::fromUTF16(utf16)); |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 | 341 |
| 342 void RtcDataChannelHandler::RecordMessageSent(size_t num_bytes) { | 342 void RtcDataChannelHandler::RecordMessageSent(size_t num_bytes) { |
| 343 DCHECK(thread_checker_.CalledOnValidThread()); | 343 DCHECK(thread_checker_.CalledOnValidThread()); |
| 344 // Currently, messages are capped at some fairly low limit (16 Kb?) | 344 // Currently, messages are capped at some fairly low limit (16 Kb?) |
| 345 // but we may allow unlimited-size messages at some point, so making | 345 // but we may allow unlimited-size messages at some point, so making |
| 346 // the histogram maximum quite large (100 Mb) to have some | 346 // the histogram maximum quite large (100 Mb) to have some |
| 347 // granularity at the higher end in that eventuality. The histogram | 347 // granularity at the higher end in that eventuality. The histogram |
| 348 // buckets are exponentially growing in size, so we'll still have | 348 // buckets are exponentially growing in size, so we'll still have |
| 349 // good granularity at the low end. | 349 // good granularity at the low end. |
| 350 | 350 |
| 351 // This makes the last bucket in the histogram count messages from | 351 // This makes the last bucket in the histogram count messages from |
| 352 // 100 Mb to infinity. | 352 // 100 Mb to infinity. |
| 353 const int kMaxBucketSize = 100 * 1024 * 1024; | 353 const int kMaxBucketSize = 100 * 1024 * 1024; |
| 354 const int kNumBuckets = 50; | 354 const int kNumBuckets = 50; |
| 355 | 355 |
| 356 if (channel()->reliable()) { | 356 if (channel()->reliable()) { |
| 357 UMA_HISTOGRAM_CUSTOM_COUNTS("WebRTC.ReliableDataChannelMessageSize", | 357 UMA_HISTOGRAM_CUSTOM_COUNTS("WebRTC.ReliableDataChannelMessageSize", |
| 358 num_bytes, | 358 num_bytes, |
| 359 1, kMaxBucketSize, kNumBuckets); | 359 1, kMaxBucketSize, kNumBuckets); |
| 360 } else { | 360 } else { |
| 361 UMA_HISTOGRAM_CUSTOM_COUNTS("WebRTC.UnreliableDataChannelMessageSize", | 361 UMA_HISTOGRAM_CUSTOM_COUNTS("WebRTC.UnreliableDataChannelMessageSize", |
| 362 num_bytes, | 362 num_bytes, |
| 363 1, kMaxBucketSize, kNumBuckets); | 363 1, kMaxBucketSize, kNumBuckets); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace content | 367 } // namespace content |
| OLD | NEW |