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

Side by Side 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, 1 month 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // ID Not In Map Note: 5 // ID Not In Map Note:
6 // A service, characteristic, or descriptor ID not in the corresponding 6 // A service, characteristic, or descriptor ID not in the corresponding
7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_,
8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer
9 // obtains the corresponding ID from this class and it will be added to the map 9 // obtains the corresponding ID from this class and it will be added to the map
10 // at that time. 10 // at that time.
(...skipping 29 matching lines...) Expand all
40 40
41 namespace { 41 namespace {
42 42
43 // TODO(ortuno): Once we have a chooser for scanning, a way to control that 43 // TODO(ortuno): Once we have a chooser for scanning, a way to control that
44 // chooser from tests, and the right callback for discovered services we should 44 // chooser from tests, and the right callback for discovered services we should
45 // delete these constants. 45 // delete these constants.
46 // https://crbug.com/436280 and https://crbug.com/484504 46 // https://crbug.com/436280 and https://crbug.com/484504
47 const int kDelayTime = 5; // 5 seconds for scanning and discovering 47 const int kDelayTime = 5; // 5 seconds for scanning and discovering
48 const int kTestingDelayTime = 0; // No need to wait during tests 48 const int kTestingDelayTime = 0; // No need to wait during tests
49 49
50 bool IsEmptyFilter(const content::BluetoothScanFilter& filter) {
51 return filter.name.empty() && filter.namePrefix.empty() &&
52 filter.services.empty();
53 }
54
55 bool HasEmptyFilter(const std::vector<content::BluetoothScanFilter>& filters) {
56 if (filters.empty()) {
57 return true;
58 }
59 for (const content::BluetoothScanFilter& filter : filters) {
60 if (IsEmptyFilter(filter)) {
61 return true;
62 }
63 }
64 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.
65 }
66
50 // Defined at 67 // Defined at
51 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter 68 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter
52 bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, 69 bool MatchesFilter(const device::BluetoothDevice& device,
53 const content::BluetoothScanFilter& filter) { 70 const content::BluetoothScanFilter& filter) {
54 if (filter.services.empty()) 71 DCHECK(!IsEmptyFilter(filter));
55 return false; 72
56 for (const BluetoothUUID& service : filter.services) { 73 const std::string device_name = base::UTF16ToUTF8(device.GetName());
57 if (!ContainsKey(device_uuids, service)) { 74
75 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.
76 if (device_name != filter.name) {
58 return false; 77 return false;
59 } 78 }
60 } 79 }
80
81 if (!filter.namePrefix.empty()) {
82 if (!base::StartsWith(device_name, filter.namePrefix,
83 base::CompareCase::SENSITIVE)) {
84 return false;
85 }
86 }
87
88 if (!filter.services.empty()) {
89 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.
90 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(),
91 device_uuid_list.end());
92 for (const BluetoothUUID& service : filter.services) {
93 if (!ContainsKey(device_uuids, service)) {
94 return false;
95 }
96 }
97 }
98
61 return true; 99 return true;
62 } 100 }
63 101
64 bool MatchesFilters(const device::BluetoothDevice& device, 102 bool MatchesFilters(const device::BluetoothDevice& device,
65 const std::vector<content::BluetoothScanFilter>& filters) { 103 const std::vector<content::BluetoothScanFilter>& filters) {
66 const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); 104 DCHECK(!HasEmptyFilter(filters));
67 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(),
68 device_uuid_list.end());
69 for (const content::BluetoothScanFilter& filter : filters) { 105 for (const content::BluetoothScanFilter& filter : filters) {
70 if (MatchesFilter(device_uuids, filter)) { 106 if (MatchesFilter(device, filter)) {
71 return true; 107 return true;
72 } 108 }
73 } 109 }
74 return false; 110 return false;
75 } 111 }
76 112
77 WebBluetoothError TranslateConnectError( 113 WebBluetoothError TranslateConnectError(
78 device::BluetoothDevice::ConnectErrorCode error_code) { 114 device::BluetoothDevice::ConnectErrorCode error_code) {
79 switch (error_code) { 115 switch (error_code) {
80 case device::BluetoothDevice::ERROR_UNKNOWN: 116 case device::BluetoothDevice::ERROR_UNKNOWN:
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 int request_id, 472 int request_id,
437 int frame_routing_id, 473 int frame_routing_id,
438 const std::vector<BluetoothScanFilter>& filters, 474 const std::vector<BluetoothScanFilter>& filters,
439 const std::vector<BluetoothUUID>& optional_services) { 475 const std::vector<BluetoothUUID>& optional_services) {
440 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 476 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
441 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); 477 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE);
442 RecordRequestDeviceArguments(filters, optional_services); 478 RecordRequestDeviceArguments(filters, optional_services);
443 479
444 VLOG(1) << "requestDevice called with the following filters: "; 480 VLOG(1) << "requestDevice called with the following filters: ";
445 for (const BluetoothScanFilter& filter : filters) { 481 for (const BluetoothScanFilter& filter : filters) {
482 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
483 VLOG(1) << "Name Prefix: " << filter.namePrefix;
484 VLOG(1) << "Services:";
446 VLOG(1) << "\t["; 485 VLOG(1) << "\t[";
447 for (const BluetoothUUID& service : filter.services) 486 for (const BluetoothUUID& service : filter.services)
448 VLOG(1) << "\t\t" << service.value(); 487 VLOG(1) << "\t\t" << service.value();
449 VLOG(1) << "\t]"; 488 VLOG(1) << "\t]";
450 } 489 }
451 490
452 VLOG(1) << "requestDevice called with the following optional services: "; 491 VLOG(1) << "requestDevice called with the following optional services: ";
453 for (const BluetoothUUID& service : optional_services) 492 for (const BluetoothUUID& service : optional_services)
454 VLOG(1) << "\t" << service.value(); 493 VLOG(1) << "\t" << service.value();
455 494
(...skipping 20 matching lines...) Expand all
476 515
477 if (!adapter_->IsPresent()) { 516 if (!adapter_->IsPresent()) {
478 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; 517 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice.";
479 RecordRequestDeviceOutcome( 518 RecordRequestDeviceOutcome(
480 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); 519 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT);
481 Send(new BluetoothMsg_RequestDeviceError( 520 Send(new BluetoothMsg_RequestDeviceError(
482 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); 521 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter));
483 return; 522 return;
484 } 523 }
485 524
525 // The renderer should never send empty filters.
526 if (HasEmptyFilter(filters)) {
527 bad_message::ReceivedBadMessage(this, bad_message::BDH_EMPTY_FILTERS);
528 return;
529 }
530
486 // Create storage for the information that backs the chooser, and show the 531 // Create storage for the information that backs the chooser, and show the
487 // chooser. 532 // chooser.
488 RequestDeviceSession* const session = new RequestDeviceSession( 533 RequestDeviceSession* const session = new RequestDeviceSession(
489 thread_id, request_id, filters, optional_services); 534 thread_id, request_id, filters, optional_services);
490 int chooser_id = request_device_sessions_.Add(session); 535 int chooser_id = request_device_sessions_.Add(session);
491 536
492 BluetoothChooser::EventHandler chooser_event_handler = 537 BluetoothChooser::EventHandler chooser_event_handler =
493 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, 538 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
494 weak_ptr_on_ui_thread_, chooser_id); 539 weak_ptr_on_ui_thread_, chooser_id);
495 if (WebContents* web_contents = 540 if (WebContents* web_contents =
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1181 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1137 NOTIMPLEMENTED(); 1182 NOTIMPLEMENTED();
1138 } 1183 }
1139 1184
1140 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { 1185 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() {
1141 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1186 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1142 NOTIMPLEMENTED(); 1187 NOTIMPLEMENTED();
1143 } 1188 }
1144 1189
1145 } // namespace content 1190 } // namespace content
OLDNEW
« 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