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 #ifndef DEVICE_NFC_NFC_ADAPTER_CHROMEOS_H_
6 #define DEVICE_NFC_NFC_ADAPTER_CHROMEOS_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/observer_list.h"
10 #include "chromeos/dbus/nfc_adapter_client.h"
11 #include "chromeos/dbus/nfc_device_client.h"
12 #include "chromeos/dbus/nfc_tag_client.h"
13 #include "dbus/object_path.h"
14 #include "device/nfc/nfc_adapter.h"
18 class NfcAdapterFactory
;
24 // The NfcAdapterChromeOS class implements NfcAdapter for the Chrome OS
26 class NfcAdapterChromeOS
: public device::NfcAdapter
,
27 public chromeos::NfcAdapterClient::Observer
,
28 public chromeos::NfcDeviceClient::Observer
,
29 public chromeos::NfcTagClient::Observer
{
31 // NfcAdapter overrides.
32 virtual void AddObserver(NfcAdapter::Observer
* observer
) override
;
33 virtual void RemoveObserver(NfcAdapter::Observer
* observer
) override
;
34 virtual bool IsPresent() const override
;
35 virtual bool IsPowered() const override
;
36 virtual bool IsPolling() const override
;
37 virtual bool IsInitialized() const override
;
38 virtual void SetPowered(bool powered
,
39 const base::Closure
& callback
,
40 const ErrorCallback
& error_callback
) override
;
41 virtual void StartPolling(const base::Closure
& callback
,
42 const ErrorCallback
& error_callback
) override
;
43 virtual void StopPolling(const base::Closure
& callback
,
44 const ErrorCallback
& error_callback
) override
;
47 friend class device::NfcAdapterFactory
;
48 friend class NfcChromeOSTest
;
51 virtual ~NfcAdapterChromeOS();
53 // NfcAdapterClient::Observer overrides.
54 virtual void AdapterAdded(const dbus::ObjectPath
& object_path
) override
;
55 virtual void AdapterRemoved(const dbus::ObjectPath
& object_path
) override
;
56 virtual void AdapterPropertyChanged(
57 const dbus::ObjectPath
& object_path
,
58 const std::string
& property_name
) override
;
60 // NfcDeviceClient::Observer overrides.
61 virtual void DeviceAdded(const dbus::ObjectPath
& object_path
) override
;
62 virtual void DeviceRemoved(const dbus::ObjectPath
& object_path
) override
;
64 // NfcTagClient::Observer overrides.
65 virtual void TagAdded(const dbus::ObjectPath
& object_path
) override
;
66 virtual void TagRemoved(const dbus::ObjectPath
& object_path
) override
;
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
);
72 // Remove the currently tracked adapter. IsPresent() will return false after
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
);
81 // Called by dbus:: on completion of the powered property change.
82 void OnSetPowered(const base::Closure
& callback
,
83 const ErrorCallback
& error_callback
,
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
);
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
);
98 // Object path of the adapter that we are currently tracking.
99 dbus::ObjectPath object_path_
;
101 // List of observers interested in event notifications from us.
102 ObserverList
<device::NfcAdapter::Observer
> observers_
;
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_
;
108 DISALLOW_COPY_AND_ASSIGN(NfcAdapterChromeOS
);
111 } // namespace chromeos
113 #endif // DEVICE_NFC_NFC_ADAPTER_CHROMEOS_H_