rtc::Buffer: Remove backwards compatibility band-aids

This CL makes two changes to rtc::Buffer that have had to wait for
Chromium's use of it to be modernized:

  1. Change default return type of rtc::Buffer::data() from char* to
     uint8_t*. uint8_t is a more natural type for bytes, and won't
     accidentally convert to a string. (Chromium previously expected
     the default return type to be char, which is why
     rtc::Buffer::data() initially got char as default return type in
     9478437f, but that's been fixed now.)

  2. Stop accepting void* inputs in constructors and methods. While
     this is convenient, it's also dangerous since any pointer type
     will implicitly convert to void*.

R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/44269004

Cr-Commit-Position: refs/heads/master@{#9121}
diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc
index 1ce65fa..0034f15 100644
--- a/talk/session/media/channel.cc
+++ b/talk/session/media/channel.cc
@@ -512,7 +512,7 @@
   // Protect if needed.
   if (srtp_filter_.IsActive()) {
     bool res;
-    uint8_t* data = packet->data<uint8_t>();
+    uint8_t* data = packet->data();
     int len = static_cast<int>(packet->size());
     if (!rtcp) {
     // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done
diff --git a/webrtc/base/buffer.h b/webrtc/base/buffer.h
index 8959b40..8071701 100644
--- a/webrtc/base/buffer.h
+++ b/webrtc/base/buffer.h
@@ -40,20 +40,6 @@
   using t = decltype(F(static_cast<T*>(nullptr)));
 };
 
-// Deprecated: Accept void* in addition to the byte-sized types.
-// TODO(kwiberg): Remove once Chromium doesn't need this anymore.
-template <typename T>
-struct ByteTypeOrVoid {
- private:
-  static int F(uint8_t*);
-  static int F(int8_t*);
-  static int F(char*);
-  static int F(void*);
-
- public:
-  using t = decltype(F(static_cast<T*>(nullptr)));
-};
-
 }  // namespace internal
 
 // Basic buffer class, can be grown and shrunk dynamically.
@@ -70,10 +56,10 @@
 
   // Construct a buffer and copy the specified number of bytes into it. The
   // source array may be (const) uint8_t*, int8_t*, or char*.
-  template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
+  template <typename T, typename internal::ByteType<T>::t = 0>
   Buffer(const T* data, size_t size)
       : Buffer(data, size, size) {}
-  template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
+  template <typename T, typename internal::ByteType<T>::t = 0>
   Buffer(const T* data, size_t size, size_t capacity)
       : Buffer(size, capacity) {
     std::memcpy(data_.get(), data, size);
@@ -86,15 +72,14 @@
 
   ~Buffer();
 
-  // Get a pointer to the data. Just .data() will give you a (const) char*,
-  // but you may also use .data<int8_t>() and .data<uint8_t>().
-  // TODO(kwiberg): Change default to uint8_t
-  template <typename T = char, typename internal::ByteType<T>::t = 0>
+  // Get a pointer to the data. Just .data() will give you a (const) uint8_t*,
+  // but you may also use .data<int8_t>() and .data<char>().
+  template <typename T = uint8_t, typename internal::ByteType<T>::t = 0>
   const T* data() const {
     assert(IsConsistent());
     return reinterpret_cast<T*>(data_.get());
   }
-  template <typename T = char, typename internal::ByteType<T>::t = 0>
+  template <typename T = uint8_t, typename internal::ByteType<T>::t = 0>
   T* data() {
     assert(IsConsistent());
     return reinterpret_cast<T*>(data_.get());
@@ -133,7 +118,7 @@
 
   // Replace the contents of the buffer. Accepts the same types as the
   // constructors.
-  template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
+  template <typename T, typename internal::ByteType<T>::t = 0>
   void SetData(const T* data, size_t size) {
     assert(IsConsistent());
     size_ = 0;
@@ -146,7 +131,7 @@
   void SetData(const Buffer& buf) { SetData(buf.data(), buf.size()); }
 
   // Append data to the buffer. Accepts the same types as the constructors.
-  template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
+  template <typename T, typename internal::ByteType<T>::t = 0>
   void AppendData(const T* data, size_t size) {
     assert(IsConsistent());
     const size_t new_size = size_ + size;
diff --git a/webrtc/base/buffer_unittest.cc b/webrtc/base/buffer_unittest.cc
index 963209c..f1ae6b8 100644
--- a/webrtc/base/buffer_unittest.cc
+++ b/webrtc/base/buffer_unittest.cc
@@ -137,11 +137,11 @@
 
 TEST(BufferTest, TestMoveConstruct) {
   Buffer buf1(kTestData, 3, 40);
-  const uint8_t* data = buf1.data<uint8_t>();
+  const uint8_t* data = buf1.data();
   Buffer buf2(buf1.Pass());
   EXPECT_EQ(buf2.size(), 3u);
   EXPECT_EQ(buf2.capacity(), 40u);
-  EXPECT_EQ(buf2.data<uint8_t>(), data);
+  EXPECT_EQ(buf2.data(), data);
   buf1.Clear();
   EXPECT_EQ(buf1.size(), 0u);
   EXPECT_EQ(buf1.capacity(), 0u);
@@ -150,12 +150,12 @@
 
 TEST(BufferTest, TestMoveAssign) {
   Buffer buf1(kTestData, 3, 40);
-  const uint8_t* data = buf1.data<uint8_t>();
+  const uint8_t* data = buf1.data();
   Buffer buf2(kTestData);
   buf2 = buf1.Pass();
   EXPECT_EQ(buf2.size(), 3u);
   EXPECT_EQ(buf2.capacity(), 40u);
-  EXPECT_EQ(buf2.data<uint8_t>(), data);
+  EXPECT_EQ(buf2.data(), data);
   buf1.Clear();
   EXPECT_EQ(buf1.size(), 0u);
   EXPECT_EQ(buf1.capacity(), 0u);
@@ -165,16 +165,16 @@
 TEST(BufferTest, TestSwap) {
   Buffer buf1(kTestData, 3);
   Buffer buf2(kTestData, 6, 40);
-  uint8_t* data1 = buf1.data<uint8_t>();
-  uint8_t* data2 = buf2.data<uint8_t>();
+  uint8_t* data1 = buf1.data();
+  uint8_t* data2 = buf2.data();
   using std::swap;
   swap(buf1, buf2);
   EXPECT_EQ(buf1.size(), 6u);
   EXPECT_EQ(buf1.capacity(), 40u);
-  EXPECT_EQ(buf1.data<uint8_t>(), data2);
+  EXPECT_EQ(buf1.data(), data2);
   EXPECT_EQ(buf2.size(), 3u);
   EXPECT_EQ(buf2.capacity(), 3u);
-  EXPECT_EQ(buf2.data<uint8_t>(), data1);
+  EXPECT_EQ(buf2.data(), data1);
 }
 
 }  // namespace rtc
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc
index 9b168fe..566772a 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc
@@ -82,7 +82,7 @@
     packets_sent_++;
     rtc::Buffer* buffer =
         new rtc::Buffer(reinterpret_cast<const uint8_t*>(data), len);
-    last_sent_packet_ = buffer->data<uint8_t>();
+    last_sent_packet_ = buffer->data();
     last_sent_packet_len_ = len;
     total_bytes_sent_ += len;
     sent_packets_.push_back(buffer);