Internal change

PiperOrigin-RevId: 346876868
Change-Id: Ibdc1bb192bab2ef00519bf8e28bb95eb46d8819a
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2596076
Reviewed-by: Ryan Keane <rwkeane@google.com>
Commit-Queue: Ryan Keane <rwkeane@google.com>
diff --git a/cast/cast_core/api/common/runtime_metadata.proto b/cast/cast_core/api/common/runtime_metadata.proto
index bb72541..00079f6 100644
--- a/cast/cast_core/api/common/runtime_metadata.proto
+++ b/cast/cast_core/api/common/runtime_metadata.proto
@@ -53,4 +53,7 @@
 
   // Flags if heartbeat is supported.
   bool heartbeat_supported = 3;
+
+  // Flags if metrics recording is supported.
+  bool metrics_recorder_supported = 4;
 }
diff --git a/cast/cast_core/api/metrics/metrics_recorder.proto b/cast/cast_core/api/metrics/metrics_recorder.proto
new file mode 100644
index 0000000..30227d3
--- /dev/null
+++ b/cast/cast_core/api/metrics/metrics_recorder.proto
@@ -0,0 +1,49 @@
+syntax = "proto3";
+
+package cast.metrics;
+
+import "google/protobuf/empty.proto";
+
+option optimize_for = LITE_RUNTIME;
+
+service MetricsRecorderService {
+  // Record a set of|Event|
+  rpc Record(RecordRequest) returns (google.protobuf.Empty);
+}
+
+message RecordRequest {
+  repeated Event event = 1;
+}
+
+// This repliciates the Fuchsia approach to Cast metrics; for documentation on
+// event structure, refer to
+// fuchsia.googlesource.com/fuchsia/+/master/sdk/fidl/fuchsia.legacymetrics/event.fidl
+message Event {
+  oneof event_type {
+    UserActionEvent user_action_event = 1;
+    Histogram histogram = 2;
+    ImplementationDefinedEvent impl_defined_event = 3;
+  }
+}
+
+message UserActionEvent {
+  string name = 1;
+  optional int64 time = 2;
+}
+
+message Histogram {
+  string name = 1;
+  repeated HistogramBucket bucket = 2;
+  int64 sum = 3;
+}
+
+message HistogramBucket {
+  int64 min = 1;
+  int64 max = 2;
+  int64 count = 3;
+}
+
+message ImplementationDefinedEvent {
+  bytes data = 1;
+  optional string name = 2;
+}
diff --git a/cast/cast_core/api/runtime/runtime_service.proto b/cast/cast_core/api/runtime/runtime_service.proto
index 5c8c8da..cc30fda 100644
--- a/cast/cast_core/api/runtime/runtime_service.proto
+++ b/cast/cast_core/api/runtime/runtime_service.proto
@@ -3,6 +3,7 @@
 package cast.runtime;
 
 import "google/protobuf/duration.proto";
+import "google/protobuf/empty.proto";
 import "cast/cast_core/api/common/service_info.proto";
 
 option optimize_for = LITE_RUNTIME;
@@ -11,7 +12,7 @@
 //
 // This service is called by CastCore after Runtime starts up.
 service RuntimeService {
-  // Launch a Cast application. The application must connect to the
+  // Launches a Cast application. The application must connect to the
   // CoreApplicationService based on cast_protocol and
   // core_application_endpoint, and provide its endpoint.
   rpc LaunchApplication(LaunchApplicationRequest)
@@ -24,8 +25,24 @@
 
   // Requests runtime to send a heartbeat in a stream. The use of server-side
   // streaming allows Core to know for sure that runtime is still running. In
-  // case of a crash, the gRPC stream will error with UNAVAILABLE error.
+  // case of a crash, the gRPC stream will error with UNAVAILABLE error. Cast
+  // Core calls this API if the runtime supports heartbeat in
+  // RuntimeCapabilities.
   rpc Heartbeat(HeartbeatRequest) returns (stream HeartbeatResponse);
+
+  // Provides information need by the runtime to start recording metrics via
+  // the core.
+  rpc StartMetricsRecorder(StartMetricsRecorderRequest)
+      returns (google.protobuf.Empty);
+
+  // Stops the metrics recorder, which may also attempt to flush.
+  rpc StopMetricsRecorder(google.protobuf.Empty)
+      returns (google.protobuf.Empty);
+}
+
+message StartMetricsRecorderRequest {
+  // Metrics service info.
+  cast.common.ServiceInfo metrics_recorder_service_info = 1;
 }
 
 message LaunchApplicationRequest {
diff --git a/cast/cast_core/api/v2/core_application_service.proto b/cast/cast_core/api/v2/core_application_service.proto
index 4c35afe..86b729a 100644
--- a/cast/cast_core/api/v2/core_application_service.proto
+++ b/cast/cast_core/api/v2/core_application_service.proto
@@ -29,17 +29,15 @@
   // application upon failures.
   rpc OnApplicationStatus(ApplicationStatus) returns (google.protobuf.Empty);
 
-  // "MessageConnectorService" provides the transport for MessagePorts.
-  // MessagePorts are connected using other services (e.g. ApiBindings), then
-  // registered with the MessageConnectorService to communicate over IPC
+  // Posts messages between MessagePorts. MessagePorts are connected using other
+  // services (e.g. ApiBindings), then registered with the
+  // MessageConnectorService to communicate over IPC.
   rpc PostMessage(cast.web.Message) returns (cast.web.MessagePortStatus);
 
-  // "ApiBindings", used for retrieving and initializing Cast bindings
-  // Gets the list of bindings to early-inject into the page at load time.
+  // Gets the list of bindings to early-inject into javascript at page load.
   rpc GetAll(google.protobuf.Empty) returns (cast.bindings.GetAllResponse);
 
-  // Should be invoked when connecting a named MessagePort to a native
-  // bindings backend.
+  // Connects to a binding returned by GetAll.
   rpc Connect(cast.bindings.ConnectRequest) returns (google.protobuf.Empty);
 }