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

Unified Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1415533006: bluetooth: Implement requestDevice by name or name prefix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-characteristic-properties
Patch Set: Tests Created 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
index d10d56e1266d48b1f242041cffe9db05d790b299..19463bd9b38be1b19fb5e4cde4ced39bac72c75e 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -49,25 +49,44 @@ const int kTestingDelayTime = 0; // No need to wait during tests
// Defined at
// https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter
-bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids,
+bool MatchesFilter(const device::BluetoothDevice& device,
const content::BluetoothScanFilter& filter) {
- if (filter.services.empty())
- return false;
- for (const BluetoothUUID& service : filter.services) {
- if (!ContainsKey(device_uuids, service)) {
+ DCHECK(!(filter.name.empty() && filter.namePrefix.empty() &&
scheib 2015/10/22 04:58:42 Malformed data from a renderer should kill it. Tha
ortuno 2015/10/22 16:21:31 Done.
+ filter.services.empty()));
+
+ const std::string device_name = base::UTF16ToUTF8(device.GetName());
+
+ if (!filter.name.empty()) {
+ if (device_name != filter.name) {
+ return false;
+ }
+ }
+
+ if (!filter.namePrefix.empty()) {
+ if (!base::StartsWith(device_name, filter.namePrefix,
+ base::CompareCase::SENSITIVE)) {
return false;
}
}
+
+ if (!filter.services.empty()) {
+ const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs();
+ const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(),
+ device_uuid_list.end());
+ for (const BluetoothUUID& service : filter.services) {
+ if (!ContainsKey(device_uuids, service)) {
+ return false;
+ }
+ }
+ }
+
return true;
}
bool MatchesFilters(const device::BluetoothDevice& device,
const std::vector<content::BluetoothScanFilter>& filters) {
- const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs();
- const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(),
- device_uuid_list.end());
for (const content::BluetoothScanFilter& filter : filters) {
- if (MatchesFilter(device_uuids, filter)) {
+ if (MatchesFilter(device, filter)) {
return true;
}
}
@@ -443,6 +462,9 @@ void BluetoothDispatcherHost::OnRequestDevice(
VLOG(1) << "requestDevice called with the following filters: ";
for (const BluetoothScanFilter& filter : filters) {
+ VLOG(1) << "Name: " << filter.name;
+ VLOG(1) << "Name Prefix: " << filter.namePrefix;
+ VLOG(1) << "Services:";
VLOG(1) << "\t[";
for (const BluetoothUUID& service : filter.services)
VLOG(1) << "\t\t" << service.value();

Powered by Google App Engine
This is Rietveld 408576698