Index: webrtc/media/base/asyncproxy.h |
diff --git a/webrtc/media/base/asyncproxy.h b/webrtc/media/base/asyncproxy.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ac1f5e8ccccb33a644fcced8e6f91138ceb2957c |
--- /dev/null |
+++ b/webrtc/media/base/asyncproxy.h |
@@ -0,0 +1,74 @@ |
+/* |
+ * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+// This file contains Macros for creating asynchronous proxies for webrtc |
+// interfaces. Many methods in the WebRtc MediaEngine callback interfaces are |
+// called on an arbitrary thread. Using these macros- it is guaranteed that |
+// all methods will be called on the same thread as where the proxy is created. |
+ |
+// TODO(perkj): Now before landing -- decide if this make sence and if it make |
nisse-webrtc
2016/02/17 08:19:46
I din't think there's any point in doing some macr
|
+// sence to created Macros instead similar to api/proxy.h. |
+ |
+#ifndef WEBRTC_MEDIA_BASE_ASYNCPROXY_H_ |
+#define WEBRTC_MEDIA_BASE_ASYNCPROXY_H_ |
+ |
+#include "webrtc/base/asyncinvoker.h" |
+#include "webrtc/base/checks.h" |
+#include "webrtc/base/event.h" |
+#include "webrtc/base/thread.h" |
+ |
+namespace rtc { |
+ |
+class LoadObserverProxy { |
+ public: |
+ explicit LoadObserverProxy(webrtc::LoadObserver* observer) { |
+ helper_ = new rtc::RefCountedObject<Helper>(observer); |
+ } |
+ ~LoadObserverProxy() { helper_->Detach(); } |
+ |
+ webrtc::LoadObserver* proxy() { return helper_; } |
+ |
+ private: |
+ class Helper : public webrtc::LoadObserver, public rtc::RefCountInterface { |
+ public: |
+ explicit Helper(webrtc::LoadObserver* observer) |
+ : thread_(rtc::Thread::Current()), observer_(observer) {} |
+ void Detach() { |
+ RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ observer_ = nullptr; |
+ } |
+ void OnLoadUpdate(webrtc::LoadObserver::Load load) override { |
+ if (rtc::Thread::Current() == thread_) { |
+ observer_->OnLoadUpdate(load); |
+ return; |
+ } |
+ invoker_.AsyncInvoke<void>( |
+ thread_, rtc::Bind(&Helper::OnLoadUpdateOnCorrectThread, this, load)); |
+ } |
+ void OnLoadUpdateOnCorrectThread(webrtc::LoadObserver::Load load) { |
+ RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ if (observer_) { |
+ observer_->OnLoadUpdate(load); |
+ } |
+ } |
+ |
+ private: |
+ rtc::ThreadChecker thread_checker_; |
+ rtc::AsyncInvoker invoker_; |
+ rtc::Thread* thread_; |
+ webrtc::LoadObserver* observer_; |
+ }; |
+ |
+ rtc::scoped_refptr<Helper> helper_; |
+}; |
+ |
+} // namespace rtc |
+ |
+#endif // WEBRTC_MEDIA_BASE_ASYNCPROXY_H_ |