Revert "[peridot][modular] Switch to new Cobalt 1.0 project."

This reverts commit 3cfae00e2f3d0ccaaa702743ae7eb2fdaef0376e.

Reason for revert: Suspected of causing FLK-292

Original change's description:
> [peridot][modular] Switch to new Cobalt 1.0 project.
> 
> Cobalt 0.1 has already been turned down so currently Cobalt is silently
> discarding all of the data we are logging to it.
> 
> This CL moves us over to our new Cobalt 1.0 project so Cobalt will start
> producing reports for us again.
> 
> Additionally, this removes the last use of Cobalt 0.1 from the Fuchsia
> codebase allowing Cobalt to delete its Cobalt 0.1 code, thereby
> greatly simplifying the Cobalt FIDL service and making it easier to test.
> 
> CB-316 #comment Removing last use Cobalt 0.1
> 
> In more detail this CL does the following:
> 
> - Switches from the old Cobalt 0.1 project to the new Cobalt 1.0 project
> - Switches the mechanism used to connect to Cobalt. We no longer need to
>   pass the bytes of our metric registry in a VMO. Now we only reference
>   our project by name and rely on the global registry to have our project.
> - Deletes the numeric constants and enums that correspond to the values
>   in the metrics registry. Instead we use the constants and enums that
>   are automatically generated by the Cobalt registry parser.
> - Switches the mechanism by which we connect to Cobalt in another way: We
>   replace the deprecated component::StartupContext with the new
>   sys::ComponentContext.
> 
> TEST=Ran modular_integration_tests and peridot_tests
> 
> Change-Id: I40ca4e025d0a4d2b809e3f87dfbaa2d9d9ad5fa5

TBR=rudominer@google.com,abarth@google.com,lindkvist@google.com

Change-Id: I052c669024ff6b7ddef3e27f9fe24a48503fc45d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
diff --git a/peridot/bin/basemgr/BUILD.gn b/peridot/bin/basemgr/BUILD.gn
index 070f7b6..37ccb40 100644
--- a/peridot/bin/basemgr/BUILD.gn
+++ b/peridot/bin/basemgr/BUILD.gn
@@ -64,6 +64,20 @@
     "//zircon/public/lib/async-loop-cpp",
     "//zircon/public/lib/trace-provider",
   ]
+
+  public_deps = [
+    "//peridot/bin/basemgr/cobalt:basemgr_metrics_registry",
+  ]
+
+  resources = [
+    {
+      path = rebase_path(
+              get_label_info(
+                  "//peridot/bin/basemgr/cobalt:basemgr_metrics_registry",
+                  "target_gen_dir") + "/basemgr_metrics_registry.pb")
+      dest = "basemgr_metrics_registry.pb"
+    },
+  ]
 }
 
 tests_package("basemgr_unittests") {
diff --git a/peridot/bin/basemgr/basemgr_impl.cc b/peridot/bin/basemgr/basemgr_impl.cc
index 583909a..890e2eb 100644
--- a/peridot/bin/basemgr/basemgr_impl.cc
+++ b/peridot/bin/basemgr/basemgr_impl.cc
@@ -43,8 +43,6 @@
 
 namespace modular {
 
-using cobalt_registry::ModularLifetimeEventsMetricDimensionEventType;
-
 namespace {
 
 // TODO(MF-134): This key is duplicated in
@@ -207,7 +205,7 @@
 
   InitializeUserProvider();
 
-  ReportEvent(ModularLifetimeEventsMetricDimensionEventType::BootedToBaseMgr);
+  ReportEvent(ModularEvent::BOOTED_TO_BASEMGR);
 }
 
 void BasemgrImpl::InitializeUserProvider() {
diff --git a/peridot/bin/basemgr/cobalt/BUILD.gn b/peridot/bin/basemgr/cobalt/BUILD.gn
index 74d66fa..d201b78 100644
--- a/peridot/bin/basemgr/cobalt/BUILD.gn
+++ b/peridot/bin/basemgr/cobalt/BUILD.gn
@@ -10,12 +10,7 @@
 ]
 
 metrics_registry("basemgr_metrics_registry") {
-  # This must match the name of our Cobalt project as specified in:
-  # https://cobalt-analytics.googlesource.com/config/+/refs/heads/master/projects.yaml
-  project_name = "modular"
-  generate_cc = true
-  namespace = "cobalt_registry"
-  generate_binarypb = false
+  project_id = 101
 }
 
 source_set("cobalt") {
diff --git a/peridot/bin/basemgr/cobalt/cobalt.cc b/peridot/bin/basemgr/cobalt/cobalt.cc
index 8cd45eb..e65277c 100644
--- a/peridot/bin/basemgr/cobalt/cobalt.cc
+++ b/peridot/bin/basemgr/cobalt/cobalt.cc
@@ -7,23 +7,23 @@
 #include <fuchsia/cobalt/cpp/fidl.h>
 #include <lib/cobalt/cpp/deprecated_cobalt_logger.h>
 
-#include "peridot/bin/basemgr/cobalt/basemgr_metrics_registry.cb.h"
 #include "src/lib/cobalt/cpp/cobalt_logger.h"
 
 namespace modular {
 namespace {
+constexpr char kConfigBinProtoPath[] = "/pkg/data/basemgr_metrics_registry.pb";
 
 cobalt::CobaltLogger* g_cobalt_logger = nullptr;
 
 }  // namespace
 
 fit::deferred_action<fit::closure> InitializeCobalt(
-    async_dispatcher_t* dispatcher, sys::ComponentContext* context) {
+    async_dispatcher_t* dispatcher, component::StartupContext* context) {
   FXL_DCHECK(!g_cobalt_logger) << "Cobalt has already been initialized.";
 
   std::unique_ptr<cobalt::CobaltLogger> cobalt_logger =
-      cobalt::NewCobaltLoggerFromProjectName(dispatcher, context,
-                                             cobalt_registry::kProjectName);
+      cobalt::DeprecatedNewCobaltLogger(dispatcher, context,
+                                        kConfigBinProtoPath);
 
   g_cobalt_logger = cobalt_logger.get();
   return fit::defer<fit::closure>([cobalt_logger = std::move(cobalt_logger)] {
@@ -31,11 +31,10 @@
   });
 }
 
-void ReportEvent(
-    cobalt_registry::ModularLifetimeEventsMetricDimensionEventType event) {
+void ReportEvent(ModularEvent event) {
   if (g_cobalt_logger) {
     g_cobalt_logger->LogEvent(
-        static_cast<uint32_t>(cobalt_registry::kModularLifetimeEventsMetricId),
+        static_cast<uint32_t>(CobaltMetric::MODULAR_EVENTS),
         static_cast<uint32_t>(event));
   }
 }
@@ -43,7 +42,7 @@
 void ReportModuleLaunchTime(std::string module_url, zx::duration time) {
   if (g_cobalt_logger) {
     g_cobalt_logger->LogElapsedTime(
-        static_cast<uint32_t>(cobalt_registry::kModuleLaunchTimeMetricId), 0,
+        static_cast<uint32_t>(CobaltMetric::MODULE_LAUNCH_LATENCY), 0,
         module_url, time);
   }
 }
@@ -51,17 +50,14 @@
 void ReportStoryLaunchTime(zx::duration time) {
   if (g_cobalt_logger) {
     g_cobalt_logger->LogElapsedTime(
-        static_cast<uint32_t>(cobalt_registry::kStoryLaunchTimeMetricId), 0, "",
-        time);
+        static_cast<uint32_t>(CobaltMetric::STORY_LAUNCH_LATENCY), 0, "", time);
   }
 }
 
-void ReportSessionAgentEvent(
-    const std::string& url,
-    cobalt_registry::SessionAgentEventsMetricDimensionEventType event) {
+void ReportSessionAgentEvent(const std::string& url, SessionAgentEvent event) {
   if (g_cobalt_logger) {
     g_cobalt_logger->LogEventCount(
-        static_cast<uint32_t>(cobalt_registry::kSessionAgentEventsMetricId),
+        static_cast<uint32_t>(CobaltMetric::SESSION_AGENT_EVENT),
         static_cast<uint32_t>(event), url /* component */,
         zx::duration(0) /* period_duration_micros */, 1 /* count */);
   }
diff --git a/peridot/bin/basemgr/cobalt/cobalt.h b/peridot/bin/basemgr/cobalt/cobalt.h
index 6631c5f..8e81bcf 100644
--- a/peridot/bin/basemgr/cobalt/cobalt.h
+++ b/peridot/bin/basemgr/cobalt/cobalt.h
@@ -6,23 +6,48 @@
 #define PERIDOT_BIN_BASEMGR_COBALT_COBALT_H_
 
 #include <lib/async/dispatcher.h>
+#include <lib/component/cpp/startup_context.h>
 #include <lib/fit/defer.h>
 #include <lib/fit/function.h>
-#include <lib/sys/cpp/component_context.h>
 #include <src/lib/fxl/memory/ref_ptr.h>
 
-#include "peridot/bin/basemgr/cobalt/basemgr_metrics_registry.cb.h"
-
 namespace modular {
 
+// Metric IDs that Cobalt requires to identify the data we are logging.
+// These are not events (events are tracked through ModularEvents index metric).
+// For information on datatypes and structure of each of these metrics, see
+// https://cobalt-analytics.googlesource.com/config/+/master/fuchsia/module_usage_tracking/config.yaml
+// Next enum value: 6
+enum class CobaltMetric : uint32_t {
+  MODULE_LAUNCHED = 1,
+  MODULE_PAIRS_IN_STORY = 2,
+  MODULAR_EVENTS = 3,
+  MODULE_LAUNCH_LATENCY = 4,
+  STORY_LAUNCH_LATENCY = 5,
+  SESSION_AGENT_EVENT = 6,
+};
+
+// The events to report.
+// Next enum value: 2
+enum class ModularEvent : uint32_t {
+  BOOTED_TO_BASEMGR = 0,
+  BOOTED_TO_SESSIONMGR = 1,
+};
+
+// The sesssion agent events to report.
+// Next enum value: 2
+enum class SessionAgentEvent : uint32_t {
+  CRASH = 0,
+  CRASH_LIMIT = 1,
+};
+
 // Cobalt initialization. When cobalt is not needed, the returned object must be
 // deleted. This method must not be called again until then.
 fit::deferred_action<fit::closure> InitializeCobalt(
-    async_dispatcher_t* dispatcher, sys::ComponentContext* context);
+    async_dispatcher_t* dispatcher, component::StartupContext* context);
 
 // Report a modular event to Cobalt.
-void ReportEvent(
-    cobalt_registry::ModularLifetimeEventsMetricDimensionEventType event);
+void ReportEvent(ModularEvent event);
 
 // Report a module launch time duration to Cobalt.
 void ReportModuleLaunchTime(std::string module_url, zx::duration time);
@@ -30,9 +55,7 @@
 // Report a story launch time duration to Cobalt.
 void ReportStoryLaunchTime(zx::duration time);
 
-void ReportSessionAgentEvent(
-    const std::string& url,
-    cobalt_registry::SessionAgentEventsMetricDimensionEventType event);
+void ReportSessionAgentEvent(const std::string& url, SessionAgentEvent event);
 
 }  // namespace modular
 
diff --git a/peridot/bin/basemgr/main.cc b/peridot/bin/basemgr/main.cc
index fa3a62e..fdd7436 100644
--- a/peridot/bin/basemgr/main.cc
+++ b/peridot/bin/basemgr/main.cc
@@ -9,7 +9,6 @@
 #include <lib/component/cpp/startup_context.h>
 #include <lib/fit/defer.h>
 #include <lib/fit/function.h>
-#include <lib/sys/cpp/component_context.h>
 #include <src/lib/fxl/command_line.h>
 #include <src/lib/fxl/macros.h>
 #include <trace-provider/provider.h>
@@ -43,11 +42,11 @@
 
 fit::deferred_action<fit::closure> SetupCobalt(
     bool enable_cobalt, async_dispatcher_t* dispatcher,
-    sys::ComponentContext* component_context) {
+    component::StartupContext* context) {
   if (!enable_cobalt) {
     return fit::defer<fit::closure>([] {});
   }
-  return modular::InitializeCobalt(dispatcher, component_context);
+  return modular::InitializeCobalt(dispatcher, context);
 };
 
 fuchsia::modular::session::BasemgrConfig CreateBasemgrConfigFromCommandLine(
@@ -151,10 +150,9 @@
 // Configures Basemgr by passing in connected services.
 std::unique_ptr<modular::BasemgrImpl> ConfigureBasemgr(
     fuchsia::modular::session::BasemgrConfig& config,
-    std::shared_ptr<component::StartupContext> context,
-    sys::ComponentContext* component_context, async::Loop* loop) {
-  fit::deferred_action<fit::closure> cobalt_cleanup = SetupCobalt(
-      config.enable_cobalt(), loop->dispatcher(), component_context);
+    std::shared_ptr<component::StartupContext> context, async::Loop* loop) {
+  fit::deferred_action<fit::closure> cobalt_cleanup =
+      SetupCobalt(config.enable_cobalt(), loop->dispatcher(), context.get());
 
   fuchsia::ui::policy::PresenterPtr presenter;
   context->ConnectToEnvironmentService(presenter.NewRequest());
@@ -203,13 +201,11 @@
   trace::TraceProvider trace_provider(loop.dispatcher());
   auto context = std::shared_ptr<component::StartupContext>(
       component::StartupContext::CreateFromStartupInfo());
-  std::unique_ptr<sys::ComponentContext> component_context(
-      sys::ComponentContext::Create());
 
   fuchsia::setui::SetUiServicePtr setui;
   std::unique_ptr<modular::BasemgrImpl> basemgr_impl;
   auto initialize_basemgr =
-      [&config, &loop, &context, &component_context, &basemgr_impl, &setui,
+      [&config, &loop, &context, &basemgr_impl, &setui,
        ran = false](fuchsia::setui::SettingsObject settings_obj) mutable {
         if (ran) {
           return;
@@ -220,7 +216,7 @@
         ConfigureLoginOverride(config, settings_obj, setui.get());
 
         std::unique_ptr<modular::BasemgrImpl> basemgr =
-            ConfigureBasemgr(config, context, component_context.get(), &loop);
+            ConfigureBasemgr(config, context, &loop);
 
         basemgr_impl = std::move(basemgr);
 
diff --git a/peridot/bin/sessionmgr/BUILD.gn b/peridot/bin/sessionmgr/BUILD.gn
index 1433346..fe98636 100644
--- a/peridot/bin/sessionmgr/BUILD.gn
+++ b/peridot/bin/sessionmgr/BUILD.gn
@@ -81,6 +81,20 @@
     "//zircon/public/lib/async-loop-cpp",
     "//zircon/public/lib/trace-provider",
   ]
+
+  public_deps = [
+    "//peridot/bin/basemgr/cobalt:basemgr_metrics_registry",
+  ]
+
+  resources = [
+    {
+      path = rebase_path(
+              get_label_info(
+                  "//peridot/bin/basemgr/cobalt:basemgr_metrics_registry",
+                  "target_gen_dir") + "/basemgr_metrics_registry.pb")
+      dest = "basemgr_metrics_registry.pb"
+    },
+  ]
 }
 
 # Collection of all new modular APIs while they undergo review.
diff --git a/peridot/bin/sessionmgr/sessionmgr.cc b/peridot/bin/sessionmgr/sessionmgr.cc
index 55d9307..f808a84 100644
--- a/peridot/bin/sessionmgr/sessionmgr.cc
+++ b/peridot/bin/sessionmgr/sessionmgr.cc
@@ -8,7 +8,6 @@
 #include <lib/component/cpp/startup_context.h>
 #include <lib/fit/defer.h>
 #include <lib/fit/function.h>
-#include <lib/sys/cpp/component_context.h>
 #include <src/lib/fxl/command_line.h>
 #include <src/lib/fxl/macros.h>
 #include <src/lib/fxl/strings/split_string.h>
@@ -23,11 +22,11 @@
 
 fit::deferred_action<fit::closure> SetupCobalt(
     const bool enable_cobalt, async_dispatcher_t* dispatcher,
-    sys::ComponentContext* component_context) {
+    component::StartupContext* const startup_context) {
   if (!enable_cobalt) {
     return fit::defer<fit::closure>([] {});
   }
-  return modular::InitializeCobalt(dispatcher, component_context);
+  return modular::InitializeCobalt(dispatcher, startup_context);
 }
 
 void OverrideConfigFromCommandLine(
@@ -101,12 +100,9 @@
   trace::TraceProvider trace_provider(loop.dispatcher());
   std::unique_ptr<component::StartupContext> context =
       component::StartupContext::CreateFromStartupInfo();
-  std::unique_ptr<sys::ComponentContext> component_context(
-      sys::ComponentContext::Create());
 
-  auto cobalt_cleanup =
-      SetupCobalt((config.enable_cobalt()), std::move(loop.dispatcher()),
-                  component_context.get());
+  auto cobalt_cleanup = SetupCobalt(
+      (config.enable_cobalt()), std::move(loop.dispatcher()), context.get());
 
   modular::AppDriver<modular::SessionmgrImpl> driver(
       context->outgoing().deprecated_services(),
diff --git a/peridot/bin/sessionmgr/sessionmgr_impl.cc b/peridot/bin/sessionmgr/sessionmgr_impl.cc
index 247cca7..14af9c2 100644
--- a/peridot/bin/sessionmgr/sessionmgr_impl.cc
+++ b/peridot/bin/sessionmgr/sessionmgr_impl.cc
@@ -52,8 +52,6 @@
 
 namespace modular {
 
-using cobalt_registry::ModularLifetimeEventsMetricDimensionEventType;
-
 namespace {
 
 constexpr char kAppId[] = "modular_sessionmgr";
@@ -223,8 +221,7 @@
           TerminateSessionShell(std::move(cont));
         });
         InitializeClipboard();
-        ReportEvent(
-            ModularLifetimeEventsMetricDimensionEventType::BootedToSessionMgr);
+        ReportEvent(ModularEvent::BOOTED_TO_SESSIONMGR);
       };
 
   session_context_ = session_context.Bind();
diff --git a/peridot/bin/sessionmgr/user_intelligence_provider_impl.cc b/peridot/bin/sessionmgr/user_intelligence_provider_impl.cc
index 5b68a33..cc3ba17 100644
--- a/peridot/bin/sessionmgr/user_intelligence_provider_impl.cc
+++ b/peridot/bin/sessionmgr/user_intelligence_provider_impl.cc
@@ -16,8 +16,6 @@
 
 namespace modular {
 
-using cobalt_registry::SessionAgentEventsMetricDimensionEventType;
-
 namespace {
 
 constexpr char kKronkUrl[] = "kronk";
@@ -206,8 +204,7 @@
     auto& agent_data = it->second;
     agent_data.services.Unbind();
     agent_data.controller.Unbind();
-    ReportSessionAgentEvent(url,
-                            SessionAgentEventsMetricDimensionEventType::Crash);
+    ReportSessionAgentEvent(url, SessionAgentEvent::CRASH);
 
     if (agent_data.restart.ShouldRetry()) {
       FXL_LOG(INFO) << "Restarting " << url << "...";
@@ -217,8 +214,7 @@
                        << kSessionAgentRetryLimit.count << " times in "
                        << kSessionAgentRetryLimit.period.to_secs()
                        << " seconds.";
-      ReportSessionAgentEvent(
-          url, SessionAgentEventsMetricDimensionEventType::CrashLimitExceeded);
+      ReportSessionAgentEvent(url, SessionAgentEvent::CRASH_LIMIT);
       // Erase so that incoming connection requests fail fast rather than
       // enqueue forever.
       session_agents_.erase(it);