Index: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
index ba365e1bfaa5c3a514fbe941934314af7dc579a6..5373b787c4fcd36fbead0893e94acc3c2a30d228 100644 |
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
@@ -11,11 +11,11 @@ |
#include <string> |
#include "base/memory/ref_counted.h" |
+#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_factory.h" |
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
-#include "chrome/browser/extensions/bluetooth_event_router.h" |
+#include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
#include "chrome/browser/extensions/event_names.h" |
#include "chrome/browser/extensions/event_router.h" |
-#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/extension_system.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/extensions/api/bluetooth.h" |
@@ -39,7 +39,7 @@ using device::BluetoothSocket; |
namespace { |
extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { |
- return profile->GetExtensionService()->bluetooth_event_router(); |
+ return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); |
} |
const BluetoothAdapter* GetAdapter(Profile* profile) { |
@@ -47,8 +47,7 @@ const BluetoothAdapter* GetAdapter(Profile* profile) { |
} |
BluetoothAdapter* GetMutableAdapter(Profile* profile) { |
- BluetoothAdapter* adapter = GetEventRouter(profile)->GetMutableAdapter(); |
- return adapter; |
+ return GetEventRouter(profile)->GetMutableAdapter(); |
} |
bool IsBluetoothSupported(Profile* profile) { |
@@ -85,6 +84,43 @@ namespace SetOutOfBandPairingData = |
namespace Write = extensions::api::bluetooth::Write; |
namespace extensions { |
+ |
+// static |
+BluetoothAPI* BluetoothAPI::Get(Profile* profile) { |
+ return BluetoothAPIFactory::GetForProfile(profile); |
+} |
+ |
+BluetoothAPI::BluetoothAPI(Profile* profile) : profile_(profile) { |
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
+ this, extensions::event_names::kBluetoothOnAvailabilityChanged); |
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
+ this, extensions::event_names::kBluetoothOnPowerChanged); |
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
+ this, extensions::event_names::kBluetoothOnDiscoveringChanged); |
+} |
+ |
+BluetoothAPI::~BluetoothAPI() { |
+} |
+ |
+ExtensionBluetoothEventRouter* BluetoothAPI::bluetooth_event_router() { |
+ if (!bluetooth_event_router_) |
+ bluetooth_event_router_.reset(new ExtensionBluetoothEventRouter(profile_)); |
+ |
+ return bluetooth_event_router_.get(); |
+} |
+ |
+void BluetoothAPI::Shutdown() { |
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
+} |
+ |
+void BluetoothAPI::OnListenerAdded(const std::string& event_name) { |
+ bluetooth_event_router()->OnListenerAdded(); |
+} |
+ |
+void BluetoothAPI::OnListenerRemoved(const std::string& event_name) { |
+ bluetooth_event_router()->OnListenerRemoved(); |
+} |
+ |
namespace api { |
bool BluetoothIsAvailableFunction::RunImpl() { |