This source file includes following definitions.
- IsNfcAvailable
- GetAdapter
#include "device/nfc/nfc_adapter_factory.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#if defined(OS_CHROMEOS)
#include "device/nfc/nfc_adapter_chromeos.h"
#endif
namespace device {
namespace {
base::LazyInstance<base::WeakPtr<device::NfcAdapter> >::Leaky
default_adapter = LAZY_INSTANCE_INITIALIZER;
}
bool NfcAdapterFactory::IsNfcAvailable() {
#if defined(OS_CHROMEOS)
return true;
#else
return false;
#endif
}
void NfcAdapterFactory::GetAdapter(const AdapterCallback& callback) {
if (!IsNfcAvailable()) {
LOG(WARNING) << "NFC is not available on the current platform.";
return;
}
if (!default_adapter.Get().get()) {
#if defined(OS_CHROMEOS)
chromeos::NfcAdapterChromeOS* new_adapter =
new chromeos::NfcAdapterChromeOS();
default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
#endif
}
if (default_adapter.Get()->IsInitialized())
callback.Run(scoped_refptr<NfcAdapter>(default_adapter.Get().get()));
}
}