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 "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_api.h" | 5 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_api_socket.h" | |
10 #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_event_
dispatcher.h" | |
11 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" | |
12 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
14 #include "device/bluetooth/bluetooth_adapter.h" | 11 #include "device/bluetooth/bluetooth_adapter.h" |
15 #include "device/bluetooth/bluetooth_adapter_factory.h" | 12 #include "device/bluetooth/bluetooth_adapter_factory.h" |
16 #include "device/bluetooth/bluetooth_device.h" | 13 #include "device/bluetooth/bluetooth_device.h" |
17 #include "device/bluetooth/bluetooth_socket.h" | 14 #include "device/bluetooth/bluetooth_socket.h" |
| 15 #include "extensions/browser/api/bluetooth_socket/bluetooth_api_socket.h" |
| 16 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatc
her.h" |
| 17 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" |
18 #include "extensions/common/permissions/permissions_data.h" | 18 #include "extensions/common/permissions/permissions_data.h" |
19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 using extensions::BluetoothApiSocket; | 22 using extensions::BluetoothApiSocket; |
23 using extensions::api::bluetooth_socket::ListenOptions; | 23 using extensions::core_api::bluetooth_socket::ListenOptions; |
24 using extensions::api::bluetooth_socket::SocketInfo; | 24 using extensions::core_api::bluetooth_socket::SocketInfo; |
25 using extensions::api::bluetooth_socket::SocketProperties; | 25 using extensions::core_api::bluetooth_socket::SocketProperties; |
| 26 |
| 27 namespace extensions { |
| 28 namespace core_api { |
26 | 29 |
27 namespace { | 30 namespace { |
28 | 31 |
29 const char kDeviceNotFoundError[] = "Device not found"; | 32 const char kDeviceNotFoundError[] = "Device not found"; |
30 const char kInvalidPsmError[] = "Invalid PSM"; | 33 const char kInvalidPsmError[] = "Invalid PSM"; |
31 const char kInvalidUuidError[] = "Invalid UUID"; | 34 const char kInvalidUuidError[] = "Invalid UUID"; |
32 const char kPermissionDeniedError[] = "Permission denied"; | 35 const char kPermissionDeniedError[] = "Permission denied"; |
33 const char kSocketNotFoundError[] = "Socket not found"; | 36 const char kSocketNotFoundError[] = "Socket not found"; |
34 | 37 |
35 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, | 38 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, |
(...skipping 28 matching lines...) Expand all Loading... |
64 if (properties->persistent.get()) { | 67 if (properties->persistent.get()) { |
65 socket->set_persistent(*properties->persistent.get()); | 68 socket->set_persistent(*properties->persistent.get()); |
66 } | 69 } |
67 if (properties->buffer_size.get()) { | 70 if (properties->buffer_size.get()) { |
68 // buffer size is validated when issuing the actual Recv operation | 71 // buffer size is validated when issuing the actual Recv operation |
69 // on the socket. | 72 // on the socket. |
70 socket->set_buffer_size(*properties->buffer_size.get()); | 73 socket->set_buffer_size(*properties->buffer_size.get()); |
71 } | 74 } |
72 } | 75 } |
73 | 76 |
74 extensions::api::BluetoothSocketEventDispatcher* GetSocketEventDispatcher( | 77 BluetoothSocketEventDispatcher* GetSocketEventDispatcher( |
75 content::BrowserContext* browser_context) { | 78 content::BrowserContext* browser_context) { |
76 extensions::api::BluetoothSocketEventDispatcher* socket_event_dispatcher = | 79 BluetoothSocketEventDispatcher* socket_event_dispatcher = |
77 extensions::api::BluetoothSocketEventDispatcher::Get(browser_context); | 80 BluetoothSocketEventDispatcher::Get(browser_context); |
78 DCHECK(socket_event_dispatcher) | 81 DCHECK(socket_event_dispatcher) |
79 << "There is no socket event dispatcher. " | 82 << "There is no socket event dispatcher. " |
80 "If this assertion is failing during a test, then it is likely that " | 83 "If this assertion is failing during a test, then it is likely that " |
81 "TestExtensionSystem is failing to provide an instance of " | 84 "TestExtensionSystem is failing to provide an instance of " |
82 "BluetoothSocketEventDispatcher."; | 85 "BluetoothSocketEventDispatcher."; |
83 return socket_event_dispatcher; | 86 return socket_event_dispatcher; |
84 } | 87 } |
85 | 88 |
86 // Returns |true| if |psm| is a valid PSM. | 89 // Returns |true| if |psm| is a valid PSM. |
87 // Per the Bluetooth specification, the PSM field must be at least two octets in | 90 // Per the Bluetooth specification, the PSM field must be at least two octets in |
(...skipping 18 matching lines...) Expand all Loading... |
106 | 109 |
107 // The least significant bit of the most significant octet must be '0'. | 110 // The least significant bit of the most significant octet must be '0'. |
108 if ((octets.back() & 0x01) != 0) | 111 if ((octets.back() & 0x01) != 0) |
109 return false; | 112 return false; |
110 | 113 |
111 return true; | 114 return true; |
112 } | 115 } |
113 | 116 |
114 } // namespace | 117 } // namespace |
115 | 118 |
116 namespace extensions { | |
117 namespace api { | |
118 | |
119 BluetoothSocketAsyncApiFunction::BluetoothSocketAsyncApiFunction() {} | 119 BluetoothSocketAsyncApiFunction::BluetoothSocketAsyncApiFunction() {} |
120 | 120 |
121 BluetoothSocketAsyncApiFunction::~BluetoothSocketAsyncApiFunction() {} | 121 BluetoothSocketAsyncApiFunction::~BluetoothSocketAsyncApiFunction() {} |
122 | 122 |
123 bool BluetoothSocketAsyncApiFunction::RunAsync() { | 123 bool BluetoothSocketAsyncApiFunction::RunAsync() { |
124 if (!PrePrepare() || !Prepare()) { | 124 if (!PrePrepare() || !Prepare()) { |
125 return false; | 125 return false; |
126 } | 126 } |
127 AsyncWorkStart(); | 127 AsyncWorkStart(); |
128 return true; | 128 return true; |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 int socket_id = *it; | 667 int socket_id = *it; |
668 BluetoothApiSocket* socket = GetSocket(socket_id); | 668 BluetoothApiSocket* socket = GetSocket(socket_id); |
669 if (socket) { | 669 if (socket) { |
670 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 670 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
671 } | 671 } |
672 } | 672 } |
673 } | 673 } |
674 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); | 674 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); |
675 } | 675 } |
676 | 676 |
677 } // namespace api | 677 } // namespace core_api |
678 } // namespace extensions | 678 } // namespace extensions |
OLD | NEW |