ml: Add model loading logic to the ML service.

This change allows MachineLearningServiceImpl objects to bind
ModelRequests. They do this using a static list of model
metadata, which right now holds only one test model.

BUG=chromium:836098
TEST=Unit tests added.

Change-Id: I6b7917f2ef2919e70670b88efbf9ae43d3bd8fcc
Reviewed-on: https://chromium-review.googlesource.com/1172236
Commit-Ready: Michael Martis <martis@chromium.org>
Tested-by: Michael Martis <martis@chromium.org>
Reviewed-by: Michael Martis <martis@chromium.org>
diff --git a/ml/machine_learning_service_impl.h b/ml/machine_learning_service_impl.h
index 1c64a2d..9b188b0 100644
--- a/ml/machine_learning_service_impl.h
+++ b/ml/machine_learning_service_impl.h
@@ -5,10 +5,14 @@
 #ifndef ML_MACHINE_LEARNING_SERVICE_IMPL_H_
 #define ML_MACHINE_LEARNING_SERVICE_IMPL_H_
 
+#include <map>
+#include <string>
+
 #include <base/callback_forward.h>
 #include <base/macros.h>
 #include <mojo/public/cpp/bindings/binding.h>
 
+#include "ml/model_metadata.h"
 #include "mojom/machine_learning_service.mojom.h"
 
 namespace ml {
@@ -22,11 +26,23 @@
   MachineLearningServiceImpl(mojo::ScopedMessagePipeHandle pipe,
                              base::Closure connection_error_handler);
 
+ protected:
+  // Testing constructor that allows overriding of the model dir. Should not be
+  // used outside of tests.
+  MachineLearningServiceImpl(mojo::ScopedMessagePipeHandle pipe,
+                             base::Closure connection_error_handler,
+                             const std::string& model_dir);
+
  private:
   // chromeos::machine_learning::mojom::MachineLearningService:
-  void LoadModel(
-      chromeos::machine_learning::mojom::ModelSpecPtr spec,
-      chromeos::machine_learning::mojom::ModelRequest request) override;
+  void LoadModel(chromeos::machine_learning::mojom::ModelSpecPtr spec,
+                 chromeos::machine_learning::mojom::ModelRequest request,
+                 const LoadModelCallback& callback) override;
+
+  // Metadata required to load models. Initialized at construction.
+  const std::map<chromeos::machine_learning::mojom::ModelId, ModelMetadata>
+      model_metadata_;
+  const std::string model_dir_;
 
   mojo::Binding<chromeos::machine_learning::mojom::MachineLearningService>
       binding_;