Index: webrtc/base/keep_ref_until_done.h |
diff --git a/webrtc/base/keep_ref_until_done.h b/webrtc/base/keep_ref_until_done.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..743a09a8065a882bcfc68d8fb17d833650276a1d |
--- /dev/null |
+++ b/webrtc/base/keep_ref_until_done.h |
@@ -0,0 +1,35 @@ |
+/* |
+ * Copyright 2015 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. |
+ */ |
+ |
+#ifndef WEBRTC_BASE_KEEP_REF_UNTIL_DONE_H_ |
+#define WEBRTC_BASE_KEEP_REF_UNTIL_DONE_H_ |
+ |
+#include "webrtc/base/bind.h" |
+#include "webrtc/base/callback.h" |
+#include "webrtc/base/refcount.h" |
+#include "webrtc/base/scoped_ref_ptr.h" |
+ |
+namespace rtc { |
+ |
+namespace impl { |
+static inline void DoNothing(const scoped_refptr<RefCountInterface>& object) {} |
+} // namespace impl |
+ |
+// KeepRefUntilDone keeps a reference to |object| until the returned |
+// callback goes out of scope. If the returned callback is copied, the |
+// reference will be released when the last callback goes out of scope. |
+static inline Callback0<void> KeepRefUntilDone(RefCountInterface* object) { |
tommi
2015/11/30 13:05:01
I actually kinda liked having the same compatibili
magjed_webrtc
2015/11/30 15:41:52
If you don't put this definition in a cc file, you
|
+ return rtc::Bind(&impl::DoNothing, scoped_refptr<RefCountInterface>(object)); |
+} |
+ |
+} // namespace rtc |
+ |
+ |
+#endif // WEBRTC_BASE_KEEP_REF_UNTIL_DONE_H_ |