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

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

Issue 11369055: Delayed adding BluetoothEventRouter as BluetoothAdapter observer until when the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed BluetoothApiTest. Created 8 years, 1 month 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_BLUETOOTH_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string>
9 10
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/api/bluetooth.h" 14 #include "chrome/common/extensions/api/bluetooth.h"
14 #include "device/bluetooth/bluetooth_adapter.h" 15 #include "device/bluetooth/bluetooth_adapter.h"
15 #include "device/bluetooth/bluetooth_socket.h" 16 #include "device/bluetooth/bluetooth_socket.h"
16 17
17 namespace extensions { 18 namespace extensions {
18 19
19 class ExtensionBluetoothEventRouter 20 class ExtensionBluetoothEventRouter
20 : public device::BluetoothAdapter::Observer { 21 : public device::BluetoothAdapter::Observer {
21 public: 22 public:
22 explicit ExtensionBluetoothEventRouter(Profile* profile); 23 explicit ExtensionBluetoothEventRouter(Profile* profile);
24
25 // Constructor for testing.
26 ExtensionBluetoothEventRouter(
27 Profile* profile, device::BluetoothAdapter* adapter);
28
23 virtual ~ExtensionBluetoothEventRouter(); 29 virtual ~ExtensionBluetoothEventRouter();
24 30
25 // adapter() will return NULL if the bluetooth adapter is not supported in the 31 // adapter() will return NULL if the bluetooth adapter is not supported in the
26 // current platform. 32 // current platform.
27 const device::BluetoothAdapter* adapter() const { 33 const device::BluetoothAdapter* adapter() const {
28 return adapter_.get(); 34 return adapter_.get();
29 } 35 }
30 36
31 // GetMutableAdapter will return NULL if the bluetooth adapter is not 37 // GetMutableAdapter will return NULL if the bluetooth adapter is not
32 // supported in the current platform. 38 // supported in the current platform.
33 device::BluetoothAdapter* GetMutableAdapter() { 39 device::BluetoothAdapter* GetMutableAdapter() {
34 return adapter_.get(); 40 return adapter_.get();
35 } 41 }
36 42
43 // Add |this| as an observer to |adapter_| if the added event is a bluetooth
44 // event.
45 void OnEventListenerAdded(const std::string& event_name);
46
37 // Register the BluetoothSocket |socket| for use by the extensions system. 47 // Register the BluetoothSocket |socket| for use by the extensions system.
38 // This class will hold onto the socket for its lifetime, or until 48 // This class will hold onto the socket for its lifetime, or until
39 // ReleaseSocket is called for the socket. Returns an id for the socket. 49 // ReleaseSocket is called for the socket. Returns an id for the socket.
40 int RegisterSocket(scoped_refptr<device::BluetoothSocket> socket); 50 int RegisterSocket(scoped_refptr<device::BluetoothSocket> socket);
41 51
42 // Release the BluetoothSocket corresponding to |id|. Returns true if 52 // Release the BluetoothSocket corresponding to |id|. Returns true if
43 // the socket was found and released, false otherwise. 53 // the socket was found and released, false otherwise.
44 bool ReleaseSocket(int id); 54 bool ReleaseSocket(int id);
45 55
46 // Get the BluetoothSocket corresponding to |id|. 56 // Get the BluetoothSocket corresponding to |id|.
(...skipping 20 matching lines...) Expand all
67 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, 77 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter,
68 bool discovering) OVERRIDE; 78 bool discovering) OVERRIDE;
69 virtual void DeviceAdded(device::BluetoothAdapter* adapter, 79 virtual void DeviceAdded(device::BluetoothAdapter* adapter,
70 device::BluetoothDevice* device) OVERRIDE; 80 device::BluetoothDevice* device) OVERRIDE;
71 81
72 // Exposed for testing. 82 // Exposed for testing.
73 void SetAdapterForTest(device::BluetoothAdapter* adapter) { 83 void SetAdapterForTest(device::BluetoothAdapter* adapter) {
74 adapter_ = adapter; 84 adapter_ = adapter;
75 } 85 }
76 private: 86 private:
87 static bool IsBluetoothEvent(const std::string& event_name);
88
77 void DispatchBooleanValueEvent(const char* event_name, bool value); 89 void DispatchBooleanValueEvent(const char* event_name, bool value);
78 90
79 bool send_discovery_events_; 91 bool send_discovery_events_;
80 bool responsible_for_discovery_; 92 bool responsible_for_discovery_;
81 93
82 Profile* profile_; 94 Profile* profile_;
83 scoped_refptr<device::BluetoothAdapter> adapter_; 95 scoped_refptr<device::BluetoothAdapter> adapter_;
84 96
97 // true if ExtensionBluetoothEventRouter is observing adapter_.
98 bool observing_;
99
85 // The next id to use for referring to a BluetoothSocket. We avoid using 100 // The next id to use for referring to a BluetoothSocket. We avoid using
86 // the fd of the socket because we don't want to leak that information to 101 // the fd of the socket because we don't want to leak that information to
87 // the extension javascript. 102 // the extension javascript.
88 int next_socket_id_; 103 int next_socket_id_;
89 104
90 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; 105 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap;
91 SocketMap socket_map_; 106 SocketMap socket_map_;
92 107
93 typedef ScopedVector<extensions::api::bluetooth::Device> 108 typedef ScopedVector<extensions::api::bluetooth::Device>
94 DeviceList; 109 DeviceList;
95 DeviceList discovered_devices_; 110 DeviceList discovered_devices_;
96 111
97 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 112 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
98 }; 113 };
99 114
100 } // namespace extensions 115 } // namespace extensions
101 116
102 #endif // CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ 117 #endif // CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc ('k') | chrome/browser/extensions/bluetooth_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698