summaryrefslogtreecommitdiffstats
path: root/components/pairing
diff options
context:
space:
mode:
authorzork <zork@chromium.org>2014-08-27 20:41:14 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-28 03:42:23 +0000
commit5e61edc42e69df36b816687ece1c831dfdf427dc (patch)
tree896fb60e0e1279e481536bdb75d527c1ba7092be /components/pairing
parentbb09ea0d942bd8ac75447a6a379849f5a14e5133 (diff)
downloadchromium_src-5e61edc42e69df36b816687ece1c831dfdf427dc.zip
chromium_src-5e61edc42e69df36b816687ece1c831dfdf427dc.tar.gz
chromium_src-5e61edc42e69df36b816687ece1c831dfdf427dc.tar.bz2
Update the pairing API to include configuration and enrollment.
BUG=405744 Review URL: https://codereview.chromium.org/491943004 Cr-Commit-Position: refs/heads/master@{#292309}
Diffstat (limited to 'components/pairing')
-rw-r--r--components/pairing/bluetooth_controller_pairing_controller.cc71
-rw-r--r--components/pairing/bluetooth_controller_pairing_controller.h11
-rw-r--r--components/pairing/bluetooth_host_pairing_controller.cc5
-rw-r--r--components/pairing/bluetooth_host_pairing_controller.h1
-rw-r--r--components/pairing/controller_pairing_controller.h20
-rw-r--r--components/pairing/fake_controller_pairing_controller.cc12
-rw-r--r--components/pairing/fake_controller_pairing_controller.h11
-rw-r--r--components/pairing/fake_host_pairing_controller.cc35
-rw-r--r--components/pairing/fake_host_pairing_controller.h11
-rw-r--r--components/pairing/host_pairing_controller.h31
10 files changed, 122 insertions, 86 deletions
diff --git a/components/pairing/bluetooth_controller_pairing_controller.cc b/components/pairing/bluetooth_controller_pairing_controller.cc
index c90dfb7..bb01dd7 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.cc
+++ b/components/pairing/bluetooth_controller_pairing_controller.cc
@@ -16,7 +16,6 @@
#include "net/base/io_buffer.h"
namespace {
-const char* kFakeEnrollmentDomain = "http://fake.com";
const int kReceiveSize = 16384;
}
@@ -304,20 +303,24 @@ void BluetoothControllerPairingController::SetConfirmationCodeIsCorrect(
}
}
-void BluetoothControllerPairingController::OnAuthenticationDone(
- const chromeos::UserContext& user_context,
- content::BrowserContext* browser_context) {
- DCHECK_EQ(current_stage_, STAGE_WAITING_FOR_CREDENTIALS);
-
+void BluetoothControllerPairingController::SetHostConfiguration(
+ bool accepted_eula,
+ const std::string& lang,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) {
// TODO(zork): Get configuration from UI and send to Host.
// (http://crbug.com/405744)
+}
+
+void BluetoothControllerPairingController::OnAuthenticationDone(
+ const std::string& domain,
+ const std::string& auth_token) {
+ DCHECK_EQ(current_stage_, STAGE_WAITING_FOR_CREDENTIALS);
- // TODO(zork): Get proper credentials. (http://crbug.com/405744)
- // For now, send a fake domain.
pairing_api::PairDevices pair_devices;
pair_devices.set_api_version(kPairingAPIVersion);
- pair_devices.mutable_parameters()->set_admin_access_token(
- kFakeEnrollmentDomain);
+ pair_devices.mutable_parameters()->set_admin_access_token(auth_token);
int size = 0;
scoped_refptr<net::IOBuffer> io_buffer(
@@ -341,39 +344,29 @@ void BluetoothControllerPairingController::StartSession() {
void BluetoothControllerPairingController::OnHostStatusMessage(
const pairing_api::HostStatus& message) {
if (got_initial_status_) {
- if (message.parameters().has_domain()) {
- // TODO(zork): Remove this if we don't actually need the domain for UI.
- // (http://crbug.com/405761)
- if (message.parameters().domain() == kFakeEnrollmentDomain) {
- 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));
-
- socket_->Send(
- io_buffer, size,
- base::Bind(&BluetoothControllerPairingController::OnSendComplete,
- ptr_factory_.GetWeakPtr()),
- base::Bind(
- &BluetoothControllerPairingController::OnErrorWithMessage,
- ptr_factory_.GetWeakPtr()));
- ChangeStage(STAGE_PAIRING_DONE);
- } else {
- ChangeStage(STAGE_HOST_ENROLLMENT_ERROR);
- }
- } else {
- ChangeStage(STAGE_HOST_ENROLLMENT_ERROR);
- }
+ // 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));
+
+ socket_->Send(
+ io_buffer, size,
+ base::Bind(&BluetoothControllerPairingController::OnSendComplete,
+ ptr_factory_.GetWeakPtr()),
+ base::Bind(
+ &BluetoothControllerPairingController::OnErrorWithMessage,
+ ptr_factory_.GetWeakPtr()));
+ ChangeStage(STAGE_PAIRING_DONE);
} else {
got_initial_status_ = true;
// TODO(zork): Check domain. (http://crbug.com/405761)
-
- // TODO(zork): Handling updating stages (http://crbug.com/405754).
ChangeStage(STAGE_WAITING_FOR_CREDENTIALS);
}
}
diff --git a/components/pairing/bluetooth_controller_pairing_controller.h b/components/pairing/bluetooth_controller_pairing_controller.h
index 43ddd75..7458154 100644
--- a/components/pairing/bluetooth_controller_pairing_controller.h
+++ b/components/pairing/bluetooth_controller_pairing_controller.h
@@ -66,9 +66,14 @@ class BluetoothControllerPairingController
virtual void RepeatDiscovery() OVERRIDE;
virtual std::string GetConfirmationCode() OVERRIDE;
virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE;
- virtual void OnAuthenticationDone(
- const chromeos::UserContext& user_context,
- content::BrowserContext* browser_context) OVERRIDE;
+ virtual void SetHostConfiguration(
+ bool accepted_eula,
+ const std::string& lang,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) OVERRIDE;
+ virtual void OnAuthenticationDone(const std::string& domain,
+ const std::string& auth_token) OVERRIDE;
virtual void StartSession() OVERRIDE;
// ProtoDecoder::Observer:
diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc
index fc229a1..74f1a5e 100644
--- a/components/pairing/bluetooth_host_pairing_controller.cc
+++ b/components/pairing/bluetooth_host_pairing_controller.cc
@@ -329,6 +329,11 @@ std::string BluetoothHostPairingController::GetEnrollmentDomain() {
return enrollment_domain_;
}
+void BluetoothHostPairingController::OnUpdateStatusChanged(
+ UpdateStatus update_status) {
+ // TODO(zork): Handling updating stages (http://crbug.com/405754).
+}
+
void BluetoothHostPairingController::RequestPinCode(
device::BluetoothDevice* device) {
// Disallow unknown device.
diff --git a/components/pairing/bluetooth_host_pairing_controller.h b/components/pairing/bluetooth_host_pairing_controller.h
index c033584..6f64bf5 100644
--- a/components/pairing/bluetooth_host_pairing_controller.h
+++ b/components/pairing/bluetooth_host_pairing_controller.h
@@ -66,6 +66,7 @@ class BluetoothHostPairingController
virtual std::string GetDeviceName() OVERRIDE;
virtual std::string GetConfirmationCode() OVERRIDE;
virtual std::string GetEnrollmentDomain() OVERRIDE;
+ virtual void OnUpdateStatusChanged(UpdateStatus update_status) OVERRIDE;
// ProtoDecoder::Observer:
virtual void OnHostStatusMessage(
diff --git a/components/pairing/controller_pairing_controller.h b/components/pairing/controller_pairing_controller.h
index 67ec581..d194292 100644
--- a/components/pairing/controller_pairing_controller.h
+++ b/components/pairing/controller_pairing_controller.h
@@ -24,6 +24,7 @@ class ControllerPairingController {
public:
enum Stage {
STAGE_NONE,
+ STAGE_INITIALIZATION_ERROR,
STAGE_DEVICES_DISCOVERY,
STAGE_DEVICE_NOT_FOUND,
STAGE_ESTABLISHING_CONNECTION,
@@ -59,9 +60,6 @@ class ControllerPairingController {
ControllerPairingController();
virtual ~ControllerPairingController();
- virtual void AddObserver(Observer* observer) = 0;
- virtual void RemoveObserver(Observer* observer) = 0;
-
// Returns current stage of pairing process.
virtual Stage GetCurrentStage() = 0;
@@ -89,16 +87,26 @@ class ControllerPairingController {
// |STAGE_WAITING_FOR_CODE_CONFIRMATION| stage.
virtual void SetConfirmationCodeIsCorrect(bool correct) = 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,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) = 0;
+
// Called when user successfully authenticated on GAIA page. Can be called
// only on |STAGE_WAITING_FOR_CREDENTIALS| stage.
- virtual void OnAuthenticationDone(
- const chromeos::UserContext& user_context,
- content::BrowserContext* browser_context) = 0;
+ // |auth_token| will be sent to the host to be used for enrollment.
+ virtual void OnAuthenticationDone(const std::string& domain,
+ const std::string& auth_token) = 0;
// Installs app and starts session.
// Can be called only on |STAGE_PAIRING_DONE| stage.
virtual void StartSession() = 0;
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(ControllerPairingController);
};
diff --git a/components/pairing/fake_controller_pairing_controller.cc b/components/pairing/fake_controller_pairing_controller.cc
index deb8615..0b05ee6 100644
--- a/components/pairing/fake_controller_pairing_controller.cc
+++ b/components/pairing/fake_controller_pairing_controller.cc
@@ -205,9 +205,17 @@ void FakeControllerPairingController::SetConfirmationCodeIsCorrect(
ChangeStage(STAGE_DEVICES_DISCOVERY);
}
+void FakeControllerPairingController::SetHostConfiguration(
+ bool accepted_eula,
+ const std::string& lang,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) {
+}
+
void FakeControllerPairingController::OnAuthenticationDone(
- const chromeos::UserContext& user_context,
- content::BrowserContext* browser_context) {
+ const std::string& domain,
+ const std::string& auth_token) {
CHECK(current_stage_ == STAGE_WAITING_FOR_CREDENTIALS);
ChangeStage(STAGE_HOST_ENROLLMENT_IN_PROGRESS);
}
diff --git a/components/pairing/fake_controller_pairing_controller.h b/components/pairing/fake_controller_pairing_controller.h
index ce6630a..99ac3de 100644
--- a/components/pairing/fake_controller_pairing_controller.h
+++ b/components/pairing/fake_controller_pairing_controller.h
@@ -73,9 +73,14 @@ class FakeControllerPairingController
virtual void RepeatDiscovery() OVERRIDE;
virtual std::string GetConfirmationCode() OVERRIDE;
virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE;
- virtual void OnAuthenticationDone(
- const chromeos::UserContext& user_context,
- content::BrowserContext* browser_context) OVERRIDE;
+ virtual void SetHostConfiguration(
+ bool accepted_eula,
+ const std::string& lang,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) OVERRIDE;
+ virtual void OnAuthenticationDone(const std::string& domain,
+ const std::string& auth_token) OVERRIDE;
virtual void StartSession() OVERRIDE;
private:
diff --git a/components/pairing/fake_host_pairing_controller.cc b/components/pairing/fake_host_pairing_controller.cc
index b2af9b0..80c00c8 100644
--- a/components/pairing/fake_host_pairing_controller.cc
+++ b/components/pairing/fake_host_pairing_controller.cc
@@ -16,7 +16,6 @@
namespace {
-const int kUpdateStepsNumber = 10;
const int kDefaultAsyncDurationMs = 3000;
const size_t kCodeLength = 6;
@@ -91,24 +90,6 @@ void FakeHostPairingController::ChangeStageLater(Stage new_stage) {
async_duration_);
}
-void FakeHostPairingController::SetUpdateProgress(int step) {
- UpdateProgress progress;
- progress.progress = double(step) / kUpdateStepsNumber;
- FOR_EACH_OBSERVER(Observer, observers_, UpdateAdvanced(progress));
- base::Closure task;
- if (step >= kUpdateStepsNumber) {
- task = base::Bind(&FakeHostPairingController::ChangeStage,
- base::Unretained(this),
- STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE);
- } else {
- task = base::Bind(&FakeHostPairingController::SetUpdateProgress,
- base::Unretained(this),
- step + 1);
- }
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE, task, async_duration_ / kUpdateStepsNumber);
-}
-
void FakeHostPairingController::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
@@ -143,6 +124,10 @@ std::string FakeHostPairingController::GetEnrollmentDomain() {
return enrollment_domain_;
}
+void FakeHostPairingController::OnUpdateStatusChanged(
+ UpdateStatus update_status) {
+}
+
void FakeHostPairingController::PairingStageChanged(Stage new_stage) {
switch (new_stage) {
case STAGE_WAITING_FOR_CONTROLLER: {
@@ -154,7 +139,7 @@ void FakeHostPairingController::PairingStageChanged(Stage new_stage) {
break;
}
case STAGE_UPDATING: {
- SetUpdateProgress(0);
+ ChangeStageLater(STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE);
break;
}
case STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE: {
@@ -186,7 +171,15 @@ void FakeHostPairingController::PairingStageChanged(Stage new_stage) {
}
}
-void FakeHostPairingController::UpdateAdvanced(const UpdateProgress& progress) {
+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 a071c5e..ce63b09 100644
--- a/components/pairing/fake_host_pairing_controller.h
+++ b/components/pairing/fake_host_pairing_controller.h
@@ -41,15 +41,20 @@ class FakeHostPairingController
virtual std::string GetDeviceName() OVERRIDE;
virtual std::string GetConfirmationCode() OVERRIDE;
virtual std::string GetEnrollmentDomain() OVERRIDE;
+ virtual void OnUpdateStatusChanged(UpdateStatus update_status) OVERRIDE;
private:
void ChangeStage(Stage new_stage);
void ChangeStageLater(Stage new_stage);
- void SetUpdateProgress(int step);
- // Overridden from HostPairingFlow::Observer:
+ // HostPairingFlow::Observer:
virtual void PairingStageChanged(Stage new_stage) OVERRIDE;
- virtual void UpdateAdvanced(const UpdateProgress& progress) OVERRIDE;
+ virtual void ConfigureHost(bool accepted_eula,
+ const std::string& lang,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) OVERRIDE;
+ virtual 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 7d14b6e..207fef5 100644
--- a/components/pairing/host_pairing_controller.h
+++ b/components/pairing/host_pairing_controller.h
@@ -15,6 +15,7 @@ class HostPairingController {
public:
enum Stage {
STAGE_NONE,
+ STAGE_INITIALIZATION_ERROR,
STAGE_WAITING_FOR_CONTROLLER,
STAGE_WAITING_FOR_CODE_CONFIRMATION,
STAGE_UPDATING,
@@ -26,9 +27,11 @@ class HostPairingController {
STAGE_FINISHED
};
- struct UpdateProgress {
- // Number in [0, 1].
- double progress;
+ enum UpdateStatus {
+ UPDATE_STATUS_UNKNOWN,
+ UPDATE_STATUS_UPDATING,
+ UPDATE_STATUS_REBOOTING,
+ UPDATE_STATUS_UPDATED,
};
class Observer {
@@ -39,9 +42,15 @@ class HostPairingController {
// Called when pairing has moved on from one stage to another.
virtual void PairingStageChanged(Stage new_stage) = 0;
- // Called periodically on |STAGE_UPDATING| stage. Current update progress
- // is stored in |progress|.
- virtual void UpdateAdvanced(const UpdateProgress& progress) = 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;
+
+ // Called when the controller has provided an |auth_token| for enrollment.
+ virtual void EnrollHost(const std::string& auth_token) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Observer);
@@ -50,9 +59,6 @@ class HostPairingController {
HostPairingController();
virtual ~HostPairingController();
- virtual void AddObserver(Observer* observer) = 0;
- virtual void RemoveObserver(Observer* observer) = 0;
-
// Returns current stage of pairing process.
virtual Stage GetCurrentStage() = 0;
@@ -70,6 +76,13 @@ class HostPairingController {
// |STAGE_ENROLLMENT| and later.
virtual std::string GetEnrollmentDomain() = 0;
+ // Notify that the update status has changed.
+ // Can be called on stage |STAGE_UPDATING|.
+ virtual void OnUpdateStatusChanged(UpdateStatus update_status) = 0;
+
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(HostPairingController);
};