Commit c8a7001d authored by Martin Kreichgauer's avatar Martin Kreichgauer Committed by Commit Bot

device/bluetooth: log WinRT API calls to chrome://device-log

We have been debugging various FIDO caBLE related issues that often only
appear sporadically on a particular combination of (computer, OS
version, phone). In some of them, WinRT behaving in exciting and
unexpected ways was at least a contributing factor. The WinRT Bluetooth
code currently VLOGs, which makes it difficult to obtain logs in these
cases. Replace them with BLUETOOTH_LOG(), which can easily be collected
by end users after the fact.

These log statements can be converted to DVLOG once the WinRT Bluetooth
and FIDO caBLE stacks have sufficiently stabilized.

Change-Id: Id13f9e107167ecdc3e0230aee86ecf90219697d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2021331
Commit-Queue: Martin Kreichgauer <martinkr@google.com>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737149}
parent 7be4d650
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/win/core_winrt_util.h" #include "base/win/core_winrt_util.h"
#include "base/win/post_async_results.h" #include "base/win/post_async_results.h"
#include "components/device_event_log/device_event_log.h"
#include "device/bluetooth/bluetooth_advertisement_winrt.h" #include "device/bluetooth/bluetooth_advertisement_winrt.h"
#include "device/bluetooth/bluetooth_device_winrt.h" #include "device/bluetooth/bluetooth_device_winrt.h"
#include "device/bluetooth/bluetooth_discovery_filter.h" #include "device/bluetooth/bluetooth_discovery_filter.h"
...@@ -141,7 +142,8 @@ bool ToStdVector(VectorView* view, std::vector<T>* vector) { ...@@ -141,7 +142,8 @@ bool ToStdVector(VectorView* view, std::vector<T>* vector) {
unsigned size; unsigned size;
HRESULT hr = view->get_Size(&size); HRESULT hr = view->get_Size(&size);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Size() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "get_Size() failed: "
<< logging::SystemErrorCodeToString(hr);
return false; return false;
} }
...@@ -161,29 +163,33 @@ base::Optional<std::vector<uint8_t>> ExtractVector(IBuffer* buffer) { ...@@ -161,29 +163,33 @@ base::Optional<std::vector<uint8_t>> ExtractVector(IBuffer* buffer) {
IDataReaderStatics, RuntimeClass_Windows_Storage_Streams_DataReader>( IDataReaderStatics, RuntimeClass_Windows_Storage_Streams_DataReader>(
&data_reader_statics); &data_reader_statics);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting DataReaderStatics Activation Factory failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "Getting DataReaderStatics Activation Factory failed: "
<< logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
ComPtr<IDataReader> data_reader; ComPtr<IDataReader> data_reader;
hr = data_reader_statics->FromBuffer(buffer, &data_reader); hr = data_reader_statics->FromBuffer(buffer, &data_reader);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "FromBuffer() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "FromBuffer() failed: "
<< logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
uint32_t buffer_length; uint32_t buffer_length;
hr = buffer->get_Length(&buffer_length); hr = buffer->get_Length(&buffer_length);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Length() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "get_Length() failed: "
<< logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
std::vector<uint8_t> bytes(buffer_length); std::vector<uint8_t> bytes(buffer_length);
hr = data_reader->ReadBytes(buffer_length, bytes.data()); hr = data_reader->ReadBytes(buffer_length, bytes.data());
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "ReadBytes() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "ReadBytes() failed: "
<< logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
...@@ -197,19 +203,21 @@ base::Optional<uint8_t> ExtractFlags(IBluetoothLEAdvertisement* advertisement) { ...@@ -197,19 +203,21 @@ base::Optional<uint8_t> ExtractFlags(IBluetoothLEAdvertisement* advertisement) {
ComPtr<IReference<BluetoothLEAdvertisementFlags>> flags_ref; ComPtr<IReference<BluetoothLEAdvertisementFlags>> flags_ref;
HRESULT hr = advertisement->get_Flags(&flags_ref); HRESULT hr = advertisement->get_Flags(&flags_ref);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Flags() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "get_Flags() failed: "
<< logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
if (!flags_ref) { if (!flags_ref) {
VLOG(2) << "No advertisement flags found."; BLUETOOTH_LOG(DEBUG) << "No advertisement flags found.";
return base::nullopt; return base::nullopt;
} }
BluetoothLEAdvertisementFlags flags; BluetoothLEAdvertisementFlags flags;
hr = flags_ref->get_Value(&flags); hr = flags_ref->get_Value(&flags);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Value() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "get_Value() failed: "
<< logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
...@@ -224,8 +232,8 @@ BluetoothDevice::UUIDList ExtractAdvertisedUUIDs( ...@@ -224,8 +232,8 @@ BluetoothDevice::UUIDList ExtractAdvertisedUUIDs(
ComPtr<IVector<GUID>> service_uuids; ComPtr<IVector<GUID>> service_uuids;
HRESULT hr = advertisement->get_ServiceUuids(&service_uuids); HRESULT hr = advertisement->get_ServiceUuids(&service_uuids);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_ServiceUuids() failed: " BLUETOOTH_LOG(ERROR) << "get_ServiceUuids() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return {}; return {};
} }
...@@ -255,7 +263,8 @@ void PopulateServiceData( ...@@ -255,7 +263,8 @@ void PopulateServiceData(
ComPtr<IBuffer> buffer; ComPtr<IBuffer> buffer;
HRESULT hr = data_section->get_Data(&buffer); HRESULT hr = data_section->get_Data(&buffer);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Data() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "get_Data() failed: "
<< logging::SystemErrorCodeToString(hr);
continue; continue;
} }
...@@ -265,8 +274,8 @@ void PopulateServiceData( ...@@ -265,8 +274,8 @@ void PopulateServiceData(
auto bytes_span = base::make_span(*bytes); auto bytes_span = base::make_span(*bytes);
if (bytes_span.size() < num_bytes_uuid) { if (bytes_span.size() < num_bytes_uuid) {
VLOG(2) << "Buffer Length is too small: " << bytes_span.size() << " vs. " BLUETOOTH_LOG(ERROR) << "Buffer Length is too small: "
<< num_bytes_uuid; << bytes_span.size() << " vs. " << num_bytes_uuid;
continue; continue;
} }
...@@ -312,8 +321,8 @@ BluetoothDevice::ServiceDataMap ExtractServiceData( ...@@ -312,8 +321,8 @@ BluetoothDevice::ServiceDataMap ExtractServiceData(
HRESULT hr = advertisement->GetSectionsByType(data_type_and_num_bits.first, HRESULT hr = advertisement->GetSectionsByType(data_type_and_num_bits.first,
&data_sections); &data_sections);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetSectionsByType() failed: " BLUETOOTH_LOG(ERROR) << "GetSectionsByType() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
continue; continue;
} }
...@@ -336,8 +345,8 @@ BluetoothDevice::ManufacturerDataMap ExtractManufacturerData( ...@@ -336,8 +345,8 @@ BluetoothDevice::ManufacturerDataMap ExtractManufacturerData(
ComPtr<IVector<BluetoothLEManufacturerData*>> manufacturer_data_ptr; ComPtr<IVector<BluetoothLEManufacturerData*>> manufacturer_data_ptr;
HRESULT hr = advertisement->get_ManufacturerData(&manufacturer_data_ptr); HRESULT hr = advertisement->get_ManufacturerData(&manufacturer_data_ptr);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetManufacturerData() failed: " BLUETOOTH_LOG(ERROR) << "GetManufacturerData() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return {}; return {};
} }
...@@ -350,15 +359,16 @@ BluetoothDevice::ManufacturerDataMap ExtractManufacturerData( ...@@ -350,15 +359,16 @@ BluetoothDevice::ManufacturerDataMap ExtractManufacturerData(
uint16_t company_id; uint16_t company_id;
hr = manufacturer_datum->get_CompanyId(&company_id); hr = manufacturer_datum->get_CompanyId(&company_id);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_CompanyId() failed: " BLUETOOTH_LOG(ERROR) << "get_CompanyId() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
continue; continue;
} }
ComPtr<IBuffer> buffer; ComPtr<IBuffer> buffer;
hr = manufacturer_datum->get_Data(&buffer); hr = manufacturer_datum->get_Data(&buffer);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Data() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "get_Data() failed: "
<< logging::SystemErrorCodeToString(hr);
continue; continue;
} }
...@@ -384,8 +394,8 @@ base::Optional<int8_t> ExtractTxPower( ...@@ -384,8 +394,8 @@ base::Optional<int8_t> ExtractTxPower(
HRESULT hr = advertisement->GetSectionsByType( HRESULT hr = advertisement->GetSectionsByType(
BluetoothDeviceWinrt::kTxPowerLevelDataSection, &data_sections); BluetoothDeviceWinrt::kTxPowerLevelDataSection, &data_sections);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetSectionsByType() failed: " BLUETOOTH_LOG(ERROR) << "GetSectionsByType() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
...@@ -394,14 +404,16 @@ base::Optional<int8_t> ExtractTxPower( ...@@ -394,14 +404,16 @@ base::Optional<int8_t> ExtractTxPower(
return base::nullopt; return base::nullopt;
if (vector.size() != 1u) { if (vector.size() != 1u) {
VLOG(2) << "Unexpected number of data sections: " << vector.size(); BLUETOOTH_LOG(ERROR) << "Unexpected number of data sections: "
<< vector.size();
return base::nullopt; return base::nullopt;
} }
ComPtr<IBuffer> buffer; ComPtr<IBuffer> buffer;
hr = vector.front()->get_Data(&buffer); hr = vector.front()->get_Data(&buffer);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Data() failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "get_Data() failed: "
<< logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
...@@ -410,7 +422,7 @@ base::Optional<int8_t> ExtractTxPower( ...@@ -410,7 +422,7 @@ base::Optional<int8_t> ExtractTxPower(
return base::nullopt; return base::nullopt;
if (bytes->size() != 1) { if (bytes->size() != 1) {
VLOG(2) << "Unexpected number of bytes: " << bytes->size(); BLUETOOTH_LOG(ERROR) << "Unexpected number of bytes: " << bytes->size();
return base::nullopt; return base::nullopt;
} }
...@@ -422,8 +434,8 @@ ComPtr<IBluetoothLEAdvertisement> GetAdvertisement( ...@@ -422,8 +434,8 @@ ComPtr<IBluetoothLEAdvertisement> GetAdvertisement(
ComPtr<IBluetoothLEAdvertisement> advertisement; ComPtr<IBluetoothLEAdvertisement> advertisement;
HRESULT hr = received->get_Advertisement(&advertisement); HRESULT hr = received->get_Advertisement(&advertisement);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_Advertisement() failed: " BLUETOOTH_LOG(ERROR) << "get_Advertisement() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
return advertisement; return advertisement;
...@@ -437,8 +449,8 @@ base::Optional<std::string> ExtractDeviceName( ...@@ -437,8 +449,8 @@ base::Optional<std::string> ExtractDeviceName(
HSTRING local_name; HSTRING local_name;
HRESULT hr = advertisement->get_LocalName(&local_name); HRESULT hr = advertisement->get_LocalName(&local_name);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting Local Name failed: " BLUETOOTH_LOG(ERROR) << "Getting Local Name failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return base::nullopt; return base::nullopt;
} }
...@@ -455,8 +467,8 @@ void ExtractAndUpdateAdvertisementData( ...@@ -455,8 +467,8 @@ void ExtractAndUpdateAdvertisementData(
int16_t rssi = 0; int16_t rssi = 0;
HRESULT hr = received->get_RawSignalStrengthInDBm(&rssi); HRESULT hr = received->get_RawSignalStrengthInDBm(&rssi);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_RawSignalStrengthInDBm() failed: " BLUETOOTH_LOG(ERROR) << "get_RawSignalStrengthInDBm() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
ComPtr<IBluetoothLEAdvertisement> advertisement = GetAdvertisement(received); ComPtr<IBluetoothLEAdvertisement> advertisement = GetAdvertisement(received);
...@@ -473,8 +485,8 @@ RadioState GetState(IRadio* radio) { ...@@ -473,8 +485,8 @@ RadioState GetState(IRadio* radio) {
RadioState state; RadioState state;
HRESULT hr = radio->get_State(&state); HRESULT hr = radio->get_State(&state);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting Radio State failed: " BLUETOOTH_LOG(ERROR) << "Getting Radio State failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return RadioState_Unknown; return RadioState_Unknown;
} }
return state; return state;
...@@ -562,7 +574,7 @@ void BluetoothAdapterWinrt::RegisterAdvertisement( ...@@ -562,7 +574,7 @@ void BluetoothAdapterWinrt::RegisterAdvertisement(
const AdvertisementErrorCallback& error_callback) { const AdvertisementErrorCallback& error_callback) {
auto advertisement = CreateAdvertisement(); auto advertisement = CreateAdvertisement();
if (!advertisement->Initialize(std::move(advertisement_data))) { if (!advertisement->Initialize(std::move(advertisement_data))) {
VLOG(2) << "Failed to Initialize Advertisement."; BLUETOOTH_LOG(ERROR) << "Failed to Initialize Advertisement.";
ui_task_runner_->PostTask( ui_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(error_callback, base::BindOnce(error_callback,
...@@ -626,8 +638,8 @@ BluetoothAdapterWinrt::~BluetoothAdapterWinrt() { ...@@ -626,8 +638,8 @@ BluetoothAdapterWinrt::~BluetoothAdapterWinrt() {
TryRemovePoweredRadioEventHandlers(); TryRemovePoweredRadioEventHandlers();
HRESULT hr = powered_radio_watcher_->Stop(); HRESULT hr = powered_radio_watcher_->Stop();
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Stopping powered radio watcher failed: " BLUETOOTH_LOG(ERROR) << "Stopping powered radio watcher failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
} }
} }
...@@ -703,8 +715,9 @@ BluetoothAdapterWinrt::PerformSlowInitTasks() { ...@@ -703,8 +715,9 @@ BluetoothAdapterWinrt::PerformSlowInitTasks() {
RuntimeClass_Windows_Devices_Bluetooth_BluetoothAdapter>( RuntimeClass_Windows_Devices_Bluetooth_BluetoothAdapter>(
&adapter_statics); &adapter_statics);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetBluetoothAdapterStaticsActivationFactory failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "GetBluetoothAdapterStaticsActivationFactory failed: "
<< logging::SystemErrorCodeToString(hr);
return BluetoothAdapterWinrt::StaticsInterfaces(); return BluetoothAdapterWinrt::StaticsInterfaces();
} }
...@@ -714,8 +727,9 @@ BluetoothAdapterWinrt::PerformSlowInitTasks() { ...@@ -714,8 +727,9 @@ BluetoothAdapterWinrt::PerformSlowInitTasks() {
RuntimeClass_Windows_Devices_Enumeration_DeviceInformation>( RuntimeClass_Windows_Devices_Enumeration_DeviceInformation>(
&device_information_statics); &device_information_statics);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetDeviceInformationStaticsActivationFactory failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "GetDeviceInformationStaticsActivationFactory failed: "
<< logging::SystemErrorCodeToString(hr);
return BluetoothAdapterWinrt::StaticsInterfaces(); return BluetoothAdapterWinrt::StaticsInterfaces();
} }
...@@ -723,8 +737,8 @@ BluetoothAdapterWinrt::PerformSlowInitTasks() { ...@@ -723,8 +737,8 @@ BluetoothAdapterWinrt::PerformSlowInitTasks() {
hr = base::win::GetActivationFactory< hr = base::win::GetActivationFactory<
IRadioStatics, RuntimeClass_Windows_Devices_Radios_Radio>(&radio_statics); IRadioStatics, RuntimeClass_Windows_Devices_Radios_Radio>(&radio_statics);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetRadioStaticsActivationFactory failed: " BLUETOOTH_LOG(ERROR) << "GetRadioStaticsActivationFactory failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return BluetoothAdapterWinrt::StaticsInterfaces(); return BluetoothAdapterWinrt::StaticsInterfaces();
} }
...@@ -829,8 +843,8 @@ void BluetoothAdapterWinrt::CompleteInit( ...@@ -829,8 +843,8 @@ void BluetoothAdapterWinrt::CompleteInit(
HRESULT hr = HRESULT hr =
bluetooth_adapter_statics_->GetDefaultAsync(&get_default_adapter_op); bluetooth_adapter_statics_->GetDefaultAsync(&get_default_adapter_op);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "BluetoothAdapter::GetDefaultAsync failed: " BLUETOOTH_LOG(ERROR) << "BluetoothAdapter::GetDefaultAsync failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -840,8 +854,8 @@ void BluetoothAdapterWinrt::CompleteInit( ...@@ -840,8 +854,8 @@ void BluetoothAdapterWinrt::CompleteInit(
weak_ptr_factory_.GetWeakPtr(), std::move(on_init))); weak_ptr_factory_.GetWeakPtr(), std::move(on_init)));
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: " BLUETOOTH_LOG(ERROR) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
} }
...@@ -859,8 +873,8 @@ bool BluetoothAdapterWinrt::SetPoweredImpl(bool powered) { ...@@ -859,8 +873,8 @@ bool BluetoothAdapterWinrt::SetPoweredImpl(bool powered) {
ComPtr<IAsyncOperation<RadioAccessStatus>> set_state_op; ComPtr<IAsyncOperation<RadioAccessStatus>> set_state_op;
HRESULT hr = radio_->SetStateAsync(state, &set_state_op); HRESULT hr = radio_->SetStateAsync(state, &set_state_op);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Radio::SetStateAsync failed: " BLUETOOTH_LOG(ERROR) << "Radio::SetStateAsync failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
...@@ -870,8 +884,8 @@ bool BluetoothAdapterWinrt::SetPoweredImpl(bool powered) { ...@@ -870,8 +884,8 @@ bool BluetoothAdapterWinrt::SetPoweredImpl(bool powered) {
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: " BLUETOOTH_LOG(ERROR) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
...@@ -896,8 +910,9 @@ void BluetoothAdapterWinrt::StartScanWithFilter( ...@@ -896,8 +910,9 @@ void BluetoothAdapterWinrt::StartScanWithFilter(
HRESULT hr = ActivateBluetoothAdvertisementLEWatcherInstance( HRESULT hr = ActivateBluetoothAdvertisementLEWatcherInstance(
&ble_advertisement_watcher_); &ble_advertisement_watcher_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "ActivateBluetoothAdvertisementLEWatcherInstance failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "ActivateBluetoothAdvertisementLEWatcherInstance failed: "
<< logging::SystemErrorCodeToString(hr);
ui_task_runner_->PostTask( ui_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(callback), /*is_error=*/true, base::BindOnce(std::move(callback), /*is_error=*/true,
...@@ -908,8 +923,8 @@ void BluetoothAdapterWinrt::StartScanWithFilter( ...@@ -908,8 +923,8 @@ void BluetoothAdapterWinrt::StartScanWithFilter(
hr = ble_advertisement_watcher_->put_ScanningMode( hr = ble_advertisement_watcher_->put_ScanningMode(
BluetoothLEScanningMode_Active); BluetoothLEScanningMode_Active);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Setting ScanningMode to Active failed: " BLUETOOTH_LOG(ERROR) << "Setting ScanningMode to Active failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
ui_task_runner_->PostTask( ui_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(callback), /*is_error=*/true, base::BindOnce(std::move(callback), /*is_error=*/true,
...@@ -934,8 +949,8 @@ void BluetoothAdapterWinrt::StartScanWithFilter( ...@@ -934,8 +949,8 @@ void BluetoothAdapterWinrt::StartScanWithFilter(
hr = ble_advertisement_watcher_->Start(); hr = ble_advertisement_watcher_->Start();
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Starting the Advertisement Watcher failed: " BLUETOOTH_LOG(ERROR) << "Starting the Advertisement Watcher failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
RemoveAdvertisementReceivedHandler(); RemoveAdvertisementReceivedHandler();
ui_task_runner_->PostTask( ui_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
...@@ -947,11 +962,12 @@ void BluetoothAdapterWinrt::StartScanWithFilter( ...@@ -947,11 +962,12 @@ void BluetoothAdapterWinrt::StartScanWithFilter(
BluetoothLEAdvertisementWatcherStatus watcher_status; BluetoothLEAdvertisementWatcherStatus watcher_status;
hr = ble_advertisement_watcher_->get_Status(&watcher_status); hr = ble_advertisement_watcher_->get_Status(&watcher_status);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting the Watcher Status failed: " BLUETOOTH_LOG(ERROR) << "Getting the Watcher Status failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} else if (watcher_status == BluetoothLEAdvertisementWatcherStatus_Aborted) { } else if (watcher_status == BluetoothLEAdvertisementWatcherStatus_Aborted) {
VLOG(2) << "Starting Advertisement Watcher failed, it is in the Aborted " BLUETOOTH_LOG(ERROR)
"state."; << "Starting Advertisement Watcher failed, it is in the Aborted "
"state.";
RemoveAdvertisementReceivedHandler(); RemoveAdvertisementReceivedHandler();
ui_task_runner_->PostTask( ui_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
...@@ -971,8 +987,8 @@ void BluetoothAdapterWinrt::StopScan(DiscoverySessionResultCallback callback) { ...@@ -971,8 +987,8 @@ void BluetoothAdapterWinrt::StopScan(DiscoverySessionResultCallback callback) {
RemoveAdvertisementReceivedHandler(); RemoveAdvertisementReceivedHandler();
HRESULT hr = ble_advertisement_watcher_->Stop(); HRESULT hr = ble_advertisement_watcher_->Stop();
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Stopped the Advertisement Watcher failed: " BLUETOOTH_LOG(ERROR) << "Stopped the Advertisement Watcher failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
ui_task_runner_->PostTask( ui_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(callback), /*is_error=*/true, base::BindOnce(std::move(callback), /*is_error=*/true,
...@@ -1005,16 +1021,16 @@ BluetoothAdapterWinrt::ActivateBluetoothAdvertisementLEWatcherInstance( ...@@ -1005,16 +1021,16 @@ BluetoothAdapterWinrt::ActivateBluetoothAdvertisementLEWatcherInstance(
HRESULT hr = HRESULT hr =
base::win::RoActivateInstance(watcher_hstring.get(), &inspectable); base::win::RoActivateInstance(watcher_hstring.get(), &inspectable);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "RoActivateInstance failed: " BLUETOOTH_LOG(ERROR) << "RoActivateInstance failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return hr; return hr;
} }
ComPtr<IBluetoothLEAdvertisementWatcher> watcher; ComPtr<IBluetoothLEAdvertisementWatcher> watcher;
hr = inspectable.As(&watcher); hr = inspectable.As(&watcher);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "As IBluetoothLEAdvertisementWatcher failed: " BLUETOOTH_LOG(ERROR) << "As IBluetoothLEAdvertisementWatcher failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return hr; return hr;
} }
...@@ -1036,7 +1052,7 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter( ...@@ -1036,7 +1052,7 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter(
ComPtr<IBluetoothAdapter> adapter) { ComPtr<IBluetoothAdapter> adapter) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (!adapter) { if (!adapter) {
VLOG(2) << "Getting Default Adapter failed."; BLUETOOTH_LOG(ERROR) << "Getting Default Adapter failed.";
return; return;
} }
...@@ -1044,8 +1060,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter( ...@@ -1044,8 +1060,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter(
uint64_t raw_address; uint64_t raw_address;
HRESULT hr = adapter_->get_BluetoothAddress(&raw_address); HRESULT hr = adapter_->get_BluetoothAddress(&raw_address);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting BluetoothAddress failed: " BLUETOOTH_LOG(ERROR) << "Getting BluetoothAddress failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1056,8 +1072,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter( ...@@ -1056,8 +1072,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter(
HSTRING device_id; HSTRING device_id;
hr = adapter_->get_DeviceId(&device_id); hr = adapter_->get_DeviceId(&device_id);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting DeviceId failed: " BLUETOOTH_LOG(ERROR) << "Getting DeviceId failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1065,8 +1081,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter( ...@@ -1065,8 +1081,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter(
hr = device_information_statics_->CreateFromIdAsync(device_id, hr = device_information_statics_->CreateFromIdAsync(device_id,
&create_from_id_op); &create_from_id_op);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "CreateFromIdAsync failed: " BLUETOOTH_LOG(ERROR) << "CreateFromIdAsync failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1075,8 +1091,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter( ...@@ -1075,8 +1091,8 @@ void BluetoothAdapterWinrt::OnGetDefaultAdapter(
base::BindOnce(&BluetoothAdapterWinrt::OnCreateFromIdAsync, base::BindOnce(&BluetoothAdapterWinrt::OnCreateFromIdAsync,
weak_ptr_factory_.GetWeakPtr(), std::move(on_init))); weak_ptr_factory_.GetWeakPtr(), std::move(on_init)));
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: " BLUETOOTH_LOG(ERROR) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
} }
...@@ -1085,14 +1101,15 @@ void BluetoothAdapterWinrt::OnCreateFromIdAsync( ...@@ -1085,14 +1101,15 @@ void BluetoothAdapterWinrt::OnCreateFromIdAsync(
ComPtr<IDeviceInformation> device_information) { ComPtr<IDeviceInformation> device_information) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (!device_information) { if (!device_information) {
VLOG(2) << "Getting Device Information failed."; BLUETOOTH_LOG(ERROR) << "Getting Device Information failed.";
return; return;
} }
HSTRING name; HSTRING name;
HRESULT hr = device_information->get_Name(&name); HRESULT hr = device_information->get_Name(&name);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting Name failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "Getting Name failed: "
<< logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1101,8 +1118,8 @@ void BluetoothAdapterWinrt::OnCreateFromIdAsync( ...@@ -1101,8 +1118,8 @@ void BluetoothAdapterWinrt::OnCreateFromIdAsync(
ComPtr<IAsyncOperation<RadioAccessStatus>> request_access_op; ComPtr<IAsyncOperation<RadioAccessStatus>> request_access_op;
hr = radio_statics_->RequestAccessAsync(&request_access_op); hr = radio_statics_->RequestAccessAsync(&request_access_op);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "RequestAccessAsync failed: " BLUETOOTH_LOG(ERROR) << "RequestAccessAsync failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1112,8 +1129,8 @@ void BluetoothAdapterWinrt::OnCreateFromIdAsync( ...@@ -1112,8 +1129,8 @@ void BluetoothAdapterWinrt::OnCreateFromIdAsync(
weak_ptr_factory_.GetWeakPtr(), std::move(on_init))); weak_ptr_factory_.GetWeakPtr(), std::move(on_init)));
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: " BLUETOOTH_LOG(ERROR) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
} }
...@@ -1125,14 +1142,16 @@ void BluetoothAdapterWinrt::OnRequestRadioAccess( ...@@ -1125,14 +1142,16 @@ void BluetoothAdapterWinrt::OnRequestRadioAccess(
if (!radio_access_allowed_) { if (!radio_access_allowed_) {
// This happens if "Allow apps to control device radios" is off in Privacy // This happens if "Allow apps to control device radios" is off in Privacy
// settings. // settings.
VLOG(2) << "RequestRadioAccessAsync failed: " << ToCString(access_status) BLUETOOTH_LOG(ERROR) << "RequestRadioAccessAsync failed: "
<< "Will not be able to change radio power."; << ToCString(access_status)
<< "Will not be able to change radio power.";
} }
ComPtr<IAsyncOperation<Radio*>> get_radio_op; ComPtr<IAsyncOperation<Radio*>> get_radio_op;
HRESULT hr = adapter_->GetRadioAsync(&get_radio_op); HRESULT hr = adapter_->GetRadioAsync(&get_radio_op);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetRadioAsync failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "GetRadioAsync failed: "
<< logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1142,8 +1161,8 @@ void BluetoothAdapterWinrt::OnRequestRadioAccess( ...@@ -1142,8 +1161,8 @@ void BluetoothAdapterWinrt::OnRequestRadioAccess(
weak_ptr_factory_.GetWeakPtr(), std::move(on_init))); weak_ptr_factory_.GetWeakPtr(), std::move(on_init)));
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: " BLUETOOTH_LOG(ERROR) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
} }
...@@ -1159,13 +1178,14 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init, ...@@ -1159,13 +1178,14 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
if (!radio_state_changed_token_) if (!radio_state_changed_token_)
VLOG(2) << "Adding Radio State Changed Handler failed."; BLUETOOTH_LOG(ERROR) << "Adding Radio State Changed Handler failed.";
return; return;
} }
// This happens within WoW64, due to an issue with non-native APIs. // This happens within WoW64, due to an issue with non-native APIs.
VLOG(2) << "Getting Radio failed. Chrome will be unable to change the power " BLUETOOTH_LOG(ERROR)
"state by itself."; << "Getting Radio failed. Chrome will be unable to change the power "
"state by itself.";
// Attempt to create a DeviceWatcher for powered radios, so that querying // Attempt to create a DeviceWatcher for powered radios, so that querying
// the power state is still possible. // the power state is still possible.
...@@ -1173,8 +1193,8 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init, ...@@ -1173,8 +1193,8 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init,
HRESULT hr = device_information_statics_->CreateWatcherAqsFilter( HRESULT hr = device_information_statics_->CreateWatcherAqsFilter(
aqs_filter.get(), &powered_radio_watcher_); aqs_filter.get(), &powered_radio_watcher_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Creating Powered Radios Watcher failed: " BLUETOOTH_LOG(ERROR) << "Creating Powered Radios Watcher failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1195,15 +1215,15 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init, ...@@ -1195,15 +1215,15 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init,
if (!powered_radio_added_token_ || !powered_radio_removed_token_ || if (!powered_radio_added_token_ || !powered_radio_removed_token_ ||
!powered_radios_enumerated_token_) { !powered_radios_enumerated_token_) {
VLOG(2) << "Failed to Register Powered Radio Event Handlers."; BLUETOOTH_LOG(ERROR) << "Failed to Register Powered Radio Event Handlers.";
TryRemovePoweredRadioEventHandlers(); TryRemovePoweredRadioEventHandlers();
return; return;
} }
hr = powered_radio_watcher_->Start(); hr = powered_radio_watcher_->Start();
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Starting the Powered Radio Watcher failed: " BLUETOOTH_LOG(ERROR) << "Starting the Powered Radio Watcher failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
TryRemovePoweredRadioEventHandlers(); TryRemovePoweredRadioEventHandlers();
return; return;
} }
...@@ -1216,8 +1236,8 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init, ...@@ -1216,8 +1236,8 @@ void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init,
void BluetoothAdapterWinrt::OnSetRadioState(RadioAccessStatus access_status) { void BluetoothAdapterWinrt::OnSetRadioState(RadioAccessStatus access_status) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (access_status != RadioAccessStatus_Allowed) { if (access_status != RadioAccessStatus_Allowed) {
VLOG(2) << "Got unexpected Radio Access Status: " BLUETOOTH_LOG(ERROR) << "Got unexpected Radio Access Status: "
<< ToCString(access_status); << ToCString(access_status);
RunPendingPowerCallbacks(); RunPendingPowerCallbacks();
} }
} }
...@@ -1241,8 +1261,8 @@ void BluetoothAdapterWinrt::OnPoweredRadioAdded(IDeviceWatcher* watcher, ...@@ -1241,8 +1261,8 @@ void BluetoothAdapterWinrt::OnPoweredRadioAdded(IDeviceWatcher* watcher,
IDeviceInformation* info) { IDeviceInformation* info) {
if (++num_powered_radios_ == 1) if (++num_powered_radios_ == 1)
NotifyAdapterPoweredChanged(true); NotifyAdapterPoweredChanged(true);
VLOG(2) << "OnPoweredRadioAdded(), Number of Powered Radios: " BLUETOOTH_LOG(ERROR) << "OnPoweredRadioAdded(), Number of Powered Radios: "
<< num_powered_radios_; << num_powered_radios_;
} }
void BluetoothAdapterWinrt::OnPoweredRadioRemoved( void BluetoothAdapterWinrt::OnPoweredRadioRemoved(
...@@ -1250,8 +1270,8 @@ void BluetoothAdapterWinrt::OnPoweredRadioRemoved( ...@@ -1250,8 +1270,8 @@ void BluetoothAdapterWinrt::OnPoweredRadioRemoved(
IDeviceInformationUpdate* update) { IDeviceInformationUpdate* update) {
if (--num_powered_radios_ == 0) if (--num_powered_radios_ == 0)
NotifyAdapterPoweredChanged(false); NotifyAdapterPoweredChanged(false);
VLOG(2) << "OnPoweredRadioRemoved(), Number of Powered Radios: " BLUETOOTH_LOG(ERROR) << "OnPoweredRadioRemoved(), Number of Powered Radios: "
<< num_powered_radios_; << num_powered_radios_;
} }
void BluetoothAdapterWinrt::OnPoweredRadiosEnumerated(IDeviceWatcher* watcher, void BluetoothAdapterWinrt::OnPoweredRadiosEnumerated(IDeviceWatcher* watcher,
...@@ -1260,8 +1280,9 @@ void BluetoothAdapterWinrt::OnPoweredRadiosEnumerated(IDeviceWatcher* watcher, ...@@ -1260,8 +1280,9 @@ void BluetoothAdapterWinrt::OnPoweredRadiosEnumerated(IDeviceWatcher* watcher,
// run. // run.
DCHECK(on_init_); DCHECK(on_init_);
on_init_.reset(); on_init_.reset();
VLOG(2) << "OnPoweredRadiosEnumerated(), Number of Powered Radios: " BLUETOOTH_LOG(ERROR)
<< num_powered_radios_; << "OnPoweredRadiosEnumerated(), Number of Powered Radios: "
<< num_powered_radios_;
} }
void BluetoothAdapterWinrt::OnAdvertisementReceived( void BluetoothAdapterWinrt::OnAdvertisementReceived(
...@@ -1272,8 +1293,8 @@ void BluetoothAdapterWinrt::OnAdvertisementReceived( ...@@ -1272,8 +1293,8 @@ void BluetoothAdapterWinrt::OnAdvertisementReceived(
uint64_t raw_bluetooth_address; uint64_t raw_bluetooth_address;
HRESULT hr = received->get_BluetoothAddress(&raw_bluetooth_address); HRESULT hr = received->get_BluetoothAddress(&raw_bluetooth_address);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "get_BluetoothAddress() failed: " BLUETOOTH_LOG(ERROR) << "get_BluetoothAddress() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
...@@ -1323,8 +1344,8 @@ void BluetoothAdapterWinrt::TryRemoveRadioStateChangedHandler() { ...@@ -1323,8 +1344,8 @@ void BluetoothAdapterWinrt::TryRemoveRadioStateChangedHandler() {
HRESULT hr = radio_->remove_StateChanged(*radio_state_changed_token_); HRESULT hr = radio_->remove_StateChanged(*radio_state_changed_token_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Removing Radio State Changed Handler failed: " BLUETOOTH_LOG(ERROR) << "Removing Radio State Changed Handler failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
radio_state_changed_token_.reset(); radio_state_changed_token_.reset();
...@@ -1336,8 +1357,9 @@ void BluetoothAdapterWinrt::TryRemovePoweredRadioEventHandlers() { ...@@ -1336,8 +1357,9 @@ void BluetoothAdapterWinrt::TryRemovePoweredRadioEventHandlers() {
HRESULT hr = HRESULT hr =
powered_radio_watcher_->remove_Added(*powered_radio_removed_token_); powered_radio_watcher_->remove_Added(*powered_radio_removed_token_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Removing the Powered Radio Added Handler failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "Removing the Powered Radio Added Handler failed: "
<< logging::SystemErrorCodeToString(hr);
} }
powered_radio_added_token_.reset(); powered_radio_added_token_.reset();
...@@ -1347,8 +1369,9 @@ void BluetoothAdapterWinrt::TryRemovePoweredRadioEventHandlers() { ...@@ -1347,8 +1369,9 @@ void BluetoothAdapterWinrt::TryRemovePoweredRadioEventHandlers() {
HRESULT hr = HRESULT hr =
powered_radio_watcher_->remove_Removed(*powered_radio_removed_token_); powered_radio_watcher_->remove_Removed(*powered_radio_removed_token_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Removing the Powered Radio Removed Handler failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "Removing the Powered Radio Removed Handler failed: "
<< logging::SystemErrorCodeToString(hr);
} }
powered_radio_removed_token_.reset(); powered_radio_removed_token_.reset();
...@@ -1358,8 +1381,9 @@ void BluetoothAdapterWinrt::TryRemovePoweredRadioEventHandlers() { ...@@ -1358,8 +1381,9 @@ void BluetoothAdapterWinrt::TryRemovePoweredRadioEventHandlers() {
HRESULT hr = powered_radio_watcher_->remove_EnumerationCompleted( HRESULT hr = powered_radio_watcher_->remove_EnumerationCompleted(
*powered_radios_enumerated_token_); *powered_radios_enumerated_token_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Removing the Powered Radios Enumerated Handler failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "Removing the Powered Radios Enumerated Handler failed: "
<< logging::SystemErrorCodeToString(hr);
} }
powered_radios_enumerated_token_.reset(); powered_radios_enumerated_token_.reset();
...@@ -1371,8 +1395,8 @@ void BluetoothAdapterWinrt::RemoveAdvertisementReceivedHandler() { ...@@ -1371,8 +1395,8 @@ void BluetoothAdapterWinrt::RemoveAdvertisementReceivedHandler() {
HRESULT hr = ble_advertisement_watcher_->remove_Received( HRESULT hr = ble_advertisement_watcher_->remove_Received(
advertisement_received_token_); advertisement_received_token_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Removing the Received Handler failed: " BLUETOOTH_LOG(ERROR) << "Removing the Received Handler failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
} }
......
...@@ -18,12 +18,16 @@ ...@@ -18,12 +18,16 @@
#include "base/win/core_winrt_util.h" #include "base/win/core_winrt_util.h"
#include "base/win/scoped_hstring.h" #include "base/win/scoped_hstring.h"
#include "base/win/winrt_storage_util.h" #include "base/win/winrt_storage_util.h"
#include "components/device_event_log/device_event_log.h"
#include "device/bluetooth/event_utils_winrt.h" #include "device/bluetooth/event_utils_winrt.h"
namespace device { namespace device {
namespace { namespace {
using ABI::Windows::Devices::Bluetooth::BluetoothError;
using ABI::Windows::Devices::Bluetooth::BluetoothError_NotSupported;
using ABI::Windows::Devices::Bluetooth::BluetoothError_RadioNotAvailable;
using ABI::Windows::Devices::Bluetooth::Advertisement:: using ABI::Windows::Devices::Bluetooth::Advertisement::
BluetoothLEAdvertisementPublisherStatus; BluetoothLEAdvertisementPublisherStatus;
using ABI::Windows::Devices::Bluetooth::Advertisement:: using ABI::Windows::Devices::Bluetooth::Advertisement::
...@@ -46,9 +50,6 @@ using ABI::Windows::Devices::Bluetooth::Advertisement:: ...@@ -46,9 +50,6 @@ using ABI::Windows::Devices::Bluetooth::Advertisement::
IBluetoothLEManufacturerData; IBluetoothLEManufacturerData;
using ABI::Windows::Devices::Bluetooth::Advertisement:: using ABI::Windows::Devices::Bluetooth::Advertisement::
IBluetoothLEManufacturerDataFactory; IBluetoothLEManufacturerDataFactory;
using ABI::Windows::Devices::Bluetooth::BluetoothError;
using ABI::Windows::Devices::Bluetooth::BluetoothError_NotSupported;
using ABI::Windows::Devices::Bluetooth::BluetoothError_RadioNotAvailable;
using ABI::Windows::Foundation::Collections::IVector; using ABI::Windows::Foundation::Collections::IVector;
using ABI::Windows::Storage::Streams::IBuffer; using ABI::Windows::Storage::Streams::IBuffer;
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
...@@ -57,8 +58,8 @@ void RemoveStatusChangedHandler(IBluetoothLEAdvertisementPublisher* publisher, ...@@ -57,8 +58,8 @@ void RemoveStatusChangedHandler(IBluetoothLEAdvertisementPublisher* publisher,
EventRegistrationToken token) { EventRegistrationToken token) {
HRESULT hr = publisher->remove_StatusChanged(token); HRESULT hr = publisher->remove_StatusChanged(token);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Removing StatusChanged Handler failed: " BLUETOOTH_LOG(ERROR) << "Removing StatusChanged Handler failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
} }
} }
...@@ -69,47 +70,50 @@ BluetoothAdvertisementWinrt::BluetoothAdvertisementWinrt() {} ...@@ -69,47 +70,50 @@ BluetoothAdvertisementWinrt::BluetoothAdvertisementWinrt() {}
bool BluetoothAdvertisementWinrt::Initialize( bool BluetoothAdvertisementWinrt::Initialize(
std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data) { std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data) {
if (advertisement_data->service_uuids()) { if (advertisement_data->service_uuids()) {
VLOG(2) << "Windows does not support advertising Service UUIDs."; BLUETOOTH_LOG(ERROR)
<< "Windows does not support advertising Service UUIDs.";
return false; return false;
} }
if (advertisement_data->solicit_uuids()) { if (advertisement_data->solicit_uuids()) {
VLOG(2) << "Windows does not support advertising Solicit UUIDs."; BLUETOOTH_LOG(ERROR)
<< "Windows does not support advertising Solicit UUIDs.";
return false; return false;
} }
if (advertisement_data->service_data()) { if (advertisement_data->service_data()) {
VLOG(2) << "Windows does not support advertising Service Data."; BLUETOOTH_LOG(ERROR)
<< "Windows does not support advertising Service Data.";
return false; return false;
} }
auto manufacturer_data = advertisement_data->manufacturer_data(); auto manufacturer_data = advertisement_data->manufacturer_data();
if (!manufacturer_data) { if (!manufacturer_data) {
VLOG(2) << "No Manufacturer Data present."; BLUETOOTH_LOG(ERROR) << "No Manufacturer Data present.";
return false; return false;
} }
ComPtr<IBluetoothLEAdvertisement> advertisement; ComPtr<IBluetoothLEAdvertisement> advertisement;
HRESULT hr = ActivateBluetoothLEAdvertisementInstance(&advertisement); HRESULT hr = ActivateBluetoothLEAdvertisementInstance(&advertisement);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "ActivateBluetoothLEAdvertisementInstance failed: " BLUETOOTH_LOG(ERROR) << "ActivateBluetoothLEAdvertisementInstance failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
ComPtr<IVector<BluetoothLEManufacturerData*>> manufacturer_data_list; ComPtr<IVector<BluetoothLEManufacturerData*>> manufacturer_data_list;
hr = advertisement->get_ManufacturerData(&manufacturer_data_list); hr = advertisement->get_ManufacturerData(&manufacturer_data_list);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting ManufacturerData failed: " BLUETOOTH_LOG(ERROR) << "Getting ManufacturerData failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
ComPtr<IBluetoothLEManufacturerDataFactory> manufacturer_data_factory; ComPtr<IBluetoothLEManufacturerDataFactory> manufacturer_data_factory;
hr = GetBluetoothLEManufacturerDataFactory(&manufacturer_data_factory); hr = GetBluetoothLEManufacturerDataFactory(&manufacturer_data_factory);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetBluetoothLEManufacturerDataFactory failed: " BLUETOOTH_LOG(ERROR) << "GetBluetoothLEManufacturerDataFactory failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
...@@ -120,8 +124,8 @@ bool BluetoothAdvertisementWinrt::Initialize( ...@@ -120,8 +124,8 @@ bool BluetoothAdvertisementWinrt::Initialize(
ComPtr<IBuffer> buffer; ComPtr<IBuffer> buffer;
hr = base::win::CreateIBufferFromData(data.data(), data.size(), &buffer); hr = base::win::CreateIBufferFromData(data.data(), data.size(), &buffer);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "CreateIBufferFromData() failed: " BLUETOOTH_LOG(ERROR) << "CreateIBufferFromData() failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
...@@ -129,15 +133,15 @@ bool BluetoothAdvertisementWinrt::Initialize( ...@@ -129,15 +133,15 @@ bool BluetoothAdvertisementWinrt::Initialize(
hr = manufacturer_data_factory->Create(manufacturer, buffer.Get(), hr = manufacturer_data_factory->Create(manufacturer, buffer.Get(),
&manufacturer_data_entry); &manufacturer_data_entry);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Creating BluetoothLEManufacturerData failed: " BLUETOOTH_LOG(ERROR) << "Creating BluetoothLEManufacturerData failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
hr = manufacturer_data_list->Append(manufacturer_data_entry.Get()); hr = manufacturer_data_list->Append(manufacturer_data_entry.Get());
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Appending BluetoothLEManufacturerData failed: " BLUETOOTH_LOG(ERROR) << "Appending BluetoothLEManufacturerData failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
} }
} }
...@@ -146,16 +150,18 @@ bool BluetoothAdvertisementWinrt::Initialize( ...@@ -146,16 +150,18 @@ bool BluetoothAdvertisementWinrt::Initialize(
hr = hr =
GetBluetoothLEAdvertisementPublisherActivationFactory(&publisher_factory); GetBluetoothLEAdvertisementPublisherActivationFactory(&publisher_factory);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GetBluetoothLEAdvertisementPublisherActivationFactory " BLUETOOTH_LOG(ERROR)
"failed:" << "GetBluetoothLEAdvertisementPublisherActivationFactory "
<< logging::SystemErrorCodeToString(hr); "failed:"
<< logging::SystemErrorCodeToString(hr);
return false; return false;
} }
hr = publisher_factory->Create(advertisement.Get(), &publisher_); hr = publisher_factory->Create(advertisement.Get(), &publisher_);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Creating IBluetoothLEAdvertisementPublisher failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "Creating IBluetoothLEAdvertisementPublisher failed: "
<< logging::SystemErrorCodeToString(hr);
return false; return false;
} }
...@@ -185,8 +191,9 @@ void BluetoothAdvertisementWinrt::Register(SuccessCallback callback, ...@@ -185,8 +191,9 @@ void BluetoothAdvertisementWinrt::Register(SuccessCallback callback,
HRESULT hr = publisher_->Start(); HRESULT hr = publisher_->Start();
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Starting IBluetoothLEAdvertisementPublisher failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "Starting IBluetoothLEAdvertisementPublisher failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(error_callback), FROM_HERE, base::BindOnce(std::move(error_callback),
ERROR_STARTING_ADVERTISEMENT)); ERROR_STARTING_ADVERTISEMENT));
...@@ -209,7 +216,7 @@ void BluetoothAdvertisementWinrt::Unregister( ...@@ -209,7 +216,7 @@ void BluetoothAdvertisementWinrt::Unregister(
DCHECK(publisher_); DCHECK(publisher_);
if (pending_unregister_callbacks_) { if (pending_unregister_callbacks_) {
VLOG(2) << "An Unregister Operation is already in progress."; BLUETOOTH_LOG(ERROR) << "An Unregister Operation is already in progress.";
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(error_callback, ERROR_RESET_ADVERTISING)); FROM_HERE, base::BindOnce(error_callback, ERROR_RESET_ADVERTISING));
return; return;
...@@ -218,8 +225,8 @@ void BluetoothAdvertisementWinrt::Unregister( ...@@ -218,8 +225,8 @@ void BluetoothAdvertisementWinrt::Unregister(
BluetoothLEAdvertisementPublisherStatus status; BluetoothLEAdvertisementPublisherStatus status;
HRESULT hr = publisher_->get_Status(&status); HRESULT hr = publisher_->get_Status(&status);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting the Publisher Status failed: " BLUETOOTH_LOG(ERROR) << "Getting the Publisher Status failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(error_callback, ERROR_RESET_ADVERTISING)); FROM_HERE, base::BindOnce(error_callback, ERROR_RESET_ADVERTISING));
return; return;
...@@ -240,8 +247,9 @@ void BluetoothAdvertisementWinrt::Unregister( ...@@ -240,8 +247,9 @@ void BluetoothAdvertisementWinrt::Unregister(
hr = publisher_->Stop(); hr = publisher_->Stop();
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "IBluetoothLEAdvertisementPublisher::Stop() failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "IBluetoothLEAdvertisementPublisher::Stop() failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(error_callback, ERROR_RESET_ADVERTISING)); FROM_HERE, base::BindOnce(error_callback, ERROR_RESET_ADVERTISING));
return; return;
...@@ -296,16 +304,16 @@ BluetoothAdvertisementWinrt::ActivateBluetoothLEAdvertisementInstance( ...@@ -296,16 +304,16 @@ BluetoothAdvertisementWinrt::ActivateBluetoothLEAdvertisementInstance(
HRESULT hr = HRESULT hr =
base::win::RoActivateInstance(advertisement_hstring.get(), &inspectable); base::win::RoActivateInstance(advertisement_hstring.get(), &inspectable);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "RoActivateInstance failed: " BLUETOOTH_LOG(ERROR) << "RoActivateInstance failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return hr; return hr;
} }
ComPtr<IBluetoothLEAdvertisement> advertisement; ComPtr<IBluetoothLEAdvertisement> advertisement;
hr = inspectable.As(&advertisement); hr = inspectable.As(&advertisement);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "As IBluetoothLEAdvertisementWatcher failed: " BLUETOOTH_LOG(ERROR) << "As IBluetoothLEAdvertisementWatcher failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return hr; return hr;
} }
...@@ -335,12 +343,12 @@ void BluetoothAdvertisementWinrt::OnStatusChanged( ...@@ -335,12 +343,12 @@ void BluetoothAdvertisementWinrt::OnStatusChanged(
BluetoothLEAdvertisementPublisherStatus status; BluetoothLEAdvertisementPublisherStatus status;
HRESULT hr = changed->get_Status(&status); HRESULT hr = changed->get_Status(&status);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting the Publisher Status failed: " BLUETOOTH_LOG(ERROR) << "Getting the Publisher Status failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return; return;
} }
VLOG(2) << "Publisher Status: " << static_cast<int>(status); BLUETOOTH_LOG(EVENT) << "Publisher Status: " << static_cast<int>(status);
if (status == BluetoothLEAdvertisementPublisherStatus_Stopped) { if (status == BluetoothLEAdvertisementPublisherStatus_Stopped) {
// Notify Observers. // Notify Observers.
for (auto& observer : observers_) for (auto& observer : observers_)
...@@ -367,17 +375,17 @@ void BluetoothAdvertisementWinrt::OnStatusChanged( ...@@ -367,17 +375,17 @@ void BluetoothAdvertisementWinrt::OnStatusChanged(
}; };
if (status == BluetoothLEAdvertisementPublisherStatus_Aborted) { if (status == BluetoothLEAdvertisementPublisherStatus_Aborted) {
VLOG(2) << "The Publisher aborted.";
BluetoothError bluetooth_error; BluetoothError bluetooth_error;
hr = changed->get_Error(&bluetooth_error); hr = changed->get_Error(&bluetooth_error);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting the Publisher Error failed: " BLUETOOTH_LOG(ERROR) << "Getting the Publisher Error failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
run_error_cb(error_code); run_error_cb(error_code);
return; return;
} }
VLOG(2) << "Publisher Error: " << static_cast<int>(bluetooth_error); BLUETOOTH_LOG(EVENT) << "Publisher aborted: "
<< static_cast<int>(bluetooth_error);
switch (bluetooth_error) { switch (bluetooth_error) {
case BluetoothError_RadioNotAvailable: case BluetoothError_RadioNotAvailable:
error_code = ERROR_ADAPTER_POWERED_OFF; error_code = ERROR_ADAPTER_POWERED_OFF;
...@@ -395,7 +403,7 @@ void BluetoothAdvertisementWinrt::OnStatusChanged( ...@@ -395,7 +403,7 @@ void BluetoothAdvertisementWinrt::OnStatusChanged(
if (is_starting && if (is_starting &&
status == BluetoothLEAdvertisementPublisherStatus_Started) { status == BluetoothLEAdvertisementPublisherStatus_Started) {
VLOG(2) << "Starting the Publisher was successful."; BLUETOOTH_LOG(EVENT) << "Starting the Publisher was successful.";
auto callbacks = std::move(pending_register_callbacks_); auto callbacks = std::move(pending_register_callbacks_);
std::move(callbacks->callback).Run(); std::move(callbacks->callback).Run();
return; return;
...@@ -403,7 +411,7 @@ void BluetoothAdvertisementWinrt::OnStatusChanged( ...@@ -403,7 +411,7 @@ void BluetoothAdvertisementWinrt::OnStatusChanged(
if (!is_starting && if (!is_starting &&
status == BluetoothLEAdvertisementPublisherStatus_Stopped) { status == BluetoothLEAdvertisementPublisherStatus_Stopped) {
VLOG(2) << "Stopping the Publisher was successful."; BLUETOOTH_LOG(EVENT) << "Stopping the Publisher was successful.";
auto callbacks = std::move(pending_unregister_callbacks_); auto callbacks = std::move(pending_unregister_callbacks_);
std::move(callbacks->callback).Run(); std::move(callbacks->callback).Run();
return; return;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/win/post_async_results.h" #include "base/win/post_async_results.h"
#include "base/win/winrt_storage_util.h" #include "base/win/winrt_storage_util.h"
#include "components/device_event_log/device_event_log.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_winrt.h" #include "device/bluetooth/bluetooth_remote_gatt_service_winrt.h"
#include "device/bluetooth/event_utils_winrt.h" #include "device/bluetooth/event_utils_winrt.h"
...@@ -53,15 +54,16 @@ BluetoothRemoteGattDescriptorWinrt::Create( ...@@ -53,15 +54,16 @@ BluetoothRemoteGattDescriptorWinrt::Create(
GUID guid; GUID guid;
HRESULT hr = descriptor->get_Uuid(&guid); HRESULT hr = descriptor->get_Uuid(&guid);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting UUID failed: " << logging::SystemErrorCodeToString(hr); BLUETOOTH_LOG(ERROR) << "Getting UUID failed: "
<< logging::SystemErrorCodeToString(hr);
return nullptr; return nullptr;
} }
uint16_t attribute_handle; uint16_t attribute_handle;
hr = descriptor->get_AttributeHandle(&attribute_handle); hr = descriptor->get_AttributeHandle(&attribute_handle);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting AttributeHandle failed: " BLUETOOTH_LOG(ERROR) << "Getting AttributeHandle failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return nullptr; return nullptr;
} }
...@@ -112,8 +114,9 @@ void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor( ...@@ -112,8 +114,9 @@ void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor(
HRESULT hr = descriptor_->ReadValueWithCacheModeAsync( HRESULT hr = descriptor_->ReadValueWithCacheModeAsync(
BluetoothCacheMode_Uncached, &read_value_op); BluetoothCacheMode_Uncached, &read_value_op);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GattDescriptor::ReadValueWithCacheModeAsync failed: " BLUETOOTH_LOG(ERROR)
<< logging::SystemErrorCodeToString(hr); << "GattDescriptor::ReadValueWithCacheModeAsync failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(error_callback), base::BindOnce(std::move(error_callback),
...@@ -127,8 +130,8 @@ void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor( ...@@ -127,8 +130,8 @@ void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor(
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: " BLUETOOTH_LOG(ERROR) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(error_callback), base::BindOnce(std::move(error_callback),
...@@ -155,8 +158,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor( ...@@ -155,8 +158,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
ComPtr<IGattDescriptor2> descriptor_2; ComPtr<IGattDescriptor2> descriptor_2;
HRESULT hr = descriptor_.As(&descriptor_2); HRESULT hr = descriptor_.As(&descriptor_2);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "As IGattDescriptor2 failed: " BLUETOOTH_LOG(ERROR) << "As IGattDescriptor2 failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(error_callback), base::BindOnce(std::move(error_callback),
...@@ -167,8 +170,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor( ...@@ -167,8 +170,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
ComPtr<IBuffer> buffer; ComPtr<IBuffer> buffer;
hr = base::win::CreateIBufferFromData(value.data(), value.size(), &buffer); hr = base::win::CreateIBufferFromData(value.data(), value.size(), &buffer);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "base::win::CreateIBufferFromData failed: " BLUETOOTH_LOG(ERROR) << "base::win::CreateIBufferFromData failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(error_callback), base::BindOnce(std::move(error_callback),
...@@ -179,8 +182,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor( ...@@ -179,8 +182,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
ComPtr<IAsyncOperation<GattWriteResult*>> write_value_op; ComPtr<IAsyncOperation<GattWriteResult*>> write_value_op;
hr = descriptor_2->WriteValueWithResultAsync(buffer.Get(), &write_value_op); hr = descriptor_2->WriteValueWithResultAsync(buffer.Get(), &write_value_op);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "GattDescriptor::WriteValueWithResultAsync failed: " BLUETOOTH_LOG(ERROR) << "GattDescriptor::WriteValueWithResultAsync failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(error_callback), base::BindOnce(std::move(error_callback),
...@@ -195,8 +198,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor( ...@@ -195,8 +198,8 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: " BLUETOOTH_LOG(ERROR) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(error_callback), base::BindOnce(std::move(error_callback),
...@@ -251,6 +254,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue( ...@@ -251,6 +254,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue(
auto pending_read_callbacks = std::move(pending_read_callbacks_); auto pending_read_callbacks = std::move(pending_read_callbacks_);
if (!read_result) { if (!read_result) {
BLUETOOTH_LOG(ERROR)
<< "GattDescriptor::ReadValueWithCacheModeAsync returned no result";
std::move(pending_read_callbacks->error_callback) std::move(pending_read_callbacks->error_callback)
.Run(BluetoothGattService::GATT_ERROR_FAILED); .Run(BluetoothGattService::GATT_ERROR_FAILED);
return; return;
...@@ -259,20 +264,20 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue( ...@@ -259,20 +264,20 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue(
GattCommunicationStatus status; GattCommunicationStatus status;
HRESULT hr = read_result->get_Status(&status); HRESULT hr = read_result->get_Status(&status);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting GATT Communication Status failed: " BLUETOOTH_LOG(ERROR) << "Getting GATT Communication Status failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
std::move(pending_read_callbacks->error_callback) std::move(pending_read_callbacks->error_callback)
.Run(BluetoothGattService::GATT_ERROR_FAILED); .Run(BluetoothGattService::GATT_ERROR_FAILED);
return; return;
} }
if (status != GattCommunicationStatus_Success) { if (status != GattCommunicationStatus_Success) {
VLOG(2) << "Unexpected GattCommunicationStatus: " << status; BLUETOOTH_LOG(ERROR) << "Unexpected GattCommunicationStatus: " << status;
ComPtr<IGattReadResult2> read_result_2; ComPtr<IGattReadResult2> read_result_2;
hr = read_result.As(&read_result_2); hr = read_result.As(&read_result_2);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "As IGattReadResult2 failed: " BLUETOOTH_LOG(ERROR) << "As IGattReadResult2 failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
std::move(pending_read_callbacks->error_callback) std::move(pending_read_callbacks->error_callback)
.Run(BluetoothGattService::GATT_ERROR_FAILED); .Run(BluetoothGattService::GATT_ERROR_FAILED);
return; return;
...@@ -287,8 +292,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue( ...@@ -287,8 +292,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue(
ComPtr<IBuffer> value; ComPtr<IBuffer> value;
hr = read_result->get_Value(&value); hr = read_result->get_Value(&value);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting Descriptor Value failed: " BLUETOOTH_LOG(ERROR) << "Getting Descriptor Value failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
std::move(pending_read_callbacks->error_callback) std::move(pending_read_callbacks->error_callback)
.Run(BluetoothGattService::GATT_ERROR_FAILED); .Run(BluetoothGattService::GATT_ERROR_FAILED);
return; return;
...@@ -298,8 +303,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue( ...@@ -298,8 +303,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnReadValue(
uint32_t length = 0; uint32_t length = 0;
hr = base::win::GetPointerToBufferData(value.Get(), &data, &length); hr = base::win::GetPointerToBufferData(value.Get(), &data, &length);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting Pointer To Buffer Data failed: " BLUETOOTH_LOG(ERROR) << "Getting Pointer To Buffer Data failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
std::move(pending_read_callbacks->error_callback) std::move(pending_read_callbacks->error_callback)
.Run(BluetoothGattService::GATT_ERROR_FAILED); .Run(BluetoothGattService::GATT_ERROR_FAILED);
return; return;
...@@ -315,6 +320,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnWriteValueWithResult( ...@@ -315,6 +320,8 @@ void BluetoothRemoteGattDescriptorWinrt::OnWriteValueWithResult(
auto pending_write_callbacks = std::move(pending_write_callbacks_); auto pending_write_callbacks = std::move(pending_write_callbacks_);
if (!write_result) { if (!write_result) {
BLUETOOTH_LOG(ERROR)
<< "GattDescriptor::WriteValueWithResultAsync returned no result";
std::move(pending_write_callbacks->error_callback) std::move(pending_write_callbacks->error_callback)
.Run(BluetoothGattService::GATT_ERROR_FAILED); .Run(BluetoothGattService::GATT_ERROR_FAILED);
return; return;
...@@ -323,15 +330,15 @@ void BluetoothRemoteGattDescriptorWinrt::OnWriteValueWithResult( ...@@ -323,15 +330,15 @@ void BluetoothRemoteGattDescriptorWinrt::OnWriteValueWithResult(
GattCommunicationStatus status; GattCommunicationStatus status;
HRESULT hr = write_result->get_Status(&status); HRESULT hr = write_result->get_Status(&status);
if (FAILED(hr)) { if (FAILED(hr)) {
VLOG(2) << "Getting GATT Communication Status failed: " BLUETOOTH_LOG(ERROR) << "Getting GATT Communication Status failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
std::move(pending_write_callbacks->error_callback) std::move(pending_write_callbacks->error_callback)
.Run(BluetoothGattService::GATT_ERROR_FAILED); .Run(BluetoothGattService::GATT_ERROR_FAILED);
return; return;
} }
if (status != GattCommunicationStatus_Success) { if (status != GattCommunicationStatus_Success) {
VLOG(2) << "Unexpected GattCommunicationStatus: " << status; BLUETOOTH_LOG(ERROR) << "Unexpected GattCommunicationStatus: " << status;
std::move(pending_write_callbacks->error_callback) std::move(pending_write_callbacks->error_callback)
.Run(BluetoothRemoteGattServiceWinrt::GetGattErrorCode( .Run(BluetoothRemoteGattServiceWinrt::GetGattErrorCode(
write_result.Get())); write_result.Get()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment