Roll src/third_party/WebKit b944946:201fd41 (svn 192400:192407)
[chromium-blink-merge.git] / device / nfc / nfc_peer.h
bloba38192f166acdaec0dbcc9985c3b13514f68665c
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_H_
6 #define DEVICE_NFC_NFC_PEER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "device/nfc/nfc_ndef_record.h"
15 namespace device {
17 // NfcPeer represents a remote NFC adapter that is available for P2P
18 // communication with the local adapter. Instances of NfcPeer allow two
19 // kinds of P2P interaction that is supported by NFC:
21 // - NDEF. Specifically, reading NDEF records found on the peer device and
22 // pushing NDEF records to it (e.g. via SNEP or Android Beam), in the form
23 // of an NDEF message as specified by the NFC forum.
24 // - Initiating a handover. On platforms that support it, handover can be
25 // used to quickly bootstrap a Bluetooth or WiFi based connection between
26 // the two devices over NFC.
27 class NfcPeer {
28 public:
29 // NFC handover types.
30 enum HandoverType {
31 kHandoverTypeBluetooth,
32 kHandoverTypeWiFi
35 // Interface for observing changes from NFC peer devices.
36 class Observer {
37 public:
38 virtual ~Observer() {}
40 // This method will be called when an NDEF record |record| from the peer
41 // device |peer| is received. Users can use this method to be notified of
42 // new records on the device and when the initial set of records are
43 // received from it, if any. All records received from |peer| can be
44 // accessed by calling |peer->GetNdefMessage()|.
45 virtual void RecordReceived(NfcPeer* peer, const NfcNdefRecord* record) {}
48 // The ErrorCallback is used by methods to asynchronously report errors.
49 typedef base::Closure ErrorCallback;
51 virtual ~NfcPeer();
53 // Adds and removes observers for events on this NFC peer. If monitoring
54 // multiple peers, check the |peer| parameter of observer methods to
55 // determine which peer is issuing the event.
56 virtual void AddObserver(Observer* observer) = 0;
57 virtual void RemoveObserver(Observer* observer) = 0;
59 // Returns the unique identifier assigned to this peer.
60 virtual std::string GetIdentifier() const = 0;
62 // Returns all NDEF records that were received from the peer device in the
63 // form of a NDEF message. If the returned NDEF message contains no records,
64 // this only means that no records have yet been received from the device.
65 // Users should use this method in conjunction with the Observer methods
66 // to be notified when the records are ready.
67 virtual const NfcNdefMessage& GetNdefMessage() const = 0;
69 // Sends the NDEF records contained in |message| to the peer device. On
70 // success, |callback| will be invoked. On failure, |error_callback| will be
71 // invoked.
72 virtual void PushNdef(const NfcNdefMessage& message,
73 const base::Closure& callback,
74 const ErrorCallback& error_callback) = 0;
76 // Initiates WiFi or Bluetooth pairing with the NFC peer device based on
77 // |handover_type|. On success, |callback| will be invoked. On failure,
78 // |error_callback| will be invoked.
79 virtual void StartHandover(HandoverType handover_type,
80 const base::Closure& callback,
81 const ErrorCallback& error_callback) = 0;
83 protected:
84 NfcPeer();
86 private:
87 DISALLOW_COPY_AND_ASSIGN(NfcPeer);
90 } // namespace device
92 #endif // DEVICE_NFC_NFC_PEER_H_