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 "chrome/browser/extensions/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/chrome_notification_types.h" | |
19 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_pairing_delegate
.h" | 18 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_pairing_delegate
.h" |
20 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | 19 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
21 #include "chrome/browser/extensions/api/bluetooth/bluetooth_private_api.h" | 20 #include "chrome/browser/extensions/api/bluetooth/bluetooth_private_api.h" |
22 #include "chrome/common/extensions/api/bluetooth.h" | 21 #include "chrome/common/extensions/api/bluetooth.h" |
23 #include "chrome/common/extensions/api/bluetooth_private.h" | 22 #include "chrome/common/extensions/api/bluetooth_private.h" |
24 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
26 #include "device/bluetooth/bluetooth_adapter.h" | 25 #include "device/bluetooth/bluetooth_adapter.h" |
27 #include "device/bluetooth/bluetooth_adapter_factory.h" | 26 #include "device/bluetooth/bluetooth_adapter_factory.h" |
28 #include "device/bluetooth/bluetooth_device.h" | 27 #include "device/bluetooth/bluetooth_device.h" |
29 #include "device/bluetooth/bluetooth_discovery_session.h" | 28 #include "device/bluetooth/bluetooth_discovery_session.h" |
30 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
31 #include "extensions/browser/extension_host.h" | 30 #include "extensions/browser/extension_host.h" |
32 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/notification_types.h" |
33 | 33 |
34 namespace extensions { | 34 namespace extensions { |
35 | 35 |
36 namespace bluetooth = api::bluetooth; | 36 namespace bluetooth = api::bluetooth; |
37 namespace bt_private = api::bluetooth_private; | 37 namespace bt_private = 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, |
48 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 48 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
49 content::Source<content::BrowserContext>(browser_context_)); | 49 content::Source<content::BrowserContext>(browser_context_)); |
50 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 50 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
51 } | 51 } |
52 | 52 |
53 BluetoothEventRouter::~BluetoothEventRouter() { | 53 BluetoothEventRouter::~BluetoothEventRouter() { |
54 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 54 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
55 if (adapter_.get()) { | 55 if (adapter_.get()) { |
56 adapter_->RemoveObserver(this); | 56 adapter_->RemoveObserver(this); |
57 adapter_ = NULL; | 57 adapter_ = NULL; |
58 } | 58 } |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 delete iter->second; | 345 delete iter->second; |
346 discovery_session_map_[extension_id] = discovery_session.release(); | 346 discovery_session_map_[extension_id] = discovery_session.release(); |
347 callback.Run(); | 347 callback.Run(); |
348 } | 348 } |
349 | 349 |
350 void BluetoothEventRouter::Observe( | 350 void BluetoothEventRouter::Observe( |
351 int type, | 351 int type, |
352 const content::NotificationSource& source, | 352 const content::NotificationSource& source, |
353 const content::NotificationDetails& details) { | 353 const content::NotificationDetails& details) { |
354 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 354 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
355 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, type); | 355 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, type); |
356 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 356 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
357 CleanUpForExtension(host->extension_id()); | 357 CleanUpForExtension(host->extension_id()); |
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 |