| 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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 13 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
| 14 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 12 | 16 |
| 13 namespace chromeos { | 17 namespace chromeos { |
| 14 | 18 |
| 15 class ExtensionBluetoothEventRouter | 19 class ExtensionBluetoothEventRouter |
| 16 : public chromeos::BluetoothAdapter::Observer { | 20 : public chromeos::BluetoothAdapter::Observer { |
| 17 public: | 21 public: |
| 18 explicit ExtensionBluetoothEventRouter(Profile* profile); | 22 explicit ExtensionBluetoothEventRouter(Profile* profile); |
| 19 virtual ~ExtensionBluetoothEventRouter(); | 23 virtual ~ExtensionBluetoothEventRouter(); |
| 20 | 24 |
| 21 const chromeos::BluetoothAdapter* adapter() const { return adapter_.get(); } | 25 const chromeos::BluetoothAdapter* adapter() const { return adapter_.get(); } |
| 22 chromeos::BluetoothAdapter* GetMutableAdapter() { return adapter_.get(); } | 26 chromeos::BluetoothAdapter* GetMutableAdapter() { return adapter_.get(); } |
| 23 | 27 |
| 28 // Register the BluetoothSocket |socket| for use by the extensions system. |
| 29 // This class will hold onto the socket for its lifetime, or until |
| 30 // ReleaseSocket is called for the socket. Returns an id for the socket. |
| 31 int RegisterSocket(scoped_refptr<BluetoothSocket> socket); |
| 32 |
| 33 // Release the BluetoothSocket corresponding to |id|. Returns true if |
| 34 // the socket was found and released, false otherwise. |
| 35 bool ReleaseSocket(int id); |
| 36 |
| 37 // Get the BluetoothSocket corresponding to |id|. |
| 38 scoped_refptr<BluetoothSocket> GetSocket(int id); |
| 39 |
| 24 // Override from chromeos::BluetoothAdapter::Observer | 40 // Override from chromeos::BluetoothAdapter::Observer |
| 25 virtual void AdapterPresentChanged( | 41 virtual void AdapterPresentChanged( |
| 26 chromeos::BluetoothAdapter* adapter, bool present) OVERRIDE; | 42 chromeos::BluetoothAdapter* adapter, bool present) OVERRIDE; |
| 27 virtual void AdapterPoweredChanged( | 43 virtual void AdapterPoweredChanged( |
| 28 chromeos::BluetoothAdapter* adapter, bool has_power) OVERRIDE; | 44 chromeos::BluetoothAdapter* adapter, bool has_power) OVERRIDE; |
| 29 private: | 45 private: |
| 30 void DispatchEvent(const char* event_name, bool value); | 46 void DispatchEvent(const char* event_name, bool value); |
| 31 | 47 |
| 32 Profile* profile_; | 48 Profile* profile_; |
| 33 scoped_ptr<chromeos::BluetoothAdapter> adapter_; | 49 scoped_ptr<chromeos::BluetoothAdapter> adapter_; |
| 50 |
| 51 // The next id to use for referring to a BluetoothSocket. We avoid using |
| 52 // the fd of the socket because we don't want to leak that information to |
| 53 // the extension javascript. |
| 54 int next_socket_id_; |
| 55 |
| 56 typedef std::map<int, scoped_refptr<BluetoothSocket> > SocketMap; |
| 57 SocketMap socket_map_; |
| 58 |
| 34 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); | 59 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); |
| 35 }; | 60 }; |
| 36 | 61 |
| 37 } // namespace chromeos | 62 } // namespace chromeos |
| 38 | 63 |
| 39 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ | 64 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
| OLD | NEW |