OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/nfc_device_client.h" | 5 #include "chromeos/dbus/nfc_device_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // NfcDeviceClient override. | 63 // NfcDeviceClient override. |
64 virtual Properties* GetProperties( | 64 virtual Properties* GetProperties( |
65 const dbus::ObjectPath& object_path) OVERRIDE { | 65 const dbus::ObjectPath& object_path) OVERRIDE { |
66 return static_cast<Properties*>( | 66 return static_cast<Properties*>( |
67 adapters_to_object_maps_.FindObjectProperties(object_path)); | 67 adapters_to_object_maps_.FindObjectProperties(object_path)); |
68 } | 68 } |
69 | 69 |
70 // NfcDeviceClient override. | 70 // NfcDeviceClient override. |
71 virtual void Push( | 71 virtual void Push( |
72 const dbus::ObjectPath& object_path, | 72 const dbus::ObjectPath& object_path, |
73 const NfcRecordClient::Attributes& attributes, | 73 const base::DictionaryValue& attributes, |
74 const base::Closure& callback, | 74 const base::Closure& callback, |
75 const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE { | 75 const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE { |
76 dbus::ObjectProxy* object_proxy = | 76 dbus::ObjectProxy* object_proxy = |
77 adapters_to_object_maps_.FindObjectProxy(object_path); | 77 adapters_to_object_maps_.FindObjectProxy(object_path); |
78 if (!object_proxy) { | 78 if (!object_proxy) { |
79 std::string error_message = | 79 std::string error_message = |
80 base::StringPrintf( | 80 base::StringPrintf( |
81 "NFC device with object path \"%s\" does not exist.", | 81 "NFC device with object path \"%s\" does not exist.", |
82 object_path.value().c_str()); | 82 object_path.value().c_str()); |
83 LOG(ERROR) << error_message; | 83 LOG(ERROR) << error_message; |
(...skipping 11 matching lines...) Expand all Loading... |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 // Create the arguments. | 98 // Create the arguments. |
99 dbus::MethodCall method_call(nfc_device::kNfcDeviceInterface, | 99 dbus::MethodCall method_call(nfc_device::kNfcDeviceInterface, |
100 nfc_device::kPush); | 100 nfc_device::kPush); |
101 dbus::MessageWriter writer(&method_call); | 101 dbus::MessageWriter writer(&method_call); |
102 dbus::MessageWriter array_writer(NULL); | 102 dbus::MessageWriter array_writer(NULL); |
103 dbus::MessageWriter dict_entry_writer(NULL); | 103 dbus::MessageWriter dict_entry_writer(NULL); |
104 writer.OpenArray("{sv}", &array_writer); | 104 writer.OpenArray("{sv}", &array_writer); |
105 for (NfcRecordClient::Attributes::const_iterator iter = attributes.begin(); | 105 for (DictionaryValue::Iterator iter(attributes); |
106 iter != attributes.end(); ++iter) { | 106 !iter.IsAtEnd(); iter.Advance()) { |
107 array_writer.OpenDictEntry(&dict_entry_writer); | 107 array_writer.OpenDictEntry(&dict_entry_writer); |
108 dict_entry_writer.AppendString(iter->first); | 108 dict_entry_writer.AppendString(iter.key()); |
109 dict_entry_writer.AppendVariantOfString(iter->second); | 109 nfc_client_helpers::AppendValueDataAsVariant(&dict_entry_writer, |
| 110 iter.value()); |
110 array_writer.CloseContainer(&dict_entry_writer); | 111 array_writer.CloseContainer(&dict_entry_writer); |
111 } | 112 } |
112 writer.CloseContainer(&array_writer); | 113 writer.CloseContainer(&array_writer); |
113 | 114 |
114 object_proxy->CallMethodWithErrorCallback( | 115 object_proxy->CallMethodWithErrorCallback( |
115 &method_call, | 116 &method_call, |
116 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 117 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
117 base::Bind(&nfc_client_helpers::OnSuccess, callback), | 118 base::Bind(&nfc_client_helpers::OnSuccess, callback), |
118 base::Bind(&nfc_client_helpers::OnError, error_callback)); | 119 base::Bind(&nfc_client_helpers::OnError, error_callback)); |
119 } | 120 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 236 |
236 NfcDeviceClient* NfcDeviceClient::Create(DBusClientImplementationType type, | 237 NfcDeviceClient* NfcDeviceClient::Create(DBusClientImplementationType type, |
237 NfcAdapterClient* adapter_client) { | 238 NfcAdapterClient* adapter_client) { |
238 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 239 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
239 return new NfcDeviceClientImpl(adapter_client); | 240 return new NfcDeviceClientImpl(adapter_client); |
240 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 241 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
241 return new FakeNfcDeviceClient(); | 242 return new FakeNfcDeviceClient(); |
242 } | 243 } |
243 | 244 |
244 } // namespace chromeos | 245 } // namespace chromeos |
OLD | NEW |