Reland Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies.

This CL removes copy and assign support from Buffer and changes various
parameters from Buffer to CopyOnWriteBuffer so they can be passed along
and copied without actually copying the underlying data.

With this changed some parameters to be "const" and fixed an issue when
creating a CopyOnWriteBuffer with empty data.

BUG=webrtc:5155

Review URL: https://codereview.webrtc.org/1823503002

Cr-Commit-Position: refs/heads/master@{#12062}
diff --git a/webrtc/pc/channel.h b/webrtc/pc/channel.h
index 1937b04..45657f8 100644
--- a/webrtc/pc/channel.h
+++ b/webrtc/pc/channel.h
@@ -191,10 +191,10 @@
   void FlushRtcpMessages();
 
   // NetworkInterface implementation, called by MediaEngine
-  bool SendPacket(rtc::Buffer* packet,
-                          const rtc::PacketOptions& options) override;
-  bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options)
-      override;
+  bool SendPacket(rtc::CopyOnWriteBuffer* packet,
+                  const rtc::PacketOptions& options) override;
+  bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
+                const rtc::PacketOptions& options) override;
 
   // From TransportChannel
   void OnWritableState(TransportChannel* channel);
@@ -210,10 +210,10 @@
   bool PacketIsRtcp(const TransportChannel* channel, const char* data,
                     size_t len);
   bool SendPacket(bool rtcp,
-                  rtc::Buffer* packet,
+                  rtc::CopyOnWriteBuffer* packet,
                   const rtc::PacketOptions& options);
-  virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet);
-  void HandlePacket(bool rtcp, rtc::Buffer* packet,
+  virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
+  void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
                     const rtc::PacketTime& packet_time);
 
   void EnableMedia_w();
@@ -502,7 +502,7 @@
   bool Init();
 
   virtual bool SendData(const SendDataParams& params,
-                        const rtc::Buffer& payload,
+                        const rtc::CopyOnWriteBuffer& payload,
                         SendDataResult* result);
 
   void StartMediaMonitor(int cms);
@@ -516,8 +516,8 @@
   sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
   sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
       SignalConnectionMonitor;
-  sigslot::signal3<DataChannel*, const ReceiveDataParams&, const rtc::Buffer&>
-      SignalDataReceived;
+  sigslot::signal3<DataChannel*, const ReceiveDataParams&,
+      const rtc::CopyOnWriteBuffer&> SignalDataReceived;
   // Signal for notifying when the channel becomes ready to send data.
   // That occurs when the channel is enabled, the transport is writable,
   // both local and remote descriptions are set, and the channel is unblocked.
@@ -534,7 +534,7 @@
  private:
   struct SendDataMessageData : public rtc::MessageData {
     SendDataMessageData(const SendDataParams& params,
-                        const rtc::Buffer* payload,
+                        const rtc::CopyOnWriteBuffer* payload,
                         SendDataResult* result)
         : params(params),
           payload(payload),
@@ -543,7 +543,7 @@
     }
 
     const SendDataParams& params;
-    const rtc::Buffer* payload;
+    const rtc::CopyOnWriteBuffer* payload;
     SendDataResult* result;
     bool succeeded;
   };
@@ -558,7 +558,7 @@
           payload(data, len) {
     }
     const ReceiveDataParams params;
-    const rtc::Buffer payload;
+    const rtc::CopyOnWriteBuffer payload;
   };
 
   typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
@@ -581,7 +581,7 @@
                                   ContentAction action,
                                   std::string* error_desc);
   virtual void ChangeState();
-  virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet);
+  virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
 
   virtual void OnMessage(rtc::Message* pmsg);
   virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const;