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

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

Issue 575273002: Clean up protocol for Bluetooth Pairing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « components/pairing/bluetooth_controller_pairing_controller.cc ('k') | 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/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "components/pairing/bluetooth_pairing_constants.h" 10 #include "components/pairing/bluetooth_pairing_constants.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 if (adapter_->IsPresent()) { 112 if (adapter_->IsPresent()) {
113 SetName(); 113 SetName();
114 } else { 114 } else {
115 // Set the name once the adapter is present. 115 // Set the name once the adapter is present.
116 adapter_->AddObserver(this); 116 adapter_->AddObserver(this);
117 } 117 }
118 } 118 }
119 119
120 void BluetoothHostPairingController::SetName() { 120 void BluetoothHostPairingController::SetName() {
121 // TODO(zork): Make the device name prettier. (http://crbug.com/405774) 121 int device_id = 0;
122 device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix, 122 for (size_t i = 0; i < adapter_->GetAddress().length(); ++i) {
123 adapter_->GetAddress().c_str()); 123 int value = adapter_->GetAddress()[i];
124 if (i % 2) {
125 value *= 0x100;
126 }
127 device_id ^= value;
128 }
129
dzhioev (left Google) 2014/09/18 04:12:37 Does this cycle calculate some hash function? Can
Zachary Kuznia 2014/09/18 08:45:47 Good call, done and done.
130 device_name_ = base::StringPrintf("%s%04X", kDeviceNamePrefix, device_id);
dzhioev (left Google) 2014/09/18 04:12:37 You should use 'unsigned int' with 'X' flag.
Zachary Kuznia 2014/09/18 08:45:47 Done.
124 131
125 adapter_->SetName( 132 adapter_->SetName(
126 device_name_, 133 device_name_,
127 base::Bind(&BluetoothHostPairingController::OnSetName, 134 base::Bind(&BluetoothHostPairingController::OnSetName,
128 ptr_factory_.GetWeakPtr()), 135 ptr_factory_.GetWeakPtr()),
129 base::Bind(&BluetoothHostPairingController::OnSetError, 136 base::Bind(&BluetoothHostPairingController::OnSetError,
130 ptr_factory_.GetWeakPtr())); 137 ptr_factory_.GetWeakPtr()));
131 } 138 }
132 139
133 void BluetoothHostPairingController::OnSetName() { 140 void BluetoothHostPairingController::OnSetName() {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 kReceiveSize, 232 kReceiveSize,
226 base::Bind(&BluetoothHostPairingController::OnReceiveComplete, 233 base::Bind(&BluetoothHostPairingController::OnReceiveComplete,
227 ptr_factory_.GetWeakPtr()), 234 ptr_factory_.GetWeakPtr()),
228 base::Bind(&BluetoothHostPairingController::OnReceiveError, 235 base::Bind(&BluetoothHostPairingController::OnReceiveError,
229 ptr_factory_.GetWeakPtr())); 236 ptr_factory_.GetWeakPtr()));
230 } 237 }
231 238
232 void BluetoothHostPairingController::OnCreateServiceError( 239 void BluetoothHostPairingController::OnCreateServiceError(
233 const std::string& message) { 240 const std::string& message) {
234 LOG(ERROR) << message; 241 LOG(ERROR) << message;
235 // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) 242 ChangeStage(STAGE_INITIALIZATION_ERROR);
236 ChangeStage(STAGE_NONE);
237 } 243 }
238 244
239 void BluetoothHostPairingController::OnSetError() { 245 void BluetoothHostPairingController::OnSetError() {
240 adapter_->RemovePairingDelegate(this); 246 adapter_->RemovePairingDelegate(this);
241 // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) 247 ChangeStage(STAGE_INITIALIZATION_ERROR);
242 ChangeStage(STAGE_NONE);
243 } 248 }
244 249
245 void BluetoothHostPairingController::OnAcceptError( 250 void BluetoothHostPairingController::OnAcceptError(
246 const std::string& error_message) { 251 const std::string& error_message) {
247 LOG(ERROR) << error_message; 252 LOG(ERROR) << error_message;
248 Reset(); 253 Reset();
249 } 254 }
250 255
251 void BluetoothHostPairingController::OnSendError( 256 void BluetoothHostPairingController::OnSendError(
252 const std::string& error_message) { 257 const std::string& error_message) {
253 LOG(ERROR) << error_message; 258 LOG(ERROR) << error_message;
254 } 259 }
255 260
256 void BluetoothHostPairingController::OnReceiveError( 261 void BluetoothHostPairingController::OnReceiveError(
257 device::BluetoothSocket::ErrorReason reason, 262 device::BluetoothSocket::ErrorReason reason,
258 const std::string& error_message) { 263 const std::string& error_message) {
259 LOG(ERROR) << reason << ", " << error_message; 264 LOG(ERROR) << reason << ", " << error_message;
260 Reset(); 265 Reset();
261 } 266 }
262 267
263 void BluetoothHostPairingController::OnHostStatusMessage( 268 void BluetoothHostPairingController::OnHostStatusMessage(
264 const pairing_api::HostStatus& message) { 269 const pairing_api::HostStatus& message) {
265 NOTREACHED(); 270 NOTREACHED();
266 } 271 }
267 272
268 void BluetoothHostPairingController::OnConfigureHostMessage( 273 void BluetoothHostPairingController::OnConfigureHostMessage(
269 const pairing_api::ConfigureHost& message) { 274 const pairing_api::ConfigureHost& message) {
270 // TODO(zork): Add event to API to handle this case. (http://crbug.com/405744) 275 FOR_EACH_OBSERVER(Observer, observers_,
276 ConfigureHost(message.parameters().accepted_eula(),
277 message.parameters().lang(),
278 message.parameters().timezone(),
279 message.parameters().send_reports(),
280 message.parameters().keyboard_layout()));
271 } 281 }
272 282
273 void BluetoothHostPairingController::OnPairDevicesMessage( 283 void BluetoothHostPairingController::OnPairDevicesMessage(
274 const pairing_api::PairDevices& message) { 284 const pairing_api::PairDevices& message) {
275 DCHECK(thread_checker_.CalledOnValidThread()); 285 DCHECK(thread_checker_.CalledOnValidThread());
276 if (current_stage_ != STAGE_WAITING_FOR_CREDENTIALS) { 286 if (current_stage_ != STAGE_WAITING_FOR_CREDENTIALS) {
277 AbortWithError(PAIRING_ERROR_PAIRING_OR_ENROLLMENT, kErrorInvalidProtocol); 287 AbortWithError(PAIRING_ERROR_PAIRING_OR_ENROLLMENT, kErrorInvalidProtocol);
278 return; 288 return;
279 } 289 }
280 290
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 340 }
331 341
332 HostPairingController::Stage BluetoothHostPairingController::GetCurrentStage() { 342 HostPairingController::Stage BluetoothHostPairingController::GetCurrentStage() {
333 return current_stage_; 343 return current_stage_;
334 } 344 }
335 345
336 void BluetoothHostPairingController::StartPairing() { 346 void BluetoothHostPairingController::StartPairing() {
337 DCHECK_EQ(current_stage_, STAGE_NONE); 347 DCHECK_EQ(current_stage_, STAGE_NONE);
338 bool bluetooth_available = 348 bool bluetooth_available =
339 device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); 349 device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable();
340 // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) 350 if (!bluetooth_available) {
341 if (!bluetooth_available) 351 ChangeStage(STAGE_INITIALIZATION_ERROR);
342 return; 352 return;
353 }
343 354
344 device::BluetoothAdapterFactory::GetAdapter( 355 device::BluetoothAdapterFactory::GetAdapter(
345 base::Bind(&BluetoothHostPairingController::OnGetAdapter, 356 base::Bind(&BluetoothHostPairingController::OnGetAdapter,
346 ptr_factory_.GetWeakPtr())); 357 ptr_factory_.GetWeakPtr()));
347 } 358 }
348 359
349 std::string BluetoothHostPairingController::GetDeviceName() { 360 std::string BluetoothHostPairingController::GetDeviceName() {
350 return device_name_; 361 return device_name_;
351 } 362 }
352 363
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); 416 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION);
406 } 417 }
407 418
408 void BluetoothHostPairingController::AuthorizePairing( 419 void BluetoothHostPairingController::AuthorizePairing(
409 device::BluetoothDevice* device) { 420 device::BluetoothDevice* device) {
410 // Disallow unknown device. 421 // Disallow unknown device.
411 device->RejectPairing(); 422 device->RejectPairing();
412 } 423 }
413 424
414 } // namespace pairing_chromeos 425 } // namespace pairing_chromeos
OLDNEW
« no previous file with comments | « components/pairing/bluetooth_controller_pairing_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698