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

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: 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..265cd6465d7d854f8b26c2006ed43235449d3b79 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();
+
+ // Initializes |adapter_| when a bluetooth event listener is added.
bryeung 2012/11/08 19:24:02 Please describe when this should be called, not it
youngki 2012/11/09 05:12:52 Done.
+ void OnEventListenerAdded(const std::string& event_name);
+
+ // Releases |adapter_| when a bluetooth event listener is removed.
bryeung 2012/11/08 19:24:02 same as above
youngki 2012/11/09 05:12:52 Done.
+ 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