summaryrefslogtreecommitdiffstats
path: root/components/pairing
diff options
context:
space:
mode:
authorachuith <achuith@chromium.org>2014-10-13 20:48:34 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-14 03:49:16 +0000
commitebd853b376cb58ea120aca3617b86ae6db8785d2 (patch)
treedeb339791071540d07c9cbf1801455cf1405b2ba /components/pairing
parent74c39357ba160b985378a5867fac496ea49f23ad (diff)
downloadchromium_src-ebd853b376cb58ea120aca3617b86ae6db8785d2.zip
chromium_src-ebd853b376cb58ea120aca3617b86ae6db8785d2.tar.gz
chromium_src-ebd853b376cb58ea120aca3617b86ae6db8785d2.tar.bz2
* Transition host to STAGE_UPDATING after pairing.
* Add enrollment status to proto * Remove stages not handled by HostPairingController, and ControllerPairingController. * UpdateScreen sends update status via remora_controller. * EnrollmentScreen sends enrollment status via remora_controller. * Remove auth_token_ from EnrollmentScreen. * Rename to shark_controller and remora_controller in WizardController. * Remove get_initial_status_ from BluetoothControllerPairingController. Review URL: https://codereview.chromium.org/652743003 Cr-Commit-Position: refs/heads/master@{#299422}
Diffstat (limited to 'components/pairing')
-rw-r--r--components/pairing/bluetooth_controller_pairing_controller.cc51
-rw-r--r--components/pairing/bluetooth_controller_pairing_controller.h2
-rw-r--r--components/pairing/bluetooth_host_pairing_controller.cc81
-rw-r--r--components/pairing/bluetooth_host_pairing_controller.h5
-rw-r--r--components/pairing/fake_host_pairing_controller.cc3
-rw-r--r--components/pairing/fake_host_pairing_controller.h15
-rw-r--r--components/pairing/host_pairing_controller.h13
-rw-r--r--components/pairing/pairing_api.proto10
8 files changed, 126 insertions, 54 deletions
diff --git a/components/pairing/bluetooth_controller_pairing_controller.cc b/components/pairing/bluetooth_controller_pairing_controller.cc
index bf5e7fd..0af8051 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.cc
+++ b/components/pairing/bluetooth_controller_pairing_controller.cc
@@ -23,7 +23,6 @@ namespace pairing_chromeos {
BluetoothControllerPairingController::BluetoothControllerPairingController()
: current_stage_(STAGE_NONE),
- got_initial_status_(false),
proto_decoder_(new ProtoDecoder(this)),
ptr_factory_(this) {
}
@@ -53,7 +52,6 @@ void BluetoothControllerPairingController::ChangeStage(Stage new_stage) {
}
void BluetoothControllerPairingController::Reset() {
- got_initial_status_ = false;
controller_device_id_.clear();
discovery_session_.reset();
@@ -356,29 +354,40 @@ void BluetoothControllerPairingController::StartSession() {
void BluetoothControllerPairingController::OnHostStatusMessage(
const pairing_api::HostStatus& message) {
- if (got_initial_status_) {
- // TODO(zork): Check that the domain matches. (http://crbug.com/405761)
- // TODO(zork): Handling updating stages (http://crbug.com/405754).
- pairing_api::CompleteSetup complete_setup;
- complete_setup.set_api_version(kPairingAPIVersion);
- // TODO(zork): Get AddAnother from UI (http://crbug.com/405757)
- complete_setup.mutable_parameters()->set_add_another(false);
-
- int size = 0;
- scoped_refptr<net::IOBuffer> io_buffer(
- ProtoDecoder::SendCompleteSetup(complete_setup, &size));
-
- SendBuffer(io_buffer, size);
- ChangeStage(STAGE_PAIRING_DONE);
- } else {
- got_initial_status_ = true;
-
- // TODO(zork): Check domain. (http://crbug.com/405761)
- // TODO(achuith): Need STAGE_HOST_UPDATE_IN_PROGRESS here.
+ pairing_api::HostStatusParameters::UpdateStatus update_status =
+ message.parameters().update_status();
+ pairing_api::HostStatusParameters::EnrollmentStatus enrollment_status =
+ message.parameters().enrollment_status();
+ VLOG(1) << "OnHostStatusMessage, update_status=" << update_status;
+ // TODO(zork): Check domain. (http://crbug.com/405761)
+ if (enrollment_status ==
+ pairing_api::HostStatusParameters::ENROLLMENT_STATUS_SUCCESS) {
+ // TODO(achuith, zork): Need to ensure that controller has also successfully
+ // enrolled.
+ CompleteSetup();
+ } else if (update_status ==
+ pairing_api::HostStatusParameters::UPDATE_STATUS_UPDATING) {
+ ChangeStage(STAGE_HOST_UPDATE_IN_PROGRESS);
+ } else if (update_status ==
+ pairing_api::HostStatusParameters::UPDATE_STATUS_UPDATED) {
ChangeStage(STAGE_WAITING_FOR_CREDENTIALS);
}
}
+void BluetoothControllerPairingController::CompleteSetup() {
+ pairing_api::CompleteSetup complete_setup;
+ complete_setup.set_api_version(kPairingAPIVersion);
+ // TODO(zork): Get AddAnother from UI (http://crbug.com/405757)
+ complete_setup.mutable_parameters()->set_add_another(false);
+
+ int size = 0;
+ scoped_refptr<net::IOBuffer> io_buffer(
+ ProtoDecoder::SendCompleteSetup(complete_setup, &size));
+
+ SendBuffer(io_buffer, size);
+ ChangeStage(STAGE_PAIRING_DONE);
+}
+
void BluetoothControllerPairingController::OnConfigureHostMessage(
const pairing_api::ConfigureHost& message) {
NOTREACHED();
diff --git a/components/pairing/bluetooth_controller_pairing_controller.h b/components/pairing/bluetooth_controller_pairing_controller.h
index e0297e9..edb79bb 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.h
+++ b/components/pairing/bluetooth_controller_pairing_controller.h
@@ -39,6 +39,7 @@ class BluetoothControllerPairingController
void DeviceFound(device::BluetoothDevice* device);
void DeviceLost(device::BluetoothDevice* device);
void SendBuffer(scoped_refptr<net::IOBuffer> io_buffer, int size);
+ void CompleteSetup();
void OnSetPowered();
void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
@@ -108,7 +109,6 @@ class BluetoothControllerPairingController
virtual void AuthorizePairing(device::BluetoothDevice* device) override;
Stage current_stage_;
- bool got_initial_status_;
scoped_refptr<device::BluetoothAdapter> adapter_;
scoped_ptr<device::BluetoothDiscoverySession> discovery_session_;
scoped_refptr<device::BluetoothSocket> socket_;
diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc
index 75308e2..d5319c9 100644
--- a/components/pairing/bluetooth_host_pairing_controller.cc
+++ b/components/pairing/bluetooth_host_pairing_controller.cc
@@ -14,14 +14,51 @@
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "net/base/io_buffer.h"
+namespace pairing_chromeos {
+
namespace {
const int kReceiveSize = 16384;
+
+pairing_api::HostStatusParameters::UpdateStatus PairingApiUpdateStatus(
+ HostPairingController::UpdateStatus update_status) {
+ switch(update_status) {
+ case HostPairingController::UPDATE_STATUS_UNKNOWN:
+ return pairing_api::HostStatusParameters::UPDATE_STATUS_UNKNOWN;
+ case HostPairingController::UPDATE_STATUS_UPDATING:
+ return pairing_api::HostStatusParameters::UPDATE_STATUS_UPDATING;
+ case HostPairingController::UPDATE_STATUS_REBOOTING:
+ return pairing_api::HostStatusParameters::UPDATE_STATUS_REBOOTING;
+ case HostPairingController::UPDATE_STATUS_UPDATED:
+ return pairing_api::HostStatusParameters::UPDATE_STATUS_UPDATED;
+ default:
+ NOTREACHED();
+ return pairing_api::HostStatusParameters::UPDATE_STATUS_UNKNOWN;
+ }
}
-namespace pairing_chromeos {
+pairing_api::HostStatusParameters::EnrollmentStatus PairingApiEnrollmentStatus(
+ HostPairingController::EnrollmentStatus enrollment_status) {
+ switch(enrollment_status) {
+ case HostPairingController::ENROLLMENT_STATUS_UNKNOWN:
+ return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_UNKNOWN;
+ case HostPairingController::ENROLLMENT_STATUS_ENROLLING:
+ return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_ENROLLING;
+ case HostPairingController::ENROLLMENT_STATUS_FAILURE:
+ return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_FAILURE;
+ case HostPairingController::ENROLLMENT_STATUS_SUCCESS:
+ return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_SUCCESS;
+ default:
+ NOTREACHED();
+ return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_UNKNOWN;
+ }
+}
+
+} // namespace
BluetoothHostPairingController::BluetoothHostPairingController()
: current_stage_(STAGE_NONE),
+ update_status_(UPDATE_STATUS_UNKNOWN),
+ enrollment_status_(ENROLLMENT_STATUS_UNKNOWN),
device_(NULL),
proto_decoder_(new ProtoDecoder(this)),
ptr_factory_(this) {
@@ -51,7 +88,9 @@ void BluetoothHostPairingController::SendHostStatus() {
host_status.mutable_parameters()->set_connectivity(
pairing_api::HostStatusParameters::CONNECTIVITY_CONNECTED);
host_status.mutable_parameters()->set_update_status(
- pairing_api::HostStatusParameters::UPDATE_STATUS_UPDATED);
+ PairingApiUpdateStatus(update_status_));
+ host_status.mutable_parameters()->set_enrollment_status(
+ PairingApiEnrollmentStatus(enrollment_status_));
// TODO(zork): Get a list of other paired controllers.
// (http://crbug.com/405757)
@@ -206,7 +245,7 @@ void BluetoothHostPairingController::OnAccept(
base::Bind(&BluetoothHostPairingController::OnReceiveError,
ptr_factory_.GetWeakPtr()));
- ChangeStage(STAGE_WAITING_FOR_CREDENTIALS);
+ ChangeStage(STAGE_UPDATING);
}
void BluetoothHostPairingController::OnSetDiscoverable(bool change_stage) {
@@ -279,27 +318,11 @@ void BluetoothHostPairingController::OnConfigureHostMessage(
void BluetoothHostPairingController::OnPairDevicesMessage(
const pairing_api::PairDevices& message) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (current_stage_ != STAGE_WAITING_FOR_CREDENTIALS) {
- AbortWithError(PAIRING_ERROR_PAIRING_OR_ENROLLMENT, kErrorInvalidProtocol);
- return;
- }
-
ChangeStage(STAGE_ENROLLING);
FOR_EACH_OBSERVER(Observer, observers_,
EnrollHost(message.parameters().admin_access_token()));
}
-void BluetoothHostPairingController::SetEnrollmentComplete(bool success) {
- DCHECK_EQ(current_stage_, STAGE_ENROLLING);
- DCHECK(thread_checker_.CalledOnValidThread());
- if (success) {
- ChangeStage(STAGE_PAIRING_DONE);
- SendHostStatus();
- } else {
- AbortWithError(PAIRING_ERROR_PAIRING_OR_ENROLLMENT, kErrorEnrollmentFailed);
- }
-}
-
void BluetoothHostPairingController::OnCompleteSetupMessage(
const pairing_api::CompleteSetup& message) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -368,7 +391,25 @@ std::string BluetoothHostPairingController::GetEnrollmentDomain() {
void BluetoothHostPairingController::OnUpdateStatusChanged(
UpdateStatus update_status) {
- // TODO(zork): Handling updating stages (http://crbug.com/405754).
+ update_status_ = update_status;
+ if (update_status == UPDATE_STATUS_UPDATED)
+ ChangeStage(STAGE_WAITING_FOR_CREDENTIALS);
+ SendHostStatus();
+}
+
+void BluetoothHostPairingController::OnEnrollmentStatusChanged(
+ EnrollmentStatus enrollment_status) {
+ DCHECK_EQ(current_stage_, STAGE_ENROLLING);
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ enrollment_status_ = enrollment_status;
+ if (enrollment_status == ENROLLMENT_STATUS_SUCCESS) {
+ ChangeStage(STAGE_PAIRING_DONE);
+ } else if (enrollment_status == ENROLLMENT_STATUS_FAILURE) {
+ AbortWithError(PAIRING_ERROR_PAIRING_OR_ENROLLMENT,
+ kErrorEnrollmentFailed);
+ }
+ SendHostStatus();
}
void BluetoothHostPairingController::RequestPinCode(
diff --git a/components/pairing/bluetooth_host_pairing_controller.h b/components/pairing/bluetooth_host_pairing_controller.h
index edc39fa..5a1dc744 100644
--- a/components/pairing/bluetooth_host_pairing_controller.h
+++ b/components/pairing/bluetooth_host_pairing_controller.h
@@ -70,7 +70,8 @@ class BluetoothHostPairingController
virtual std::string GetConfirmationCode() override;
virtual std::string GetEnrollmentDomain() override;
virtual void OnUpdateStatusChanged(UpdateStatus update_status) override;
- virtual void SetEnrollmentComplete(bool success) override;
+ virtual void OnEnrollmentStatusChanged(
+ EnrollmentStatus enrollment_status) override;
// ProtoDecoder::Observer:
virtual void OnHostStatusMessage(
@@ -104,6 +105,8 @@ class BluetoothHostPairingController
std::string device_name_;
std::string confirmation_code_;
std::string enrollment_domain_;
+ UpdateStatus update_status_;
+ EnrollmentStatus enrollment_status_;
scoped_refptr<device::BluetoothAdapter> adapter_;
device::BluetoothDevice* device_;
diff --git a/components/pairing/fake_host_pairing_controller.cc b/components/pairing/fake_host_pairing_controller.cc
index 541a433..7b3cc0d 100644
--- a/components/pairing/fake_host_pairing_controller.cc
+++ b/components/pairing/fake_host_pairing_controller.cc
@@ -128,7 +128,8 @@ void FakeHostPairingController::OnUpdateStatusChanged(
UpdateStatus update_status) {
}
-void FakeHostPairingController::SetEnrollmentComplete(bool success) {
+void FakeHostPairingController::OnEnrollmentStatusChanged(
+ EnrollmentStatus enrollment_status) {
}
void FakeHostPairingController::PairingStageChanged(Stage new_stage) {
diff --git a/components/pairing/fake_host_pairing_controller.h b/components/pairing/fake_host_pairing_controller.h
index 138963a..48335ce 100644
--- a/components/pairing/fake_host_pairing_controller.h
+++ b/components/pairing/fake_host_pairing_controller.h
@@ -33,7 +33,11 @@ class FakeHostPairingController
// Applies given |config| to flow.
void ApplyConfig(const std::string& config);
- // Overridden from HostPairingFlow:
+ private:
+ void ChangeStage(Stage new_stage);
+ void ChangeStageLater(Stage new_stage);
+
+ // HostPairingController:
virtual void AddObserver(Observer* observer) override;
virtual void RemoveObserver(Observer* observer) override;
virtual Stage GetCurrentStage() override;
@@ -42,13 +46,10 @@ class FakeHostPairingController
virtual std::string GetConfirmationCode() override;
virtual std::string GetEnrollmentDomain() override;
virtual void OnUpdateStatusChanged(UpdateStatus update_status) override;
- virtual void SetEnrollmentComplete(bool success) override;
-
- private:
- void ChangeStage(Stage new_stage);
- void ChangeStageLater(Stage new_stage);
+ virtual void OnEnrollmentStatusChanged(
+ EnrollmentStatus enrollment_status) override;
- // HostPairingFlow::Observer:
+ // HostPairingController::Observer:
virtual void PairingStageChanged(Stage new_stage) override;
virtual void ConfigureHost(bool accepted_eula,
const std::string& lang,
diff --git a/components/pairing/host_pairing_controller.h b/components/pairing/host_pairing_controller.h
index 6ca88ea..5c5d96d 100644
--- a/components/pairing/host_pairing_controller.h
+++ b/components/pairing/host_pairing_controller.h
@@ -34,6 +34,13 @@ class HostPairingController {
UPDATE_STATUS_UPDATED,
};
+ enum EnrollmentStatus {
+ ENROLLMENT_STATUS_UNKNOWN,
+ ENROLLMENT_STATUS_ENROLLING,
+ ENROLLMENT_STATUS_FAILURE,
+ ENROLLMENT_STATUS_SUCCESS,
+ };
+
class Observer {
public:
Observer();
@@ -80,8 +87,10 @@ class HostPairingController {
// Can be called on stage |STAGE_UPDATING|.
virtual void OnUpdateStatusChanged(UpdateStatus update_status) = 0;
- // Called when enrollment has completed.
- virtual void SetEnrollmentComplete(bool success) = 0;
+ // Notify that enrollment status has changed.
+ // Can be called on stage |STAGE_WAITING_FOR_CREDENTIALS|.
+ virtual void OnEnrollmentStatusChanged(
+ EnrollmentStatus enrollment_status) = 0;
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
diff --git a/components/pairing/pairing_api.proto b/components/pairing/pairing_api.proto
index 98eab7a..0d8e668 100644
--- a/components/pairing/pairing_api.proto
+++ b/components/pairing/pairing_api.proto
@@ -26,10 +26,18 @@ message HostStatusParameters {
UPDATE_STATUS_UPDATED = 3;
}
+ enum EnrollmentStatus {
+ ENROLLMENT_STATUS_UNKNOWN = 0;
+ ENROLLMENT_STATUS_ENROLLING = 1;
+ ENROLLMENT_STATUS_FAILURE = 2;
+ ENROLLMENT_STATUS_SUCCESS = 3;
+ }
+
optional string domain = 1;
optional Connectivity connectivity = 2;
optional UpdateStatus update_status = 3;
- repeated string paired_controllers = 4;
+ optional EnrollmentStatus enrollment_status = 4;
+ repeated string paired_controllers = 5;
}
message HostStatus {