OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h
" | 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const char kErrorAdapterNotInitialized[] = | 26 const char kErrorAdapterNotInitialized[] = |
27 "Could not initialize Bluetooth adapter"; | 27 "Could not initialize Bluetooth adapter"; |
28 const char kErrorAlreadyConnected[] = "Already connected"; | 28 const char kErrorAlreadyConnected[] = "Already connected"; |
29 const char kErrorAlreadyNotifying[] = "Already notifying"; | 29 const char kErrorAlreadyNotifying[] = "Already notifying"; |
30 const char kErrorInProgress[] = "In progress"; | 30 const char kErrorInProgress[] = "In progress"; |
31 const char kErrorNotConnected[] = "Not connected"; | 31 const char kErrorNotConnected[] = "Not connected"; |
32 const char kErrorNotNotifying[] = "Not notifying"; | 32 const char kErrorNotNotifying[] = "Not notifying"; |
33 const char kErrorNotFound[] = "Instance not found"; | 33 const char kErrorNotFound[] = "Instance not found"; |
34 const char kErrorOperationFailed[] = "Operation failed"; | 34 const char kErrorOperationFailed[] = "Operation failed"; |
35 const char kErrorPermissionDenied[] = "Permission denied"; | 35 const char kErrorPermissionDenied[] = "Permission denied"; |
| 36 const char kErrorAuthenticationFailed[] = "Authentication failed"; |
| 37 const char kErrorCanceled[] = "Request canceled"; |
| 38 const char kErrorTimeout[] = "Operation timed out"; |
| 39 const char kErrorInvalidLength[] = "Invalid data length"; |
| 40 const char kErrorGattNotSupported[] = "Operation not supported by this service"; |
| 41 const char kErrorUnsupportedDevice[] = |
| 42 "This device is not supported on the current platform"; |
36 const char kErrorPlatformNotSupported[] = | 43 const char kErrorPlatformNotSupported[] = |
37 "This operation is not supported on the current platform"; | 44 "This operation is not supported on the current platform"; |
38 | 45 |
39 // Returns the correct error string based on error status |status|. This is used | 46 // Returns the correct error string based on error status |status|. This is used |
40 // to set the value of |chrome.runtime.lastError.message| and should not be | 47 // to set the value of |chrome.runtime.lastError.message| and should not be |
41 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|. | 48 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|. |
42 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) { | 49 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) { |
43 switch (status) { | 50 switch (status) { |
44 case BluetoothLowEnergyEventRouter::kStatusErrorPermissionDenied: | 51 case BluetoothLowEnergyEventRouter::kStatusErrorPermissionDenied: |
45 return kErrorPermissionDenied; | 52 return kErrorPermissionDenied; |
46 case BluetoothLowEnergyEventRouter::kStatusErrorNotFound: | 53 case BluetoothLowEnergyEventRouter::kStatusErrorNotFound: |
47 return kErrorNotFound; | 54 return kErrorNotFound; |
48 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyConnected: | 55 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyConnected: |
49 return kErrorAlreadyConnected; | 56 return kErrorAlreadyConnected; |
50 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyNotifying: | 57 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyNotifying: |
51 return kErrorAlreadyNotifying; | 58 return kErrorAlreadyNotifying; |
52 case BluetoothLowEnergyEventRouter::kStatusErrorNotConnected: | 59 case BluetoothLowEnergyEventRouter::kStatusErrorNotConnected: |
53 return kErrorNotConnected; | 60 return kErrorNotConnected; |
54 case BluetoothLowEnergyEventRouter::kStatusErrorNotNotifying: | 61 case BluetoothLowEnergyEventRouter::kStatusErrorNotNotifying: |
55 return kErrorNotNotifying; | 62 return kErrorNotNotifying; |
56 case BluetoothLowEnergyEventRouter::kStatusErrorInProgress: | 63 case BluetoothLowEnergyEventRouter::kStatusErrorInProgress: |
57 return kErrorInProgress; | 64 return kErrorInProgress; |
| 65 case BluetoothLowEnergyEventRouter::kStatusErrorAuthenticationFailed: |
| 66 return kErrorAuthenticationFailed; |
| 67 case BluetoothLowEnergyEventRouter::kStatusErrorCanceled: |
| 68 return kErrorCanceled; |
| 69 case BluetoothLowEnergyEventRouter::kStatusErrorTimeout: |
| 70 return kErrorTimeout; |
| 71 case BluetoothLowEnergyEventRouter::kStatusErrorUnsupportedDevice: |
| 72 return kErrorUnsupportedDevice; |
| 73 case BluetoothLowEnergyEventRouter::kStatusErrorInvalidLength: |
| 74 return kErrorInvalidLength; |
| 75 case BluetoothLowEnergyEventRouter::kStatusErrorGattNotSupported: |
| 76 return kErrorGattNotSupported; |
58 case BluetoothLowEnergyEventRouter::kStatusSuccess: | 77 case BluetoothLowEnergyEventRouter::kStatusSuccess: |
59 NOTREACHED(); | 78 NOTREACHED(); |
60 break; | 79 break; |
61 default: | 80 default: |
62 return kErrorOperationFailed; | 81 return kErrorOperationFailed; |
63 } | 82 } |
64 return ""; | 83 return ""; |
65 } | 84 } |
66 | 85 |
67 extensions::BluetoothLowEnergyEventRouter* GetEventRouter( | 86 extensions::BluetoothLowEnergyEventRouter* GetEventRouter( |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 783 } |
765 | 784 |
766 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( | 785 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( |
767 BluetoothLowEnergyEventRouter::Status status) { | 786 BluetoothLowEnergyEventRouter::Status status) { |
768 SetError(StatusToString(status)); | 787 SetError(StatusToString(status)); |
769 SendResponse(false); | 788 SendResponse(false); |
770 } | 789 } |
771 | 790 |
772 } // namespace core_api | 791 } // namespace core_api |
773 } // namespace extensions | 792 } // namespace extensions |
OLD | NEW |