Use Runtime.getRuntime().gc() instead System.gc()
[chromium-blink-merge.git] / device / nfc / nfc_adapter.cc
blob520d4f31092617d050c3932544abbf3715231023
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "device/nfc/nfc_adapter.h"
7 #include "base/stl_util.h"
8 #include "device/nfc/nfc_peer.h"
9 #include "device/nfc/nfc_tag.h"
11 namespace device {
13 NfcAdapter::NfcAdapter() {
16 NfcAdapter::~NfcAdapter() {
17 STLDeleteValues(&peers_);
18 STLDeleteValues(&tags_);
21 void NfcAdapter::GetPeers(PeerList* peer_list) const {
22 peer_list->clear();
23 for (PeersMap::const_iterator iter = peers_.begin();
24 iter != peers_.end(); ++iter) {
25 peer_list->push_back(iter->second);
29 void NfcAdapter::GetTags(TagList* tag_list) const {
30 tag_list->clear();
31 for (TagsMap::const_iterator iter = tags_.begin();
32 iter != tags_.end(); ++iter) {
33 tag_list->push_back(iter->second);
37 NfcPeer* NfcAdapter::GetPeer(const std::string& identifier) const {
38 PeersMap::const_iterator iter = peers_.find(identifier);
39 if (iter != peers_.end())
40 return iter->second;
41 return NULL;
44 NfcTag* NfcAdapter::GetTag(const std::string& identifier) const {
45 TagsMap::const_iterator iter = tags_.find(identifier);
46 if (iter != tags_.end())
47 return iter->second;
48 return NULL;
51 void NfcAdapter::SetTag(const std::string& identifier, NfcTag* tag) {
52 if (GetTag(identifier)) {
53 VLOG(1) << "Tag object for tag \"" << identifier << "\" already exists.";
54 return;
56 tags_[identifier] = tag;
59 void NfcAdapter::SetPeer(const std::string& identifier, NfcPeer* peer) {
60 if (GetPeer(identifier)) {
61 VLOG(1) << "Peer object for peer \"" << identifier << "\" already exists.";
62 return;
64 peers_[identifier] = peer;
67 NfcTag* NfcAdapter::RemoveTag(const std::string& identifier) {
68 TagsMap::iterator iter = tags_.find(identifier);
69 if (iter == tags_.end()) {
70 VLOG(1) << "Tag with identifier \"" << identifier << "\" not found.";
71 return NULL;
73 NfcTag* tag = iter->second;
74 tags_.erase(iter);
75 return tag;
78 NfcPeer* NfcAdapter::RemovePeer(const std::string& identifier) {
79 PeersMap::iterator iter = peers_.find(identifier);
80 if (iter == peers_.end()) {
81 VLOG(1) << "Peer object for peer \"" << identifier << "\" not found.";
82 return NULL;
84 NfcPeer* peer = iter->second;
85 peers_.erase(iter);
86 return peer;
89 void NfcAdapter::ClearTags() {
90 tags_.clear();
93 void NfcAdapter::ClearPeers() {
94 peers_.clear();
97 } // namespace device