Files.app: Stop to use autogen IDs of TreeItems to identify tree items.
[chromium-blink-merge.git] / device / nfc / nfc_adapter_chromeos.h
blob1a8c24864e5a762c62467c58752c87b6cc8263dc
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"
16 namespace device {
18 class NfcAdapterFactory;
20 } // namespace device
22 namespace chromeos {
24 // The NfcAdapterChromeOS class implements NfcAdapter for the Chrome OS
25 // platform.
26 class NfcAdapterChromeOS : public device::NfcAdapter,
27 public chromeos::NfcAdapterClient::Observer,
28 public chromeos::NfcDeviceClient::Observer,
29 public chromeos::NfcTagClient::Observer {
30 public:
31 // NfcAdapter overrides.
32 void AddObserver(NfcAdapter::Observer* observer) override;
33 void RemoveObserver(NfcAdapter::Observer* observer) override;
34 bool IsPresent() const override;
35 bool IsPowered() const override;
36 bool IsPolling() const override;
37 bool IsInitialized() const override;
38 void SetPowered(bool powered,
39 const base::Closure& callback,
40 const ErrorCallback& error_callback) override;
41 void StartPolling(const base::Closure& callback,
42 const ErrorCallback& error_callback) override;
43 void StopPolling(const base::Closure& callback,
44 const ErrorCallback& error_callback) override;
46 private:
47 friend class device::NfcAdapterFactory;
48 friend class NfcChromeOSTest;
50 NfcAdapterChromeOS();
51 ~NfcAdapterChromeOS() override;
53 // NfcAdapterClient::Observer overrides.
54 void AdapterAdded(const dbus::ObjectPath& object_path) override;
55 void AdapterRemoved(const dbus::ObjectPath& object_path) override;
56 void AdapterPropertyChanged(const dbus::ObjectPath& object_path,
57 const std::string& property_name) override;
59 // NfcDeviceClient::Observer overrides.
60 void DeviceAdded(const dbus::ObjectPath& object_path) override;
61 void DeviceRemoved(const dbus::ObjectPath& object_path) override;
63 // NfcTagClient::Observer overrides.
64 void TagAdded(const dbus::ObjectPath& object_path) override;
65 void TagRemoved(const dbus::ObjectPath& object_path) override;
67 // Set the tracked adapter to the one in |object_path|, this object will
68 // subsequently operate on that adapter until it is removed.
69 void SetAdapter(const dbus::ObjectPath& object_path);
71 // Remove the currently tracked adapter. IsPresent() will return false after
72 // this is called.
73 void RemoveAdapter();
75 // Announce to observers a change in the adapter state.
76 void PoweredChanged(bool powered);
77 void PollingChanged(bool polling);
78 void PresentChanged(bool present);
80 // Called by dbus:: on completion of the powered property change.
81 void OnSetPowered(const base::Closure& callback,
82 const ErrorCallback& error_callback,
83 bool success);
85 // Called by dbus:: on completion of the D-Bus method call to start polling.
86 void OnStartPolling(const base::Closure& callback);
87 void OnStartPollingError(const ErrorCallback& error_callback,
88 const std::string& error_name,
89 const std::string& error_message);
91 // Called by dbus:: on completion of the D-Bus method call to stop polling.
92 void OnStopPolling(const base::Closure& callback);
93 void OnStopPollingError(const ErrorCallback& error_callback,
94 const std::string& error_name,
95 const std::string& error_message);
97 // Object path of the adapter that we are currently tracking.
98 dbus::ObjectPath object_path_;
100 // List of observers interested in event notifications from us.
101 base::ObserverList<device::NfcAdapter::Observer> observers_;
103 // Note: This should remain the last member so it'll be destroyed and
104 // invalidate its weak pointers before any other members are destroyed.
105 base::WeakPtrFactory<NfcAdapterChromeOS> weak_ptr_factory_;
107 DISALLOW_COPY_AND_ASSIGN(NfcAdapterChromeOS);
110 } // namespace chromeos
112 #endif // DEVICE_NFC_NFC_ADAPTER_CHROMEOS_H_