| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef DEVICE_NFC_NFC_ADAPTER_CHROMEOS_H_ | |
| 6 #define DEVICE_NFC_NFC_ADAPTER_CHROMEOS_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/observer_list.h" | |
| 11 #include "chromeos/dbus/nfc_adapter_client.h" | |
| 12 #include "chromeos/dbus/nfc_device_client.h" | |
| 13 #include "chromeos/dbus/nfc_tag_client.h" | |
| 14 #include "dbus/object_path.h" | |
| 15 #include "device/nfc/nfc_adapter.h" | |
| 16 | |
| 17 namespace device { | |
| 18 | |
| 19 class NfcAdapterFactory; | |
| 20 | |
| 21 } // namespace device | |
| 22 | |
| 23 namespace chromeos { | |
| 24 | |
| 25 // The NfcAdapterChromeOS class implements NfcAdapter for the Chrome OS | |
| 26 // platform. | |
| 27 class NfcAdapterChromeOS : public device::NfcAdapter, | |
| 28 public chromeos::NfcAdapterClient::Observer, | |
| 29 public chromeos::NfcDeviceClient::Observer, | |
| 30 public chromeos::NfcTagClient::Observer { | |
| 31 public: | |
| 32 // NfcAdapter overrides. | |
| 33 void AddObserver(NfcAdapter::Observer* observer) override; | |
| 34 void RemoveObserver(NfcAdapter::Observer* observer) override; | |
| 35 bool IsPresent() const override; | |
| 36 bool IsPowered() const override; | |
| 37 bool IsPolling() const override; | |
| 38 bool IsInitialized() const override; | |
| 39 void SetPowered(bool powered, | |
| 40 const base::Closure& callback, | |
| 41 const ErrorCallback& error_callback) override; | |
| 42 void StartPolling(const base::Closure& callback, | |
| 43 const ErrorCallback& error_callback) override; | |
| 44 void StopPolling(const base::Closure& callback, | |
| 45 const ErrorCallback& error_callback) override; | |
| 46 | |
| 47 private: | |
| 48 friend class device::NfcAdapterFactory; | |
| 49 friend class NfcChromeOSTest; | |
| 50 | |
| 51 NfcAdapterChromeOS(); | |
| 52 ~NfcAdapterChromeOS() override; | |
| 53 | |
| 54 // NfcAdapterClient::Observer overrides. | |
| 55 void AdapterAdded(const dbus::ObjectPath& object_path) override; | |
| 56 void AdapterRemoved(const dbus::ObjectPath& object_path) override; | |
| 57 void AdapterPropertyChanged(const dbus::ObjectPath& object_path, | |
| 58 const std::string& property_name) override; | |
| 59 | |
| 60 // NfcDeviceClient::Observer overrides. | |
| 61 void DeviceAdded(const dbus::ObjectPath& object_path) override; | |
| 62 void DeviceRemoved(const dbus::ObjectPath& object_path) override; | |
| 63 | |
| 64 // NfcTagClient::Observer overrides. | |
| 65 void TagAdded(const dbus::ObjectPath& object_path) override; | |
| 66 void TagRemoved(const dbus::ObjectPath& object_path) override; | |
| 67 | |
| 68 // Set the tracked adapter to the one in |object_path|, this object will | |
| 69 // subsequently operate on that adapter until it is removed. | |
| 70 void SetAdapter(const dbus::ObjectPath& object_path); | |
| 71 | |
| 72 // Remove the currently tracked adapter. IsPresent() will return false after | |
| 73 // this is called. | |
| 74 void RemoveAdapter(); | |
| 75 | |
| 76 // Announce to observers a change in the adapter state. | |
| 77 void PoweredChanged(bool powered); | |
| 78 void PollingChanged(bool polling); | |
| 79 void PresentChanged(bool present); | |
| 80 | |
| 81 // Called by dbus:: on completion of the powered property change. | |
| 82 void OnSetPowered(const base::Closure& callback, | |
| 83 const ErrorCallback& error_callback, | |
| 84 bool success); | |
| 85 | |
| 86 // Called by dbus:: on completion of the D-Bus method call to start polling. | |
| 87 void OnStartPolling(const base::Closure& callback); | |
| 88 void OnStartPollingError(const ErrorCallback& error_callback, | |
| 89 const std::string& error_name, | |
| 90 const std::string& error_message); | |
| 91 | |
| 92 // Called by dbus:: on completion of the D-Bus method call to stop polling. | |
| 93 void OnStopPolling(const base::Closure& callback); | |
| 94 void OnStopPollingError(const ErrorCallback& error_callback, | |
| 95 const std::string& error_name, | |
| 96 const std::string& error_message); | |
| 97 | |
| 98 // Object path of the adapter that we are currently tracking. | |
| 99 dbus::ObjectPath object_path_; | |
| 100 | |
| 101 // List of observers interested in event notifications from us. | |
| 102 base::ObserverList<device::NfcAdapter::Observer> observers_; | |
| 103 | |
| 104 // Note: This should remain the last member so it'll be destroyed and | |
| 105 // invalidate its weak pointers before any other members are destroyed. | |
| 106 base::WeakPtrFactory<NfcAdapterChromeOS> weak_ptr_factory_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(NfcAdapterChromeOS); | |
| 109 }; | |
| 110 | |
| 111 } // namespace chromeos | |
| 112 | |
| 113 #endif // DEVICE_NFC_NFC_ADAPTER_CHROMEOS_H_ | |
| OLD | NEW |