| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/common/extensions/api/bluetooth.h" | 13 #include "chrome/common/extensions/api/bluetooth.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
| 17 #include "device/bluetooth/bluetooth_adapter_factory.h" | 17 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 18 #include "device/bluetooth/bluetooth_socket.h" | 18 #include "device/bluetooth/bluetooth_socket.h" |
| 19 | 19 |
| 20 class Profile; | 20 namespace content { |
| 21 class BrowserContext; |
| 22 } |
| 21 | 23 |
| 22 namespace device { | 24 namespace device { |
| 23 | 25 |
| 24 class BluetoothDevice; | 26 class BluetoothDevice; |
| 25 class BluetoothProfile; | 27 class BluetoothProfile; |
| 26 | 28 |
| 27 } // namespace device | 29 } // namespace device |
| 28 | 30 |
| 29 namespace extensions { | 31 namespace extensions { |
| 30 | 32 |
| 31 // Foward declarations of internal structs. | 33 // Foward declarations of internal structs. |
| 32 struct ExtensionBluetoothSocketRecord; | 34 struct ExtensionBluetoothSocketRecord; |
| 33 struct ExtensionBluetoothProfileRecord; | 35 struct ExtensionBluetoothProfileRecord; |
| 34 | 36 |
| 35 class ExtensionBluetoothEventRouter | 37 class ExtensionBluetoothEventRouter |
| 36 : public device::BluetoothAdapter::Observer, | 38 : public device::BluetoothAdapter::Observer, |
| 37 public content::NotificationObserver { | 39 public content::NotificationObserver { |
| 38 public: | 40 public: |
| 39 explicit ExtensionBluetoothEventRouter(Profile* profile); | 41 explicit ExtensionBluetoothEventRouter(content::BrowserContext* context); |
| 40 virtual ~ExtensionBluetoothEventRouter(); | 42 virtual ~ExtensionBluetoothEventRouter(); |
| 41 | 43 |
| 42 // Returns true if adapter_ has been initialized for testing or bluetooth | 44 // Returns true if adapter_ has been initialized for testing or bluetooth |
| 43 // adapter is available for the current platform. | 45 // adapter is available for the current platform. |
| 44 bool IsBluetoothSupported() const; | 46 bool IsBluetoothSupported() const; |
| 45 | 47 |
| 46 void GetAdapter( | 48 void GetAdapter( |
| 47 const device::BluetoothAdapterFactory::AdapterCallback& callback); | 49 const device::BluetoothAdapterFactory::AdapterCallback& callback); |
| 48 | 50 |
| 49 // Called when a bluetooth event listener is added. | 51 // Called when a bluetooth event listener is added. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 private: | 130 private: |
| 129 void InitializeAdapterIfNeeded(); | 131 void InitializeAdapterIfNeeded(); |
| 130 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | 132 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 131 void MaybeReleaseAdapter(); | 133 void MaybeReleaseAdapter(); |
| 132 void DispatchAdapterStateEvent(); | 134 void DispatchAdapterStateEvent(); |
| 133 void CleanUpForExtension(const std::string& extension_id); | 135 void CleanUpForExtension(const std::string& extension_id); |
| 134 | 136 |
| 135 bool send_discovery_events_; | 137 bool send_discovery_events_; |
| 136 bool responsible_for_discovery_; | 138 bool responsible_for_discovery_; |
| 137 | 139 |
| 138 Profile* profile_; | 140 content::BrowserContext* browser_context_; |
| 139 scoped_refptr<device::BluetoothAdapter> adapter_; | 141 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 140 | 142 |
| 141 int num_event_listeners_; | 143 int num_event_listeners_; |
| 142 | 144 |
| 143 // The next id to use for referring to a BluetoothSocket. We avoid using | 145 // The next id to use for referring to a BluetoothSocket. We avoid using |
| 144 // the fd of the socket because we don't want to leak that information to | 146 // the fd of the socket because we don't want to leak that information to |
| 145 // the extension javascript. | 147 // the extension javascript. |
| 146 int next_socket_id_; | 148 int next_socket_id_; |
| 147 | 149 |
| 148 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap; | 150 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 160 content::NotificationRegistrar registrar_; | 162 content::NotificationRegistrar registrar_; |
| 161 | 163 |
| 162 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; | 164 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; |
| 163 | 165 |
| 164 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); | 166 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); |
| 165 }; | 167 }; |
| 166 | 168 |
| 167 } // namespace extensions | 169 } // namespace extensions |
| 168 | 170 |
| 169 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 171 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
| OLD | NEW |