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

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

Issue 469613002: Add bluetooth host and controller delegates for pairing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review fixes 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_
6 #define CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/pairing/host_pairing_controller.h"
14 #include "components/pairing/proto_decoder.h"
15 #include "device/bluetooth/bluetooth_device.h"
16 #include "device/bluetooth/bluetooth_socket.h"
17
18 namespace device {
19 class BluetoothAdapter;
20 }
21
22 namespace net {
23 class IOBuffer;
24 }
25
26 namespace pairing_chromeos {
27
28 class BluetoothHostPairingController
29 : public HostPairingController,
30 public ProtoDecoder::Observer,
31 public device::BluetoothDevice::PairingDelegate {
32 public:
33 typedef HostPairingController::Observer Observer;
34
35 BluetoothHostPairingController();
36 virtual ~BluetoothHostPairingController();
37
38 private:
39 void ChangeStage(Stage new_stage);
40 void SendHostStatus();
41 void AbortWithError(int code, const std::string& message);
42 void Reset();
43
44 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
45 void OnSetName();
46 void OnSetPowered();
47 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket);
48 void OnSetDiscoverable(bool change_stage);
49 void OnAccept(const device::BluetoothDevice* device,
50 scoped_refptr<device::BluetoothSocket> socket);
51 void OnSendComplete(int bytes_sent);
52 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer);
53
54 void OnCreateServiceError(const std::string& message);
55 void OnSetError();
56 void OnAcceptError(const std::string& error_message);
57 void OnSendError(const std::string& error_message);
58 void OnReceiveError(device::BluetoothSocket::ErrorReason reason,
59 const std::string& error_message);
60
61 // HostPairingController:
62 virtual void AddObserver(Observer* observer) OVERRIDE;
63 virtual void RemoveObserver(Observer* observer) OVERRIDE;
64 virtual Stage GetCurrentStage() OVERRIDE;
65 virtual void StartPairing() OVERRIDE;
66 virtual std::string GetDeviceName() OVERRIDE;
67 virtual std::string GetConfirmationCode() OVERRIDE;
68 virtual std::string GetEnrollmentDomain() OVERRIDE;
69
70 // ProtoDecoder::Observer:
71 virtual void OnHostStatusMessage(
72 const pairing_api::HostStatus& message) OVERRIDE;
73 virtual void OnConfigureHostMessage(
74 const pairing_api::ConfigureHost& message) OVERRIDE;
75 virtual void OnPairDevicesMessage(
76 const pairing_api::PairDevices& message) OVERRIDE;
77 virtual void OnCompleteSetupMessage(
78 const pairing_api::CompleteSetup& message) OVERRIDE;
79 virtual void OnErrorMessage(const pairing_api::Error& message) OVERRIDE;
80
81 // device::BluetoothDevice::PairingDelegate:
82 virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE;
83 virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE;
84 virtual void DisplayPinCode(device::BluetoothDevice* device,
85 const std::string& pincode) OVERRIDE;
86 virtual void DisplayPasskey(device::BluetoothDevice* device,
87 uint32 passkey) OVERRIDE;
88 virtual void KeysEntered(device::BluetoothDevice* device,
89 uint32 entered) OVERRIDE;
90 virtual void ConfirmPasskey(device::BluetoothDevice* device,
91 uint32 passkey) OVERRIDE;
92 virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE;
93
94 Stage current_stage_;
95 std::string device_name_;
96 std::string confirmation_code_;
97 std::string enrollment_domain_;
98
99 scoped_refptr<device::BluetoothAdapter> adapter_;
100 device::BluetoothDevice* device_;
101 scoped_refptr<device::BluetoothSocket> service_socket_;
102 scoped_refptr<device::BluetoothSocket> controller_socket_;
103 scoped_ptr<ProtoDecoder> proto_decoder_;
104
105 base::ThreadChecker thread_checker_;
106 ObserverList<Observer> observers_;
107 base::WeakPtrFactory<BluetoothHostPairingController> ptr_factory_;
108
109 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingController);
110 };
111
112 } // namespace pairing_chromeos
113
114 #endif // CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698