Add a comment to the Browser Blacklist List
[chromium-blink-merge.git] / chromeos / dbus / nfc_property_set.cc
blobf6ab8c0d996c7082032e20af536b0410831e38a2
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 #include "chromeos/dbus/nfc_property_set.h"
7 #include "base/bind.h"
8 #include "third_party/cros_system_api/dbus/service_constants.h"
10 namespace chromeos {
12 NfcPropertySet::NfcPropertySet(dbus::ObjectProxy* object_proxy,
13 const std::string& interface,
14 const PropertyChangedCallback& callback)
15 : dbus::PropertySet(object_proxy, interface, callback) {
18 NfcPropertySet::~NfcPropertySet() {
21 void NfcPropertySet::ConnectSignals() {
22 object_proxy()->ConnectToSignal(
23 interface(),
24 nfc_common::kPropertyChangedSignal,
25 base::Bind(&dbus::PropertySet::ChangedReceived, GetWeakPtr()),
26 base::Bind(&dbus::PropertySet::ChangedConnected, GetWeakPtr()));
29 void NfcPropertySet::SetAllPropertiesReceivedCallback(
30 const base::Closure& callback) {
31 on_get_all_callback_ = callback;
34 void NfcPropertySet::Get(dbus::PropertyBase* property,
35 GetCallback callback) {
36 NOTREACHED() << "neard does not implement Get for properties.";
39 void NfcPropertySet::GetAll() {
40 dbus::MethodCall method_call(
41 interface(), nfc_common::kGetProperties);
42 object_proxy()->CallMethod(&method_call,
43 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
44 base::Bind(&dbus::PropertySet::OnGetAll,
45 GetWeakPtr()));
48 void NfcPropertySet::OnGetAll(dbus::Response* response) {
49 // First invoke the superclass implementation. If the call to GetAll was
50 // successful, this will invoke the PropertyChangedCallback passed to the
51 // constructor for each individual property received through the call and
52 // make sure that the values of the properties have been cached. This way,
53 // all received properties will be available when |on_get_all_callback_| is
54 // run.
55 dbus::PropertySet::OnGetAll(response);
56 if (response) {
57 VLOG(2) << "NfcPropertySet::GetAll returned successfully.";
58 if (!on_get_all_callback_.is_null())
59 on_get_all_callback_.Run();
63 void NfcPropertySet::Set(dbus::PropertyBase* property,
64 SetCallback callback) {
65 dbus::MethodCall method_call(
66 interface(), nfc_common::kSetProperty);
67 dbus::MessageWriter writer(&method_call);
68 writer.AppendString(property->name());
69 property->AppendSetValueToWriter(&writer);
70 object_proxy()->CallMethod(&method_call,
71 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
72 base::Bind(&dbus::PropertySet::OnSet,
73 GetWeakPtr(),
74 property,
75 callback));
78 void NfcPropertySet::ChangedReceived(dbus::Signal* signal) {
79 DCHECK(signal);
80 dbus::MessageReader reader(signal);
81 UpdatePropertyFromReader(&reader);
84 } // namespace chromeos