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

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

Issue 552983003: Wait for the Bluetooth adapter to be present before starting 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_host_pairing_controller.h ('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"
11 #include "components/pairing/pairing_api.pb.h" 11 #include "components/pairing/pairing_api.pb.h"
12 #include "components/pairing/proto_decoder.h" 12 #include "components/pairing/proto_decoder.h"
13 #include "device/bluetooth/bluetooth_adapter_factory.h" 13 #include "device/bluetooth/bluetooth_adapter_factory.h"
14 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
15 15
16 namespace { 16 namespace {
17 const int kReceiveSize = 16384; 17 const int kReceiveSize = 16384;
18 } 18 }
19 19
20 namespace pairing_chromeos { 20 namespace pairing_chromeos {
21 21
22 BluetoothHostPairingController::BluetoothHostPairingController() 22 BluetoothHostPairingController::BluetoothHostPairingController()
23 : current_stage_(STAGE_NONE), 23 : current_stage_(STAGE_NONE),
24 device_(NULL), 24 device_(NULL),
25 proto_decoder_(new ProtoDecoder(this)), 25 proto_decoder_(new ProtoDecoder(this)),
26 ptr_factory_(this) { 26 ptr_factory_(this) {
27 } 27 }
28 28
29 BluetoothHostPairingController::~BluetoothHostPairingController() {} 29 BluetoothHostPairingController::~BluetoothHostPairingController() {}
Nikita (slow) 2014/09/16 21:54:56 Remove observer on dtor?
Zachary Kuznia 2014/09/16 22:06:37 Done.
30 30
31 void BluetoothHostPairingController::ChangeStage(Stage new_stage) { 31 void BluetoothHostPairingController::ChangeStage(Stage new_stage) {
32 if (current_stage_ == new_stage) 32 if (current_stage_ == new_stage)
33 return; 33 return;
34 current_stage_ = new_stage; 34 current_stage_ = new_stage;
35 FOR_EACH_OBSERVER(Observer, observers_, PairingStageChanged(new_stage)); 35 FOR_EACH_OBSERVER(Observer, observers_, PairingStageChanged(new_stage));
36 } 36 }
37 37
38 void BluetoothHostPairingController::SendHostStatus() { 38 void BluetoothHostPairingController::SendHostStatus() {
39 pairing_api::HostStatus host_status; 39 pairing_api::HostStatus host_status;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 99 }
100 ChangeStage(STAGE_NONE); 100 ChangeStage(STAGE_NONE);
101 } 101 }
102 102
103 void BluetoothHostPairingController::OnGetAdapter( 103 void BluetoothHostPairingController::OnGetAdapter(
104 scoped_refptr<device::BluetoothAdapter> adapter) { 104 scoped_refptr<device::BluetoothAdapter> adapter) {
105 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
106 DCHECK(!adapter_); 106 DCHECK(!adapter_);
107 adapter_ = adapter; 107 adapter_ = adapter;
108 108
109 if (adapter_->IsPresent()) {
110 SetName();
111 } else {
112 // Set the name once the adapter is present.
113 adapter_->AddObserver(this);
114 }
115 }
116
117 void BluetoothHostPairingController::SetName() {
109 // TODO(zork): Make the device name prettier. (http://crbug.com/405774) 118 // TODO(zork): Make the device name prettier. (http://crbug.com/405774)
110 device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix, 119 device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix,
111 adapter_->GetAddress().c_str()); 120 adapter_->GetAddress().c_str());
121
112 adapter_->SetName( 122 adapter_->SetName(
113 device_name_, 123 device_name_,
114 base::Bind(&BluetoothHostPairingController::OnSetName, 124 base::Bind(&BluetoothHostPairingController::OnSetName,
115 ptr_factory_.GetWeakPtr()), 125 ptr_factory_.GetWeakPtr()),
116 base::Bind(&BluetoothHostPairingController::OnSetError, 126 base::Bind(&BluetoothHostPairingController::OnSetError,
117 ptr_factory_.GetWeakPtr())); 127 ptr_factory_.GetWeakPtr()));
118 } 128 }
119 129
120 void BluetoothHostPairingController::OnSetName() { 130 void BluetoothHostPairingController::OnSetName() {
121 DCHECK(thread_checker_.CalledOnValidThread()); 131 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 301
292 // TODO(zork): Handle adding another controller. (http://crbug.com/405757) 302 // TODO(zork): Handle adding another controller. (http://crbug.com/405757)
293 ChangeStage(STAGE_FINISHED); 303 ChangeStage(STAGE_FINISHED);
294 } 304 }
295 305
296 void BluetoothHostPairingController::OnErrorMessage( 306 void BluetoothHostPairingController::OnErrorMessage(
297 const pairing_api::Error& message) { 307 const pairing_api::Error& message) {
298 NOTREACHED(); 308 NOTREACHED();
299 } 309 }
300 310
311 void BluetoothHostPairingController::AdapterPresentChanged(
312 device::BluetoothAdapter* adapter,
313 bool present) {
314 DCHECK_EQ(adapter, adapter_.get());
315 if (present) {
316 adapter_->RemoveObserver(this);
317 SetName();
318 }
319 }
320
301 void BluetoothHostPairingController::AddObserver(Observer* observer) { 321 void BluetoothHostPairingController::AddObserver(Observer* observer) {
302 observers_.AddObserver(observer); 322 observers_.AddObserver(observer);
303 } 323 }
304 324
305 void BluetoothHostPairingController::RemoveObserver(Observer* observer) { 325 void BluetoothHostPairingController::RemoveObserver(Observer* observer) {
306 observers_.RemoveObserver(observer); 326 observers_.RemoveObserver(observer);
307 } 327 }
308 328
309 HostPairingController::Stage BluetoothHostPairingController::GetCurrentStage() { 329 HostPairingController::Stage BluetoothHostPairingController::GetCurrentStage() {
310 return current_stage_; 330 return current_stage_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); 402 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION);
383 } 403 }
384 404
385 void BluetoothHostPairingController::AuthorizePairing( 405 void BluetoothHostPairingController::AuthorizePairing(
386 device::BluetoothDevice* device) { 406 device::BluetoothDevice* device) {
387 // Disallow unknown device. 407 // Disallow unknown device.
388 device->RejectPairing(); 408 device->RejectPairing();
389 } 409 }
390 410
391 } // namespace pairing_chromeos 411 } // namespace pairing_chromeos
OLDNEW
« no previous file with comments | « components/pairing/bluetooth_host_pairing_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698