| Index: device/nfc/nfc_adapter.cc
|
| diff --git a/device/nfc/nfc_adapter.cc b/device/nfc/nfc_adapter.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..64578bca86337bae0cbfbb1e249bb1af1a2a0bba
|
| --- /dev/null
|
| +++ b/device/nfc/nfc_adapter.cc
|
| @@ -0,0 +1,78 @@
|
| +// Copyright (c) 2013 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 "device/nfc/nfc_adapter.h"
|
| +
|
| +#include "base/lazy_instance.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/stl_util.h"
|
| +#include "device/nfc/nfc_peer.h"
|
| +#include "device/nfc/nfc_tag.h"
|
| +
|
| +namespace {
|
| +
|
| +// Shared default adapter instance. We don't want to keep this class around if
|
| +// nobody is using it, so use a WeakPtr and create the object when needed.
|
| +// Since Google C++ Style (and clang's static analyzer) forbids us from having
|
| +// exit-time destructors, we use a leaky lazy instance for it.
|
| +base::LazyInstance<base::WeakPtr<device::NfcAdapter> >::Leaky default_adapter =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +} // namespace
|
| +
|
| +namespace device {
|
| +
|
| +NfcAdapter::NfcAdapter() {
|
| +}
|
| +
|
| +NfcAdapter::~NfcAdapter() {
|
| + STLDeleteValues(&peers_);
|
| + STLDeleteValues(&tags_);
|
| +}
|
| +
|
| +// static
|
| +bool NfcAdapter::IsNfcAvailable() {
|
| + // TODO(armansito): Return true on supported platforms here.
|
| + return false;
|
| +}
|
| +
|
| +// static
|
| +scoped_refptr<NfcAdapter> NfcAdapter::GetAdapter() {
|
| + if (!default_adapter.Get().get())
|
| + // TODO(armansito): Create platform-specific implementation instances here.
|
| + return scoped_refptr<NfcAdapter>(); // Return a NULL pointer.
|
| + return scoped_refptr<NfcAdapter>(default_adapter.Get().get());
|
| +}
|
| +
|
| +void NfcAdapter::GetPeers(PeerList* peer_list) const {
|
| + peer_list->clear();
|
| + for (PeersMap::const_iterator iter = peers_.begin();
|
| + iter != peers_.end(); ++iter) {
|
| + peer_list->push_back(iter->second);
|
| + }
|
| +}
|
| +
|
| +void NfcAdapter::GetTags(TagList* tag_list) const {
|
| + tag_list->clear();
|
| + for (TagsMap::const_iterator iter = tags_.begin();
|
| + iter != tags_.end(); ++iter) {
|
| + tag_list->push_back(iter->second);
|
| + }
|
| +}
|
| +
|
| +NfcPeer* NfcAdapter::GetPeer(const std::string& identifier) const {
|
| + PeersMap::const_iterator iter = peers_.find(identifier);
|
| + if (iter != peers_.end())
|
| + return iter->second;
|
| + return NULL;
|
| +}
|
| +
|
| +NfcTag* NfcAdapter::GetTag(const std::string& identifier) const {
|
| + TagsMap::const_iterator iter = tags_.find(identifier);
|
| + if (iter != tags_.end())
|
| + return iter->second;
|
| + return NULL;
|
| +}
|
| +
|
| +} // namespace device
|
|
|