Stop printing LOG(ERROR) when NFC service is unknown
Add a new callback method to NfcPropertySet and let it own its WeakPtrFactory. Check the error name to reduce LOG(ERROR) noise. BUG=393311 TEST=Boot a Chromebook (link) and "grep neard /var/log/ui/ui.LATEST" to see nothing. Review URL: https://codereview.chromium.org/1778273002 Cr-Commit-Position: refs/heads/master@{#383025}
This commit is contained in:
@ -420,7 +420,7 @@ TEST_F(NfcClientTest, AdaptersAddedAndRemoved) {
|
||||
EXPECT_CALL(*this,
|
||||
ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
|
||||
EXPECT_CALL(*mock_adapter1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
|
||||
.Times(0);
|
||||
.Times(1);
|
||||
adapter_client_->StartPollLoop(
|
||||
dbus::ObjectPath(kTestAdapterPath1),
|
||||
nfc_adapter::kModeInitiator,
|
||||
@ -547,7 +547,7 @@ TEST_F(NfcClientTest, TagsAddedAndRemoved) {
|
||||
EXPECT_CALL(*this,
|
||||
ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
|
||||
EXPECT_CALL(*mock_tag1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
|
||||
.Times(0);
|
||||
.Times(1);
|
||||
tag_client_->Write(dbus::ObjectPath(kTestTagPath1), write_data,
|
||||
base::Bind(&NfcClientTest::SuccessCallback,
|
||||
base::Unretained(this)),
|
||||
@ -675,7 +675,7 @@ TEST_F(NfcClientTest, DevicesAddedAndRemoved) {
|
||||
EXPECT_CALL(*this,
|
||||
ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
|
||||
EXPECT_CALL(*mock_device1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
|
||||
.Times(0);
|
||||
.Times(1);
|
||||
device_client_->Push(dbus::ObjectPath(kTestDevicePath1), write_data,
|
||||
base::Bind(&NfcClientTest::SuccessCallback,
|
||||
base::Unretained(this)),
|
||||
|
@ -12,18 +12,19 @@ namespace chromeos {
|
||||
NfcPropertySet::NfcPropertySet(dbus::ObjectProxy* object_proxy,
|
||||
const std::string& interface,
|
||||
const PropertyChangedCallback& callback)
|
||||
: dbus::PropertySet(object_proxy, interface, callback) {
|
||||
}
|
||||
: dbus::PropertySet(object_proxy, interface, callback),
|
||||
weak_ptr_factory_(this) {}
|
||||
|
||||
NfcPropertySet::~NfcPropertySet() {
|
||||
}
|
||||
|
||||
void NfcPropertySet::ConnectSignals() {
|
||||
object_proxy()->ConnectToSignal(
|
||||
interface(),
|
||||
nfc_common::kPropertyChangedSignal,
|
||||
base::Bind(&dbus::PropertySet::ChangedReceived, GetWeakPtr()),
|
||||
base::Bind(&dbus::PropertySet::ChangedConnected, GetWeakPtr()));
|
||||
interface(), nfc_common::kPropertyChangedSignal,
|
||||
base::Bind(&dbus::PropertySet::ChangedReceived,
|
||||
weak_ptr_factory_.GetWeakPtr()),
|
||||
base::Bind(&dbus::PropertySet::ChangedConnected,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void NfcPropertySet::SetAllPropertiesReceivedCallback(
|
||||
@ -39,10 +40,11 @@ void NfcPropertySet::Get(dbus::PropertyBase* property,
|
||||
void NfcPropertySet::GetAll() {
|
||||
dbus::MethodCall method_call(
|
||||
interface(), nfc_common::kGetProperties);
|
||||
object_proxy()->CallMethod(&method_call,
|
||||
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
||||
base::Bind(&dbus::PropertySet::OnGetAll,
|
||||
GetWeakPtr()));
|
||||
object_proxy()->CallMethodWithErrorCallback(
|
||||
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
||||
base::Bind(&dbus::PropertySet::OnGetAll, weak_ptr_factory_.GetWeakPtr()),
|
||||
base::Bind(&NfcPropertySet::OnGetAllError,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void NfcPropertySet::OnGetAll(dbus::Response* response) {
|
||||
@ -67,12 +69,10 @@ void NfcPropertySet::Set(dbus::PropertyBase* property,
|
||||
dbus::MessageWriter writer(&method_call);
|
||||
writer.AppendString(property->name());
|
||||
property->AppendSetValueToWriter(&writer);
|
||||
object_proxy()->CallMethod(&method_call,
|
||||
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
||||
base::Bind(&dbus::PropertySet::OnSet,
|
||||
GetWeakPtr(),
|
||||
property,
|
||||
callback));
|
||||
object_proxy()->CallMethod(
|
||||
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
||||
base::Bind(&dbus::PropertySet::OnSet, weak_ptr_factory_.GetWeakPtr(),
|
||||
property, callback));
|
||||
}
|
||||
|
||||
void NfcPropertySet::ChangedReceived(dbus::Signal* signal) {
|
||||
@ -81,4 +81,21 @@ void NfcPropertySet::ChangedReceived(dbus::Signal* signal) {
|
||||
UpdatePropertyFromReader(&reader);
|
||||
}
|
||||
|
||||
void NfcPropertySet::OnGetAllError(dbus::ErrorResponse* response) {
|
||||
if (response) {
|
||||
dbus::MessageReader reader(response);
|
||||
std::string error_message;
|
||||
reader.PopString(&error_message);
|
||||
|
||||
if (response->GetErrorName() == DBUS_ERROR_SERVICE_UNKNOWN) {
|
||||
// Do not LOG(ERROR) if service is unknown. crbug.com/393311.
|
||||
VLOG(2) << "NfcPropertySet::GetAll failed because the service is unknown."
|
||||
<< " NFC not enabled on this device? : " << error_message;
|
||||
} else {
|
||||
LOG(ERROR) << "NfcPropertySet::GetAll failed: " << error_message;
|
||||
}
|
||||
}
|
||||
OnGetAll(nullptr);
|
||||
}
|
||||
|
||||
} // namespace chromeos
|
||||
|
@ -45,10 +45,14 @@ class NfcPropertySet : public dbus::PropertySet {
|
||||
const base::Closure& on_get_all_callback() { return on_get_all_callback_; }
|
||||
|
||||
private:
|
||||
void OnGetAllError(dbus::ErrorResponse* response);
|
||||
|
||||
// Optional callback used to notify clients when all properties were received
|
||||
// after a call to GetAll.
|
||||
base::Closure on_get_all_callback_;
|
||||
|
||||
base::WeakPtrFactory<NfcPropertySet> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NfcPropertySet);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user