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 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/extensions/api/experimental_bluetooth.h" | 10 #include "chrome/common/extensions/api/experimental_bluetooth.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 chromeos::BluetoothAdapter* GetMutableAdapter(Profile* profile) { | 37 chromeos::BluetoothAdapter* GetMutableAdapter(Profile* profile) { |
38 return GetEventRouter(profile)->GetMutableAdapter(); | 38 return GetEventRouter(profile)->GetMutableAdapter(); |
39 } | 39 } |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 #endif | 42 #endif |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
| 46 const char kFailedToConnect[] = "Connection failed"; |
| 47 const char kInvalidDevice[] = "Invalid device"; |
46 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; | 48 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; |
47 | 49 |
48 } // namespace | 50 } // namespace |
49 | 51 |
50 namespace Connect = extensions::api::experimental_bluetooth::Connect; | 52 namespace Connect = extensions::api::experimental_bluetooth::Connect; |
51 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; | 53 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; |
52 namespace GetDevicesWithServiceName = | 54 namespace GetDevicesWithServiceName = |
53 extensions::api::experimental_bluetooth::GetDevicesWithServiceName; | 55 extensions::api::experimental_bluetooth::GetDevicesWithServiceName; |
54 namespace GetDevicesWithServiceUUID = | 56 namespace GetDevicesWithServiceUUID = |
55 extensions::api::experimental_bluetooth::GetDevicesWithServiceUUID; | 57 extensions::api::experimental_bluetooth::GetDevicesWithServiceUUID; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 int socket_id = GetEventRouter(profile())->RegisterSocket(socket); | 160 int socket_id = GetEventRouter(profile())->RegisterSocket(socket); |
159 | 161 |
160 experimental_bluetooth::Socket result_socket; | 162 experimental_bluetooth::Socket result_socket; |
161 result_socket.device.address = device->address(); | 163 result_socket.device.address = device->address(); |
162 result_socket.device.name = UTF16ToUTF8(device->GetName()); | 164 result_socket.device.name = UTF16ToUTF8(device->GetName()); |
163 result_socket.service_uuid = service_uuid; | 165 result_socket.service_uuid = service_uuid; |
164 result_socket.id = socket_id; | 166 result_socket.id = socket_id; |
165 result_.reset(result_socket.ToValue().release()); | 167 result_.reset(result_socket.ToValue().release()); |
166 SendResponse(true); | 168 SendResponse(true); |
167 } else { | 169 } else { |
| 170 SetError(kFailedToConnect); |
168 SendResponse(false); | 171 SendResponse(false); |
169 } | 172 } |
170 | 173 |
171 Release(); // Added in RunImpl | 174 Release(); // Added in RunImpl |
172 } | 175 } |
173 | 176 |
174 bool BluetoothConnectFunction::RunImpl() { | 177 bool BluetoothConnectFunction::RunImpl() { |
175 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); | 178 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); |
176 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 179 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
177 | 180 |
178 chromeos::BluetoothDevice* device = | 181 chromeos::BluetoothDevice* device = |
179 GetMutableAdapter(profile())->GetDevice(params->device.address); | 182 GetMutableAdapter(profile())->GetDevice(params->device.address); |
180 if (!device) { | 183 if (!device) { |
181 SendResponse(false); | 184 SendResponse(false); |
| 185 SetError(kInvalidDevice); |
182 return false; | 186 return false; |
183 } | 187 } |
184 | 188 |
185 AddRef(); | 189 AddRef(); |
186 device->ConnectToService(params->service, | 190 device->ConnectToService(params->service, |
187 base::Bind(&BluetoothConnectFunction::ConnectToServiceCallback, | 191 base::Bind(&BluetoothConnectFunction::ConnectToServiceCallback, |
188 this, | 192 this, |
189 device, | 193 device, |
190 params->service)); | 194 params->service)); |
191 return true; | 195 return true; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 return false; | 379 return false; |
376 } | 380 } |
377 | 381 |
378 bool BluetoothGetOutOfBandPairingDataFunction::RunImpl() { | 382 bool BluetoothGetOutOfBandPairingDataFunction::RunImpl() { |
379 NOTREACHED() << "Not implemented yet"; | 383 NOTREACHED() << "Not implemented yet"; |
380 return false; | 384 return false; |
381 } | 385 } |
382 | 386 |
383 } // namespace api | 387 } // namespace api |
384 } // namespace extensions | 388 } // namespace extensions |
OLD | NEW |