Index: chrome/browser/extensions/bluetooth_event_router.h |
diff --git a/chrome/browser/extensions/bluetooth_event_router.h b/chrome/browser/extensions/bluetooth_event_router.h |
index 657053879190b2520ae6f936a4d4e8c665fa1105..f521a170721673d2798d434fcd90fee00e459629 100644 |
--- a/chrome/browser/extensions/bluetooth_event_router.h |
+++ b/chrome/browser/extensions/bluetooth_event_router.h |
@@ -6,6 +6,7 @@ |
#define CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
#include <map> |
+#include <string> |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_vector.h" |
@@ -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 an event listener is added. |
+ void OnEventListenerAdded(const std::string& event_name); |
+ |
+ // Called when an event listener is removed. |
+ void OnEventListenerRemoved(const std::string& event_name); |
// Register the BluetoothSocket |socket| for use by the extensions system. |
// This class will hold onto the socket for its lifetime, or until |
@@ -73,7 +76,15 @@ class ExtensionBluetoothEventRouter |
void SetAdapterForTest(device::BluetoothAdapter* adapter) { |
adapter_ = adapter; |
} |
+ |
private: |
+ static bool IsBluetoothEvent(const std::string& event_name); |
+ |
+ bool IsAdapterNeeded() const; |
+ |
+ void InitializeAdapterIfNeeded(); |
+ void MaybeReleaseAdapter(); |
+ |
void DispatchBooleanValueEvent(const char* event_name, bool value); |
bool send_discovery_events_; |
@@ -82,6 +93,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. |