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

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: Use GetMutableAdapter 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..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.
« no previous file with comments | « chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc ('k') | chrome/browser/extensions/bluetooth_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698