media: Support simultaneous permission requests from multiple WebContents in Protecte...
[chromium-blink-merge.git] / device / nfc / nfc_peer_chromeos.h
blobdb9e58b301dc5885f2171d6e78018b3eee6ed9f5
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_PEER_CHROMEOS_H_
6 #define DEVICE_NFC_NFC_PEER_CHROMEOS_H_
8 #include <map>
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "chromeos/dbus/nfc_record_client.h"
13 #include "dbus/object_path.h"
14 #include "device/nfc/nfc_ndef_record.h"
15 #include "device/nfc/nfc_peer.h"
17 namespace chromeos {
19 // The NfcPeerChromeOS class implements NfcPeer for the Chrome OS platform.
20 class NfcPeerChromeOS : public device::NfcPeer,
21 public NfcRecordClient::Observer {
22 public:
23 // NfcPeer overrides.
24 void AddObserver(device::NfcPeer::Observer* observer) override;
25 void RemoveObserver(device::NfcPeer::Observer* observer) override;
26 std::string GetIdentifier() const override;
27 const device::NfcNdefMessage& GetNdefMessage() const override;
28 void PushNdef(const device::NfcNdefMessage& message,
29 const base::Closure& callback,
30 const ErrorCallback& error_callback) override;
31 void StartHandover(HandoverType handover_type,
32 const base::Closure& callback,
33 const ErrorCallback& error_callback) override;
35 private:
36 friend class NfcAdapterChromeOS;
38 // Mapping from D-Bus object paths to NfcNdefRecord objects.
39 typedef std::map<dbus::ObjectPath, device::NfcNdefRecord*> NdefRecordMap;
41 explicit NfcPeerChromeOS(const dbus::ObjectPath& object_path);
42 ~NfcPeerChromeOS() override;
44 // NfcRecordClient::Observer overrides.
45 void RecordAdded(const dbus::ObjectPath& object_path) override;
46 void RecordRemoved(const dbus::ObjectPath& object_path) override;
47 void RecordPropertiesReceived(const dbus::ObjectPath& object_path) override;
49 // Called by dbus:: on completion of the D-Bus method call to push an NDEF.
50 void OnPushNdef(const base::Closure& callback);
51 void OnPushNdefError(const ErrorCallback& error_callback,
52 const std::string& error_name,
53 const std::string& error_message);
55 // Creates a record object for the record with object path |object_path| and
56 // notifies the observers, if a record object did not already exist for it.
57 void AddRecord(const dbus::ObjectPath& object_path);
59 // Object path of the peer that we are currently tracking.
60 dbus::ObjectPath object_path_;
62 // A map containing the NDEF records that were received from the peer.
63 NdefRecordMap records_;
65 // Message instance that contains pointers to all created records.
66 device::NfcNdefMessage message_;
68 // List of observers interested in event notifications from us.
69 ObserverList<device::NfcPeer::Observer> observers_;
71 // Note: This should remain the last member so it'll be destroyed and
72 // invalidate its weak pointers before any other members are destroyed.
73 base::WeakPtrFactory<NfcPeerChromeOS> weak_ptr_factory_;
75 DISALLOW_COPY_AND_ASSIGN(NfcPeerChromeOS);
78 } // namespace chromeos
80 #endif // DEVICE_NFC_NFC_PEER_CHROMEOS_H_