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

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

Issue 2888033002: Devices shoule not be found by Android enrollment app after successful enrollment. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 adapter_ = adapter; 187 adapter_ = adapter;
188 188
189 if (adapter_->IsPresent()) { 189 if (adapter_->IsPresent()) {
190 SetName(); 190 SetName();
191 } else { 191 } else {
192 // Set the name once the adapter is present. 192 // Set the name once the adapter is present.
193 adapter_->AddObserver(this); 193 adapter_->AddObserver(this);
194 } 194 }
195 } 195 }
196 196
197 void BluetoothHostPairingController::SetName() { 197 void BluetoothHostPairingController::SetName() {
zork 2017/05/17 16:59:07 I think a better name for this function would be "
198 // Hash the bluetooth address and take the lower 2 bytes to create a human 198 // Hash the bluetooth address and take the lower 2 bytes to create a human
199 // readable device name. 199 // readable device name. Clean |device_name_| if pairing is finished. Make
200 const uint32_t device_id = base::Hash(adapter_->GetAddress()) & 0xFFFF; 200 // sure the device will not be found by Android enrollment app after
201 device_name_ = 201 // successful enrollment.
202 base::StringPrintf("%s_%04X", GetChromeOSDeviceType().c_str(), device_id); 202 if (current_stage_ == STAGE_FINISHED) {
xdai1 2017/05/17 17:46:51 Per offline discussion, I would suggest to have a
203 device_name_ = std::string();
204 } else if (device_name_.empty()) {
205 const uint32_t device_id = base::Hash(adapter_->GetAddress()) & 0xFFFF;
206 device_name_ = base::StringPrintf(
207 "%s_%04X", GetChromeOSDeviceType().c_str(), device_id);
208 } else {
209 return;
210 }
203 211
204 adapter_->SetName( 212 adapter_->SetName(
205 device_name_, 213 device_name_,
206 base::Bind(&BluetoothHostPairingController::OnSetName, 214 base::Bind(&BluetoothHostPairingController::OnSetName,
207 ptr_factory_.GetWeakPtr()), 215 ptr_factory_.GetWeakPtr()),
208 base::Bind(&BluetoothHostPairingController::OnSetError, 216 base::Bind(&BluetoothHostPairingController::OnSetError,
209 ptr_factory_.GetWeakPtr())); 217 ptr_factory_.GetWeakPtr()));
210 } 218 }
211 219
212 void BluetoothHostPairingController::OnSetName() { 220 void BluetoothHostPairingController::OnSetName() {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 432 }
425 433
426 void BluetoothHostPairingController::OnCompleteSetupMessage( 434 void BluetoothHostPairingController::OnCompleteSetupMessage(
427 const pairing_api::CompleteSetup& message) { 435 const pairing_api::CompleteSetup& message) {
428 DCHECK(thread_checker_.CalledOnValidThread()); 436 DCHECK(thread_checker_.CalledOnValidThread());
429 if (current_stage_ != STAGE_ENROLLMENT_SUCCESS) { 437 if (current_stage_ != STAGE_ENROLLMENT_SUCCESS) {
430 ChangeStage(STAGE_ENROLLMENT_ERROR); 438 ChangeStage(STAGE_ENROLLMENT_ERROR);
431 } else { 439 } else {
432 // TODO(zork): Handle adding another controller. (http://crbug.com/405757) 440 // TODO(zork): Handle adding another controller. (http://crbug.com/405757)
433 ChangeStage(STAGE_FINISHED); 441 ChangeStage(STAGE_FINISHED);
442 SetName();
xdai1 2017/05/17 17:46:51 I think you should reset Bluetooth name for both s
434 } 443 }
435 Reset(); 444 Reset();
436 } 445 }
437 446
438 void BluetoothHostPairingController::OnErrorMessage( 447 void BluetoothHostPairingController::OnErrorMessage(
439 const pairing_api::Error& message) { 448 const pairing_api::Error& message) {
440 NOTREACHED(); 449 NOTREACHED();
441 } 450 }
442 451
443 void BluetoothHostPairingController::OnAddNetworkMessage( 452 void BluetoothHostPairingController::OnAddNetworkMessage(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); 586 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION);
578 } 587 }
579 588
580 void BluetoothHostPairingController::AuthorizePairing( 589 void BluetoothHostPairingController::AuthorizePairing(
581 device::BluetoothDevice* device) { 590 device::BluetoothDevice* device) {
582 // Disallow unknown device. 591 // Disallow unknown device.
583 device->RejectPairing(); 592 device->RejectPairing();
584 } 593 }
585 594
586 } // namespace pairing_chromeos 595 } // namespace pairing_chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698