Sync up latest changes including the foreground behavior type.

PiperOrigin-RevId: 712547630
Change-Id: Idf7bbe37c1a5f91b87197f621ba48d08693be6c4
Reviewed-on: https://chromium-review.googlesource.com/c/cast_core/public/+/6150151
Tested-by: Shawn Quereshi <shawnq@google.com>
Reviewed-by: Shawn Quereshi <shawnq@google.com>
Tested-by: Vigen Issahhanjan <vigeni@google.com>
diff --git a/build/chromium/cast_core_grpc_generator.cc b/build/chromium/cast_core_grpc_generator.cc
index 7be9c0b..c042955 100644
--- a/build/chromium/cast_core_grpc_generator.cc
+++ b/build/chromium/cast_core_grpc_generator.cc
@@ -10,6 +10,7 @@
 #include <set>
 #include <sstream>
 #include <string>
+#include <string_view>
 #include <utility>
 #include <vector>
 
@@ -66,10 +67,9 @@
   return file_path.substr(0, ext_pos);
 }
 
-std::string ReplaceString(const std::string& input,
-                          const std::string& old_token,
+std::string ReplaceString(const std::string& input, const std::string& old_token,
                           const std::string& new_token) {
-  std::string output = input;
+  std::string output(input);
   std::string::size_type pos;
   while ((pos = output.find(old_token)) != std::string::npos) {
     output.replace(pos, old_token.length(), new_token);
@@ -139,10 +139,10 @@
     std::string::size_type start_pos = 0;
     std::string::size_type next_pos;
     while ((next_pos = package.find(".", start_pos)) != std::string::npos) {
-      namespaces_.push_back(package.substr(start_pos, next_pos - start_pos));
+      namespaces_.emplace_back(package.substr(start_pos, next_pos - start_pos));
       start_pos = next_pos + 1;
     }
-    namespaces_.push_back(package.substr(start_pos));
+    namespaces_.emplace_back(package.substr(start_pos));
     return true;
   }
 
@@ -209,7 +209,7 @@
 
   void PrintCastCoreHandlerDefinition(
       std::ostream& header, const ServiceDescriptor* service_descriptor) const {
-    const std::string service_name = service_descriptor->name();
+    const std::string& service_name = service_descriptor->name();
     std::ostringstream method_names;
     std::ostringstream class_methods;
     for (int i = 0; i < service_descriptor->method_count(); ++i) {
@@ -223,8 +223,9 @@
 
       const Descriptor* input = method->input_type();
       const Descriptor* output = method->output_type();
-      const std::string method_name_var =
-          "k" + service_name + "_" + method->name() + "_MethodName";
+      const std::string method_name_var = "k" + std::string(service_name) +
+                                          "_" + std::string(method->name()) +
+                                          "_MethodName";
       method_names << "constexpr char " << method_name_var << "[] = \""
                    << method->name() << "\";" << std::endl;
       class_methods << "    using " << method->name() << " = ";
@@ -249,7 +250,7 @@
 
   void PrintCastCoreStubDefinition(
       std::ostream& header, const ServiceDescriptor* service_descriptor) const {
-    const std::string service_name = service_descriptor->name();
+    const std::string& service_name = service_descriptor->name();
     header << "// " << service_name << " gRPC stub." << std::endl
            << "class " << service_name << "Stub : "
            << " public ::cast::utils::GrpcStub<" << service_name << "> {"
@@ -272,7 +273,8 @@
 
       const Descriptor* input = method->input_type();
       const Descriptor* output = method->output_type();
-      const std::string method_name_var = "k" + method->name() + "Method";
+      const std::string method_name_var =
+          "k" + std::string(method->name()) + "Method";
       header << "  using " << method->name() << " = ";
       if (method->server_streaming()) {
         header << "::cast::utils::GrpcServerStreamingCall<";
diff --git a/proto/common/runtime_metadata.proto b/proto/common/runtime_metadata.proto
index 0b073e5..1ce0925 100644
--- a/proto/common/runtime_metadata.proto
+++ b/proto/common/runtime_metadata.proto
@@ -103,6 +103,17 @@
   cast.common.Duration polling_frequency = 2;
 }
 
+message ForegroundBehavior {
+  enum Type {
+    // Bring runtime to foreground only after the application is started
+    // (default behavior on Linux TVs).
+    ON_APPLICATION_STARTED = 0;
+    // Bring runtime to foreground as application is visible (default behavior
+    // on Android TVs).
+    ON_APPLICATION_VISIBLE = 1;
+  }
+}
+
 message RuntimeCapabilities {
   // Media capabilities of the runtime.
   MediaCapabilities media_capabilities = 1;
@@ -110,4 +121,6 @@
   ApplicationCapabilities application_capabilities = 2;
   // Runtime prelaunch capabilities.
   PrelaunchCapabilities prelaunch_capabilities = 5;
+  // Defines when to bring runtime to foreground.
+  ForegroundBehavior.Type foreground_behavior = 6;
 }