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

Side by Side Diff: device/bluetooth/bluetooth_device.cc

Issue 13416005: Bluetooth: clean up BluetoothDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More win visible fixes Created 7 years, 8 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
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_device_chromeos.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "device/bluetooth/bluetooth_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "device/bluetooth/bluetooth_utils.h" 10 #include "device/bluetooth/bluetooth_utils.h"
11 #include "grit/device_bluetooth_strings.h" 11 #include "grit/device_bluetooth_strings.h"
12 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 13
14 namespace device { 14 namespace device {
15 15
16 // static 16 // static
17 bool BluetoothDevice::IsUUIDValid(const std::string& uuid) { 17 bool BluetoothDevice::IsUUIDValid(const std::string& uuid) {
18 return !bluetooth_utils::CanonicalUuid(uuid).empty(); 18 return !bluetooth_utils::CanonicalUuid(uuid).empty();
19 } 19 }
20 20
21 BluetoothDevice::BluetoothDevice() 21 BluetoothDevice::BluetoothDevice() {
22 : bluetooth_class_(0),
23 visible_(false),
24 bonded_(false),
25 connected_(false),
26 connectable_(true),
27 connecting_(false) {
28 } 22 }
29 23
30 BluetoothDevice::~BluetoothDevice() { 24 BluetoothDevice::~BluetoothDevice() {
31 } 25 }
32 26
33 const std::string& BluetoothDevice::address() const {
34 return address_;
35 }
36
37 string16 BluetoothDevice::GetName() const { 27 string16 BluetoothDevice::GetName() const {
38 if (!name_.empty()) { 28 std::string name = GetDeviceName();
39 return UTF8ToUTF16(name_); 29 if (!name.empty()) {
30 return UTF8ToUTF16(name);
40 } else { 31 } else {
41 return GetAddressWithLocalizedDeviceTypeName(); 32 return GetAddressWithLocalizedDeviceTypeName();
42 } 33 }
43 } 34 }
44 35
45 string16 BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() const { 36 string16 BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() const {
46 string16 address = UTF8ToUTF16(address_); 37 string16 address_utf16 = UTF8ToUTF16(GetAddress());
47 BluetoothDevice::DeviceType device_type = GetDeviceType(); 38 BluetoothDevice::DeviceType device_type = GetDeviceType();
48 switch (device_type) { 39 switch (device_type) {
49 case DEVICE_COMPUTER: 40 case DEVICE_COMPUTER:
50 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER, 41 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER,
51 address); 42 address_utf16);
52 case DEVICE_PHONE: 43 case DEVICE_PHONE:
53 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE, 44 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE,
54 address); 45 address_utf16);
55 case DEVICE_MODEM: 46 case DEVICE_MODEM:
56 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM, 47 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM,
57 address); 48 address_utf16);
58 case DEVICE_AUDIO: 49 case DEVICE_AUDIO:
59 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_AUDIO, 50 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_AUDIO,
60 address); 51 address_utf16);
61 case DEVICE_CAR_AUDIO: 52 case DEVICE_CAR_AUDIO:
62 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_CAR_AUDIO, 53 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_CAR_AUDIO,
63 address); 54 address_utf16);
64 case DEVICE_VIDEO: 55 case DEVICE_VIDEO:
65 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_VIDEO, 56 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_VIDEO,
66 address); 57 address_utf16);
67 case DEVICE_JOYSTICK: 58 case DEVICE_JOYSTICK:
68 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_JOYSTICK, 59 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_JOYSTICK,
69 address); 60 address_utf16);
70 case DEVICE_GAMEPAD: 61 case DEVICE_GAMEPAD:
71 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_GAMEPAD, 62 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_GAMEPAD,
72 address); 63 address_utf16);
73 case DEVICE_KEYBOARD: 64 case DEVICE_KEYBOARD:
74 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_KEYBOARD, 65 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_KEYBOARD,
75 address); 66 address_utf16);
76 case DEVICE_MOUSE: 67 case DEVICE_MOUSE:
77 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MOUSE, 68 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MOUSE,
78 address); 69 address_utf16);
79 case DEVICE_TABLET: 70 case DEVICE_TABLET:
80 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET, 71 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET,
81 address); 72 address_utf16);
82 case DEVICE_KEYBOARD_MOUSE_COMBO: 73 case DEVICE_KEYBOARD_MOUSE_COMBO:
83 return l10n_util::GetStringFUTF16( 74 return l10n_util::GetStringFUTF16(
84 IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address); 75 IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address_utf16);
85 default: 76 default:
86 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN, address); 77 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN,
78 address_utf16);
87 } 79 }
88 } 80 }
89 81
90 BluetoothDevice::DeviceType BluetoothDevice::GetDeviceType() const { 82 BluetoothDevice::DeviceType BluetoothDevice::GetDeviceType() const {
91 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm 83 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
92 switch ((bluetooth_class_ & 0x1f00) >> 8) { 84 uint32 bluetooth_class = GetBluetoothClass();
85 switch ((bluetooth_class & 0x1f00) >> 8) {
93 case 0x01: 86 case 0x01:
94 // Computer major device class. 87 // Computer major device class.
95 return DEVICE_COMPUTER; 88 return DEVICE_COMPUTER;
96 case 0x02: 89 case 0x02:
97 // Phone major device class. 90 // Phone major device class.
98 switch ((bluetooth_class_ & 0xfc) >> 2) { 91 switch ((bluetooth_class & 0xfc) >> 2) {
99 case 0x01: 92 case 0x01:
100 case 0x02: 93 case 0x02:
101 case 0x03: 94 case 0x03:
102 // Cellular, cordless and smart phones. 95 // Cellular, cordless and smart phones.
103 return DEVICE_PHONE; 96 return DEVICE_PHONE;
104 case 0x04: 97 case 0x04:
105 case 0x05: 98 case 0x05:
106 // Modems: wired or voice gateway and common ISDN access. 99 // Modems: wired or voice gateway and common ISDN access.
107 return DEVICE_MODEM; 100 return DEVICE_MODEM;
108 } 101 }
109 break; 102 break;
110 case 0x04: 103 case 0x04:
111 // Audio major device class. 104 // Audio major device class.
112 switch ((bluetooth_class_ & 0xfc) >> 2) { 105 switch ((bluetooth_class & 0xfc) >> 2) {
113 case 0x08: 106 case 0x08:
114 // Car audio. 107 // Car audio.
115 return DEVICE_CAR_AUDIO; 108 return DEVICE_CAR_AUDIO;
116 case 0x0b: 109 case 0x0b:
117 case 0x0c: 110 case 0x0c:
118 case 0x0d: 111 case 0x0d:
119 case 0x0e: 112 case 0x0e:
120 case 0x0f: 113 case 0x0f:
121 case 0x010: 114 case 0x010:
122 // Video devices. 115 // Video devices.
123 return DEVICE_VIDEO; 116 return DEVICE_VIDEO;
124 default: 117 default:
125 return DEVICE_AUDIO; 118 return DEVICE_AUDIO;
126 } 119 }
127 break; 120 break;
128 case 0x05: 121 case 0x05:
129 // Peripheral major device class. 122 // Peripheral major device class.
130 switch ((bluetooth_class_ & 0xc0) >> 6) { 123 switch ((bluetooth_class & 0xc0) >> 6) {
131 case 0x00: 124 case 0x00:
132 // "Not a keyboard or pointing device." 125 // "Not a keyboard or pointing device."
133 switch ((bluetooth_class_ & 0x01e) >> 2) { 126 switch ((bluetooth_class & 0x01e) >> 2) {
134 case 0x01: 127 case 0x01:
135 // Joystick. 128 // Joystick.
136 return DEVICE_JOYSTICK; 129 return DEVICE_JOYSTICK;
137 case 0x02: 130 case 0x02:
138 // Gamepad. 131 // Gamepad.
139 return DEVICE_GAMEPAD; 132 return DEVICE_GAMEPAD;
140 default: 133 default:
141 return DEVICE_PERIPHERAL; 134 return DEVICE_PERIPHERAL;
142 } 135 }
143 break; 136 break;
144 case 0x01: 137 case 0x01:
145 // Keyboard. 138 // Keyboard.
146 return DEVICE_KEYBOARD; 139 return DEVICE_KEYBOARD;
147 case 0x02: 140 case 0x02:
148 // Pointing device. 141 // Pointing device.
149 switch ((bluetooth_class_ & 0x01e) >> 2) { 142 switch ((bluetooth_class & 0x01e) >> 2) {
150 case 0x05: 143 case 0x05:
151 // Digitizer tablet. 144 // Digitizer tablet.
152 return DEVICE_TABLET; 145 return DEVICE_TABLET;
153 default: 146 default:
154 // Mouse. 147 // Mouse.
155 return DEVICE_MOUSE; 148 return DEVICE_MOUSE;
156 } 149 }
157 break; 150 break;
158 case 0x03: 151 case 0x03:
159 // Combo device. 152 // Combo device.
160 return DEVICE_KEYBOARD_MOUSE_COMBO; 153 return DEVICE_KEYBOARD_MOUSE_COMBO;
161 } 154 }
162 break; 155 break;
163 } 156 }
164 157
165 return DEVICE_UNKNOWN; 158 return DEVICE_UNKNOWN;
166 } 159 }
167 160
168 bool BluetoothDevice::IsVisible() const {
169 return visible_;
170 }
171
172 bool BluetoothDevice::IsBonded() const {
173 return bonded_;
174 }
175
176 bool BluetoothDevice::IsConnected() const {
177 return connected_;
178 }
179
180 bool BluetoothDevice::IsConnectable() const {
181 return connectable_;
182 }
183
184 bool BluetoothDevice::IsConnecting() const {
185 return connecting_;
186 }
187 161
188 bool BluetoothDevice::ProvidesServiceWithUUID( 162 bool BluetoothDevice::ProvidesServiceWithUUID(
189 const std::string& uuid) const { 163 const std::string& uuid) const {
190 std::string canonical_uuid = bluetooth_utils::CanonicalUuid(uuid); 164 std::string canonical_uuid = bluetooth_utils::CanonicalUuid(uuid);
191 const BluetoothDevice::ServiceList& services = GetServices(); 165 BluetoothDevice::ServiceList services = GetServices();
192 for (BluetoothDevice::ServiceList::const_iterator iter = services.begin(); 166 for (BluetoothDevice::ServiceList::const_iterator iter = services.begin();
193 iter != services.end(); 167 iter != services.end();
194 ++iter) { 168 ++iter) {
195 if (bluetooth_utils::CanonicalUuid(*iter) == canonical_uuid) 169 if (bluetooth_utils::CanonicalUuid(*iter) == canonical_uuid)
196 return true; 170 return true;
197 } 171 }
198 return false; 172 return false;
199 } 173 }
200 174
201 } // namespace device 175 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_device_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698