Pepper: Fix crash on allocation failure.
[chromium-blink-merge.git] / chromeos / dbus / nfc_device_client.h
blob47ab9b74d658b88510b09a9c6c430a9ed84f84a8
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 CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/values.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_client.h"
15 #include "chromeos/dbus/nfc_client_helpers.h"
16 #include "chromeos/dbus/nfc_property_set.h"
17 #include "chromeos/dbus/nfc_record_client.h"
18 #include "dbus/object_path.h"
19 #include "dbus/object_proxy.h"
20 #include "dbus/property.h"
22 namespace chromeos {
24 class NfcAdapterClient;
26 // NfcDeviceClient is used to communicate with objects representing remote NFC
27 // devices that can be communicated with.
28 class CHROMEOS_EXPORT NfcDeviceClient : public DBusClient {
29 public:
30 // Structure of properties associated with an NFC device.
31 struct Properties : public NfcPropertySet {
32 // List of object paths for NDEF records associated with the NFC device.
33 // Read-only.
34 dbus::Property<std::vector<dbus::ObjectPath> > records;
36 Properties(dbus::ObjectProxy* object_proxy,
37 const PropertyChangedCallback& callback);
38 virtual ~Properties();
41 // Interface for observing changes from a remote NFC device.
42 class Observer {
43 public:
44 virtual ~Observer() {}
46 // Called when a remote NFC device with the object |object_path| is added
47 // to the set of known devices.
48 virtual void DeviceAdded(const dbus::ObjectPath& object_path) {}
50 // Called when a remote NFC device with the object path |object_path| is
51 // removed from the set of known devices.
52 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) {}
54 // Called when the device property with the name |property_name| on device
55 // with object path |object_path| has acquired a new value.
56 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
57 const std::string& property_name) {}
60 virtual ~NfcDeviceClient();
62 // Adds and removes observers for events on all remote NFC devices. Check the
63 // |object_path| parameter of observer methods to determine which device is
64 // issuing the event.
65 virtual void AddObserver(Observer* observer) = 0;
66 virtual void RemoveObserver(Observer* observer) = 0;
68 // Returns the list of device object paths associated with the given adapter
69 // identified by the D-Bus object path |adapter_path|.
70 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter(
71 const dbus::ObjectPath& adapter_path) = 0;
73 // Obtain the properties for the NFC device with object path |object_path|;
74 // any values should be copied if needed.
75 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
77 // Creates an NDEF record for the NFC device with object path |object_path|
78 // using the parameters in |attributes|. |attributes| is a dictionary,
79 // containing the NFC Record properties which will be assigned to the
80 // resulting record object and pushed to the device. The properties are
81 // defined by the NFC Record interface (see namespace "nfc_record" in
82 // third_party/cros_system_api/dbus/service_constants.h and
83 // NfcRecordClient::Properties). |attributes| should at least contain a
84 // "Type" plus any other properties associated with that type. For example:
86 // {
87 // "Type": "Text",
88 // "Encoding": "UTF-8",
89 // "Language": "en",
90 // "Representation": "Chrome OS rulez!"
91 // },
92 // {
93 // "Type": "URI",
94 // "URI": "http://www.chromium.org"
95 // },
96 // etc.
97 virtual void Push(
98 const dbus::ObjectPath& object_path,
99 const base::DictionaryValue& attributes,
100 const base::Closure& callback,
101 const nfc_client_helpers::ErrorCallback& error_callback) = 0;
103 // Creates the instance.
104 static NfcDeviceClient* Create(NfcAdapterClient* adapter_client);
106 protected:
107 friend class NfcClientTest;
109 NfcDeviceClient();
111 private:
112 DISALLOW_COPY_AND_ASSIGN(NfcDeviceClient);
115 } // namespace chromeos
117 #endif // CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_