| 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 deb626df075cda1a08b08e8fc27ee6164cdd1dbf..3c2c6fe697a75a419f06b402cede60a4e63e2a5b 100644
|
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
|
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
|
| @@ -19,6 +19,7 @@
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/thread_task_runner_handle.h"
|
| +#include "components/device_event_log/device_event_log.h"
|
| #include "content/browser/bad_message.h"
|
| #include "content/browser/bluetooth/bluetooth_metrics.h"
|
| #include "content/browser/bluetooth/first_device_bluetooth_chooser.h"
|
| @@ -77,12 +78,16 @@ bool MatchesFilter(const device::BluetoothDevice& device,
|
| const std::string device_name = base::UTF16ToUTF8(device.GetName());
|
|
|
| if (!filter.name.empty() && (device_name != filter.name)) {
|
| - return false;
|
| + BLUETOOTH_LOG(DEBUG) << "Name filter does not match device: "
|
| + << device_name;
|
| + return false;
|
| }
|
|
|
| if (!filter.namePrefix.empty() &&
|
| (!base::StartsWith(device_name, filter.namePrefix,
|
| base::CompareCase::SENSITIVE))) {
|
| + BLUETOOTH_LOG(DEBUG) << "Name prefix filter does not match device: "
|
| + << device_name;
|
| return false;
|
| }
|
|
|
| @@ -92,6 +97,8 @@ bool MatchesFilter(const device::BluetoothDevice& device,
|
| device_uuid_list.end());
|
| for (const auto& service : filter.services) {
|
| if (!ContainsKey(device_uuids, service)) {
|
| + BLUETOOTH_LOG(DEBUG) << "Services filter does not match device: "
|
| + << device_name;
|
| return false;
|
| }
|
| }
|
| @@ -221,9 +228,10 @@ std::vector<BluetoothGattService*> GetPrimaryServicesByUUID(
|
| device::BluetoothDevice* device,
|
| const std::string& service_uuid) {
|
| std::vector<BluetoothGattService*> services;
|
| - VLOG(1) << "Looking for service: " << service_uuid;
|
| + BLUETOOTH_LOG(EVENT) << "Looking for service: " << service_uuid;
|
| for (BluetoothGattService* service : device->GetGattServices()) {
|
| - VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value();
|
| + BLUETOOTH_LOG(EVENT) << "Service in cache: "
|
| + << service->GetUUID().canonical_value();
|
| if (service->GetUUID().canonical_value() == service_uuid &&
|
| service->IsPrimary()) {
|
| services.push_back(service);
|
| @@ -463,6 +471,7 @@ void BluetoothDispatcherHost::StartDeviceDiscovery(
|
|
|
| void BluetoothDispatcherHost::StopDeviceDiscovery() {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + BLUETOOTH_LOG(EVENT) << "Stopping discovery session";
|
| for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
|
| &request_device_sessions_);
|
| !iter.IsAtEnd(); iter.Advance()) {
|
| @@ -496,7 +505,8 @@ void BluetoothDispatcherHost::AdapterPoweredChanged(
|
| void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter,
|
| device::BluetoothDevice* device) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - VLOG(1) << "Adding device to all choosers: " << device->GetAddress();
|
| + BLUETOOTH_LOG(EVENT) << "Adding device to all choosers: "
|
| + << device->GetAddress();
|
| for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
|
| &request_device_sessions_);
|
| !iter.IsAtEnd(); iter.Advance()) {
|
| @@ -508,7 +518,8 @@ void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter,
|
| void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter,
|
| device::BluetoothDevice* device) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - VLOG(1) << "Marking device removed on all choosers: " << device->GetAddress();
|
| + BLUETOOTH_LOG(EVENT) << "Marking device removed on all choosers: "
|
| + << device->GetAddress();
|
| for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
|
| &request_device_sessions_);
|
| !iter.IsAtEnd(); iter.Advance()) {
|
| @@ -524,7 +535,7 @@ void BluetoothDispatcherHost::GattServicesDiscovered(
|
| device::BluetoothDevice* device) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| const std::string& device_address = device->GetAddress();
|
| - VLOG(1) << "Services discovered for device: " << device_address;
|
| + BLUETOOTH_LOG(EVENT) << "Services discovered for device: " << device_address;
|
|
|
| auto iter = pending_primary_services_requests_.find(device_address);
|
| if (iter == pending_primary_services_requests_.end()) {
|
| @@ -543,7 +554,7 @@ void BluetoothDispatcherHost::GattServicesDiscovered(
|
| AddToServicesMapAndSendGetPrimaryServiceSuccess(
|
| *services[0], request.thread_id, request.request_id);
|
| } else {
|
| - VLOG(1) << "No service found";
|
| + BLUETOOTH_LOG(EVENT) << "No service found";
|
| RecordGetPrimaryServiceOutcome(
|
| UMAGetPrimaryServiceOutcome::NOT_FOUND);
|
| Send(new BluetoothMsg_GetPrimaryServiceError(
|
| @@ -564,7 +575,8 @@ void BluetoothDispatcherHost::GattCharacteristicValueChanged(
|
| device::BluetoothAdapter* adapter,
|
| device::BluetoothGattCharacteristic* characteristic,
|
| const std::vector<uint8_t>& value) {
|
| - VLOG(1) << "Characteristic updated: " << characteristic->GetIdentifier();
|
| + BLUETOOTH_LOG(EVENT) << "Characteristic updated: "
|
| + << characteristic->GetIdentifier();
|
| auto iter =
|
| active_characteristic_threads_.find(characteristic->GetIdentifier());
|
|
|
| @@ -606,20 +618,21 @@ void BluetoothDispatcherHost::OnRequestDevice(
|
| RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE);
|
| RecordRequestDeviceArguments(filters, optional_services);
|
|
|
| - VLOG(1) << "requestDevice called with the following filters: ";
|
| + BLUETOOTH_LOG(USER) << "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[";
|
| + BLUETOOTH_LOG(USER) << "Name: " << filter.name;
|
| + BLUETOOTH_LOG(USER) << "Name Prefix: " << filter.namePrefix;
|
| + BLUETOOTH_LOG(USER) << "Services:";
|
| + BLUETOOTH_LOG(USER) << "\t[";
|
| for (const BluetoothUUID& service : filter.services)
|
| - VLOG(1) << "\t\t" << service.value();
|
| - VLOG(1) << "\t]";
|
| + BLUETOOTH_LOG(USER) << "\t\t" << service.value();
|
| + BLUETOOTH_LOG(USER) << "\t]";
|
| }
|
|
|
| - VLOG(1) << "requestDevice called with the following optional services: ";
|
| + BLUETOOTH_LOG(USER)
|
| + << "requestDevice called with the following optional services: ";
|
| for (const BluetoothUUID& service : optional_services)
|
| - VLOG(1) << "\t" << service.value();
|
| + BLUETOOTH_LOG(USER) << "\t" << service.value();
|
|
|
| RenderFrameHostImpl* render_frame_host =
|
| RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
|
| @@ -635,7 +648,7 @@ void BluetoothDispatcherHost::OnRequestDevice(
|
| }
|
|
|
| if (!adapter_) {
|
| - VLOG(1) << "No BluetoothAdapter. Can't serve requestDevice.";
|
| + BLUETOOTH_LOG(EVENT) << "No BluetoothAdapter. Can't serve requestDevice.";
|
| RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER);
|
| Send(new BluetoothMsg_RequestDeviceError(
|
| thread_id, request_id, WebBluetoothError::NoBluetoothAdapter));
|
| @@ -643,7 +656,8 @@ void BluetoothDispatcherHost::OnRequestDevice(
|
| }
|
|
|
| if (!adapter_->IsPresent()) {
|
| - VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice.";
|
| + BLUETOOTH_LOG(EVENT)
|
| + << "Bluetooth Adapter not present. Can't serve requestDevice.";
|
| RecordRequestDeviceOutcome(
|
| UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT);
|
| Send(new BluetoothMsg_RequestDeviceError(
|
| @@ -679,24 +693,25 @@ void BluetoothDispatcherHost::OnRequestDevice(
|
| }
|
| }
|
| if (!session->chooser) {
|
| - LOG(WARNING)
|
| + BLUETOOTH_LOG(EVENT)
|
| << "No Bluetooth chooser implementation; falling back to first device.";
|
| session->chooser.reset(
|
| new FirstDeviceBluetoothChooser(chooser_event_handler));
|
| }
|
|
|
| if (!session->chooser->CanAskForScanningPermission()) {
|
| - VLOG(1) << "Closing immediately because Chooser cannot obtain permission.";
|
| + BLUETOOTH_LOG(EVENT)
|
| + << "Closing immediately because Chooser cannot obtain permission.";
|
| OnBluetoothChooserEvent(chooser_id,
|
| BluetoothChooser::Event::DENIED_PERMISSION, "");
|
| return;
|
| }
|
|
|
| // Populate the initial list of devices.
|
| - VLOG(1) << "Populating " << adapter_->GetDevices().size()
|
| - << " devices in chooser " << chooser_id;
|
| + BLUETOOTH_LOG(EVENT) << "Populating " << adapter_->GetDevices().size()
|
| + << " devices in chooser " << chooser_id;
|
| for (const device::BluetoothDevice* device : adapter_->GetDevices()) {
|
| - VLOG(1) << "\t" << device->GetAddress();
|
| + BLUETOOTH_LOG(EVENT) << "\t" << device->GetAddress();
|
| session->AddFilteredDevice(*device);
|
| }
|
|
|
| @@ -736,7 +751,7 @@ void BluetoothDispatcherHost::OnConnectGATT(int thread_id,
|
| auto connection_iter = device_id_to_connection_map_.find(device_id);
|
| if (connection_iter != device_id_to_connection_map_.end()) {
|
| if (connection_iter->second->IsConnected()) {
|
| - VLOG(1) << "Already connected.";
|
| + BLUETOOTH_LOG(EVENT) << "Already connected.";
|
| Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
|
| device_id));
|
| return;
|
| @@ -773,7 +788,7 @@ void BluetoothDispatcherHost::OnDisconnect(int thread_id,
|
| // The last BluetoothGattConnection for a device closes the connection when
|
| // it's destroyed.
|
| if (device_id_to_connection_map_.erase(device_id)) {
|
| - VLOG(1) << "Disconnecting device: " << device_id;
|
| + BLUETOOTH_LOG(EVENT) << "Disconnecting device: " << device_id;
|
| }
|
| }
|
|
|
| @@ -815,7 +830,7 @@ void BluetoothDispatcherHost::OnGetPrimaryService(
|
|
|
| // 1. & 2.
|
| if (!services.empty()) {
|
| - VLOG(1) << "Service found in device.";
|
| + BLUETOOTH_LOG(EVENT) << "Service found in device.";
|
| const BluetoothGattService& service = *services[0];
|
| DCHECK(service.IsPrimary());
|
| AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id,
|
| @@ -825,14 +840,14 @@ void BluetoothDispatcherHost::OnGetPrimaryService(
|
|
|
| // 3.
|
| if (query_result.device->IsGattServicesDiscoveryComplete()) {
|
| - VLOG(1) << "Service not found in device.";
|
| + BLUETOOTH_LOG(EVENT) << "Service not found in device.";
|
| RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND);
|
| Send(new BluetoothMsg_GetPrimaryServiceError(
|
| thread_id, request_id, WebBluetoothError::ServiceNotFound));
|
| return;
|
| }
|
|
|
| - VLOG(1) << "Adding service request to pending requests.";
|
| + BLUETOOTH_LOG(EVENT) << "Adding service request to pending requests.";
|
| // 4.
|
| AddToPendingPrimaryServicesRequest(
|
| query_result.device->GetAddress(),
|
| @@ -1068,7 +1083,7 @@ void BluetoothDispatcherHost::OnDiscoverySessionStarted(
|
| int chooser_id,
|
| scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - VLOG(1) << "Started discovery session for " << chooser_id;
|
| + BLUETOOTH_LOG(EVENT) << "Started discovery session for " << chooser_id;
|
| if (RequestDeviceSession* session =
|
| request_device_sessions_.Lookup(chooser_id)) {
|
| session->discovery_session = std::move(discovery_session);
|
| @@ -1076,15 +1091,17 @@ void BluetoothDispatcherHost::OnDiscoverySessionStarted(
|
| // Arrange to stop discovery later.
|
| discovery_session_timer_.Reset();
|
| } else {
|
| - VLOG(1) << "Chooser " << chooser_id
|
| - << " was closed before the session finished starting. Stopping.";
|
| + BLUETOOTH_LOG(EVENT)
|
| + << "Chooser " << chooser_id
|
| + << " was closed before the session finished starting. Stopping.";
|
| StopDiscoverySession(std::move(discovery_session));
|
| }
|
| }
|
|
|
| void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int chooser_id) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - VLOG(1) << "Failed to start discovery session for " << chooser_id;
|
| + BLUETOOTH_LOG(EVENT) << "Failed to start discovery session for "
|
| + << chooser_id;
|
| if (RequestDeviceSession* session =
|
| request_device_sessions_.Lookup(chooser_id)) {
|
| if (session->chooser && !session->discovery_session) {
|
| @@ -1155,7 +1172,7 @@ void BluetoothDispatcherHost::FinishClosingChooser(
|
| if (event == BluetoothChooser::Event::CANCELLED) {
|
| RecordRequestDeviceOutcome(
|
| UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED);
|
| - VLOG(1) << "Bluetooth chooser cancelled";
|
| + BLUETOOTH_LOG(EVENT) << "Bluetooth chooser cancelled";
|
| Send(new BluetoothMsg_RequestDeviceError(
|
| session->thread_id, session->request_id,
|
| WebBluetoothError::ChooserCancelled));
|
| @@ -1165,7 +1182,7 @@ void BluetoothDispatcherHost::FinishClosingChooser(
|
| if (event == BluetoothChooser::Event::DENIED_PERMISSION) {
|
| RecordRequestDeviceOutcome(
|
| UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_DENIED_PERMISSION);
|
| - VLOG(1) << "Bluetooth chooser denied permission";
|
| + BLUETOOTH_LOG(EVENT) << "Bluetooth chooser denied permission";
|
| Send(new BluetoothMsg_RequestDeviceError(
|
| session->thread_id, session->request_id,
|
| WebBluetoothError::ChooserDeniedPermission));
|
| @@ -1179,7 +1196,7 @@ void BluetoothDispatcherHost::FinishClosingChooser(
|
| // chooser->AddDevice().
|
| const device::BluetoothDevice* const device = adapter_->GetDevice(device_id);
|
| if (device == nullptr) {
|
| - VLOG(1) << "Device " << device_id << " no longer in adapter";
|
| + BLUETOOTH_LOG(EVENT) << "Device " << device_id << " no longer in adapter";
|
| RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED);
|
| Send(new BluetoothMsg_RequestDeviceError(
|
| session->thread_id, session->request_id,
|
| @@ -1188,10 +1205,10 @@ void BluetoothDispatcherHost::FinishClosingChooser(
|
| return;
|
| }
|
|
|
| - VLOG(1) << "Device: " << device->GetName();
|
| - VLOG(1) << "UUIDs: ";
|
| + BLUETOOTH_LOG(EVENT) << "Device: " << device->GetName();
|
| + BLUETOOTH_LOG(EVENT) << "UUIDs: ";
|
| for (BluetoothUUID uuid : device->GetUUIDs())
|
| - VLOG(1) << "\t" << uuid.canonical_value();
|
| + BLUETOOTH_LOG(EVENT) << "\t" << uuid.canonical_value();
|
|
|
| const std::string& device_id_for_origin = allowed_devices_map_.AddDevice(
|
| session->origin, device->GetAddress(), session->filters,
|
|
|