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

Side by Side Diff: components/pairing/bluetooth_host_pairing_controller.cc

Issue 2890383003: Bootstrapping: Send meaningful error code/message from Slave to Master (Closed)
Patch Set: Address achuith@'s comments. Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/pairing/bluetooth_host_pairing_controller.h" 5 #include "components/pairing/bluetooth_host_pairing_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 ProtoDecoder::SendHostStatus(host_status, &size)); 143 ProtoDecoder::SendHostStatus(host_status, &size));
144 144
145 controller_socket_->Send( 145 controller_socket_->Send(
146 io_buffer, size, 146 io_buffer, size,
147 base::Bind(&BluetoothHostPairingController::OnSendComplete, 147 base::Bind(&BluetoothHostPairingController::OnSendComplete,
148 ptr_factory_.GetWeakPtr()), 148 ptr_factory_.GetWeakPtr()),
149 base::Bind(&BluetoothHostPairingController::OnSendError, 149 base::Bind(&BluetoothHostPairingController::OnSendError,
150 ptr_factory_.GetWeakPtr())); 150 ptr_factory_.GetWeakPtr()));
151 } 151 }
152 152
153 void BluetoothHostPairingController::SendErrorCodeAndMessage() {
154 if (error_code_ ==
155 static_cast<int>(HostPairingController::ErrorCode::ERROR_NONE)) {
156 return;
157 }
158
159 pairing_api::Error error_status;
160 error_status.set_api_version(kPairingAPIVersion);
161 error_status.mutable_parameters()->set_code(error_code_);
162 error_status.mutable_parameters()->set_description(error_message_);
163
164 int size = 0;
165 scoped_refptr<net::IOBuffer> io_buffer(
166 ProtoDecoder::SendError(error_status, &size));
167
168 controller_socket_->Send(
169 io_buffer, size,
170 base::Bind(&BluetoothHostPairingController::OnSendComplete,
171 ptr_factory_.GetWeakPtr()),
172 base::Bind(&BluetoothHostPairingController::OnSendError,
173 ptr_factory_.GetWeakPtr()));
174 }
175
153 void BluetoothHostPairingController::Reset() { 176 void BluetoothHostPairingController::Reset() {
154 if (adapter_.get()) { 177 if (adapter_.get()) {
155 device::BluetoothDevice* device = 178 device::BluetoothDevice* device =
156 adapter_->GetDevice(controller_device_address_); 179 adapter_->GetDevice(controller_device_address_);
157 if (device && device->IsPaired()) { 180 if (device && device->IsPaired()) {
158 device->Forget(base::Bind(&BluetoothHostPairingController::OnForget, 181 device->Forget(base::Bind(&BluetoothHostPairingController::OnForget,
159 ptr_factory_.GetWeakPtr()), 182 ptr_factory_.GetWeakPtr()),
160 base::Bind(&BluetoothHostPairingController::OnForget, 183 base::Bind(&BluetoothHostPairingController::OnForget,
161 ptr_factory_.GetWeakPtr())); 184 ptr_factory_.GetWeakPtr()));
162 return; 185 return;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 return confirmation_code_; 492 return confirmation_code_;
470 } 493 }
471 494
472 std::string BluetoothHostPairingController::GetEnrollmentDomain() { 495 std::string BluetoothHostPairingController::GetEnrollmentDomain() {
473 return enrollment_domain_; 496 return enrollment_domain_;
474 } 497 }
475 498
476 void BluetoothHostPairingController::OnNetworkConnectivityChanged( 499 void BluetoothHostPairingController::OnNetworkConnectivityChanged(
477 Connectivity connectivity_status) { 500 Connectivity connectivity_status) {
478 connectivity_status_ = connectivity_status; 501 connectivity_status_ = connectivity_status;
479 if (connectivity_status == CONNECTIVITY_NONE) 502 if (connectivity_status == CONNECTIVITY_NONE) {
480 ChangeStage(STAGE_SETUP_NETWORK_ERROR); 503 ChangeStage(STAGE_SETUP_NETWORK_ERROR);
481 SendHostStatus(); 504 SendErrorCodeAndMessage();
505 } else {
506 SendHostStatus();
507 }
482 } 508 }
483 509
484 void BluetoothHostPairingController::OnUpdateStatusChanged( 510 void BluetoothHostPairingController::OnUpdateStatusChanged(
485 UpdateStatus update_status) { 511 UpdateStatus update_status) {
486 update_status_ = update_status; 512 update_status_ = update_status;
487 if (update_status == UPDATE_STATUS_UPDATED) 513 if (update_status == UPDATE_STATUS_UPDATED)
488 ChangeStage(STAGE_WAITING_FOR_CREDENTIALS); 514 ChangeStage(STAGE_WAITING_FOR_CREDENTIALS);
489 SendHostStatus(); 515 SendHostStatus();
490 } 516 }
491 517
492 void BluetoothHostPairingController::OnEnrollmentStatusChanged( 518 void BluetoothHostPairingController::OnEnrollmentStatusChanged(
493 EnrollmentStatus enrollment_status) { 519 EnrollmentStatus enrollment_status) {
494 DCHECK_EQ(current_stage_, STAGE_ENROLLING); 520 DCHECK_EQ(current_stage_, STAGE_ENROLLING);
495 DCHECK(thread_checker_.CalledOnValidThread()); 521 DCHECK(thread_checker_.CalledOnValidThread());
496 522
497 enrollment_status_ = enrollment_status; 523 enrollment_status_ = enrollment_status;
498 if (enrollment_status == ENROLLMENT_STATUS_SUCCESS) { 524 if (enrollment_status == ENROLLMENT_STATUS_SUCCESS) {
499 ChangeStage(STAGE_ENROLLMENT_SUCCESS); 525 ChangeStage(STAGE_ENROLLMENT_SUCCESS);
526 SendHostStatus();
500 } else if (enrollment_status == ENROLLMENT_STATUS_FAILURE) { 527 } else if (enrollment_status == ENROLLMENT_STATUS_FAILURE) {
501 ChangeStage(STAGE_ENROLLMENT_ERROR); 528 ChangeStage(STAGE_ENROLLMENT_ERROR);
529 SendErrorCodeAndMessage();
502 } 530 }
503 SendHostStatus();
504 } 531 }
505 532
506 void BluetoothHostPairingController::SetPermanentId( 533 void BluetoothHostPairingController::SetPermanentId(
507 const std::string& permanent_id) { 534 const std::string& permanent_id) {
508 permanent_id_ = permanent_id; 535 permanent_id_ = permanent_id;
509 } 536 }
510 537
538 void BluetoothHostPairingController::SetErrorCodeAndMessage(
539 int error_code,
540 const std::string& error_message) {
541 error_code_ = error_code;
542 error_message_ = error_message;
543 }
544
511 void BluetoothHostPairingController::RequestPinCode( 545 void BluetoothHostPairingController::RequestPinCode(
512 device::BluetoothDevice* device) { 546 device::BluetoothDevice* device) {
513 // Disallow unknown device. 547 // Disallow unknown device.
514 device->RejectPairing(); 548 device->RejectPairing();
515 } 549 }
516 550
517 void BluetoothHostPairingController::RequestPasskey( 551 void BluetoothHostPairingController::RequestPasskey(
518 device::BluetoothDevice* device) { 552 device::BluetoothDevice* device) {
519 // Disallow unknown device. 553 // Disallow unknown device.
520 device->RejectPairing(); 554 device->RejectPairing();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); 588 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION);
555 } 589 }
556 590
557 void BluetoothHostPairingController::AuthorizePairing( 591 void BluetoothHostPairingController::AuthorizePairing(
558 device::BluetoothDevice* device) { 592 device::BluetoothDevice* device) {
559 // Disallow unknown device. 593 // Disallow unknown device.
560 device->RejectPairing(); 594 device->RejectPairing();
561 } 595 }
562 596
563 } // namespace pairing_chromeos 597 } // namespace pairing_chromeos
OLDNEW
« 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