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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h

Issue 10899037: Refactoring bluetooth API code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added #include <string> into bluetooth_adapter_dbus.cc. Created 8 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
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_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" 13 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_dbus.h"
bryeung 2012/09/07 18:35:57 should be using the interface
youngki 2012/09/13 18:05:02 Done.
14 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" 14 #include "chrome/browser/chromeos/bluetooth/bluetooth_device_dbus.h"
15 #include "chrome/browser/ui/webui/options/options_ui.h" 15 #include "chrome/browser/ui/webui/options/options_ui.h"
16 16
17 namespace base { 17 namespace base {
18 class DictionaryValue; 18 class DictionaryValue;
19 } 19 }
20 20
21 namespace chromeos { 21 namespace chromeos {
22 namespace options { 22 namespace options {
23 23
24 // Handler for Bluetooth options on the system options page. 24 // Handler for Bluetooth options on the system options page.
25 class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, 25 class BluetoothOptionsHandler
26 public chromeos::BluetoothAdapter::Observer, 26 : public ::options::OptionsPageUIHandler,
27 public BluetoothDevice::PairingDelegate { 27 public chromeos::BluetoothAdapterDBus::Observer,
28 public BluetoothDeviceDBus::PairingDelegate {
28 public: 29 public:
29 BluetoothOptionsHandler(); 30 BluetoothOptionsHandler();
30 virtual ~BluetoothOptionsHandler(); 31 virtual ~BluetoothOptionsHandler();
31 32
32 // OptionsPageUIHandler implementation. 33 // OptionsPageUIHandler implementation.
33 virtual void GetLocalizedValues( 34 virtual void GetLocalizedValues(
34 base::DictionaryValue* localized_strings) OVERRIDE; 35 base::DictionaryValue* localized_strings) OVERRIDE;
35 virtual void RegisterMessages() OVERRIDE; 36 virtual void RegisterMessages() OVERRIDE;
36 virtual void InitializeHandler() OVERRIDE; 37 virtual void InitializeHandler() OVERRIDE;
37 virtual void InitializePage() OVERRIDE; 38 virtual void InitializePage() OVERRIDE;
38 39
39 // Sends a notification to the Web UI of the status of a Bluetooth device. 40 // Sends a notification to the Web UI of the status of a Bluetooth device.
40 // |device| is the Bluetooth device. 41 // |device| is the Bluetooth device.
41 // |params| is an optional set of parameters. 42 // |params| is an optional set of parameters.
42 void SendDeviceNotification(const BluetoothDevice* device, 43 void SendDeviceNotification(const BluetoothDeviceInterface* device,
43 base::DictionaryValue* params); 44 base::DictionaryValue* params);
44 45
45 // BluetoothDevice::PairingDelegate override. 46 // BluetoothDeviceDBus::PairingDelegate override.
46 // 47 //
47 // This method will be called when the Bluetooth daemon requires a 48 // This method will be called when the Bluetooth daemon requires a
48 // PIN Code for authentication of the device |device|, the UI will display 49 // PIN Code for authentication of the device |device|, the UI will display
49 // a blank entry form to obtain the PIN code from the user. 50 // a blank entry form to obtain the PIN code from the user.
50 // 51 //
51 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices 52 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
52 // for which there is no automatic pairing or special handling. 53 // for which there is no automatic pairing or special handling.
53 virtual void RequestPinCode(BluetoothDevice* device) OVERRIDE; 54 virtual void RequestPinCode(BluetoothDeviceDBus* device) OVERRIDE;
54 55
55 // BluetoothDevice::PairingDelegate override. 56 // BluetoothDeviceDBus::PairingDelegate override.
56 // 57 //
57 // This method will be called when the Bluetooth daemon requires a 58 // This method will be called when the Bluetooth daemon requires a
58 // Passkey for authentication of the device |device|, the UI will display 59 // Passkey for authentication of the device |device|, the UI will display
59 // a blank entry form to obtain the passkey from the user (a numeric in the 60 // a blank entry form to obtain the passkey from the user (a numeric in the
60 // range 0-999999). 61 // range 0-999999).
61 // 62 //
62 // Passkeys are generally required for Bluetooth 2.1 and later devices 63 // Passkeys are generally required for Bluetooth 2.1 and later devices
63 // which cannot provide input or display on their own, and don't accept 64 // which cannot provide input or display on their own, and don't accept
64 // passkey-less pairing. 65 // passkey-less pairing.
65 virtual void RequestPasskey(BluetoothDevice* device) OVERRIDE; 66 virtual void RequestPasskey(BluetoothDeviceDBus* device) OVERRIDE;
66 67
67 // BluetoothDevice::PairingDelegate override. 68 // BluetoothDeviceDBus::PairingDelegate override.
68 // 69 //
69 // This method will be called when the Bluetooth daemon requires that the 70 // This method will be called when the Bluetooth daemon requires that the
70 // user enter the PIN code |pincode| into the device |device| so that it 71 // user enter the PIN code |pincode| into the device |device| so that it
71 // may be authenticated, the UI will display the PIN code with accompanying 72 // may be authenticated, the UI will display the PIN code with accompanying
72 // instructions. 73 // instructions.
73 // 74 //
74 // This is used for Bluetooth 2.0 and earlier keyboard devices, the 75 // This is used for Bluetooth 2.0 and earlier keyboard devices, the
75 // |pincode| will always be a six-digit numeric in the range 000000-999999 76 // |pincode| will always be a six-digit numeric in the range 000000-999999
76 // for compatibilty with later specifications. 77 // for compatibilty with later specifications.
77 virtual void DisplayPinCode(BluetoothDevice* device, 78 virtual void DisplayPinCode(BluetoothDeviceDBus* device,
78 const std::string& pincode) OVERRIDE; 79 const std::string& pincode) OVERRIDE;
79 80
80 // BluetoothDevice::PairingDelegate override. 81 // BluetoothDeviceDBus::PairingDelegate override.
81 // 82 //
82 // This method will be called when the Bluetooth daemon requires that the 83 // This method will be called when the Bluetooth daemon requires that the
83 // user enter the Passkey |passkey| into the device |device| so that it 84 // user enter the Passkey |passkey| into the device |device| so that it
84 // may be authenticated, the UI will display the passkey with accompanying 85 // may be authenticated, the UI will display the passkey with accompanying
85 // instructions. 86 // instructions.
86 // 87 //
87 // This is used for Bluetooth 2.1 and later devices that support input 88 // This is used for Bluetooth 2.1 and later devices that support input
88 // but not display, such as keyboards. The Passkey is a numeric in the 89 // but not display, such as keyboards. The Passkey is a numeric in the
89 // range 0-999999 and should be always presented zero-padded to six 90 // range 0-999999 and should be always presented zero-padded to six
90 // digits. 91 // digits.
91 virtual void DisplayPasskey(BluetoothDevice* device, 92 virtual void DisplayPasskey(BluetoothDeviceDBus* device,
92 uint32 passkey) OVERRIDE; 93 uint32 passkey) OVERRIDE;
93 94
94 // BluetoothDevice::PairingDelegate override. 95 // BluetoothDeviceDBus::PairingDelegate override.
95 // 96 //
96 // This method will be called when the Bluetooth daemon requires that the 97 // This method will be called when the Bluetooth daemon requires that the
97 // user confirm that the Passkey |passkey| is displayed on the screen 98 // user confirm that the Passkey |passkey| is displayed on the screen
98 // of the device |device| so that it may be authenticated, the UI will 99 // of the device |device| so that it may be authenticated, the UI will
99 // display the passkey with accompanying instructions. 100 // display the passkey with accompanying instructions.
100 // 101 //
101 // This is used for Bluetooth 2.1 and later devices that support display, 102 // This is used for Bluetooth 2.1 and later devices that support display,
102 // such as other computers or phones. The Passkey is a numeric in the 103 // such as other computers or phones. The Passkey is a numeric in the
103 // range 0-999999 and should be always present zero-padded to six 104 // range 0-999999 and should be always present zero-padded to six
104 // digits. 105 // digits.
105 virtual void ConfirmPasskey(BluetoothDevice* device, 106 virtual void ConfirmPasskey(BluetoothDeviceDBus* device,
106 uint32 passkey) OVERRIDE; 107 uint32 passkey) OVERRIDE;
107 108
108 // BluetoothDevice::PairingDelegate override. 109 // BluetoothDeviceDBus::PairingDelegate override.
109 // 110 //
110 // This method will be called when any previous DisplayPinCode(), 111 // This method will be called when any previous DisplayPinCode(),
111 // DisplayPasskey() or ConfirmPasskey() request should be concluded 112 // DisplayPasskey() or ConfirmPasskey() request should be concluded
112 // and removed from the user. 113 // and removed from the user.
113 virtual void DismissDisplayOrConfirm() OVERRIDE; 114 virtual void DismissDisplayOrConfirm() OVERRIDE;
114 115
115 // Displays a Bluetooth error. 116 // Displays a Bluetooth error.
116 // |error| maps to a localized resource for the error message. 117 // |error| maps to a localized resource for the error message.
117 // |address| is the address of the Bluetooth device. May be an empty 118 // |address| is the address of the Bluetooth device. May be an empty
118 // string if the error is not specific to a single device. 119 // string if the error is not specific to a single device.
119 void ReportError(const std::string& error, const std::string& address); 120 void ReportError(const std::string& error, const std::string& address);
120 121
121 // BluetoothAdapter::Observer implementation. 122 // BluetoothAdapterDBus::Observer implementation.
122 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, 123 virtual void AdapterPresentChanged(BluetoothAdapterDBus* adapter,
123 bool present) OVERRIDE; 124 bool present) OVERRIDE;
124 virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, 125 virtual void AdapterPoweredChanged(BluetoothAdapterDBus* adapter,
125 bool powered) OVERRIDE; 126 bool powered) OVERRIDE;
126 virtual void DeviceAdded(BluetoothAdapter* adapter, 127 virtual void DeviceAdded(BluetoothAdapterDBus* adapter,
127 BluetoothDevice* device) OVERRIDE; 128 BluetoothDeviceDBus* device) OVERRIDE;
128 virtual void DeviceChanged(BluetoothAdapter* adapter, 129 virtual void DeviceChanged(BluetoothAdapterDBus* adapter,
129 BluetoothDevice* device) OVERRIDE; 130 BluetoothDeviceDBus* device) OVERRIDE;
130 virtual void DeviceRemoved(BluetoothAdapter* adapter, 131 virtual void DeviceRemoved(BluetoothAdapterDBus* adapter,
131 BluetoothDevice* device) OVERRIDE; 132 BluetoothDeviceDBus* device) OVERRIDE;
132 133
133 private: 134 private:
134 // Called by BluetoothAdapter in response to a failure to change the 135 // Called by BluetoothAdapterDBus in response to a failure to change the
135 // power status of the adapter. 136 // power status of the adapter.
136 void EnableChangeError(); 137 void EnableChangeError();
137 138
138 // Called by BluetoothAdapter in response to a failure to set the adapter 139 // Called by BluetoothAdapterDBus in response to a failure to set the adapter
139 // into discovery mode. 140 // into discovery mode.
140 void FindDevicesError(); 141 void FindDevicesError();
141 142
142 // Called by BluetoothAdapter in response to a failure to remove the adapter 143 // Called by BluetoothAdapterDBus in response to a failure to remove the
143 // from discovery mode. 144 // adapter from discovery mode.
144 void StopDiscoveryError(); 145 void StopDiscoveryError();
145 146
146 // Called by BluetoothDevice in response to a failure to connect to the 147 // Called by BluetoothDeviceDBus in response to a failure to connect to the
147 // device with bluetooth address |address|. 148 // device with bluetooth address |address|.
148 void ConnectError(const std::string& address); 149 void ConnectError(const std::string& address);
149 150
150 // Called by BluetoothDevice in response to a failure to disconnect the 151 // Called by BluetoothDeviceDBus in response to a failure to disconnect the
151 // device with bluetooth address |address|. 152 // device with bluetooth address |address|.
152 void DisconnectError(const std::string& address); 153 void DisconnectError(const std::string& address);
153 154
154 // Called by BluetoothDevice in response to a failure to disconnect and 155 // Called by BluetoothDeviceDBus in response to a failure to disconnect and
155 // unpair the device with bluetooth address |address|. 156 // unpair the device with bluetooth address |address|.
156 void ForgetError(const std::string& address); 157 void ForgetError(const std::string& address);
157 158
158 // Called when the 'Enable bluetooth' checkbox value is changed. 159 // Called when the 'Enable bluetooth' checkbox value is changed.
159 // |args| will contain the checkbox checked state as a string 160 // |args| will contain the checkbox checked state as a string
160 // ("true" or "false"). 161 // ("true" or "false").
161 void EnableChangeCallback(const base::ListValue* args); 162 void EnableChangeCallback(const base::ListValue* args);
162 163
163 // Called when the 'Find Devices' button is pressed from the Bluetooth 164 // Called when the 'Find Devices' button is pressed from the Bluetooth
164 // ssettings. 165 // ssettings.
(...skipping 11 matching lines...) Expand all
176 // process. 177 // process.
177 // |args| will be an empty list. 178 // |args| will be an empty list.
178 void StopDiscoveryCallback(const base::ListValue* args); 179 void StopDiscoveryCallback(const base::ListValue* args);
179 180
180 // Called when the list of paired devices is initialized in order to 181 // Called when the list of paired devices is initialized in order to
181 // populate the list. 182 // populate the list.
182 // |args| will be an empty list. 183 // |args| will be an empty list.
183 void GetPairedDevicesCallback(const base::ListValue* args); 184 void GetPairedDevicesCallback(const base::ListValue* args);
184 185
185 // Default bluetooth adapter, used for all operations. 186 // Default bluetooth adapter, used for all operations.
186 scoped_refptr<BluetoothAdapter> adapter_; 187 scoped_refptr<BluetoothAdapterDBus> adapter_;
187 188
188 // Weak pointer factory for generating 'this' pointers that might live longer 189 // Weak pointer factory for generating 'this' pointers that might live longer
189 // than this object does. 190 // than this object does.
190 base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_; 191 base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_;
191 192
192 DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler); 193 DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler);
193 }; 194 };
194 195
195 } // namespace options 196 } // namespace options
196 } // namespace chromeos 197 } // namespace chromeos
197 198
198 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ 199 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698