diff options
author | hashimoto <hashimoto@chromium.org> | 2016-03-23 20:54:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-24 03:55:34 +0000 |
commit | 0ec21794e4e82b2b88f7a6b7fce48c0e47a442ef (patch) | |
tree | c36c7672f35ded53f91f7524572abf495c6e20d9 /chromeos | |
parent | 71bb0096a02097ca761be2404e0645315674a77b (diff) | |
download | chromium_src-0ec21794e4e82b2b88f7a6b7fce48c0e47a442ef.zip chromium_src-0ec21794e4e82b2b88f7a6b7fce48c0e47a442ef.tar.gz chromium_src-0ec21794e4e82b2b88f7a6b7fce48c0e47a442ef.tar.bz2 |
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}
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/nfc_client_unittest.cc | 6 | ||||
-rw-r--r-- | chromeos/dbus/nfc_property_set.cc | 49 | ||||
-rw-r--r-- | chromeos/dbus/nfc_property_set.h | 4 |
3 files changed, 40 insertions, 19 deletions
diff --git a/chromeos/dbus/nfc_client_unittest.cc b/chromeos/dbus/nfc_client_unittest.cc index 8b431e9..a91a766 100644 --- a/chromeos/dbus/nfc_client_unittest.cc +++ b/chromeos/dbus/nfc_client_unittest.cc @@ -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)), diff --git a/chromeos/dbus/nfc_property_set.cc b/chromeos/dbus/nfc_property_set.cc index f6ab8c0..5b0ead8 100644 --- a/chromeos/dbus/nfc_property_set.cc +++ b/chromeos/dbus/nfc_property_set.cc @@ -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 diff --git a/chromeos/dbus/nfc_property_set.h b/chromeos/dbus/nfc_property_set.h index ee18528..4b5016a 100644 --- a/chromeos/dbus/nfc_property_set.h +++ b/chromeos/dbus/nfc_property_set.h @@ -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); }; |