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

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: Merge with ToT 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
« no previous file with comments | « content/browser/bad_message.h ('k') | content/common/bluetooth/bluetooth_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b176917dd12a203417c028f68481575d0c149aa8 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -47,27 +47,63 @@ namespace {
const int kDelayTime = 5; // 5 seconds for scanning and discovering
const int kTestingDelayTime = 0; // No need to wait during tests
+bool IsEmptyFilter(const content::BluetoothScanFilter& filter) {
+ return filter.name.empty() && filter.namePrefix.empty() &&
+ filter.services.empty();
+}
+
+bool HasEmptyFilter(const std::vector<content::BluetoothScanFilter>& filters) {
+ if (filters.empty()) {
+ return true;
+ }
+ for (const content::BluetoothScanFilter& filter : filters) {
+ if (IsEmptyFilter(filter)) {
+ return true;
+ }
+ }
+ return false;
palmer 2015/10/27 21:43:18 Nit: Maybe this is cleaner/more clear: return fil
ortuno 2015/10/28 17:53:25 Done.
+}
+
// 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(!IsEmptyFilter(filter));
+
+ const std::string device_name = base::UTF16ToUTF8(device.GetName());
+
+ if (!filter.name.empty()) {
palmer 2015/10/27 21:43:18 Nit: I think you can combine these 2 conditions in
ortuno 2015/10/28 17:53:25 Done.
+ 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();
palmer 2015/10/27 21:43:18 This whole block is a good use for auto: const au
ortuno 2015/10/28 17:53:25 Done.
+ 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());
+ DCHECK(!HasEmptyFilter(filters));
for (const content::BluetoothScanFilter& filter : filters) {
- if (MatchesFilter(device_uuids, filter)) {
+ if (MatchesFilter(device, filter)) {
return true;
}
}
@@ -443,6 +479,9 @@ void BluetoothDispatcherHost::OnRequestDevice(
VLOG(1) << "requestDevice called with the following filters: ";
for (const BluetoothScanFilter& filter : filters) {
+ VLOG(1) << "Name: " << filter.name;
palmer 2015/10/27 21:43:18 Are name and namePrefix ever going to be used for
palmer 2015/10/27 21:46:56 Also, do they have any length, lexical, or syntact
ortuno 2015/10/28 17:53:25 We don't have any plans to use it beyond what's im
Jeffrey Yasskin 2015/10/30 22:04:44 We can enforce a maximum of 248 UTF-8 code units i
ortuno 2015/10/30 22:36:02 Yup. It's 29 if you don't count the flags which ar
+ VLOG(1) << "Name Prefix: " << filter.namePrefix;
+ VLOG(1) << "Services:";
VLOG(1) << "\t[";
for (const BluetoothUUID& service : filter.services)
VLOG(1) << "\t\t" << service.value();
@@ -483,6 +522,12 @@ void BluetoothDispatcherHost::OnRequestDevice(
return;
}
+ // The renderer should never send empty filters.
+ if (HasEmptyFilter(filters)) {
+ bad_message::ReceivedBadMessage(this, bad_message::BDH_EMPTY_FILTERS);
+ return;
+ }
+
// Create storage for the information that backs the chooser, and show the
// chooser.
RequestDeviceSession* const session = new RequestDeviceSession(
« no previous file with comments | « content/browser/bad_message.h ('k') | content/common/bluetooth/bluetooth_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698