Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Unified Diff: components/pairing/bluetooth_host_pairing_controller.cc

Issue 652743003: Fix update and enrollment flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: indent Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/pairing/bluetooth_host_pairing_controller.cc
diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc
index 75308e226ce187838676a4f67ad40ef922206a9f..d5319c9f753feff4d26eb0a3d733df21dff65720 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(
« no previous file with comments | « components/pairing/bluetooth_host_pairing_controller.h ('k') | components/pairing/fake_host_pairing_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698