summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorjpawlowski <jpawlowski@chromium.org>2015-04-20 16:41:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-20 23:41:40 +0000
commit909a4810497de84a03bcb1accf7ca606371ce444 (patch)
treeaf5b6a5e53b5f19bdc252a033804723de6c4c9c7 /chromeos
parentd819416ed0e47918577d7f3f24765a20d9f506f6 (diff)
downloadchromium_src-909a4810497de84a03bcb1accf7ca606371ce444.zip
chromium_src-909a4810497de84a03bcb1accf7ca606371ce444.tar.gz
chromium_src-909a4810497de84a03bcb1accf7ca606371ce444.tar.bz2
Implement SetDiscoveryFilter for ChromiumOS
BUG=407773 R=armansito@chromium.org Review URL: https://codereview.chromium.org/1082173002 Cr-Commit-Position: refs/heads/master@{#325939}
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/dbus/bluetooth_adapter_client.cc23
-rw-r--r--chromeos/dbus/bluetooth_adapter_client.h7
-rw-r--r--chromeos/dbus/fake_bluetooth_adapter_client.cc21
-rw-r--r--chromeos/dbus/fake_bluetooth_adapter_client.h12
4 files changed, 62 insertions, 1 deletions
diff --git a/chromeos/dbus/bluetooth_adapter_client.cc b/chromeos/dbus/bluetooth_adapter_client.cc
index c7adcb7a6a..7294ac4 100644
--- a/chromeos/dbus/bluetooth_adapter_client.cc
+++ b/chromeos/dbus/bluetooth_adapter_client.cc
@@ -20,6 +20,29 @@ BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {
BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {
}
+void BluetoothAdapterClient::DiscoveryFilter::CopyFrom(
+ const DiscoveryFilter& filter) {
+ if (filter.rssi.get())
+ rssi.reset(new int16_t(*filter.rssi));
+ else
+ rssi.reset();
+
+ if (filter.pathloss.get())
+ pathloss.reset(new uint16_t(*filter.pathloss));
+ else
+ pathloss.reset();
+
+ if (filter.transport.get())
+ transport.reset(new std::string(*filter.transport));
+ else
+ transport.reset();
+
+ if (filter.uuids.get())
+ uuids.reset(new std::vector<std::string>(*filter.uuids));
+ else
+ uuids.reset();
+}
+
const char BluetoothAdapterClient::kNoResponseError[] =
"org.chromium.Error.NoResponse";
const char BluetoothAdapterClient::kUnknownAdapterError[] =
diff --git a/chromeos/dbus/bluetooth_adapter_client.h b/chromeos/dbus/bluetooth_adapter_client.h
index df2dc20..4530127 100644
--- a/chromeos/dbus/bluetooth_adapter_client.h
+++ b/chromeos/dbus/bluetooth_adapter_client.h
@@ -22,14 +22,21 @@ namespace chromeos {
// local Bluetooth Adapters.
class CHROMEOS_EXPORT BluetoothAdapterClient : public DBusClient {
public:
+ // A DiscoveryFilter represents a filter passed to the SetDiscoveryFilter
+ // method.
struct DiscoveryFilter {
DiscoveryFilter();
~DiscoveryFilter();
+ // Copy content of |filter| into this filter
+ void CopyFrom(const DiscoveryFilter& filter);
+
scoped_ptr<std::vector<std::string>> uuids;
scoped_ptr<int16_t> rssi;
scoped_ptr<uint16_t> pathloss;
scoped_ptr<std::string> transport;
+
+ DISALLOW_COPY_AND_ASSIGN(DiscoveryFilter);
};
// Structure of properties associated with bluetooth adapters.
diff --git a/chromeos/dbus/fake_bluetooth_adapter_client.cc b/chromeos/dbus/fake_bluetooth_adapter_client.cc
index cb59019..51a5cf8 100644
--- a/chromeos/dbus/fake_bluetooth_adapter_client.cc
+++ b/chromeos/dbus/fake_bluetooth_adapter_client.cc
@@ -75,6 +75,7 @@ FakeBluetoothAdapterClient::FakeBluetoothAdapterClient()
: visible_(true),
second_visible_(false),
discovering_count_(0),
+ set_discovery_filter_should_fail_(false),
simulation_interval_ms_(kSimulationIntervalMs) {
properties_.reset(new Properties(base::Bind(
&FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this))));
@@ -181,6 +182,7 @@ void FakeBluetoothAdapterClient::StopDiscovery(
dbus::ObjectPath(kAdapterPath));
}
+ discovery_filter_.reset();
properties_->discovering.ReplaceValue(false);
}
}
@@ -205,6 +207,10 @@ void FakeBluetoothAdapterClient::RemoveDevice(
device_client->RemoveDevice(dbus::ObjectPath(kAdapterPath), device_path);
}
+void FakeBluetoothAdapterClient::MakeSetDiscoveryFilterFail() {
+ set_discovery_filter_should_fail_ = true;
+}
+
void FakeBluetoothAdapterClient::SetDiscoveryFilter(
const dbus::ObjectPath& object_path,
const DiscoveryFilter& discovery_filter,
@@ -214,8 +220,16 @@ void FakeBluetoothAdapterClient::SetDiscoveryFilter(
PostDelayedTask(base::Bind(error_callback, kNoResponseError, ""));
return;
}
-
VLOG(1) << "SetDiscoveryFilter: " << object_path.value();
+
+ if (set_discovery_filter_should_fail_) {
+ PostDelayedTask(base::Bind(error_callback, kNoResponseError, ""));
+ set_discovery_filter_should_fail_ = false;
+ return;
+ }
+
+ discovery_filter_.reset(new DiscoveryFilter());
+ discovery_filter_->CopyFrom(discovery_filter);
PostDelayedTask(callback);
}
@@ -223,6 +237,11 @@ void FakeBluetoothAdapterClient::SetSimulationIntervalMs(int interval_ms) {
simulation_interval_ms_ = interval_ms;
}
+BluetoothAdapterClient::DiscoveryFilter*
+FakeBluetoothAdapterClient::GetDiscoveryFilter() {
+ return discovery_filter_.get();
+}
+
void FakeBluetoothAdapterClient::SetVisible(
bool visible) {
if (visible && !visible_) {
diff --git a/chromeos/dbus/fake_bluetooth_adapter_client.h b/chromeos/dbus/fake_bluetooth_adapter_client.h
index fc281e9..54a6dbd 100644
--- a/chromeos/dbus/fake_bluetooth_adapter_client.h
+++ b/chromeos/dbus/fake_bluetooth_adapter_client.h
@@ -62,6 +62,12 @@ class CHROMEOS_EXPORT FakeBluetoothAdapterClient
// Sets the current simulation timeout interval.
void SetSimulationIntervalMs(int interval_ms);
+ // Returns current discovery filter in use by this adapter.
+ DiscoveryFilter* GetDiscoveryFilter();
+
+ // Make SetDiscoveryFilter fail when called next time.
+ void MakeSetDiscoveryFilterFail();
+
// Mark the adapter and second adapter as visible or invisible.
void SetVisible(bool visible);
void SetSecondVisible(bool visible);
@@ -97,6 +103,12 @@ class CHROMEOS_EXPORT FakeBluetoothAdapterClient
// Number of times we've been asked to discover.
int discovering_count_;
+ // Current discovery filter
+ scoped_ptr<DiscoveryFilter> discovery_filter_;
+
+ // When set, next call to SetDiscoveryFilter would fail.
+ bool set_discovery_filter_should_fail_;
+
// Current timeout interval used when posting delayed tasks.
int simulation_interval_ms_;
};