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