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

Side by Side Diff: chrome/browser/chromeos/bluetooth/bluetooth_device.cc

Issue 11075006: Moved bluetooth adapter files to device/bluetooth/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 (c) 2012 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 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "grit/generated_resources.h"
9 #include "ui/base/l10n/l10n_util.h"
10
11 namespace chromeos {
12
13 BluetoothDevice::BluetoothDevice()
14 : bluetooth_class_(0),
15 visible_(false),
16 bonded_(false),
17 connected_(false) {
18 }
19
20 BluetoothDevice::~BluetoothDevice() {
21 }
22
23 const std::string& BluetoothDevice::address() const {
24 return address_;
25 }
26
27 string16 BluetoothDevice::GetName() const {
28 if (!name_.empty()) {
29 return UTF8ToUTF16(name_);
30 } else {
31 return GetAddressWithLocalizedDeviceTypeName();
32 }
33 }
34
35 string16 BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() const {
36 string16 address = UTF8ToUTF16(address_);
37 BluetoothDevice::DeviceType device_type = GetDeviceType();
38 switch (device_type) {
39 case DEVICE_COMPUTER:
40 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER,
41 address);
42 case DEVICE_PHONE:
43 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE,
44 address);
45 case DEVICE_MODEM:
46 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM,
47 address);
48 case DEVICE_JOYSTICK:
49 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_JOYSTICK,
50 address);
51 case DEVICE_GAMEPAD:
52 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_GAMEPAD,
53 address);
54 case DEVICE_KEYBOARD:
55 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_KEYBOARD,
56 address);
57 case DEVICE_MOUSE:
58 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MOUSE,
59 address);
60 case DEVICE_TABLET:
61 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET,
62 address);
63 case DEVICE_KEYBOARD_MOUSE_COMBO:
64 return l10n_util::GetStringFUTF16(
65 IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address);
66 default:
67 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN, address);
68 }
69 }
70
71 BluetoothDevice::DeviceType BluetoothDevice::GetDeviceType() const {
72 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
73 switch ((bluetooth_class_ & 0x1f00) >> 8) {
74 case 0x01:
75 // Computer major device class.
76 return DEVICE_COMPUTER;
77 case 0x02:
78 // Phone major device class.
79 switch ((bluetooth_class_ & 0xfc) >> 2) {
80 case 0x01:
81 case 0x02:
82 case 0x03:
83 // Cellular, cordless and smart phones.
84 return DEVICE_PHONE;
85 case 0x04:
86 case 0x05:
87 // Modems: wired or voice gateway and common ISDN access.
88 return DEVICE_MODEM;
89 }
90 break;
91 case 0x05:
92 // Peripheral major device class.
93 switch ((bluetooth_class_ & 0xc0) >> 6) {
94 case 0x00:
95 // "Not a keyboard or pointing device."
96 switch ((bluetooth_class_ & 0x01e) >> 2) {
97 case 0x01:
98 // Joystick.
99 return DEVICE_JOYSTICK;
100 case 0x02:
101 // Gamepad.
102 return DEVICE_GAMEPAD;
103 default:
104 return DEVICE_PERIPHERAL;
105 }
106 break;
107 case 0x01:
108 // Keyboard.
109 return DEVICE_KEYBOARD;
110 case 0x02:
111 // Pointing device.
112 switch ((bluetooth_class_ & 0x01e) >> 2) {
113 case 0x05:
114 // Digitizer tablet.
115 return DEVICE_TABLET;
116 default:
117 // Mouse.
118 return DEVICE_MOUSE;
119 }
120 break;
121 case 0x03:
122 // Combo device.
123 return DEVICE_KEYBOARD_MOUSE_COMBO;
124 }
125 break;
126 }
127
128 return DEVICE_UNKNOWN;
129 }
130
131 bool BluetoothDevice::IsVisible() const {
132 return visible_;
133 }
134
135 bool BluetoothDevice::IsBonded() const {
136 return bonded_;
137 }
138
139 bool BluetoothDevice::IsConnected() const {
140 return connected_;
141 }
142
143 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698