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

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: Created IsBluetoothSupported in BluetoothEventRouter to fix browser_tests. 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 // Returns true if adapter_ has been initialized for testing or bluetooth
27 // supported in the current platform. 29 // adapter is available for the current platform.
28 scoped_refptr<device::BluetoothAdapter> GetAdapter(); 30 bool IsBluetoothSupported() const;
31
32 void RunCallbackOnAdapterReady(
33 const device::BluetoothAdapterFactory::AdapterCallback& callback);
29 34
30 // Called when a bluetooth event listener is added. 35 // Called when a bluetooth event listener is added.
31 void OnListenerAdded(); 36 void OnListenerAdded();
32 37
33 // Called when a bluetooth event listener is removed. 38 // Called when a bluetooth event listener is removed.
34 void OnListenerRemoved(); 39 void OnListenerRemoved();
35 40
36 // Register the BluetoothSocket |socket| for use by the extensions system. 41 // Register the BluetoothSocket |socket| for use by the extensions system.
37 // This class will hold onto the socket for its lifetime, or until 42 // 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. 43 // ReleaseSocket is called for the socket. Returns an id for the socket.
(...skipping 28 matching lines...) Expand all
67 bool discovering) OVERRIDE; 72 bool discovering) OVERRIDE;
68 virtual void DeviceAdded(device::BluetoothAdapter* adapter, 73 virtual void DeviceAdded(device::BluetoothAdapter* adapter,
69 device::BluetoothDevice* device) OVERRIDE; 74 device::BluetoothDevice* device) OVERRIDE;
70 75
71 // Exposed for testing. 76 // Exposed for testing.
72 void SetAdapterForTest(device::BluetoothAdapter* adapter) { 77 void SetAdapterForTest(device::BluetoothAdapter* adapter) {
73 adapter_ = adapter; 78 adapter_ = adapter;
74 } 79 }
75 private: 80 private:
76 void InitializeAdapterIfNeeded(); 81 void InitializeAdapterIfNeeded();
82 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
77 void MaybeReleaseAdapter(); 83 void MaybeReleaseAdapter();
78 void DispatchAdapterStateEvent(); 84 void DispatchAdapterStateEvent();
79 85
80 bool send_discovery_events_; 86 bool send_discovery_events_;
81 bool responsible_for_discovery_; 87 bool responsible_for_discovery_;
82 88
83 Profile* profile_; 89 Profile* profile_;
84 scoped_refptr<device::BluetoothAdapter> adapter_; 90 scoped_refptr<device::BluetoothAdapter> adapter_;
85 91
86 int num_event_listeners_; 92 int num_event_listeners_;
87 93
88 // The next id to use for referring to a BluetoothSocket. We avoid using 94 // 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 95 // the fd of the socket because we don't want to leak that information to
90 // the extension javascript. 96 // the extension javascript.
91 int next_socket_id_; 97 int next_socket_id_;
92 98
93 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; 99 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap;
94 SocketMap socket_map_; 100 SocketMap socket_map_;
95 101
96 typedef ScopedVector<extensions::api::bluetooth::Device> 102 typedef ScopedVector<extensions::api::bluetooth::Device>
97 DeviceList; 103 DeviceList;
98 DeviceList discovered_devices_; 104 DeviceList discovered_devices_;
99 105
106 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_;
107
100 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 108 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
101 }; 109 };
102 110
103 } // namespace extensions 111 } // namespace extensions
104 112
105 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 113 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698