Add AddNetwork message to pairing API.

BUG=None

Review URL: https://codereview.chromium.org/1090483002

Cr-Commit-Position: refs/heads/master@{#326206}
diff --git a/components/pairing/bluetooth_controller_pairing_controller.cc b/components/pairing/bluetooth_controller_pairing_controller.cc
index 1d8e026..476b205 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.cc
+++ b/components/pairing/bluetooth_controller_pairing_controller.cc
@@ -417,6 +417,11 @@
   ChangeStage(STAGE_HOST_ENROLLMENT_ERROR);
 }
 
+void BluetoothControllerPairingController::OnAddNetworkMessage(
+    const pairing_api::AddNetwork& message) {
+  NOTREACHED();
+}
+
 void BluetoothControllerPairingController::DeviceAdded(
     device::BluetoothAdapter* adapter,
     device::BluetoothDevice* device) {
diff --git a/components/pairing/bluetooth_controller_pairing_controller.h b/components/pairing/bluetooth_controller_pairing_controller.h
index c4a3258d..ab67aed 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.h
+++ b/components/pairing/bluetooth_controller_pairing_controller.h
@@ -83,6 +83,7 @@
   void OnCompleteSetupMessage(
       const pairing_api::CompleteSetup& message) override;
   void OnErrorMessage(const pairing_api::Error& message) override;
+  void OnAddNetworkMessage(const pairing_api::AddNetwork& message) override;
 
   // BluetoothAdapter::Observer:
   void DeviceAdded(device::BluetoothAdapter* adapter,
diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc
index 5ffd2f5..580d92f0 100644
--- a/components/pairing/bluetooth_host_pairing_controller.cc
+++ b/components/pairing/bluetooth_host_pairing_controller.cc
@@ -307,11 +307,12 @@
 void BluetoothHostPairingController::OnConfigureHostMessage(
     const pairing_api::ConfigureHost& message) {
   FOR_EACH_OBSERVER(Observer, observers_,
-                    ConfigureHost(message.parameters().accepted_eula(),
-                                  message.parameters().lang(),
-                                  message.parameters().timezone(),
-                                  message.parameters().send_reports(),
-                                  message.parameters().keyboard_layout()));
+                    ConfigureHostRequested(
+                        message.parameters().accepted_eula(),
+                        message.parameters().lang(),
+                        message.parameters().timezone(),
+                        message.parameters().send_reports(),
+                        message.parameters().keyboard_layout()));
 }
 
 void BluetoothHostPairingController::OnPairDevicesMessage(
@@ -319,7 +320,8 @@
   DCHECK(thread_checker_.CalledOnValidThread());
   ChangeStage(STAGE_ENROLLING);
   FOR_EACH_OBSERVER(Observer, observers_,
-                    EnrollHost(message.parameters().admin_access_token()));
+                    EnrollHostRequested(
+                        message.parameters().admin_access_token()));
 }
 
 void BluetoothHostPairingController::OnCompleteSetupMessage(
@@ -339,6 +341,13 @@
   NOTREACHED();
 }
 
+void BluetoothHostPairingController::OnAddNetworkMessage(
+    const pairing_api::AddNetwork& message) {
+  DCHECK(thread_checker_.CalledOnValidThread());
+  FOR_EACH_OBSERVER(Observer, observers_,
+                    AddNetworkRequested(message.parameters().onc_spec()));
+}
+
 void BluetoothHostPairingController::AdapterPresentChanged(
     device::BluetoothAdapter* adapter,
     bool present) {
diff --git a/components/pairing/bluetooth_host_pairing_controller.h b/components/pairing/bluetooth_host_pairing_controller.h
index b99af24d..20ba506 100644
--- a/components/pairing/bluetooth_host_pairing_controller.h
+++ b/components/pairing/bluetooth_host_pairing_controller.h
@@ -80,6 +80,7 @@
   void OnCompleteSetupMessage(
       const pairing_api::CompleteSetup& message) override;
   void OnErrorMessage(const pairing_api::Error& message) override;
+  void OnAddNetworkMessage(const pairing_api::AddNetwork& message) override;
 
   // BluetoothAdapter::Observer:
   void AdapterPresentChanged(device::BluetoothAdapter* adapter,
diff --git a/components/pairing/fake_host_pairing_controller.cc b/components/pairing/fake_host_pairing_controller.cc
index e6d1e76..25250d02 100644
--- a/components/pairing/fake_host_pairing_controller.cc
+++ b/components/pairing/fake_host_pairing_controller.cc
@@ -169,15 +169,4 @@
   }
 }
 
-void FakeHostPairingController::ConfigureHost(
-    bool accepted_eula,
-    const std::string& lang,
-    const std::string& timezone,
-    bool send_reports,
-    const std::string& keyboard_layout) {
-}
-
-void FakeHostPairingController::EnrollHost(const std::string& auth_token) {
-}
-
 }  // namespace pairing_chromeos
diff --git a/components/pairing/fake_host_pairing_controller.h b/components/pairing/fake_host_pairing_controller.h
index 8ef2f4b..17d68840 100644
--- a/components/pairing/fake_host_pairing_controller.h
+++ b/components/pairing/fake_host_pairing_controller.h
@@ -50,12 +50,6 @@
 
   // HostPairingController::Observer:
   void PairingStageChanged(Stage new_stage) override;
-  void ConfigureHost(bool accepted_eula,
-                     const std::string& lang,
-                     const std::string& timezone,
-                     bool send_reports,
-                     const std::string& keyboard_layout) override;
-  void EnrollHost(const std::string& auth_token) override;
 
   ObserverList<Observer> observers_;
   Stage current_stage_;
diff --git a/components/pairing/host_pairing_controller.h b/components/pairing/host_pairing_controller.h
index 7d79c4f..731707a 100644
--- a/components/pairing/host_pairing_controller.h
+++ b/components/pairing/host_pairing_controller.h
@@ -49,14 +49,17 @@
     virtual void PairingStageChanged(Stage new_stage) = 0;
 
     // Called when the controller has sent a configuration to apply.
-    virtual void ConfigureHost(bool accepted_eula,
-                               const std::string& lang,
-                               const std::string& timezone,
-                               bool send_reports,
-                               const std::string& keyboard_layout) = 0;
+    virtual void ConfigureHostRequested(bool accepted_eula,
+                                        const std::string& lang,
+                                        const std::string& timezone,
+                                        bool send_reports,
+                                        const std::string& keyboard_layout) {}
+
+    // Called when the controller has sent a network to add.
+    virtual void AddNetworkRequested(const std::string& onc_spec) {}
 
     // Called when the controller has provided an |auth_token| for enrollment.
-    virtual void EnrollHost(const std::string& auth_token) = 0;
+    virtual void EnrollHostRequested(const std::string& auth_token) {}
 
    private:
     DISALLOW_COPY_AND_ASSIGN(Observer);
diff --git a/components/pairing/pairing_api.proto b/components/pairing/pairing_api.proto
index 0d8e6680..856feae6 100644
--- a/components/pairing/pairing_api.proto
+++ b/components/pairing/pairing_api.proto
@@ -86,3 +86,12 @@
   optional int32 api_version = 1;
   optional ErrorParameters parameters = 2;
 }
+
+message AddNetworkParameters {
+  optional string onc_spec = 1;
+}
+
+message AddNetwork {
+  optional int32 api_version = 1;
+  optional AddNetworkParameters parameters = 2;
+}
diff --git a/components/pairing/proto_decoder.cc b/components/pairing/proto_decoder.cc
index 96b3c24f..f8e42a4b 100644
--- a/components/pairing/proto_decoder.cc
+++ b/components/pairing/proto_decoder.cc
@@ -15,6 +15,7 @@
   MESSAGE_PAIR_DEVICES,
   MESSAGE_COMPLETE_SETUP,
   MESSAGE_ERROR,
+  MESSAGE_ADD_NETWORK,
   NUM_MESSAGES,
 };
 }
@@ -105,9 +106,15 @@
         observer_->OnErrorMessage(message);
       }
       break;
+    case MESSAGE_ADD_NETWORK: {
+        pairing_api::AddNetwork message;
+        message.ParseFromArray(&buffer[0], buffer.size());
+        observer_->OnAddNetworkMessage(message);
+      }
+      break;
 
     default:
-      NOTREACHED();
+      LOG(WARNING) << "Skipping unknown message type: " << next_message_type_;
       break;
   }
 
diff --git a/components/pairing/proto_decoder.h b/components/pairing/proto_decoder.h
index e36eb7f..826c4bb0 100644
--- a/components/pairing/proto_decoder.h
+++ b/components/pairing/proto_decoder.h
@@ -18,6 +18,7 @@
 }
 
 namespace pairing_api {
+class AddNetwork;
 class CompleteSetup;
 class ConfigureHost;
 class Error;
@@ -47,6 +48,8 @@
         const pairing_api::CompleteSetup& message) = 0;
     virtual void OnErrorMessage(
         const pairing_api::Error& message) = 0;
+    virtual void OnAddNetworkMessage(
+        const pairing_api::AddNetwork& message) = 0;
 
    protected:
     Observer() {}
diff --git a/components/pairing/shark_connection_listener.cc b/components/pairing/shark_connection_listener.cc
index ce63aa0..a6bc655f 100644
--- a/components/pairing/shark_connection_listener.cc
+++ b/components/pairing/shark_connection_listener.cc
@@ -30,17 +30,4 @@
   }
 }
 
-void SharkConnectionListener::ConfigureHost(
-    bool accepted_eula,
-    const std::string& lang,
-    const std::string& timezone,
-    bool send_reports,
-    const std::string& keyboard_layout) {
-  NOTREACHED();
-}
-
-void SharkConnectionListener::EnrollHost(const std::string& auth_token) {
-  NOTREACHED();
-}
-
 }  // namespace pairing_chromeos
diff --git a/components/pairing/shark_connection_listener.h b/components/pairing/shark_connection_listener.h
index 98a7829..c0b3836b 100644
--- a/components/pairing/shark_connection_listener.h
+++ b/components/pairing/shark_connection_listener.h
@@ -30,12 +30,6 @@
 
   // HostPairingController::Observer overrides:
   void PairingStageChanged(Stage new_stage) override;
-  void ConfigureHost(bool accepted_eula,
-                     const std::string& lang,
-                     const std::string& timezone,
-                     bool send_reports,
-                     const std::string& keyboard_layout) override;
-  void EnrollHost(const std::string& auth_token) override;
 
   OnConnectedCallback callback_;
   scoped_ptr<HostPairingController> controller_;