Index: chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h |
diff --git a/chrome/browser/extensions/bluetooth_event_router.h b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h |
similarity index 83% |
rename from chrome/browser/extensions/bluetooth_event_router.h |
rename to chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h |
index 657053879190b2520ae6f936a4d4e8c665fa1105..e1935a7b2984e2736446098c72568254dfc12a18 100644 |
--- a/chrome/browser/extensions/bluetooth_event_router.h |
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h |
@@ -2,18 +2,19 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
-#define CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
+#ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
+#define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
#include <map> |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_vector.h" |
-#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/extensions/api/bluetooth.h" |
#include "device/bluetooth/bluetooth_adapter.h" |
#include "device/bluetooth/bluetooth_socket.h" |
+class Profile; |
+ |
namespace extensions { |
class ExtensionBluetoothEventRouter |
@@ -24,15 +25,17 @@ class ExtensionBluetoothEventRouter |
// adapter() will return NULL if the bluetooth adapter is not supported in the |
// current platform. |
- const device::BluetoothAdapter* adapter() const { |
- return adapter_.get(); |
- } |
+ scoped_refptr<const device::BluetoothAdapter> adapter(); |
// GetMutableAdapter will return NULL if the bluetooth adapter is not |
// supported in the current platform. |
- device::BluetoothAdapter* GetMutableAdapter() { |
- return adapter_.get(); |
- } |
+ scoped_refptr<device::BluetoothAdapter> GetMutableAdapter(); |
+ |
+ // Called when a bluetooth event listener is added. |
+ void OnListenerAdded(); |
+ |
+ // Called when a bluetooth event listener is removed. |
+ void OnListenerRemoved(); |
// Register the BluetoothSocket |socket| for use by the extensions system. |
// This class will hold onto the socket for its lifetime, or until |
@@ -74,6 +77,9 @@ class ExtensionBluetoothEventRouter |
adapter_ = adapter; |
} |
private: |
+ bool IsAdapterNeeded() const; |
+ void InitializeAdapterIfNeeded(); |
+ void MaybeReleaseAdapter(); |
void DispatchBooleanValueEvent(const char* event_name, bool value); |
bool send_discovery_events_; |
@@ -82,6 +88,8 @@ class ExtensionBluetoothEventRouter |
Profile* profile_; |
scoped_refptr<device::BluetoothAdapter> adapter_; |
+ int num_event_listeners_; |
+ |
// The next id to use for referring to a BluetoothSocket. We avoid using |
// the fd of the socket because we don't want to leak that information to |
// the extension javascript. |
@@ -99,4 +107,4 @@ class ExtensionBluetoothEventRouter |
} // namespace extensions |
-#endif // CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
+#endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |