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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h

Issue 11819007: Changed DefaultAdapter to RunCallbackOnAdapterReady function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed device_unittests. Created 7 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h"
12 #include "chrome/common/extensions/api/bluetooth.h" 13 #include "chrome/common/extensions/api/bluetooth.h"
13 #include "device/bluetooth/bluetooth_adapter.h" 14 #include "device/bluetooth/bluetooth_adapter.h"
15 #include "device/bluetooth/bluetooth_adapter_factory.h"
14 #include "device/bluetooth/bluetooth_socket.h" 16 #include "device/bluetooth/bluetooth_socket.h"
15 17
16 class Profile; 18 class Profile;
17 19
18 namespace extensions { 20 namespace extensions {
19 21
20 class ExtensionBluetoothEventRouter 22 class ExtensionBluetoothEventRouter
21 : public device::BluetoothAdapter::Observer { 23 : public device::BluetoothAdapter::Observer {
22 public: 24 public:
23 explicit ExtensionBluetoothEventRouter(Profile* profile); 25 explicit ExtensionBluetoothEventRouter(Profile* profile);
24 virtual ~ExtensionBluetoothEventRouter(); 26 virtual ~ExtensionBluetoothEventRouter();
25 27
26 // GetAdapter will return NULL if the bluetooth adapter is not 28 void RunCallbackOnAdapterReady(
27 // supported in the current platform. 29 const device::BluetoothAdapterFactory::AdapterCallback& callback);
28 scoped_refptr<device::BluetoothAdapter> GetAdapter();
29 30
30 // Called when a bluetooth event listener is added. 31 // Called when a bluetooth event listener is added.
31 void OnListenerAdded(); 32 void OnListenerAdded();
32 33
33 // Called when a bluetooth event listener is removed. 34 // Called when a bluetooth event listener is removed.
34 void OnListenerRemoved(); 35 void OnListenerRemoved();
35 36
36 // Register the BluetoothSocket |socket| for use by the extensions system. 37 // Register the BluetoothSocket |socket| for use by the extensions system.
37 // This class will hold onto the socket for its lifetime, or until 38 // This class will hold onto the socket for its lifetime, or until
38 // ReleaseSocket is called for the socket. Returns an id for the socket. 39 // ReleaseSocket is called for the socket. Returns an id for the socket.
(...skipping 28 matching lines...) Expand all
67 bool discovering) OVERRIDE; 68 bool discovering) OVERRIDE;
68 virtual void DeviceAdded(device::BluetoothAdapter* adapter, 69 virtual void DeviceAdded(device::BluetoothAdapter* adapter,
69 device::BluetoothDevice* device) OVERRIDE; 70 device::BluetoothDevice* device) OVERRIDE;
70 71
71 // Exposed for testing. 72 // Exposed for testing.
72 void SetAdapterForTest(device::BluetoothAdapter* adapter) { 73 void SetAdapterForTest(device::BluetoothAdapter* adapter) {
73 adapter_ = adapter; 74 adapter_ = adapter;
74 } 75 }
75 private: 76 private:
76 void InitializeAdapterIfNeeded(); 77 void InitializeAdapterIfNeeded();
78 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
77 void MaybeReleaseAdapter(); 79 void MaybeReleaseAdapter();
78 void DispatchAdapterStateEvent(); 80 void DispatchAdapterStateEvent();
79 81
80 bool send_discovery_events_; 82 bool send_discovery_events_;
81 bool responsible_for_discovery_; 83 bool responsible_for_discovery_;
82 84
83 Profile* profile_; 85 Profile* profile_;
84 scoped_refptr<device::BluetoothAdapter> adapter_; 86 scoped_refptr<device::BluetoothAdapter> adapter_;
85 87
86 int num_event_listeners_; 88 int num_event_listeners_;
87 89
88 // The next id to use for referring to a BluetoothSocket. We avoid using 90 // The next id to use for referring to a BluetoothSocket. We avoid using
89 // the fd of the socket because we don't want to leak that information to 91 // the fd of the socket because we don't want to leak that information to
90 // the extension javascript. 92 // the extension javascript.
91 int next_socket_id_; 93 int next_socket_id_;
92 94
93 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; 95 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap;
94 SocketMap socket_map_; 96 SocketMap socket_map_;
95 97
96 typedef ScopedVector<extensions::api::bluetooth::Device> 98 typedef ScopedVector<extensions::api::bluetooth::Device>
97 DeviceList; 99 DeviceList;
98 DeviceList discovered_devices_; 100 DeviceList discovered_devices_;
99 101
102 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_;
103
100 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 104 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
101 }; 105 };
102 106
103 } // namespace extensions 107 } // namespace extensions
104 108
105 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 109 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698