summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_task_manager_win.h
diff options
context:
space:
mode:
authoryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-21 22:27:05 +0000
committeryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-21 22:27:05 +0000
commitd7ba4375ff5397e48cace373c094de118228c6eb (patch)
tree819360053382a21a7f58f96123cc72ffd6d99272 /device/bluetooth/bluetooth_task_manager_win.h
parent71b05e336fad0c76397a041bcb681fb84c6decb2 (diff)
downloadchromium_src-d7ba4375ff5397e48cace373c094de118228c6eb.zip
chromium_src-d7ba4375ff5397e48cace373c094de118228c6eb.tar.gz
chromium_src-d7ba4375ff5397e48cace373c094de118228c6eb.tar.bz2
Implemented Device/Service discovery with incremented timeout values.
BluetoothTaskManagerWin::StartDiscovery() calls BluetoothTaskManagerWin::DiscoverDevices() with timeout = 1. DiscoverDevices() then issues a device inquiry for timeout period, then posts another DiscoverDevices() with timeout+1. DiscoverDevices() stops posting itself when StopDiscovery() is called, or timeout reaches maximum (48). BUG=135470,168361 Review URL: https://chromiumcodereview.appspot.com/12041035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth/bluetooth_task_manager_win.h')
-rw-r--r--device/bluetooth/bluetooth_task_manager_win.h73
1 files changed, 62 insertions, 11 deletions
diff --git a/device/bluetooth/bluetooth_task_manager_win.h b/device/bluetooth/bluetooth_task_manager_win.h
index 1f2e1d6..9b8d690 100644
--- a/device/bluetooth/bluetooth_task_manager_win.h
+++ b/device/bluetooth/bluetooth_task_manager_win.h
@@ -6,14 +6,14 @@
#define DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_
#include <string>
+#include <vector>
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_vector.h"
#include "base/observer_list.h"
#include "base/win/scoped_handle.h"
#include "device/bluetooth/bluetooth_adapter.h"
-class MessageLoop;
-
namespace base {
class SequencedTaskRunner;
@@ -40,11 +40,31 @@ class BluetoothTaskManagerWin
bool powered;
};
+ struct ServiceRecordState {
+ std::string name;
+ std::string address;
+ std::vector<uint8> sdp_bytes;
+ };
+
+ struct DeviceState {
+ std::string name;
+ std::string address;
+ uint32 bluetooth_class;
+ bool visible;
+ bool connected;
+ bool authenticated;
+ ScopedVector<ServiceRecordState> service_record_states;
+ };
+
class Observer {
public:
virtual ~Observer() {}
virtual void AdapterStateChanged(const AdapterState& state) {}
+ virtual void DiscoveryStarted(bool success) {}
+ virtual void DiscoveryStopped() {}
+ virtual void ScanningChanged(bool scanning) {}
+ virtual void DevicesDiscovered(const ScopedVector<DeviceState>& devices) {}
};
BluetoothTaskManagerWin(
@@ -54,12 +74,16 @@ class BluetoothTaskManagerWin
void RemoveObserver(Observer* observer);
void Initialize();
+ void InitializeWithBluetoothTaskRunner(
+ scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
void Shutdown();
void PostSetPoweredBluetoothTask(
bool powered,
const base::Closure& callback,
const BluetoothAdapter::ErrorCallback& error_callback);
+ void PostStartDiscoveryTask();
+ void PostStopDiscoveryTask();
private:
friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>;
@@ -67,30 +91,54 @@ class BluetoothTaskManagerWin
static const int kPollIntervalMs;
- // Constructor to pass |ui_task_runner_| and |bluetooth_task_runner_| for
- // testing.
- BluetoothTaskManagerWin(
- scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
- scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
-
virtual ~BluetoothTaskManagerWin();
// Notify all Observers of updated AdapterState. Should only be called on the
// UI thread.
void OnAdapterStateChanged(const AdapterState* state);
+ void OnDiscoveryStarted(bool success);
+ void OnDiscoveryStopped();
+ void OnScanningChanged(bool scanning);
+ void OnDevicesDiscovered(const ScopedVector<DeviceState>* devices);
// Called on BluetoothTaskRunner.
void StartPolling();
void PollAdapter();
+ void PostAdapterStateToUi();
void SetPowered(bool powered,
const base::Closure& callback,
const BluetoothAdapter::ErrorCallback& error_callback);
+ // Starts discovery. Once the discovery starts, it issues a discovery inquiry
+ // with a short timeout, then issues more inquiries with greater timeout
+ // values. The discovery finishes when StopDiscovery() is called or timeout
+ // has reached its maximum value.
+ void StartDiscovery();
+ void StopDiscovery();
+
+ // Issues a device inquiry that runs for |timeout| * 1.28 seconds.
+ // This posts itself again with |timeout| + 1 until |timeout| reaches the
+ // maximum value or stop discovery call is received.
+ void DiscoverDevices(int timeout);
+
+ // Fetch already known device information. Similar to |StartDiscovery|, except
+ // this function does not issue a discovery inquiry. Instead it gets the
+ // device info cached in the adapter.
+ void GetKnownDevices();
+
+ // Sends a device search API call to the adapter.
+ void SearchDevices(int timeout,
+ bool search_cached_devices_only,
+ ScopedVector<DeviceState>* device_list);
+
+ // Discover services for the devices in |device_list|.
+ void DiscoverServices(ScopedVector<DeviceState>* device_list);
+
// UI task runner reference.
- const scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
- const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
- const scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_;
+ scoped_refptr<base::SequencedWorkerPool> worker_pool_;
+ scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_;
// List of observers interested in event notifications.
ObserverList<Observer> observers_;
@@ -98,6 +146,9 @@ class BluetoothTaskManagerWin
// Adapter handle owned by bluetooth task runner.
base::win::ScopedHandle adapter_handle_;
+ // indicates whether the adapter is in discovery mode or not.
+ bool discovering_;
+
DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin);
};