[crash] switch to runner's incoming services

instead of connecting to the crash analyzer from the component's startup context, we connect from the runner's incoming services, which allows us to only list the crash analyzer service once (in the runner's cmx file instead of each component's cmx file)

CF-261 #comment
DX-246 #comment

TESTED=`fx shell 'run fuchsia-pkg://fuchsia.com/crasher_dart#meta/crasher_dart.cmx'`

Change-Id: I7be9388fec33f4db8a2190d0f5d5957d22fd1bf6
diff --git a/bin/crasher_dart/meta/crasher_dart.cmx b/bin/crasher_dart/meta/crasher_dart.cmx
index ce15bf6..ec51d08 100644
--- a/bin/crasher_dart/meta/crasher_dart.cmx
+++ b/bin/crasher_dart/meta/crasher_dart.cmx
@@ -4,7 +4,6 @@
     },
     "sandbox": {
         "services": [
-            "fuchsia.crash.Analyzer",
             "fuchsia.sys.Environment"
         ]
     }
diff --git a/runtime/dart/utils/BUILD.gn b/runtime/dart/utils/BUILD.gn
index 742becb..94f22c2 100644
--- a/runtime/dart/utils/BUILD.gn
+++ b/runtime/dart/utils/BUILD.gn
@@ -15,6 +15,7 @@
   ]
 
   public_deps = [
+    "//garnet/public/lib/svc/cpp",
     "//zircon/public/lib/fs",
     "//zircon/public/lib/zx",
   ]
diff --git a/runtime/dart/utils/handle_exception.cc b/runtime/dart/utils/handle_exception.cc
index 2c1eb38..12efc32 100644
--- a/runtime/dart/utils/handle_exception.cc
+++ b/runtime/dart/utils/handle_exception.cc
@@ -18,7 +18,7 @@
 namespace fuchsia {
 namespace dart {
 
-zx_status_t HandleIfException(component::StartupContext* context,
+zx_status_t HandleIfException(std::shared_ptr<component::Services> services,
                               const std::string& component_url,
                               Dart_Handle result) {
   if (!Dart_IsError(result) || !Dart_ErrorHasException(result)) {
@@ -36,7 +36,7 @@
   }
 
   fuchsia::crash::AnalyzerSyncPtr analyzer;
-  context->ConnectToEnvironmentService(analyzer.NewRequest());
+  services->ConnectToService(analyzer.NewRequest());
   FXL_DCHECK(analyzer);
 
   zx_status_t out_status;
diff --git a/runtime/dart/utils/handle_exception.h b/runtime/dart/utils/handle_exception.h
index b5766ca..9f1f03d 100644
--- a/runtime/dart/utils/handle_exception.h
+++ b/runtime/dart/utils/handle_exception.h
@@ -5,9 +5,10 @@
 #ifndef TOPAZ_RUNTIME_DART_UTILS_HANDLE_EXCEPTION_H_
 #define TOPAZ_RUNTIME_DART_UTILS_HANDLE_EXCEPTION_H_
 
+#include <memory>
 #include <string>
 
-#include <lib/component/cpp/startup_context.h>
+#include <lib/svc/cpp/services.h>
 #include <sys/types.h>
 #include <third_party/dart/runtime/include/dart_api.h>
 
@@ -18,7 +19,7 @@
 // to the crash analyzer service for further handling.
 //
 // Otherwise early returns with OK status.
-zx_status_t HandleIfException(component::StartupContext* context,
+zx_status_t HandleIfException(std::shared_ptr<component::Services> services,
                               const std::string& component_url,
                               Dart_Handle result);
 
diff --git a/runtime/dart_runner/dart_component_controller.cc b/runtime/dart_runner/dart_component_controller.cc
index 67948ab..17194e0 100644
--- a/runtime/dart_runner/dart_component_controller.cc
+++ b/runtime/dart_runner/dart_component_controller.cc
@@ -52,11 +52,13 @@
 DartComponentController::DartComponentController(
     std::string label, fuchsia::sys::Package package,
     fuchsia::sys::StartupInfo startup_info,
+    std::shared_ptr<component::Services> runner_incoming_services,
     fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller)
     : label_(label),
       url_(std::move(package.resolved_url)),
       package_(std::move(package)),
       startup_info_(std::move(startup_info)),
+      runner_incoming_services_(runner_incoming_services),
       binding_(this) {
   for (size_t i = 0; i < startup_info_.program_metadata->size(); ++i) {
     auto pg = startup_info_.program_metadata->at(i);
@@ -392,7 +394,8 @@
       FXL_LOG(ERROR) << Dart_GetError(main_result);
       return_code_ = tonic::GetErrorExitCode(main_result);
 
-      fuchsia::dart::HandleIfException(context_.get(), url_, main_result);
+      fuchsia::dart::HandleIfException(runner_incoming_services_, url_,
+                                       main_result);
     }
     Dart_ExitScope();
     return false;
@@ -441,7 +444,7 @@
     return;
   }
 
-  fuchsia::dart::HandleIfException(context_.get(), url_, result);
+  fuchsia::dart::HandleIfException(runner_incoming_services_, url_, result);
 
   // Otherwise, see if there was any other error.
   return_code_ = tonic::GetErrorExitCode(result);
diff --git a/runtime/dart_runner/dart_component_controller.h b/runtime/dart_runner/dart_component_controller.h
index 06f332b..cad3719 100644
--- a/runtime/dart_runner/dart_component_controller.h
+++ b/runtime/dart_runner/dart_component_controller.h
@@ -5,6 +5,8 @@
 #ifndef TOPAZ_RUNTIME_DART_RUNNER_DART_COMPONENT_CONTROLLER_H_
 #define TOPAZ_RUNTIME_DART_RUNNER_DART_COMPONENT_CONTROLLER_H_
 
+#include <memory>
+
 #include <lib/async/cpp/wait.h>
 #include <lib/fdio/namespace.h>
 #include <lib/zx/timer.h>
@@ -15,6 +17,7 @@
 #include "lib/fsl/vmo/sized_vmo.h"
 #include "lib/fxl/macros.h"
 #include "lib/svc/cpp/service_provider_bridge.h"
+#include "lib/svc/cpp/services.h"
 #include "third_party/dart/runtime/include/dart_api.h"
 #include "topaz/runtime/dart_runner/mapped_resource.h"
 
@@ -25,6 +28,7 @@
   DartComponentController(
       std::string label, fuchsia::sys::Package package,
       fuchsia::sys::StartupInfo startup_info,
+      std::shared_ptr<component::Services> runner_incoming_services,
       fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller);
   ~DartComponentController() override;
 
@@ -58,6 +62,7 @@
   std::string url_;
   fuchsia::sys::Package package_;
   fuchsia::sys::StartupInfo startup_info_;
+  std::shared_ptr<component::Services> runner_incoming_services_;
   std::string data_path_;
   fidl::Binding<fuchsia::sys::ComponentController> binding_;
   std::unique_ptr<component::StartupContext> context_;
diff --git a/runtime/dart_runner/dart_runner.cc b/runtime/dart_runner/dart_runner.cc
index 2a3254a..cf5e09d 100644
--- a/runtime/dart_runner/dart_runner.cc
+++ b/runtime/dart_runner/dart_runner.cc
@@ -88,11 +88,13 @@
 void RunApplication(
     DartRunner* runner, ControllerToken* token, fuchsia::sys::Package package,
     fuchsia::sys::StartupInfo startup_info,
+    std::shared_ptr<component::Services> runner_incoming_services,
     ::fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
   int64_t start = Dart_TimelineGetMicros();
   deprecated_loop::MessageLoop loop;
   DartComponentController app(token->label(), std::move(package),
-                              std::move(startup_info), std::move(controller));
+                              std::move(startup_info), runner_incoming_services,
+                              std::move(controller));
   bool success = app.Setup();
   int64_t end = Dart_TimelineGetMicros();
   Dart_TimelineEvent("DartComponentController::Setup", start, end,
@@ -207,7 +209,7 @@
   std::string label = GetLabelFromURL(package.resolved_url);
   std::thread thread(RunApplication, this, AddController(label),
                      std::move(package), std::move(startup_info),
-                     std::move(controller));
+                     context_->incoming_services(), std::move(controller));
   thread.detach();
 }
 
diff --git a/runtime/dart_runner/meta/dart_aot_product_runner.cmx b/runtime/dart_runner/meta/dart_aot_product_runner.cmx
index 2f4c2ab..6f13121 100644
--- a/runtime/dart_runner/meta/dart_aot_product_runner.cmx
+++ b/runtime/dart_runner/meta/dart_aot_product_runner.cmx
@@ -7,6 +7,7 @@
             "root-ssl-certificates"
         ],
         "services": [
+            "fuchsia.crash.Analyzer",
             "fuchsia.net.LegacySocketProvider",
             "fuchsia.timezone.Timezone",
             "fuchsia.tracelink.Registry"
diff --git a/runtime/dart_runner/meta/dart_aot_runner.cmx b/runtime/dart_runner/meta/dart_aot_runner.cmx
index 2f4c2ab..6f13121 100644
--- a/runtime/dart_runner/meta/dart_aot_runner.cmx
+++ b/runtime/dart_runner/meta/dart_aot_runner.cmx
@@ -7,6 +7,7 @@
             "root-ssl-certificates"
         ],
         "services": [
+            "fuchsia.crash.Analyzer",
             "fuchsia.net.LegacySocketProvider",
             "fuchsia.timezone.Timezone",
             "fuchsia.tracelink.Registry"
diff --git a/runtime/dart_runner/meta/dart_dbc_product_runner.cmx b/runtime/dart_runner/meta/dart_dbc_product_runner.cmx
index 2f4c2ab..6f13121 100644
--- a/runtime/dart_runner/meta/dart_dbc_product_runner.cmx
+++ b/runtime/dart_runner/meta/dart_dbc_product_runner.cmx
@@ -7,6 +7,7 @@
             "root-ssl-certificates"
         ],
         "services": [
+            "fuchsia.crash.Analyzer",
             "fuchsia.net.LegacySocketProvider",
             "fuchsia.timezone.Timezone",
             "fuchsia.tracelink.Registry"
diff --git a/runtime/dart_runner/meta/dart_dbc_runner.cmx b/runtime/dart_runner/meta/dart_dbc_runner.cmx
index 2f4c2ab..6f13121 100644
--- a/runtime/dart_runner/meta/dart_dbc_runner.cmx
+++ b/runtime/dart_runner/meta/dart_dbc_runner.cmx
@@ -7,6 +7,7 @@
             "root-ssl-certificates"
         ],
         "services": [
+            "fuchsia.crash.Analyzer",
             "fuchsia.net.LegacySocketProvider",
             "fuchsia.timezone.Timezone",
             "fuchsia.tracelink.Registry"
diff --git a/runtime/dart_runner/meta/dart_jit_product_runner.cmx b/runtime/dart_runner/meta/dart_jit_product_runner.cmx
index 2f4c2ab..6f13121 100644
--- a/runtime/dart_runner/meta/dart_jit_product_runner.cmx
+++ b/runtime/dart_runner/meta/dart_jit_product_runner.cmx
@@ -7,6 +7,7 @@
             "root-ssl-certificates"
         ],
         "services": [
+            "fuchsia.crash.Analyzer",
             "fuchsia.net.LegacySocketProvider",
             "fuchsia.timezone.Timezone",
             "fuchsia.tracelink.Registry"
diff --git a/runtime/dart_runner/meta/dart_jit_runner.cmx b/runtime/dart_runner/meta/dart_jit_runner.cmx
index 2f4c2ab..6f13121 100644
--- a/runtime/dart_runner/meta/dart_jit_runner.cmx
+++ b/runtime/dart_runner/meta/dart_jit_runner.cmx
@@ -7,6 +7,7 @@
             "root-ssl-certificates"
         ],
         "services": [
+            "fuchsia.crash.Analyzer",
             "fuchsia.net.LegacySocketProvider",
             "fuchsia.timezone.Timezone",
             "fuchsia.tracelink.Registry"