OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 14 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
14 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | 15 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
15 #include "chrome/browser/ui/webui/options2/options_ui2.h" | 16 #include "chrome/browser/ui/webui/options2/options_ui2.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class DictionaryValue; | 19 class DictionaryValue; |
19 } | 20 } |
20 | 21 |
21 namespace chromeos { | 22 namespace chromeos { |
22 namespace options2 { | 23 namespace options2 { |
23 | 24 |
24 // Handler for Bluetooth options on the system options page. | 25 // Handler for Bluetooth options on the system options page. |
25 class BluetoothOptionsHandler : public OptionsPageUIHandler, | 26 class BluetoothOptionsHandler : public OptionsPageUIHandler, |
26 public chromeos::BluetoothAdapter::Observer { | 27 public chromeos::BluetoothAdapter::Observer, |
28 public BluetoothDevice::PairingDelegate { | |
27 public: | 29 public: |
28 BluetoothOptionsHandler(); | 30 BluetoothOptionsHandler(); |
29 virtual ~BluetoothOptionsHandler(); | 31 virtual ~BluetoothOptionsHandler(); |
30 | 32 |
31 // Potential errors during the process of pairing or connecting to a | 33 // Potential errors during the process of pairing or connecting to a |
32 // Bluetooth device. Each enumerated value is associated with an i18n | 34 // Bluetooth device. Each enumerated value is associated with an i18n |
33 // label for display in the Bluetooth UI. | 35 // label for display in the Bluetooth UI. |
34 enum ConnectionError { | 36 enum ConnectionError { |
35 DEVICE_NOT_FOUND, | 37 DEVICE_NOT_FOUND, |
36 INCORRECT_PIN, | 38 INCORRECT_PIN, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 // populate the list. | 77 // populate the list. |
76 // |args| will be an empty list. | 78 // |args| will be an empty list. |
77 void GetPairedDevicesCallback(const base::ListValue* args); | 79 void GetPairedDevicesCallback(const base::ListValue* args); |
78 | 80 |
79 // Sends a notification to the Web UI of the status of a Bluetooth device. | 81 // Sends a notification to the Web UI of the status of a Bluetooth device. |
80 // |device| is the Bluetooth device. | 82 // |device| is the Bluetooth device. |
81 // |params| is an optional set of parameters. | 83 // |params| is an optional set of parameters. |
82 void SendDeviceNotification(const BluetoothDevice* device, | 84 void SendDeviceNotification(const BluetoothDevice* device, |
83 base::DictionaryValue* params); | 85 base::DictionaryValue* params); |
84 | 86 |
85 // Displays a PIN code for a device, which is being typed remotely. This | 87 // BluetoothDevice::PairingDelegate override. |
86 // method is used for pairing Bluetooth 2.0 and older keyboards. | 88 // |
87 // |device| is the Bluetooth device being paired. | 89 // This method will be called when the Bluetooth daemon requires a |
88 // |pincode| is the required pincode. | 90 // PIN Code for authentication of the device |device|, the UI will display |
89 void DisplayPinCode(const BluetoothDevice* device, | 91 // a blank entry form to obtain the PIN code from the user. |
90 const std::string& pincode); | 92 // |
93 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices | |
94 // for which there is no automatic pairing or special handling. | |
95 virtual void RequestPinCode(BluetoothDevice* device) OVERRIDE; | |
91 | 96 |
92 // Displays a passkey for a device, which is being typed remotely. During | 97 // BluetoothDevice::PairingDelegate override. |
93 // the pairing process, this method may be called repeatedly to track the | 98 // |
94 // number of characters entered. This method is commonly used for pairing | 99 // This method will be called when the Bluetooth daemon requires a |
95 // keyboards. | 100 // Passkey for authentication of the device |device|, the UI will display |
96 // |device| is the Bluetooth device being paired. | 101 // a blank entry form to obtain the passkey from the user (a numeric in the |
97 // |passkey| is the required passkey. | 102 // range 0-999999). |
98 // |entered| is the number of characters that have already been entered on | 103 // |
99 // the remote device. | 104 // Passkeys are generally required for Bluetooth 2.1 and later devices |
100 void DisplayPasskey(const BluetoothDevice* device, | 105 // which cannot provide input or display on their own, and don't accept |
101 int passkey, | 106 // passkey-less pairing. |
102 int entered); | 107 virtual void RequestPasskey(BluetoothDevice* device) OVERRIDE; |
103 | 108 |
104 // Displays a blank field for entering a PIN code. The PIN code may be | 109 // BluetoothDevice::PairingDelegate override. |
105 // a set value specified by the manufacturer of the Bluetooth device, or | 110 // |
106 // on a remote display. | 111 // This method will be called when the Bluetooth daemon requires that the |
107 // |device| is the Bluetooth device being paired. | 112 // user enter the PIN code |pincode| into the device |device| so that it |
108 void RequestPinCode(const BluetoothDevice* device); | 113 // may be authenticated, the UI will display the PIN code with accompanying |
114 // instructions. | |
115 // | |
116 // This is used for Bluetooth 2.0 and earlier keyboard devices, the | |
117 // |pincode| will always be a six-digit numeric in the range 000000-999999 | |
118 // for compatibilty with later specifications. | |
119 virtual void DisplayPinCode(BluetoothDevice* device, | |
120 const std::string& pincode) OVERRIDE; | |
109 | 121 |
110 // Displays a blank field for entering a passkey. The passkey may be | 122 // BluetoothDevice::PairingDelegate override. |
111 // a set value specified by the manufacturer of the Bluetooth device, or | 123 // |
112 // on a remote display. The validation is asychronous, and a call is made | 124 // This method will be called when the Bluetooth daemon requires that the |
113 // to |ValidatePasskeyCallback| when the passkey entry is complete. | 125 // user enter the Passkey |passkey| into the device |device| so that it |
114 // |device| is the Bluetooth device being paired. | 126 // may be authenticated, the UI will display the passkey with accompanying |
115 void RequestPasskey(const BluetoothDevice* device); | 127 // instructions. |
128 // | |
129 // This is used for Bluetooth 2.1 and later devices that support input | |
130 // but not display, such as keyboards. The Passkey is a numeric in the | |
131 // range 0-999999 and should be always presented zero-padded to six | |
132 // digits. | |
133 virtual void DisplayPasskey(BluetoothDevice* device, | |
134 uint32 passkey) OVERRIDE; | |
116 | 135 |
117 // Displays a passkey for a device, requesting user confirmation that the | 136 // BluetoothDevice::PairingDelegate override. |
118 // key matches an expected value (value displayed on a smartphone for | 137 // |
119 // example). | 138 // This method will be called when the Bluetooth daemon requires that the |
120 // |device| is the Bluetooth device being paired. | 139 // user confirm that the Passkey |passkey| is displayed on the screen |
121 // |passkey| is the passkey to display for confirmation. | 140 // of the device |device| so that it may be authenticated, the UI will |
122 void RequestConfirmation(const BluetoothDevice* device, | 141 // display the passkey with accompanying instructions. |
123 int passkey); | 142 // |
143 // This is used for Bluetooth 2.1 and later devices that support display, | |
144 // such as other computers or phones. The Passkey is a numeric in the | |
145 // range 0-999999 and should be always present zero-padded to six | |
146 // digits. | |
147 virtual void ConfirmPasskey(BluetoothDevice* device, | |
148 uint32 passkey) OVERRIDE; | |
149 | |
150 // BluetoothDevice::PairingDelegate override. | |
151 // | |
152 // This method will be called when any previous DisplayPinCode(), | |
153 // DisplayPasskey() or ConfirmPasskey() request should be concluded | |
154 // and removed from the user. | |
155 virtual void DismissDisplayOrConfirm() OVERRIDE; | |
124 | 156 |
125 // Displays an error that occurred during the pairing or connection process. | 157 // Displays an error that occurred during the pairing or connection process. |
126 // |device| is the Bluetooth device being paired or connected. | 158 // |device| is the Bluetooth device being paired or connected. |
127 // |error| is the type of error that occurred. | 159 // |error| is the type of error that occurred. |
128 void ReportError(const BluetoothDevice* device, ConnectionError error); | 160 void ReportError(const BluetoothDevice* device, ConnectionError error); |
129 | 161 |
130 // BluetoothAdapter::Observer implementation. | 162 // BluetoothAdapter::Observer implementation. |
131 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | 163 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, |
132 bool present) OVERRIDE; | 164 bool present) OVERRIDE; |
133 virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, | 165 virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, |
134 bool powered) OVERRIDE; | 166 bool powered) OVERRIDE; |
135 virtual void DeviceAdded(BluetoothAdapter* adapter, | 167 virtual void DeviceAdded(BluetoothAdapter* adapter, |
136 BluetoothDevice* device) OVERRIDE; | 168 BluetoothDevice* device) OVERRIDE; |
137 virtual void DeviceChanged(BluetoothAdapter* adapter, | 169 virtual void DeviceChanged(BluetoothAdapter* adapter, |
138 BluetoothDevice* device) OVERRIDE; | 170 BluetoothDevice* device) OVERRIDE; |
139 virtual void DeviceRemoved(BluetoothAdapter* adapter, | 171 virtual void DeviceRemoved(BluetoothAdapter* adapter, |
140 BluetoothDevice* device) OVERRIDE; | 172 BluetoothDevice* device) OVERRIDE; |
141 | 173 |
142 private: | 174 private: |
143 // Called by BluetoothAdapter in response to our method calls in case of | 175 // Called by BluetoothAdapter in response to our method calls in case of |
144 // error. | 176 // error. |
145 void ErrorCallback(); | 177 void ErrorCallback(); |
146 | 178 |
147 // Default bluetooth adapter, used for all operations. Owned by this object. | 179 // Default bluetooth adapter, used for all operations. Owned by this object. |
148 scoped_ptr<BluetoothAdapter> adapter_; | 180 scoped_ptr<BluetoothAdapter> adapter_; |
149 | 181 |
182 // Weak pointer factory for generating 'this' pointers that might live longer | |
183 // than we do. | |
James Hawkins
2012/03/13 23:12:45
nit: Don't use 'we' (or other pronouns) in comment
keybuk
2012/03/14 00:15:26
Done.
| |
184 base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_; | |
185 | |
150 DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler); | 186 DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler); |
151 }; | 187 }; |
152 | 188 |
153 } // namespace options2 | 189 } // namespace options2 |
154 } // namespace chromeos | 190 } // namespace chromeos |
155 | 191 |
156 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_ H_ | 192 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_ H_ |
OLD | NEW |