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

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

Issue 11075006: Moved bluetooth adapter files to device/bluetooth/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_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 "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
13 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h"
14 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/extensions/api/experimental_bluetooth.h" 13 #include "chrome/common/extensions/api/experimental_bluetooth.h"
14 #include "device/bluetooth/bluetooth_adapter.h"
15 #include "device/bluetooth/bluetooth_socket.h"
16 16
17 namespace chromeos { 17 using bluetooth::BluetoothSocket;
bryeung 2012/10/10 15:03:53 remove
youngki 2012/10/10 18:34:57 Done.
18
19 namespace extensions {
18 20
19 class ExtensionBluetoothEventRouter 21 class ExtensionBluetoothEventRouter
20 : public chromeos::BluetoothAdapter::Observer { 22 : public bluetooth::BluetoothAdapter::Observer {
21 public: 23 public:
22 explicit ExtensionBluetoothEventRouter(Profile* profile); 24 explicit ExtensionBluetoothEventRouter(Profile* profile);
23 virtual ~ExtensionBluetoothEventRouter(); 25 virtual ~ExtensionBluetoothEventRouter();
24 26
25 const chromeos::BluetoothAdapter& adapter() const { return *adapter_.get(); } 27 // adapter() will return NULL if the bluetooth adapter is not supported in the
28 // current platform.
29 const bluetooth::BluetoothAdapter* adapter() const {
30 return adapter_.get();
31 }
26 32
27 // GetMutableAdapter will never return NULL. 33 // GetMutableAdapter will return NULL if the bluetooth adapter is not
28 chromeos::BluetoothAdapter* GetMutableAdapter() { return adapter_.get(); } 34 // supported in the current platform.
35 bluetooth::BluetoothAdapter* GetMutableAdapter() {
36 return adapter_.get();
37 }
29 38
30 // Register the BluetoothSocket |socket| for use by the extensions system. 39 // Register the BluetoothSocket |socket| for use by the extensions system.
31 // This class will hold onto the socket for its lifetime, or until 40 // This class will hold onto the socket for its lifetime, or until
32 // ReleaseSocket is called for the socket. Returns an id for the socket. 41 // ReleaseSocket is called for the socket. Returns an id for the socket.
33 int RegisterSocket(scoped_refptr<BluetoothSocket> socket); 42 int RegisterSocket(scoped_refptr<BluetoothSocket> socket);
34 43
35 // Release the BluetoothSocket corresponding to |id|. Returns true if 44 // Release the BluetoothSocket corresponding to |id|. Returns true if
36 // the socket was found and released, false otherwise. 45 // the socket was found and released, false otherwise.
37 bool ReleaseSocket(int id); 46 bool ReleaseSocket(int id);
38 47
39 // Get the BluetoothSocket corresponding to |id|. 48 // Get the BluetoothSocket corresponding to |id|.
40 scoped_refptr<BluetoothSocket> GetSocket(int id); 49 scoped_refptr<BluetoothSocket> GetSocket(int id);
41 50
42 // Sets whether this Profile is responsible for the discovering state of the 51 // Sets whether this Profile is responsible for the discovering state of the
43 // adapter. 52 // adapter.
44 void SetResponsibleForDiscovery(bool responsible); 53 void SetResponsibleForDiscovery(bool responsible);
45 bool IsResponsibleForDiscovery() const; 54 bool IsResponsibleForDiscovery() const;
46 55
47 // Sets whether or not DeviceAdded events will be dispatched to extensions. 56 // Sets whether or not DeviceAdded events will be dispatched to extensions.
48 void SetSendDiscoveryEvents(bool should_send); 57 void SetSendDiscoveryEvents(bool should_send);
49 58
50 // Dispatch an event that takes a device as a parameter to all renderers. 59 // Dispatch an event that takes a device as a parameter to all renderers.
51 void DispatchDeviceEvent( 60 void DispatchDeviceEvent(
52 const char* event_name, 61 const char* event_name,
53 const extensions::api::experimental_bluetooth::Device& device); 62 const extensions::api::experimental_bluetooth::Device& device);
54 63
55 // Override from chromeos::BluetoothAdapter::Observer 64 // Override from bluetooth::BluetoothAdapter::Observer
56 virtual void AdapterPresentChanged(chromeos::BluetoothAdapter* adapter, 65 virtual void AdapterPresentChanged(
57 bool present) OVERRIDE; 66 bluetooth::BluetoothAdapter* adapter,
58 virtual void AdapterPoweredChanged(chromeos::BluetoothAdapter* adapter, 67 bool present) OVERRIDE;
59 bool has_power) OVERRIDE; 68 virtual void AdapterPoweredChanged(
60 virtual void AdapterDiscoveringChanged(chromeos::BluetoothAdapter* adapter, 69 bluetooth::BluetoothAdapter* adapter,
61 bool discovering) OVERRIDE; 70 bool has_power) OVERRIDE;
62 virtual void DeviceAdded(chromeos::BluetoothAdapter* adapter, 71 virtual void AdapterDiscoveringChanged(
63 chromeos::BluetoothDevice* device) OVERRIDE; 72 bluetooth::BluetoothAdapter* adapter,
73 bool discovering) OVERRIDE;
74 virtual void DeviceAdded(bluetooth::BluetoothAdapter* adapter,
75 bluetooth::BluetoothDevice* device) OVERRIDE;
64 76
65 // Exposed for testing. 77 // Exposed for testing.
66 void SetAdapterForTest(chromeos::BluetoothAdapter* adapter) { 78 void SetAdapterForTest(bluetooth::BluetoothAdapter* adapter) {
67 adapter_ = adapter; 79 adapter_ = adapter;
68 } 80 }
69 private: 81 private:
70 void DispatchBooleanValueEvent(const char* event_name, bool value); 82 void DispatchBooleanValueEvent(const char* event_name, bool value);
71 83
72 bool send_discovery_events_; 84 bool send_discovery_events_;
73 bool responsible_for_discovery_; 85 bool responsible_for_discovery_;
74 86
75 Profile* profile_; 87 Profile* profile_;
76 scoped_refptr<chromeos::BluetoothAdapter> adapter_; 88 scoped_refptr<bluetooth::BluetoothAdapter> adapter_;
77 89
78 // 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
79 // 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
80 // the extension javascript. 92 // the extension javascript.
81 int next_socket_id_; 93 int next_socket_id_;
82 94
83 typedef std::map<int, scoped_refptr<BluetoothSocket> > SocketMap; 95 typedef std::map<int, scoped_refptr<BluetoothSocket> > SocketMap;
84 SocketMap socket_map_; 96 SocketMap socket_map_;
85 97
86 typedef ScopedVector<extensions::api::experimental_bluetooth::Device> 98 typedef ScopedVector<extensions::api::experimental_bluetooth::Device>
87 DeviceList; 99 DeviceList;
88 DeviceList discovered_devices_; 100 DeviceList discovered_devices_;
89 101
90 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 102 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
91 }; 103 };
92 104
93 } // namespace chromeos 105 } // namespace extensions
94 106
95 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ 107 #endif // CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698