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_tag_client.h" | 5 #include "chromeos/dbus/nfc_tag_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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // NfcTagClient override. | 65 // NfcTagClient override. |
66 virtual Properties* GetProperties( | 66 virtual Properties* GetProperties( |
67 const dbus::ObjectPath& object_path) OVERRIDE { | 67 const dbus::ObjectPath& object_path) OVERRIDE { |
68 return static_cast<Properties*>( | 68 return static_cast<Properties*>( |
69 adapters_to_object_maps_.FindObjectProperties(object_path)); | 69 adapters_to_object_maps_.FindObjectProperties(object_path)); |
70 } | 70 } |
71 | 71 |
72 // NfcTagClient override. | 72 // NfcTagClient override. |
73 virtual void Write( | 73 virtual void Write( |
74 const dbus::ObjectPath& object_path, | 74 const dbus::ObjectPath& object_path, |
75 const NfcRecordClient::Attributes& attributes, | 75 const base::DictionaryValue& attributes, |
76 const base::Closure& callback, | 76 const base::Closure& callback, |
77 const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE { | 77 const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE { |
78 dbus::ObjectProxy* object_proxy = | 78 dbus::ObjectProxy* object_proxy = |
79 adapters_to_object_maps_.FindObjectProxy(object_path); | 79 adapters_to_object_maps_.FindObjectProxy(object_path); |
80 if (!object_proxy) { | 80 if (!object_proxy) { |
81 std::string error_message = | 81 std::string error_message = |
82 base::StringPrintf("NFC tag with object path \"%s\" does not exist.", | 82 base::StringPrintf("NFC tag with object path \"%s\" does not exist.", |
83 object_path.value().c_str()); | 83 object_path.value().c_str()); |
84 LOG(ERROR) << error_message; | 84 LOG(ERROR) << error_message; |
85 error_callback.Run(nfc_client_helpers::kUnknownObjectError, | 85 error_callback.Run(nfc_client_helpers::kUnknownObjectError, |
86 error_message); | 86 error_message); |
87 return; | 87 return; |
88 } | 88 } |
89 | 89 |
90 // |attributes| should not be empty. | 90 // |attributes| should not be empty. |
91 if (attributes.empty()) { | 91 if (attributes.empty()) { |
92 std::string error_message = | 92 std::string error_message = |
93 "Cannot write data to tag with empty arguments."; | 93 "Cannot write data to tag with empty arguments."; |
94 LOG(ERROR) << error_message; | 94 LOG(ERROR) << error_message; |
95 error_callback.Run(nfc_error::kInvalidArguments, error_message); | 95 error_callback.Run(nfc_error::kInvalidArguments, error_message); |
96 return; | 96 return; |
97 } | 97 } |
98 | 98 |
99 // Create the arguments. | 99 // Create the arguments. |
100 dbus::MethodCall method_call(nfc_tag::kNfcTagInterface, nfc_tag::kWrite); | 100 dbus::MethodCall method_call(nfc_tag::kNfcTagInterface, nfc_tag::kWrite); |
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 238 } |
238 | 239 |
239 NfcTagClient::~NfcTagClient() { | 240 NfcTagClient::~NfcTagClient() { |
240 } | 241 } |
241 | 242 |
242 NfcTagClient* NfcTagClient::Create(NfcAdapterClient* adapter_client) { | 243 NfcTagClient* NfcTagClient::Create(NfcAdapterClient* adapter_client) { |
243 return new NfcTagClientImpl(adapter_client); | 244 return new NfcTagClientImpl(adapter_client); |
244 } | 245 } |
245 | 246 |
246 } // namespace chromeos | 247 } // namespace chromeos |
OLD | NEW |