diff options
22 files changed, 152 insertions, 93 deletions
diff --git a/chrome/browser/chromeos/login/enrollment/enrollment_screen.cc b/chrome/browser/chromeos/login/enrollment/enrollment_screen.cc index 07039ae..8e6c4f4 100644 --- a/chrome/browser/chromeos/login/enrollment/enrollment_screen.cc +++ b/chrome/browser/chromeos/login/enrollment/enrollment_screen.cc @@ -141,14 +141,7 @@ void EnrollmentScreen::PairingStageChanged(Stage new_stage) { } } -void EnrollmentScreen::ConfigureHost(bool accepted_eula, - const std::string& lang, - const std::string& timezone, - bool send_reports, - const std::string& keyboard_layout) { -} - -void EnrollmentScreen::EnrollHost(const std::string& auth_token) { +void EnrollmentScreen::EnrollHostRequested(const std::string& auth_token) { actor_->Show(); actor_->ShowEnrollmentSpinnerScreen(); CreateEnrollmentHelper(); diff --git a/chrome/browser/chromeos/login/enrollment/enrollment_screen.h b/chrome/browser/chromeos/login/enrollment/enrollment_screen.h index 664cc63..b932144 100644 --- a/chrome/browser/chromeos/login/enrollment/enrollment_screen.h +++ b/chrome/browser/chromeos/login/enrollment/enrollment_screen.h @@ -68,12 +68,7 @@ class EnrollmentScreen // pairing_chromeos::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; + void EnrollHostRequested(const std::string& auth_token) override; // EnrollmentScreenActor::Controller implementation: void OnLoginDone(const std::string& user, diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index decb068..a0177c5 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/command_line.h" +#include "base/json/json_reader.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" @@ -13,6 +14,7 @@ #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/grit/generated_resources.h" #include "chromeos/chromeos_switches.h" +#include "chromeos/network/managed_network_configuration_handler.h" #include "chromeos/network/network_handler.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" @@ -131,18 +133,50 @@ base::string16 NetworkStateHelper::GetCurrentNetworkName() const { return base::string16(); } +void NetworkStateHelper::CreateNetworkFromOnc( + const std::string& onc_spec) const { + std::string error; + scoped_ptr<base::Value> root(base::JSONReader::ReadAndReturnError( + onc_spec, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error)); + + base::DictionaryValue* toplevel_onc = nullptr; + if (!root || !root->GetAsDictionary(&toplevel_onc)) { + LOG(ERROR) << "Invalid JSON Dictionary: " << error; + return; + } + + NetworkHandler::Get()->managed_network_configuration_handler()-> + CreateConfiguration( + "", *toplevel_onc, + base::Bind(&NetworkStateHelper::OnCreateConfiguration, + base::Unretained(this)), + base::Bind(&NetworkStateHelper::OnCreateConfigurationFailed, + base::Unretained(this))); +} + +void NetworkStateHelper::OnCreateConfiguration( + const std::string& service_path) const { + // Do Nothing. +} + +void NetworkStateHelper::OnCreateConfigurationFailed( + const std::string& error_name, + scoped_ptr<base::DictionaryValue> error_data) const { + LOG(ERROR) << "Failed to create network configuration: " << error_name; +} + bool NetworkStateHelper::IsConnected() const { chromeos::NetworkStateHandler* nsh = chromeos::NetworkHandler::Get()->network_state_handler(); return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) != - NULL; + nullptr; } bool NetworkStateHelper::IsConnecting() const { chromeos::NetworkStateHandler* nsh = chromeos::NetworkHandler::Get()->network_state_handler(); return nsh->ConnectingNetworkByType( - chromeos::NetworkTypePattern::Default()) != NULL; + chromeos::NetworkTypePattern::Default()) != nullptr; } content::StoragePartition* GetSigninPartition() { diff --git a/chrome/browser/chromeos/login/helper.h b/chrome/browser/chromeos/login/helper.h index 2809d66..c02cd5890 100644 --- a/chrome/browser/chromeos/login/helper.h +++ b/chrome/browser/chromeos/login/helper.h @@ -64,6 +64,9 @@ class NetworkStateHelper { // Ethernet > WiFi > Cellular. Same for connecting network. virtual base::string16 GetCurrentNetworkName() const; + // Add a network configuration. + virtual void CreateNetworkFromOnc(const std::string& onc_spec) const; + // Returns true if the default network is in connected state. virtual bool IsConnected() const; @@ -71,6 +74,11 @@ class NetworkStateHelper { virtual bool IsConnecting() const; private: + void OnCreateConfiguration(const std::string& service_path) const; + void OnCreateConfigurationFailed( + const std::string& error_name, + scoped_ptr<base::DictionaryValue> error_data) const; + DISALLOW_COPY_AND_ASSIGN(NetworkStateHelper); }; diff --git a/chrome/browser/chromeos/login/screens/host_pairing_screen.cc b/chrome/browser/chromeos/login/screens/host_pairing_screen.cc index a2921e2..fba3190 100644 --- a/chrome/browser/chromeos/login/screens/host_pairing_screen.cc +++ b/chrome/browser/chromeos/login/screens/host_pairing_screen.cc @@ -84,24 +84,30 @@ void HostPairingScreen::PairingStageChanged(Stage new_stage) { CommitContextChanges(); } -void HostPairingScreen::ConfigureHost(bool accepted_eula, - const std::string& lang, - const std::string& timezone, - bool send_reports, - const std::string& keyboard_layout) { +void HostPairingScreen::ConfigureHostRequested( + bool accepted_eula, + const std::string& lang, + const std::string& timezone, + bool send_reports, + const std::string& keyboard_layout) { VLOG(1) << "ConfigureHostMessage language=" << lang << ", timezone=" << timezone << ", keyboard_layout=" << keyboard_layout; remora_controller_->RemoveObserver(this); if (delegate_) { - delegate_->ConfigureHost( + delegate_->ConfigureHostRequested( accepted_eula, lang, timezone, send_reports, keyboard_layout); } Finish(WizardController::HOST_PAIRING_FINISHED); } -void HostPairingScreen::EnrollHost(const std::string& auth_token) { +void HostPairingScreen::AddNetworkRequested(const std::string& onc_spec) { + if (delegate_) + delegate_->AddNetworkRequested(onc_spec); +} + +void HostPairingScreen::EnrollHostRequested(const std::string& auth_token) { NOTREACHED(); } diff --git a/chrome/browser/chromeos/login/screens/host_pairing_screen.h b/chrome/browser/chromeos/login/screens/host_pairing_screen.h index 37c4598..73df4b8 100644 --- a/chrome/browser/chromeos/login/screens/host_pairing_screen.h +++ b/chrome/browser/chromeos/login/screens/host_pairing_screen.h @@ -21,11 +21,18 @@ class HostPairingScreen class Delegate { public: virtual ~Delegate() {} - virtual void ConfigureHost(bool accepted_eula, - const std::string& lang, - const std::string& timezone, - bool send_reports, - const std::string& keyboard_layout) = 0; + + // Called when a configuration has been received, and should be applied to + // this device. + virtual void ConfigureHostRequested(bool accepted_eula, + const std::string& lang, + const std::string& timezone, + bool send_reports, + const std::string& keyboard_layout) = 0; + + // Called when a network configuration has been received, and should be + // used on this device. + virtual void AddNetworkRequested(const std::string& onc_spec) = 0; }; HostPairingScreen(BaseScreenDelegate* base_screen_delegate, @@ -47,12 +54,13 @@ class HostPairingScreen // pairing_chromeos::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; + void ConfigureHostRequested(bool accepted_eula, + const std::string& lang, + const std::string& timezone, + bool send_reports, + const std::string& keyboard_layout) override; + void AddNetworkRequested(const std::string& onc_spec) override; + void EnrollHostRequested(const std::string& auth_token) override; // Overridden from ControllerPairingView::Delegate: void OnActorDestroyed(HostPairingScreenActor* actor) override; diff --git a/chrome/browser/chromeos/login/screens/network_screen.cc b/chrome/browser/chromeos/login/screens/network_screen.cc index f451b52..c842646 100644 --- a/chrome/browser/chromeos/login/screens/network_screen.cc +++ b/chrome/browser/chromeos/login/screens/network_screen.cc @@ -224,6 +224,10 @@ std::string NetworkScreen::GetTimezone() const { return timezone_; } +void NetworkScreen::CreateNetworkFromOnc(const std::string& onc_spec) { + network_state_helper_->CreateNetworkFromOnc(onc_spec); +} + void NetworkScreen::AddObserver(Observer* observer) { if (observer) observers_.AddObserver(observer); diff --git a/chrome/browser/chromeos/login/screens/network_screen.h b/chrome/browser/chromeos/login/screens/network_screen.h index 5c8cc2d..9c1ae66 100644 --- a/chrome/browser/chromeos/login/screens/network_screen.h +++ b/chrome/browser/chromeos/login/screens/network_screen.h @@ -88,6 +88,8 @@ class NetworkScreen : public NetworkModel, void SetTimezone(const std::string& timezone_id); std::string GetTimezone() const; + void CreateNetworkFromOnc(const std::string& onc_spec); + void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index 56f4a8a..cf5f6df 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -1054,11 +1054,12 @@ void WizardController::SetHostConfiguration() { } } -void WizardController::ConfigureHost(bool accepted_eula, - const std::string& lang, - const std::string& timezone, - bool send_reports, - const std::string& keyboard_layout) { +void WizardController::ConfigureHostRequested( + bool accepted_eula, + const std::string& lang, + const std::string& timezone, + bool send_reports, + const std::string& keyboard_layout) { VLOG(1) << "ConfigureHost locale=" << lang << ", timezone=" << timezone << ", keyboard_layout=" << keyboard_layout; if (accepted_eula) // Always true. @@ -1071,6 +1072,11 @@ void WizardController::ConfigureHost(bool accepted_eula, network_screen->SetInputMethod(keyboard_layout); } +void WizardController::AddNetworkRequested(const std::string& onc_spec) { + NetworkScreen* network_screen = NetworkScreen::Get(this); + network_screen->CreateNetworkFromOnc(onc_spec); +} + void WizardController::OnEnableDebuggingScreenRequested() { if (!login_screen_started()) AdvanceToScreen(WizardController::kEnableDebuggingScreenName); diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h index 0a4b8c6..1767d16 100644 --- a/chrome/browser/chromeos/login/wizard_controller.h +++ b/chrome/browser/chromeos/login/wizard_controller.h @@ -248,11 +248,12 @@ class WizardController : public BaseScreenDelegate, void SetHostConfiguration() override; // Override from HostPairingScreen::Delegate: - void ConfigureHost(bool accepted_eula, - const std::string& lang, - const std::string& timezone, - bool send_reports, - const std::string& keyboard_layout) override; + void ConfigureHostRequested(bool accepted_eula, + const std::string& lang, + const std::string& timezone, + bool send_reports, + const std::string& keyboard_layout) override; + void AddNetworkRequested(const std::string& onc_spec) override; // Override from NetworkScreen::Delegate: void OnEnableDebuggingScreenRequested() override; 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 @@ void BluetoothControllerPairingController::OnErrorMessage( 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 c4a3258..ab67aed 100644 --- a/components/pairing/bluetooth_controller_pairing_controller.h +++ b/components/pairing/bluetooth_controller_pairing_controller.h @@ -83,6 +83,7 @@ class BluetoothControllerPairingController 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..580d92f 100644 --- a/components/pairing/bluetooth_host_pairing_controller.cc +++ b/components/pairing/bluetooth_host_pairing_controller.cc @@ -307,11 +307,12 @@ void BluetoothHostPairingController::OnHostStatusMessage( 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 @@ void BluetoothHostPairingController::OnPairDevicesMessage( 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 @@ void BluetoothHostPairingController::OnErrorMessage( 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 b99af24..20ba506 100644 --- a/components/pairing/bluetooth_host_pairing_controller.h +++ b/components/pairing/bluetooth_host_pairing_controller.h @@ -80,6 +80,7 @@ class BluetoothHostPairingController 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::PairingStageChanged(Stage new_stage) { } } -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..17d6884 100644 --- a/components/pairing/fake_host_pairing_controller.h +++ b/components/pairing/fake_host_pairing_controller.h @@ -50,12 +50,6 @@ class FakeHostPairingController // 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 @@ class HostPairingController { 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 0d8e668..856feae 100644 --- a/components/pairing/pairing_api.proto +++ b/components/pairing/pairing_api.proto @@ -86,3 +86,12 @@ message Error { 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 96b3c24..f8e42a4 100644 --- a/components/pairing/proto_decoder.cc +++ b/components/pairing/proto_decoder.cc @@ -15,6 +15,7 @@ enum { MESSAGE_PAIR_DEVICES, MESSAGE_COMPLETE_SETUP, MESSAGE_ERROR, + MESSAGE_ADD_NETWORK, NUM_MESSAGES, }; } @@ -105,9 +106,15 @@ bool ProtoDecoder::DecodeIOBuffer(int size, 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..826c4bb 100644 --- a/components/pairing/proto_decoder.h +++ b/components/pairing/proto_decoder.h @@ -18,6 +18,7 @@ class IOBuffer; } namespace pairing_api { +class AddNetwork; class CompleteSetup; class ConfigureHost; class Error; @@ -47,6 +48,8 @@ class ProtoDecoder { 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..a6bc655 100644 --- a/components/pairing/shark_connection_listener.cc +++ b/components/pairing/shark_connection_listener.cc @@ -30,17 +30,4 @@ void SharkConnectionListener::PairingStageChanged(Stage new_stage) { } } -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..c0b3836 100644 --- a/components/pairing/shark_connection_listener.h +++ b/components/pairing/shark_connection_listener.h @@ -30,12 +30,6 @@ class SharkConnectionListener : public HostPairingController::Observer { // 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_; |