Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1443)

Unified Diff: chrome/browser/extensions/bluetooth_event_router.h

Issue 11368145: Lazy-creates BluetoothAdapter in ExtensionBluetoothEventRouter (EBEE). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed .get, double assignment, etc Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..575c9f13621d36160ef23a06abfb95ec461725b7 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,18 @@ class ExtensionBluetoothEventRouter
void SetAdapterForTest(device::BluetoothAdapter* adapter) {
adapter_ = adapter;
}
+
+ protected:
+ virtual scoped_refptr<device::BluetoothAdapter> GetDefaultAdapter() const;
+
private:
+ static bool IsBluetoothEvent(const std::string& event_name);
+
+ bool IsAdapterNeeded() const;
+
+ void InitializeAdapter();
+ void ReleaseAdapter();
+
void DispatchBooleanValueEvent(const char* event_name, bool value);
bool send_discovery_events_;
@@ -82,6 +96,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.

Powered by Google App Engine
This is Rietveld 408576698