nfc_adapter_client.cc revision 0f1bc08d4cfcc34181b0b5cbf065c40f687bf740
11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_adapter_client.h"
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <map>
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <utility>
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/bind.h"
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/observer_list.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/stringprintf.h"
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/fake_nfc_adapter_client.h"
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_manager_client.h"
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/bus.h"
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/message.h"
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "third_party/cros_system_api/dbus/service_constants.h"
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace chromeos {
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)NfcAdapterClient::Properties::Properties(
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::ObjectProxy* object_proxy,
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const PropertyChangedCallback& callback)
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    : NfcPropertySet(object_proxy,
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                     nfc_adapter::kNfcAdapterInterface,
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                     callback) {
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  RegisterProperty(nfc_adapter::kModeProperty, &mode);
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  RegisterProperty(nfc_adapter::kPoweredProperty, &powered);
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  RegisterProperty(nfc_adapter::kPollingProperty, &polling);
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  RegisterProperty(nfc_adapter::kProtocolsProperty, &protocols);
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  RegisterProperty(nfc_adapter::kTagsProperty, &tags);
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  RegisterProperty(nfc_adapter::kDevicesProperty, &devices);
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)NfcAdapterClient::Properties::~Properties() {
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The NfcAdapterClient implementation used in production.
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class NfcAdapterClientImpl
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    : public NfcAdapterClient,
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      public NfcManagerClient::Observer,
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      public nfc_client_helpers::DBusObjectMap::Delegate {
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  explicit NfcAdapterClientImpl(NfcManagerClient* manager_client)
460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      : bus_(NULL),
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        manager_client_(manager_client),
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        weak_ptr_factory_(this) {
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DCHECK(manager_client);
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~NfcAdapterClientImpl() {
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    manager_client_->RemoveObserver(this);
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // NfcAdapterClient override.
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void AddObserver(NfcAdapterClient::Observer* observer) OVERRIDE {
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DCHECK(observer);
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    observers_.AddObserver(observer);
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // NfcAdapterClient override.
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void RemoveObserver(NfcAdapterClient::Observer* observer) OVERRIDE {
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DCHECK(observer);
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    observers_.RemoveObserver(observer);
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // NfcAdapterClient override.
691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      OVERRIDE {
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return static_cast<Properties*>(
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        object_map_->GetObjectProperties(object_path));
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // NfcAdapterClient override.
761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void StartPollLoop(
771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const dbus::ObjectPath& object_path,
781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const std::string& mode,
791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const base::Closure& callback,
801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE {
811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::ObjectProxy* object_proxy = object_map_->GetObjectProxy(object_path);
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (!object_proxy) {
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      std::string error_message =
841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          base::StringPrintf("NFC adapter with object path \"%s\" does not "
851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             "exist.", object_path.value().c_str());
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      LOG(ERROR) << error_message;
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      error_callback.Run(nfc_client_helpers::kUnknownObjectError,
881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                         error_message);
891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return;
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::MethodCall method_call(nfc_adapter::kNfcAdapterInterface,
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                 nfc_adapter::kStartPollLoop);
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::MessageWriter writer(&method_call);
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    writer.AppendString(mode);
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    object_proxy->CallMethodWithErrorCallback(
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        &method_call,
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        base::Bind(&nfc_client_helpers::OnSuccess, callback),
991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        base::Bind(&nfc_client_helpers::OnError, error_callback));
1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // NfcAdapterClient override.
1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void StopPollLoop(
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const dbus::ObjectPath& object_path,
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const base::Closure& callback,
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE {
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::ObjectProxy* object_proxy = object_map_->GetObjectProxy(object_path);
1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (!object_proxy) {
1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      std::string error_message =
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          base::StringPrintf("NFC adapter with object path \"%s\" does not "
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             "exist.", object_path.value().c_str());
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      LOG(ERROR) << error_message;
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      error_callback.Run(nfc_client_helpers::kUnknownObjectError,
1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                         error_message);
1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return;
1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::MethodCall method_call(nfc_adapter::kNfcAdapterInterface,
1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                 nfc_adapter::kStopPollLoop);
1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    object_proxy->CallMethodWithErrorCallback(
1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        &method_call,
1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        base::Bind(&nfc_client_helpers::OnSuccess, callback),
1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        base::Bind(&nfc_client_helpers::OnError, error_callback));
1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected:
1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // DBusClient override.
1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void Init(dbus::Bus* bus) OVERRIDE {
1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    VLOG(1) << "Creating NfcAdapterClientImpl";
1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DCHECK(bus);
1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    bus_ = bus;
1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    object_map_.reset(new nfc_client_helpers::DBusObjectMap(
1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        nfc_adapter::kNfcAdapterServiceName, this, bus));
1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DCHECK(manager_client_);
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    manager_client_->AddObserver(this);
1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // NfcManagerClient::Observer override.
1400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual void ManagerPropertyChanged(
1410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      const std::string& property_name) OVERRIDE {
1420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Update the adapter proxies.
1430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    DCHECK(manager_client_);
1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    NfcManagerClient::Properties* manager_properties =
1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        manager_client_->GetProperties();
1460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Ignore changes to properties other than "Adapters".
1480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    if (property_name != manager_properties->adapters.name())
1490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      return;
1500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    VLOG(1) << "NFC adapters changed.";
1520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Update the known adapters.
1540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    const std::vector<dbus::ObjectPath>& received_adapters =
1550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        manager_properties->adapters.value();
1560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    object_map_->UpdateObjects(received_adapters);
1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // nfc_client_helpers::DBusObjectMap::Delegate override.
1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual NfcPropertySet* CreateProperties(
1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectProxy* object_proxy) OVERRIDE {
1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return new Properties(
1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        object_proxy,
1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        base::Bind(&NfcAdapterClientImpl::OnPropertyChanged,
1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   weak_ptr_factory_.GetWeakPtr(),
1661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   object_proxy->object_path()));
1671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // nfc_client_helpers::DBusObjectMap::Delegate override.
1700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual void ObjectAdded(const dbus::ObjectPath& object_path) OVERRIDE {
1710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    FOR_EACH_OBSERVER(NfcAdapterClient::Observer, observers_,
1720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                      AdapterAdded(object_path));
1730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  }
1740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual void ObjectRemoved(const dbus::ObjectPath& object_path) OVERRIDE {
1760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    FOR_EACH_OBSERVER(NfcAdapterClient::Observer, observers_,
1770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                      AdapterRemoved(object_path));
1780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  }
1790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Called by NfcPropertySet when a property value is changed, either by
1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // result of a signal or response to a GetAll() or Get() call.
1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void OnPropertyChanged(const dbus::ObjectPath& object_path,
1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                         const std::string& property_name) {
1841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    VLOG(1) << "Adapter property changed; Path: " << object_path.value()
1851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            << " Property: " << property_name;
1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    FOR_EACH_OBSERVER(NfcAdapterClient::Observer, observers_,
1871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                      AdapterPropertyChanged(object_path, property_name));
1881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // We maintain a pointer to the bus to be able to request proxies for
1911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // new NFC adapters that appear.
1921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  dbus::Bus* bus_;
1931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Mapping from object paths to object proxies and properties structures that
1951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // were already created by us.
1961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<nfc_client_helpers::DBusObjectMap> object_map_;
1971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The manager client that we listen to events notifications from.
1991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  NfcManagerClient* manager_client_;
2001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // List of observers interested in event notifications.
2021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ObserverList<NfcAdapterClient::Observer> observers_;
2031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Weak pointer factory for generating 'this' pointers that might live longer
2051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // than we do.
2061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Note: This should remain the last member so it'll be destroyed and
2071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // invalidate its weak pointers before any other members are destroyed.
2081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  base::WeakPtrFactory<NfcAdapterClientImpl> weak_ptr_factory_;
2091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(NfcAdapterClientImpl);
2111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
2121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)NfcAdapterClient::NfcAdapterClient() {
2141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)NfcAdapterClient::~NfcAdapterClient() {
2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)NfcAdapterClient* NfcAdapterClient::Create(DBusClientImplementationType type,
2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                           NfcManagerClient* manager_client) {
2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return new NfcAdapterClientImpl(manager_client);
2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return new FakeNfcAdapterClient();
2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace chromeos
228