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

Unified Diff: dbus/object_proxy.cc

Issue 9373039: Allow dbus clients to silence logging when a service is unavailable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use pair, factor out error logging logic Created 8 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/object_proxy.h ('k') | dbus/scoped_dbus_error.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/object_proxy.cc
diff --git a/dbus/object_proxy.cc b/dbus/object_proxy.cc
index 5da5901f888c0b5dbc73f0d81b4670d15662fec8..757da99e3606c3ba4ebf8e4471099283481de45c 100644
--- a/dbus/object_proxy.cc
+++ b/dbus/object_proxy.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
+#include "base/string_piece.h"
#include "base/stringprintf.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
@@ -17,6 +18,8 @@
namespace {
+const char kErrorServiceUnknown[] = "org.freedesktop.DBus.Error.ServiceUnknown";
+
// Used for success ratio histograms. 1 for success, 0 for failure.
const int kSuccessRatioHistogramMaxValue = 2;
@@ -39,11 +42,14 @@ namespace dbus {
ObjectProxy::ObjectProxy(Bus* bus,
const std::string& service_name,
- const std::string& object_path)
+ const std::string& object_path,
+ int options)
: bus_(bus),
service_name_(service_name),
object_path_(object_path),
- filter_added_(false) {
+ filter_added_(false),
+ ignore_service_unknown_errors_(
+ options & IGNORE_SERVICE_UNKNOWN_ERRORS) {
}
ObjectProxy::~ObjectProxy() {
@@ -75,8 +81,8 @@ Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call,
kSuccessRatioHistogramMaxValue);
if (!response_message) {
- LOG(ERROR) << "Failed to call method: "
- << (error.is_set() ? error.message() : "");
+ LogMethodCallFailure(error.is_set() ? error.name() : "unknown error type",
+ error.is_set() ? error.message() : "");
return NULL;
}
// Record time spent for the method call. Don't include failures.
@@ -236,8 +242,7 @@ void ObjectProxy::RunResponseCallback(ResponseCallback response_callback,
dbus::MessageReader reader(error_response.get());
std::string error_message;
reader.PopString(&error_message);
- LOG(ERROR) << "Failed to call method: " << error_response->GetErrorName()
- << ": " << error_message;
+ LogMethodCallFailure(error_response->GetErrorName(), error_message);
// We don't give the error message to the callback.
response_callback.Run(NULL);
} else {
@@ -416,4 +421,13 @@ DBusHandlerResult ObjectProxy::HandleMessageThunk(
return self->HandleMessage(connection, raw_message);
}
+void ObjectProxy::LogMethodCallFailure(
+ const base::StringPiece& error_name,
+ const base::StringPiece& error_message) const {
+ if (ignore_service_unknown_errors_ && error_name == kErrorServiceUnknown)
+ return;
satorux1 2012/02/10 20:00:11 Nice. it's now easier to understand and cleaner!
+ LOG(ERROR) << "Failed to call method: " << error_name
+ << ": " << error_message;
+}
+
} // namespace dbus
« no previous file with comments | « dbus/object_proxy.h ('k') | dbus/scoped_dbus_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698