| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 5 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_pairing_delegate
.h" | |
| 19 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | |
| 20 #include "chrome/browser/extensions/api/bluetooth/bluetooth_private_api.h" | |
| 21 #include "chrome/common/extensions/api/bluetooth.h" | |
| 22 #include "chrome/common/extensions/api/bluetooth_private.h" | |
| 23 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 24 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 25 #include "device/bluetooth/bluetooth_adapter.h" | 20 #include "device/bluetooth/bluetooth_adapter.h" |
| 26 #include "device/bluetooth/bluetooth_adapter_factory.h" | 21 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 27 #include "device/bluetooth/bluetooth_device.h" | 22 #include "device/bluetooth/bluetooth_device.h" |
| 28 #include "device/bluetooth/bluetooth_discovery_session.h" | 23 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 24 #include "extensions/browser/api/bluetooth/bluetooth_api_pairing_delegate.h" |
| 25 #include "extensions/browser/api/bluetooth/bluetooth_api_utils.h" |
| 26 #include "extensions/browser/api/bluetooth/bluetooth_private_api.h" |
| 29 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
| 30 #include "extensions/browser/extension_host.h" | 28 #include "extensions/browser/extension_host.h" |
| 31 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/notification_types.h" | 30 #include "extensions/browser/notification_types.h" |
| 31 #include "extensions/common/api/bluetooth.h" |
| 32 #include "extensions/common/api/bluetooth_private.h" |
| 33 | 33 |
| 34 namespace extensions { | 34 namespace extensions { |
| 35 | 35 |
| 36 namespace bluetooth = api::bluetooth; | 36 namespace bluetooth = core_api::bluetooth; |
| 37 namespace bt_private = api::bluetooth_private; | 37 namespace bt_private = core_api::bluetooth_private; |
| 38 | 38 |
| 39 BluetoothEventRouter::BluetoothEventRouter(content::BrowserContext* context) | 39 BluetoothEventRouter::BluetoothEventRouter(content::BrowserContext* context) |
| 40 : browser_context_(context), | 40 : browser_context_(context), |
| 41 adapter_(NULL), | 41 adapter_(NULL), |
| 42 num_event_listeners_(0), | 42 num_event_listeners_(0), |
| 43 extension_registry_observer_(this), | 43 extension_registry_observer_(this), |
| 44 weak_ptr_factory_(this) { | 44 weak_ptr_factory_(this) { |
| 45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 46 DCHECK(browser_context_); | 46 DCHECK(browser_context_); |
| 47 registrar_.Add(this, | 47 registrar_.Add(this, |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 277 } |
| 278 | 278 |
| 279 void BluetoothEventRouter::OnListenerRemoved() { | 279 void BluetoothEventRouter::OnListenerRemoved() { |
| 280 if (num_event_listeners_ > 0) | 280 if (num_event_listeners_ > 0) |
| 281 num_event_listeners_--; | 281 num_event_listeners_--; |
| 282 MaybeReleaseAdapter(); | 282 MaybeReleaseAdapter(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void BluetoothEventRouter::DispatchAdapterStateEvent() { | 285 void BluetoothEventRouter::DispatchAdapterStateEvent() { |
| 286 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 286 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 287 api::bluetooth::AdapterState state; | 287 core_api::bluetooth::AdapterState state; |
| 288 PopulateAdapterState(*adapter_.get(), &state); | 288 PopulateAdapterState(*adapter_.get(), &state); |
| 289 | 289 |
| 290 scoped_ptr<base::ListValue> args = | 290 scoped_ptr<base::ListValue> args = |
| 291 bluetooth::OnAdapterStateChanged::Create(state); | 291 bluetooth::OnAdapterStateChanged::Create(state); |
| 292 scoped_ptr<Event> event(new Event( | 292 scoped_ptr<Event> event(new Event( |
| 293 bluetooth::OnAdapterStateChanged::kEventName, | 293 bluetooth::OnAdapterStateChanged::kEventName, |
| 294 args.Pass())); | 294 args.Pass())); |
| 295 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 295 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
| 296 } | 296 } |
| 297 | 297 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 358 } |
| 359 | 359 |
| 360 void BluetoothEventRouter::OnExtensionUnloaded( | 360 void BluetoothEventRouter::OnExtensionUnloaded( |
| 361 content::BrowserContext* browser_context, | 361 content::BrowserContext* browser_context, |
| 362 const Extension* extension, | 362 const Extension* extension, |
| 363 UnloadedExtensionInfo::Reason reason) { | 363 UnloadedExtensionInfo::Reason reason) { |
| 364 CleanUpForExtension(extension->id()); | 364 CleanUpForExtension(extension->id()); |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace extensions | 367 } // namespace extensions |
| OLD | NEW |