15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/callback.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "device/bluetooth/bluetooth_adapter.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace device {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// A factory class for building a Bluetooth adapter on platforms where Bluetooth
150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// is available.
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BluetoothAdapterFactory {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  typedef base::Callback<void(scoped_refptr<BluetoothAdapter> adapter)>
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      AdapterCallback;
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the Bluetooth adapter is available for the current
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // platform.
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool IsBluetoothAdapterAvailable();
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the shared instance of the default adapter, creating and
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // initializing it if necessary. |callback| is called with the adapter
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // instance passed only once the adapter is fully initialized and ready to
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // use.
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void GetAdapter(const AdapterCallback& callback);
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
31010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Sets the shared instance of the default adapter for testing purposes only,
32010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // no reference is retained after completion of the call, removing the last
33010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // reference will reset the factory.
34010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  static void SetAdapterForTesting(scoped_refptr<BluetoothAdapter> adapter);
35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Returns true iff the implementation has a (non-NULL) shared instance of the
370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // adapter. Exposed for testing.
380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  static bool HasSharedInstanceForTesting();
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace device
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_
44