Implement an OperationsChain, to be used by PeerConnection in follow-up.

This allows asynchronous tasks to be queued to be executed in order.
The class is motivated by the "operations chain" in the spec:
https://w3c.github.io/webrtc-pc/#dfn-operations-chain

In a follow-up CL I intend to use this in PeerConnection's
CreateOffer(), CreateAnswer() SetLocalDescription() and
SetRemoteDescription() and unblock https://crbug.com/980885.

For background, motivation, requirements and implementation notes, see
https://docs.google.com/document/d/1XLwNN2kUIGGTwz9LQ0NwJNkcybi9oKnynUEZB1jGA14/edit?usp=sharing

Bug: webrtc:11019
Change-Id: I982e4a1c0e77fa62096c16deed459d9d9e9b63f0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/156120
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29582}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index f453ace..acd54b9 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -465,6 +465,21 @@
   ]
 }
 
+rtc_source_set("rtc_operations_chain") {
+  visibility = [ "*" ]
+  sources = [
+    "operations_chain.cc",
+    "operations_chain.h",
+  ]
+  deps = [
+    ":checks",
+    ":macromagic",
+    ":refcount",
+    "../api:scoped_refptr",
+    "synchronization:sequence_checker",
+  ]
+}
+
 if (rtc_enable_libevent) {
   rtc_library("rtc_task_queue_libevent") {
     visibility = [ "../api/task_queue:default_task_queue_factory" ]
@@ -1233,6 +1248,21 @@
     ]
   }
 
+  rtc_library("rtc_operations_chain_unittests") {
+    testonly = true
+
+    sources = [
+      "operations_chain_unittest.cc",
+    ]
+    deps = [
+      ":rtc_base",
+      ":rtc_base_approved",
+      ":rtc_event",
+      ":rtc_operations_chain",
+      "../test:test_support",
+    ]
+  }
+
   rtc_library("weak_ptr_unittests") {
     testonly = true