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_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/lazy_instance.h" |
9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_factory.h" | |
11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
13 #include "chrome/browser/extensions/event_names.h" | 13 #include "chrome/browser/extensions/event_names.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/api/bluetooth.h" | 15 #include "chrome/common/extensions/api/bluetooth.h" |
16 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" | 16 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
19 #include "device/bluetooth/bluetooth_device.h" | 19 #include "device/bluetooth/bluetooth_device.h" |
20 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 20 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
21 #include "device/bluetooth/bluetooth_profile.h" | 21 #include "device/bluetooth/bluetooth_profile.h" |
22 #include "device/bluetooth/bluetooth_service_record.h" | 22 #include "device/bluetooth/bluetooth_service_record.h" |
23 #include "device/bluetooth/bluetooth_socket.h" | 23 #include "device/bluetooth/bluetooth_socket.h" |
24 #include "device/bluetooth/bluetooth_utils.h" | 24 #include "device/bluetooth/bluetooth_utils.h" |
25 #include "extensions/browser/event_router.h" | 25 #include "extensions/browser/event_router.h" |
26 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
27 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
28 #include "net/base/io_buffer.h" | 28 #include "net/base/io_buffer.h" |
29 | 29 |
| 30 using content::BrowserContext; |
30 using device::BluetoothAdapter; | 31 using device::BluetoothAdapter; |
31 using device::BluetoothDevice; | 32 using device::BluetoothDevice; |
32 using device::BluetoothProfile; | 33 using device::BluetoothProfile; |
33 using device::BluetoothServiceRecord; | 34 using device::BluetoothServiceRecord; |
34 using device::BluetoothSocket; | 35 using device::BluetoothSocket; |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { | 39 extensions::ExtensionBluetoothEventRouter* GetEventRouter( |
39 return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); | 40 BrowserContext* context) { |
| 41 return extensions::BluetoothAPI::Get(context)->bluetooth_event_router(); |
40 } | 42 } |
41 | 43 |
42 } // namespace | 44 } // namespace |
43 | 45 |
44 namespace { | 46 namespace { |
45 | 47 |
46 const char kCouldNotGetLocalOutOfBandPairingData[] = | 48 const char kCouldNotGetLocalOutOfBandPairingData[] = |
47 "Could not get local Out Of Band Pairing Data"; | 49 "Could not get local Out Of Band Pairing Data"; |
48 const char kCouldNotSetOutOfBandPairingData[] = | 50 const char kCouldNotSetOutOfBandPairingData[] = |
49 "Could not set Out Of Band Pairing Data"; | 51 "Could not set Out Of Band Pairing Data"; |
(...skipping 20 matching lines...) Expand all Loading... |
70 namespace GetProfiles = extensions::api::bluetooth::GetProfiles; | 72 namespace GetProfiles = extensions::api::bluetooth::GetProfiles; |
71 namespace GetServices = extensions::api::bluetooth::GetServices; | 73 namespace GetServices = extensions::api::bluetooth::GetServices; |
72 namespace Read = extensions::api::bluetooth::Read; | 74 namespace Read = extensions::api::bluetooth::Read; |
73 namespace RemoveProfile = extensions::api::bluetooth::RemoveProfile; | 75 namespace RemoveProfile = extensions::api::bluetooth::RemoveProfile; |
74 namespace SetOutOfBandPairingData = | 76 namespace SetOutOfBandPairingData = |
75 extensions::api::bluetooth::SetOutOfBandPairingData; | 77 extensions::api::bluetooth::SetOutOfBandPairingData; |
76 namespace Write = extensions::api::bluetooth::Write; | 78 namespace Write = extensions::api::bluetooth::Write; |
77 | 79 |
78 namespace extensions { | 80 namespace extensions { |
79 | 81 |
| 82 static base::LazyInstance<ProfileKeyedAPIFactory<BluetoothAPI> > g_factory = |
| 83 LAZY_INSTANCE_INITIALIZER; |
| 84 |
80 // static | 85 // static |
81 BluetoothAPI* BluetoothAPI::Get(Profile* profile) { | 86 ProfileKeyedAPIFactory<BluetoothAPI>* BluetoothAPI::GetFactoryInstance() { |
82 return BluetoothAPIFactory::GetForProfile(profile); | 87 return g_factory.Pointer(); |
83 } | 88 } |
84 | 89 |
85 BluetoothAPI::BluetoothAPI(Profile* profile) : profile_(profile) { | 90 // static |
| 91 BluetoothAPI* BluetoothAPI::Get(BrowserContext* context) { |
| 92 return GetFactoryInstance()->GetForProfile(context); |
| 93 } |
| 94 |
| 95 BluetoothAPI::BluetoothAPI(BrowserContext* context) |
| 96 : profile_(Profile::FromBrowserContext(context)) { |
86 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 97 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
87 this, bluetooth::OnAdapterStateChanged::kEventName); | 98 this, bluetooth::OnAdapterStateChanged::kEventName); |
88 } | 99 } |
89 | 100 |
90 BluetoothAPI::~BluetoothAPI() { | 101 BluetoothAPI::~BluetoothAPI() { |
91 } | 102 } |
92 | 103 |
93 ExtensionBluetoothEventRouter* BluetoothAPI::bluetooth_event_router() { | 104 ExtensionBluetoothEventRouter* BluetoothAPI::bluetooth_event_router() { |
94 if (!bluetooth_event_router_) | 105 if (!bluetooth_event_router_) |
95 bluetooth_event_router_.reset(new ExtensionBluetoothEventRouter(profile_)); | 106 bluetooth_event_router_.reset(new ExtensionBluetoothEventRouter(profile_)); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 adapter->StopDiscovering( | 675 adapter->StopDiscovering( |
665 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 676 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
666 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 677 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
667 } | 678 } |
668 | 679 |
669 return true; | 680 return true; |
670 } | 681 } |
671 | 682 |
672 } // namespace api | 683 } // namespace api |
673 } // namespace extensions | 684 } // namespace extensions |
OLD | NEW |