Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: chromeos/dbus/nfc_tag_client.cc

Issue 99903003: nfc: Various fixes to the NFC D-Bus client in chromeos/dbus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // NfcTagClient override. 66 // NfcTagClient override.
67 virtual Properties* GetProperties( 67 virtual Properties* GetProperties(
68 const dbus::ObjectPath& object_path) OVERRIDE { 68 const dbus::ObjectPath& object_path) OVERRIDE {
69 return static_cast<Properties*>( 69 return static_cast<Properties*>(
70 adapters_to_object_maps_.FindObjectProperties(object_path)); 70 adapters_to_object_maps_.FindObjectProperties(object_path));
71 } 71 }
72 72
73 // NfcTagClient override. 73 // NfcTagClient override.
74 virtual void Write( 74 virtual void Write(
75 const dbus::ObjectPath& object_path, 75 const dbus::ObjectPath& object_path,
76 const NfcRecordClient::Attributes& attributes, 76 const base::DictionaryValue& attributes,
77 const base::Closure& callback, 77 const base::Closure& callback,
78 const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE { 78 const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE {
79 dbus::ObjectProxy* object_proxy = 79 dbus::ObjectProxy* object_proxy =
80 adapters_to_object_maps_.FindObjectProxy(object_path); 80 adapters_to_object_maps_.FindObjectProxy(object_path);
81 if (!object_proxy) { 81 if (!object_proxy) {
82 std::string error_message = 82 std::string error_message =
83 base::StringPrintf("NFC tag with object path \"%s\" does not exist.", 83 base::StringPrintf("NFC tag with object path \"%s\" does not exist.",
84 object_path.value().c_str()); 84 object_path.value().c_str());
85 LOG(ERROR) << error_message; 85 LOG(ERROR) << error_message;
86 error_callback.Run(nfc_client_helpers::kUnknownObjectError, 86 error_callback.Run(nfc_client_helpers::kUnknownObjectError,
87 error_message); 87 error_message);
88 return; 88 return;
89 } 89 }
90 90
91 // |attributes| should not be empty. 91 // |attributes| should not be empty.
92 if (attributes.empty()) { 92 if (attributes.empty()) {
93 std::string error_message = 93 std::string error_message =
94 "Cannot write data to tag with empty arguments."; 94 "Cannot write data to tag with empty arguments.";
95 LOG(ERROR) << error_message; 95 LOG(ERROR) << error_message;
96 error_callback.Run(nfc_error::kInvalidArguments, error_message); 96 error_callback.Run(nfc_error::kInvalidArguments, error_message);
97 return; 97 return;
98 } 98 }
99 99
100 // Create the arguments. 100 // Create the arguments.
101 dbus::MethodCall method_call(nfc_tag::kNfcTagInterface, nfc_tag::kWrite); 101 dbus::MethodCall method_call(nfc_tag::kNfcTagInterface, nfc_tag::kWrite);
102 dbus::MessageWriter writer(&method_call); 102 dbus::MessageWriter writer(&method_call);
103 dbus::MessageWriter array_writer(NULL); 103 dbus::MessageWriter array_writer(NULL);
104 dbus::MessageWriter dict_entry_writer(NULL); 104 dbus::MessageWriter dict_entry_writer(NULL);
105 writer.OpenArray("{sv}", &array_writer); 105 writer.OpenArray("{sv}", &array_writer);
106 for (NfcRecordClient::Attributes::const_iterator iter = attributes.begin(); 106 for (DictionaryValue::Iterator iter(attributes);
107 iter != attributes.end(); ++iter) { 107 !iter.IsAtEnd(); iter.Advance()) {
108 array_writer.OpenDictEntry(&dict_entry_writer); 108 array_writer.OpenDictEntry(&dict_entry_writer);
109 dict_entry_writer.AppendString(iter->first); 109 dict_entry_writer.AppendString(iter.key());
110 dict_entry_writer.AppendVariantOfString(iter->second); 110 nfc_client_helpers::AppendValueDataAsVariant(&dict_entry_writer,
111 iter.value());
111 array_writer.CloseContainer(&dict_entry_writer); 112 array_writer.CloseContainer(&dict_entry_writer);
112 } 113 }
113 writer.CloseContainer(&array_writer); 114 writer.CloseContainer(&array_writer);
114 115
115 object_proxy->CallMethodWithErrorCallback( 116 object_proxy->CallMethodWithErrorCallback(
116 &method_call, 117 &method_call,
117 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 118 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
118 base::Bind(&nfc_client_helpers::OnSuccess, callback), 119 base::Bind(&nfc_client_helpers::OnSuccess, callback),
119 base::Bind(&nfc_client_helpers::OnError, error_callback)); 120 base::Bind(&nfc_client_helpers::OnError, error_callback));
120 } 121 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 243
243 NfcTagClient* NfcTagClient::Create(DBusClientImplementationType type, 244 NfcTagClient* NfcTagClient::Create(DBusClientImplementationType type,
244 NfcAdapterClient* adapter_client) { 245 NfcAdapterClient* adapter_client) {
245 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 246 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
246 return new NfcTagClientImpl(adapter_client); 247 return new NfcTagClientImpl(adapter_client);
247 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 248 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
248 return new FakeNfcTagClient(); 249 return new FakeNfcTagClient();
249 } 250 }
250 251
251 } // namespace chromeos 252 } // namespace chromeos
OLDNEW
« chromeos/dbus/dbus_thread_manager.cc ('K') | « chromeos/dbus/nfc_tag_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698