Add the ability to use the START_TRACE trigger mode.

This enables Perfetto to defer the start of a trace until a trigger is
received, but the trace will be configured and ready to go when
requested. The actual ability to send triggers is added in a follow up CL to
keep this nicely split.

Tests are added with the ability to send triggers again in the follow up CL.
Which I will land together with this change.

Bug: 128966650
Change-Id: Iabe5dc9a14ce33cbcd0330612711ae5c16fd2ada
diff --git a/src/tracing/core/tracing_service_impl.h b/src/tracing/core/tracing_service_impl.h
index b0a9233..63beaa7 100644
--- a/src/tracing/core/tracing_service_impl.h
+++ b/src/tracing/core/tracing_service_impl.h
@@ -22,6 +22,7 @@
 #include <memory>
 #include <mutex>
 #include <set>
+#include <vector>
 
 #include "perfetto/base/gtest_prod_util.h"
 #include "perfetto/base/logging.h"
@@ -231,6 +232,7 @@
   void NotifyFlushDoneForProducer(ProducerID, FlushRequestID);
   void NotifyDataSourceStarted(ProducerID, const DataSourceInstanceID);
   void NotifyDataSourceStopped(ProducerID, const DataSourceInstanceID);
+  void ActivateTriggers(ProducerID, const std::vector<std::string>& triggers);
 
   // Called by ConsumerEndpointImpl.
   bool DetachConsumer(ConsumerEndpointImpl*, const std::string& key);
@@ -390,6 +392,13 @@
     // prevent that a consumer re-attaches to a session from a different uid.
     uid_t const consumer_uid;
 
+    // The list of triggers this session received while alive and the time they
+    // were received at. This is used to insert 'fake' packets back to the
+    // consumer so they can tell when some event happened. The order matches the
+    // order they were received.
+    std::vector<std::pair<uint64_t, TraceConfig::TriggerConfig::Trigger>>
+        received_triggers;
+
     // The trace config provided by the Consumer when calling
     // EnableTracing(), plus any updates performed by ChangeTraceConfig.
     TraceConfig config;
@@ -479,6 +488,7 @@
   void ScrapeSharedMemoryBuffers(TracingSession* tracing_session,
                                  ProducerEndpointImpl* producer);
   TraceBuffer* GetBufferByID(BufferID);
+  void OnStartTriggersTimeout(TracingSessionID tsid);
 
   base::TaskRunner* const task_runner_;
   std::unique_ptr<SharedMemory::Factory> shm_factory_;