Introduce BYPASS_PROXY_CONSTMETHOD0.

This allows const getters that query const state to be called without
marshalling calls between threads. This must not be used to
return pointers/references etc.

I'm starting by using this macro with the data channel which has a
few of these getters, as well as changing things a bit to make more
parts of the implementation, const.

Change-Id: I6ec7a3774cd8f7be2ef122fb7c7fc5919afee600
Bug: webrtc:11547
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176846
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31489}
diff --git a/api/proxy.h b/api/proxy.h
index 385992e..b1ebe31 100644
--- a/api/proxy.h
+++ b/api/proxy.h
@@ -55,6 +55,7 @@
 #include <memory>
 #include <string>
 #include <tuple>
+#include <type_traits>
 #include <utility>
 
 #include "api/scoped_refptr.h"
@@ -396,6 +397,16 @@
     return call.Marshal(RTC_FROM_HERE, worker_thread_);                   \
   }
 
+// For use when returning purely const state (set during construction).
+// Use with caution. This method should only be used when the return value will
+// always be the same.
+#define BYPASS_PROXY_CONSTMETHOD0(r, method)                            \
+  r method() const override {                                           \
+    static_assert(!std::is_pointer<r>::value, "Type is a pointer");     \
+    static_assert(!std::is_reference<r>::value, "Type is a reference"); \
+    return c_->method();                                                \
+  }
+
 }  // namespace webrtc
 
 #endif  //  API_PROXY_H_