| Index: components/proximity_auth/bluetooth_low_energy_advertiser.cc
|
| diff --git a/components/proximity_auth/bluetooth_low_energy_advertiser.cc b/components/proximity_auth/bluetooth_low_energy_advertiser.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..37b6adfb8726d4caf64da688f99f60e09503fce9
|
| --- /dev/null
|
| +++ b/components/proximity_auth/bluetooth_low_energy_advertiser.cc
|
| @@ -0,0 +1,65 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/proximity_auth/bluetooth_low_energy_advertiser.h"
|
| +
|
| +#include <memory>
|
| +#include <string>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "components/proximity_auth/logging/logging.h"
|
| +#include "device/bluetooth/bluetooth_adapter_factory.h"
|
| +
|
| +namespace proximity_auth {
|
| +namespace {
|
| +const char kAdvertisementUUID[] = "0000fe50-0000-1000-8000-00805f9b34fb";
|
| +}
|
| +
|
| +BluetoothLowEnergyAdvertiser::BluetoothLowEnergyAdvertiser()
|
| + : weak_ptr_factory_(this) {}
|
| +
|
| +BluetoothLowEnergyAdvertiser::~BluetoothLowEnergyAdvertiser() {}
|
| +
|
| +void BluetoothLowEnergyAdvertiser::Advertise() {
|
| + device::BluetoothAdapterFactory::GetAdapter(
|
| + base::Bind(&BluetoothLowEnergyAdvertiser::OnAdapterInitialized,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +void BluetoothLowEnergyAdvertiser::OnAdapterInitialized(
|
| + scoped_refptr<device::BluetoothAdapter> adapter) {
|
| + PA_LOG(INFO) << "Adapter ready";
|
| + adapter_ = adapter;
|
| +
|
| + std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data =
|
| + base::MakeUnique<device::BluetoothAdvertisement::Data>(
|
| + device::BluetoothAdvertisement::AdvertisementType::
|
| + ADVERTISEMENT_TYPE_PERIPHERAL);
|
| + std::unique_ptr<device::BluetoothAdvertisement::UUIDList> list =
|
| + base::MakeUnique<device::BluetoothAdvertisement::UUIDList>();
|
| + list->push_back(std::string(kAdvertisementUUID));
|
| + advertisement_data->set_service_uuids(std::move(list));
|
| +
|
| + adapter_->RegisterAdvertisement(
|
| + std::move(advertisement_data),
|
| + base::Bind(&BluetoothLowEnergyAdvertiser::OnAdvertisementRegistered,
|
| + weak_ptr_factory_.GetWeakPtr()),
|
| + base::Bind(&BluetoothLowEnergyAdvertiser::OnAdvertisementError,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +void BluetoothLowEnergyAdvertiser::OnAdvertisementRegistered(
|
| + scoped_refptr<device::BluetoothAdvertisement> advertisement) {
|
| + PA_LOG(INFO) << "Advertisement started";
|
| + advertisement_ = advertisement;
|
| +}
|
| +
|
| +void BluetoothLowEnergyAdvertiser::OnAdvertisementError(
|
| + device::BluetoothAdvertisement::ErrorCode error_code) {
|
| + PA_LOG(INFO) << "Advertisement failed";
|
| +}
|
| +
|
| +} // namespace proximity_auth
|
|
|