summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxdai <xdai@chromium.org>2015-11-09 17:30:15 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-10 01:31:19 +0000
commitca9c8150df20f27a6da0526bbf4e7b417629e103 (patch)
tree6628187a5cad4a606bf708a0dfa609e6931cb95c
parent34b9c5e95141c667baaabb1b22c790b5797639af (diff)
downloadchromium_src-ca9c8150df20f27a6da0526bbf4e7b417629e103.zip
chromium_src-ca9c8150df20f27a6da0526bbf4e7b417629e103.tar.gz
chromium_src-ca9c8150df20f27a6da0526bbf4e7b417629e103.tar.bz2
Network Setup from Shark to Remora via Bluetooth.
BUG=552591 Review URL: https://codereview.chromium.org/1428353002 Cr-Commit-Position: refs/heads/master@{#358732}
-rw-r--r--chrome/browser/chromeos/login/helper.cc49
-rw-r--r--chrome/browser/chromeos/login/helper.h14
-rw-r--r--chrome/browser/chromeos/login/screens/controller_pairing_screen.cc4
-rw-r--r--chrome/browser/chromeos/login/screens/controller_pairing_screen.h3
-rw-r--r--chrome/browser/chromeos/login/screens/network_screen.cc52
-rw-r--r--chrome/browser/chromeos/login/screens/network_screen.h8
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.cc26
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.h1
-rw-r--r--components/pairing/bluetooth_controller_pairing_controller.cc22
-rw-r--r--components/pairing/bluetooth_controller_pairing_controller.h1
-rw-r--r--components/pairing/controller_pairing_controller.h3
-rw-r--r--components/pairing/fake_controller_pairing_controller.cc3
-rw-r--r--components/pairing/fake_controller_pairing_controller.h1
-rw-r--r--components/pairing/proto_decoder.cc25
-rw-r--r--components/pairing/proto_decoder.h2
15 files changed, 167 insertions, 47 deletions
diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc
index 69696fc..9db91de 100644
--- a/chrome/browser/chromeos/login/helper.cc
+++ b/chrome/browser/chromeos/login/helper.cc
@@ -15,6 +15,7 @@
#include "chrome/grit/generated_resources.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/network/managed_network_configuration_handler.h"
+#include "chromeos/network/network_connection_handler.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
@@ -128,8 +129,10 @@ base::string16 NetworkStateHelper::GetCurrentNetworkName() const {
return base::string16();
}
-void NetworkStateHelper::CreateNetworkFromOnc(
- const std::string& onc_spec) const {
+void NetworkStateHelper::CreateAndConnectNetworkFromOnc(
+ const std::string& onc_spec,
+ const base::Closure& success_callback,
+ const base::Closure& error_callback) const {
std::string error;
scoped_ptr<base::Value> root = base::JSONReader::ReadAndReturnError(
onc_spec, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error);
@@ -140,24 +143,14 @@ void NetworkStateHelper::CreateNetworkFromOnc(
return;
}
- NetworkHandler::Get()->managed_network_configuration_handler()->
- CreateConfiguration(
+ 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;
+ base::Unretained(this), success_callback, error_callback),
+ base::Bind(&NetworkStateHelper::OnCreateOrConnectNetworkFailed,
+ base::Unretained(this), error_callback));
}
bool NetworkStateHelper::IsConnected() const {
@@ -174,6 +167,26 @@ bool NetworkStateHelper::IsConnecting() const {
chromeos::NetworkTypePattern::Default()) != nullptr;
}
+void NetworkStateHelper::OnCreateConfiguration(
+ const base::Closure& success_callback,
+ const base::Closure& error_callback,
+ const std::string& service_path) const {
+ // Connect to the network.
+ NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
+ service_path, success_callback,
+ base::Bind(&NetworkStateHelper::OnCreateOrConnectNetworkFailed,
+ base::Unretained(this), error_callback),
+ false);
+}
+
+void NetworkStateHelper::OnCreateOrConnectNetworkFailed(
+ const base::Closure& error_callback,
+ const std::string& error_name,
+ scoped_ptr<base::DictionaryValue> error_data) const {
+ LOG(ERROR) << "Failed to create or connect to network: " << error_name;
+ error_callback.Run();
+}
+
content::StoragePartition* GetSigninPartition() {
content::WebContents* embedder = GetLoginWebContents();
if (!embedder)
diff --git a/chrome/browser/chromeos/login/helper.h b/chrome/browser/chromeos/login/helper.h
index c02cd5890..f25eec7 100644
--- a/chrome/browser/chromeos/login/helper.h
+++ b/chrome/browser/chromeos/login/helper.h
@@ -64,8 +64,11 @@ 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;
+ // Add and apply a network configuration. Used in shark/remora mode.
+ virtual void CreateAndConnectNetworkFromOnc(
+ const std::string& onc_spec,
+ const base::Closure& success_callback,
+ const base::Closure& error_callback) const;
// Returns true if the default network is in connected state.
virtual bool IsConnected() const;
@@ -74,8 +77,11 @@ class NetworkStateHelper {
virtual bool IsConnecting() const;
private:
- void OnCreateConfiguration(const std::string& service_path) const;
- void OnCreateConfigurationFailed(
+ void OnCreateConfiguration(const base::Closure& success_callback,
+ const base::Closure& error_callback,
+ const std::string& service_path) const;
+ void OnCreateOrConnectNetworkFailed(
+ const base::Closure& error_callback,
const std::string& error_name,
scoped_ptr<base::DictionaryValue> error_data) const;
diff --git a/chrome/browser/chromeos/login/screens/controller_pairing_screen.cc b/chrome/browser/chromeos/login/screens/controller_pairing_screen.cc
index 8fd8d0d..427d164 100644
--- a/chrome/browser/chromeos/login/screens/controller_pairing_screen.cc
+++ b/chrome/browser/chromeos/login/screens/controller_pairing_screen.cc
@@ -101,8 +101,10 @@ void ControllerPairingScreen::PairingStageChanged(Stage new_stage) {
break;
}
case ControllerPairingController::STAGE_PAIRING_DONE: {
- if (delegate_)
+ if (delegate_) {
+ delegate_->SetHostNetwork();
delegate_->SetHostConfiguration();
+ }
break;
}
case ControllerPairingController::STAGE_HOST_UPDATE_IN_PROGRESS: {
diff --git a/chrome/browser/chromeos/login/screens/controller_pairing_screen.h b/chrome/browser/chromeos/login/screens/controller_pairing_screen.h
index 9ff5323..3fd6376 100644
--- a/chrome/browser/chromeos/login/screens/controller_pairing_screen.h
+++ b/chrome/browser/chromeos/login/screens/controller_pairing_screen.h
@@ -23,6 +23,9 @@ class ControllerPairingScreen
public:
virtual ~Delegate() {}
+ // Set remora network from shark.
+ virtual void SetHostNetwork() = 0;
+
// Set remora configuration from shark.
virtual void SetHostConfiguration() = 0;
};
diff --git a/chrome/browser/chromeos/login/screens/network_screen.cc b/chrome/browser/chromeos/login/screens/network_screen.cc
index e6c7ca6..57f858b 100644
--- a/chrome/browser/chromeos/login/screens/network_screen.cc
+++ b/chrome/browser/chromeos/login/screens/network_screen.cc
@@ -4,10 +4,12 @@
#include "chrome/browser/chromeos/login/screens/network_screen.h"
+#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string16.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/base/locale_util.h"
@@ -25,7 +27,9 @@
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/network/network_handler.h"
+#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
+#include "chromeos/network/network_util.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h"
@@ -229,8 +233,43 @@ std::string NetworkScreen::GetTimezone() const {
return timezone_;
}
-void NetworkScreen::CreateNetworkFromOnc(const std::string& onc_spec) {
- network_state_helper_->CreateNetworkFromOnc(onc_spec);
+void NetworkScreen::GetConnectedWifiNetwork(std::string* out_onc_spec) {
+ // Currently We can only transfer unsecured WiFi configuration from shark to
+ // remora. There is no way to get password for a secured Wifi network in Cros
+ // for security reasons.
+ const NetworkState* network_state =
+ NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
+ NetworkTypePattern::WiFi());
+
+ if (!network_state)
+ return;
+
+ scoped_ptr<base::DictionaryValue> current_onc =
+ network_util::TranslateNetworkStateToONC(network_state);
+ std::string security;
+ current_onc->GetString(
+ onc::network_config::WifiProperty(onc::wifi::kSecurity), &security);
+ if (security != onc::wifi::kSecurityNone)
+ return;
+
+ const std::string hex_ssid = network_state->GetHexSsid();
+
+ scoped_ptr<base::DictionaryValue> copied_onc(new base::DictionaryValue());
+ copied_onc->Set(onc::toplevel_config::kType,
+ new base::StringValue(onc::network_type::kWiFi));
+ copied_onc->Set(onc::network_config::WifiProperty(onc::wifi::kHexSSID),
+ new base::StringValue(hex_ssid));
+ copied_onc->Set(onc::network_config::WifiProperty(onc::wifi::kSecurity),
+ new base::StringValue(security));
+ base::JSONWriter::Write(*copied_onc.get(), out_onc_spec);
+}
+
+void NetworkScreen::CreateAndConnectNetworkFromOnc(
+ const std::string& onc_spec) {
+ network_state_helper_->CreateAndConnectNetworkFromOnc(
+ onc_spec, base::Bind(&base::DoNothing),
+ base::Bind(&NetworkScreen::OnConnectNetworkFromOncFailed,
+ base::Unretained(this)));
}
void NetworkScreen::AddObserver(Observer* observer) {
@@ -398,4 +437,13 @@ void NetworkScreen::OnSystemTimezoneChanged() {
GetContextEditor().SetString(kContextKeyTimezone, current_timezone_id);
}
+void NetworkScreen::OnConnectNetworkFromOncFailed() {
+ if (!network_state_helper_->IsConnected() && view_) {
+ // Show error bubble.
+ view_->ShowError(l10n_util::GetStringFUTF16(
+ IDS_NETWORK_SELECTION_ERROR,
+ l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME)));
+ }
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/screens/network_screen.h b/chrome/browser/chromeos/login/screens/network_screen.h
index 749e8a3..4ee03ea 100644
--- a/chrome/browser/chromeos/login/screens/network_screen.h
+++ b/chrome/browser/chromeos/login/screens/network_screen.h
@@ -89,7 +89,10 @@ class NetworkScreen : public NetworkModel,
void SetTimezone(const std::string& timezone_id);
std::string GetTimezone() const;
- void CreateNetworkFromOnc(const std::string& onc_spec);
+ // Currently We can only get unsecured Wifi network configuration from shark
+ // that can be applied to remora. Returns the network ONC configuration.
+ void GetConnectedWifiNetwork(std::string* out_onc_spec);
+ void CreateAndConnectNetworkFromOnc(const std::string& onc_spec);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
@@ -151,6 +154,9 @@ class NetworkScreen : public NetworkModel,
// Callback when the system timezone settings is changed.
void OnSystemTimezoneChanged();
+ // Called when connection the network from ONC failed.
+ void OnConnectNetworkFromOncFailed();
+
// True if subscribed to network change notification.
bool is_network_subscribed_;
diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc
index 2e7d4b0..9b86520 100644
--- a/chrome/browser/chromeos/login/wizard_controller.cc
+++ b/chrome/browser/chromeos/login/wizard_controller.cc
@@ -1046,14 +1046,24 @@ bool WizardController::GetUsageStatisticsReporting() const {
return usage_statistics_reporting_;
}
+void WizardController::SetHostNetwork() {
+ if (!shark_controller_)
+ return;
+ NetworkScreen* network_screen = NetworkScreen::Get(this);
+ std::string onc_spec;
+ network_screen->GetConnectedWifiNetwork(&onc_spec);
+ if (!onc_spec.empty())
+ shark_controller_->SetHostNetwork(onc_spec);
+}
+
void WizardController::SetHostConfiguration() {
- if (shark_controller_) {
- NetworkScreen* network_screen = NetworkScreen::Get(this);
- shark_controller_->SetHostConfiguration(
- true, // Eula must be accepted before we get this far.
- network_screen->GetApplicationLocale(), network_screen->GetTimezone(),
- GetUsageStatisticsReporting(), network_screen->GetInputMethod());
- }
+ if (!shark_controller_)
+ return;
+ NetworkScreen* network_screen = NetworkScreen::Get(this);
+ shark_controller_->SetHostConfiguration(
+ true, // Eula must be accepted before we get this far.
+ network_screen->GetApplicationLocale(), network_screen->GetTimezone(),
+ GetUsageStatisticsReporting(), network_screen->GetInputMethod());
}
void WizardController::ConfigureHostRequested(
@@ -1076,7 +1086,7 @@ void WizardController::ConfigureHostRequested(
void WizardController::AddNetworkRequested(const std::string& onc_spec) {
NetworkScreen* network_screen = NetworkScreen::Get(this);
- network_screen->CreateNetworkFromOnc(onc_spec);
+ network_screen->CreateAndConnectNetworkFromOnc(onc_spec);
}
void WizardController::OnEnableDebuggingScreenRequested() {
diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h
index eaae940..935014c 100644
--- a/chrome/browser/chromeos/login/wizard_controller.h
+++ b/chrome/browser/chromeos/login/wizard_controller.h
@@ -246,6 +246,7 @@ class WizardController : public BaseScreenDelegate,
bool GetUsageStatisticsReporting() const override;
// Override from ControllerPairingScreen::Delegate:
+ void SetHostNetwork() override;
void SetHostConfiguration() override;
// Override from HostPairingScreen::Delegate:
diff --git a/components/pairing/bluetooth_controller_pairing_controller.cc b/components/pairing/bluetooth_controller_pairing_controller.cc
index 3d8cb6a..8f744bb 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.cc
+++ b/components/pairing/bluetooth_controller_pairing_controller.cc
@@ -312,6 +312,19 @@ void BluetoothControllerPairingController::SetConfirmationCodeIsCorrect(
}
}
+void BluetoothControllerPairingController::SetHostNetwork(
+ const std::string& onc_spec) {
+ pairing_api::AddNetwork add_network;
+ add_network.set_api_version(kPairingAPIVersion);
+ add_network.mutable_parameters()->set_onc_spec(onc_spec);
+
+ int size = 0;
+ scoped_refptr<net::IOBuffer> io_buffer(
+ ProtoDecoder::SendHostNetwork(add_network, &size));
+
+ SendBuffer(io_buffer, size);
+}
+
void BluetoothControllerPairingController::SetHostConfiguration(
bool accepted_eula,
const std::string& lang,
@@ -325,10 +338,13 @@ void BluetoothControllerPairingController::SetHostConfiguration(
pairing_api::ConfigureHost host_config;
host_config.set_api_version(kPairingAPIVersion);
host_config.mutable_parameters()->set_accepted_eula(accepted_eula);
- host_config.mutable_parameters()->set_lang(lang);
- host_config.mutable_parameters()->set_timezone(timezone);
+ if (!lang.empty())
+ host_config.mutable_parameters()->set_lang(lang);
+ if (!timezone.empty())
+ host_config.mutable_parameters()->set_timezone(timezone);
host_config.mutable_parameters()->set_send_reports(send_reports);
- host_config.mutable_parameters()->set_keyboard_layout(keyboard_layout);
+ if (!keyboard_layout.empty())
+ host_config.mutable_parameters()->set_keyboard_layout(keyboard_layout);
int size = 0;
scoped_refptr<net::IOBuffer> io_buffer(
diff --git a/components/pairing/bluetooth_controller_pairing_controller.h b/components/pairing/bluetooth_controller_pairing_controller.h
index d77f033..c987563 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.h
+++ b/components/pairing/bluetooth_controller_pairing_controller.h
@@ -66,6 +66,7 @@ class BluetoothControllerPairingController
void RepeatDiscovery() override;
std::string GetConfirmationCode() override;
void SetConfirmationCodeIsCorrect(bool correct) override;
+ void SetHostNetwork(const std::string& onc_spec) override;
void SetHostConfiguration(bool accepted_eula,
const std::string& lang,
const std::string& timezone,
diff --git a/components/pairing/controller_pairing_controller.h b/components/pairing/controller_pairing_controller.h
index 60b17a9..59a072a 100644
--- a/components/pairing/controller_pairing_controller.h
+++ b/components/pairing/controller_pairing_controller.h
@@ -88,6 +88,9 @@ class ControllerPairingController {
// |STAGE_WAITING_FOR_CODE_CONFIRMATION| stage.
virtual void SetConfirmationCodeIsCorrect(bool correct) = 0;
+ // Set the values that will be sent to the host to set its network.
+ virtual void SetHostNetwork(const std::string& onc_spec) = 0;
+
// Set the values that will be sent to the host if it needs to be configured.
virtual void SetHostConfiguration(bool accepted_eula,
const std::string& lang,
diff --git a/components/pairing/fake_controller_pairing_controller.cc b/components/pairing/fake_controller_pairing_controller.cc
index ff24b9e..89a0761 100644
--- a/components/pairing/fake_controller_pairing_controller.cc
+++ b/components/pairing/fake_controller_pairing_controller.cc
@@ -204,6 +204,9 @@ void FakeControllerPairingController::SetConfirmationCodeIsCorrect(
ChangeStage(STAGE_DEVICES_DISCOVERY);
}
+void FakeControllerPairingController::SetHostNetwork(
+ const std::string& onc_spec) {}
+
void FakeControllerPairingController::SetHostConfiguration(
bool accepted_eula,
const std::string& lang,
diff --git a/components/pairing/fake_controller_pairing_controller.h b/components/pairing/fake_controller_pairing_controller.h
index a342539..3992674 100644
--- a/components/pairing/fake_controller_pairing_controller.h
+++ b/components/pairing/fake_controller_pairing_controller.h
@@ -73,6 +73,7 @@ class FakeControllerPairingController
void RepeatDiscovery() override;
std::string GetConfirmationCode() override;
void SetConfirmationCodeIsCorrect(bool correct) override;
+ void SetHostNetwork(const std::string& onc_spec) override;
void SetHostConfiguration(bool accepted_eula,
const std::string& lang,
const std::string& timezone,
diff --git a/components/pairing/proto_decoder.cc b/components/pairing/proto_decoder.cc
index f8e42a4..52853d3 100644
--- a/components/pairing/proto_decoder.cc
+++ b/components/pairing/proto_decoder.cc
@@ -128,19 +128,27 @@ bool ProtoDecoder::DecodeIOBuffer(int size,
ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendHostStatus(
const pairing_api::HostStatus& message, int* size) {
std::string serialized_proto;
- if (!message.SerializeToString(&serialized_proto)) {
+ if (!message.SerializeToString(&serialized_proto))
NOTREACHED();
- }
return SendMessage(MESSAGE_HOST_STATUS, serialized_proto, size);
}
+ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendHostNetwork(
+ const pairing_api::AddNetwork& message,
+ int* size) {
+ std::string serialized_proto;
+ if (!message.SerializeToString(&serialized_proto))
+ NOTREACHED();
+
+ return SendMessage(MESSAGE_ADD_NETWORK, serialized_proto, size);
+}
+
ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendConfigureHost(
const pairing_api::ConfigureHost& message, int* size) {
std::string serialized_proto;
- if (!message.SerializeToString(&serialized_proto)) {
+ if (!message.SerializeToString(&serialized_proto))
NOTREACHED();
- }
return SendMessage(MESSAGE_CONFIGURE_HOST, serialized_proto, size);
}
@@ -148,9 +156,8 @@ ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendConfigureHost(
ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendPairDevices(
const pairing_api::PairDevices& message, int* size) {
std::string serialized_proto;
- if (!message.SerializeToString(&serialized_proto)) {
+ if (!message.SerializeToString(&serialized_proto))
NOTREACHED();
- }
return SendMessage(MESSAGE_PAIR_DEVICES, serialized_proto, size);
}
@@ -158,9 +165,8 @@ ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendPairDevices(
ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendCompleteSetup(
const pairing_api::CompleteSetup& message, int* size) {
std::string serialized_proto;
- if (!message.SerializeToString(&serialized_proto)) {
+ if (!message.SerializeToString(&serialized_proto))
NOTREACHED();
- }
return SendMessage(MESSAGE_COMPLETE_SETUP, serialized_proto, size);
}
@@ -168,9 +174,8 @@ ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendCompleteSetup(
ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendError(
const pairing_api::Error& message, int* size) {
std::string serialized_proto;
- if (!message.SerializeToString(&serialized_proto)) {
+ if (!message.SerializeToString(&serialized_proto))
NOTREACHED();
- }
return SendMessage(MESSAGE_ERROR, serialized_proto, size);
}
diff --git a/components/pairing/proto_decoder.h b/components/pairing/proto_decoder.h
index 826c4bb..fc02819 100644
--- a/components/pairing/proto_decoder.h
+++ b/components/pairing/proto_decoder.h
@@ -68,6 +68,8 @@ class ProtoDecoder {
// Convenience functions for serializing messages into an IOBuffer.
static IOBufferRefPtr SendHostStatus(const pairing_api::HostStatus& message,
int* size);
+ static IOBufferRefPtr SendHostNetwork(const pairing_api::AddNetwork& message,
+ int* size);
static IOBufferRefPtr SendConfigureHost(
const pairing_api::ConfigureHost& message, int* size);
static IOBufferRefPtr SendPairDevices(const pairing_api::PairDevices& message,