diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 19:29:57 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 19:29:57 +0000 |
commit | 73c7151e9e4fd385a9ddffaf9248ebd1ff208c7a (patch) | |
tree | 32bda26946802b5417db258dbdc8b2a67b3cc031 /dbus | |
parent | 18cbf3c914ac7b64bedcb9dc7377144f5bf62637 (diff) | |
download | chromium_src-73c7151e9e4fd385a9ddffaf9248ebd1ff208c7a.zip chromium_src-73c7151e9e4fd385a9ddffaf9248ebd1ff208c7a.tar.gz chromium_src-73c7151e9e4fd385a9ddffaf9248ebd1ff208c7a.tar.bz2 |
Expose functionality to tests.
Second try of https://chromiumcodereview.appspot.com/10815083
BUG=None
TEST=None
TBR=satorux
Review URL: https://chromiumcodereview.appspot.com/10833011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148382 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/message.cc | 24 | ||||
-rw-r--r-- | dbus/message.h | 10 | ||||
-rw-r--r-- | dbus/message_unittest.cc | 2 |
3 files changed, 22 insertions, 14 deletions
diff --git a/dbus/message.cc b/dbus/message.cc index fd7c077..af3c1c5 100644 --- a/dbus/message.cc +++ b/dbus/message.cc @@ -18,9 +18,9 @@ namespace { // Appends the header name and the value to |output|, if the value is // not empty. -static void AppendStringHeader(const std::string& header_name, - const std::string& header_value, - std::string* output) { +void AppendStringHeader(const std::string& header_name, + const std::string& header_value, + std::string* output) { if (!header_value.empty()) { *output += header_name + ": " + header_value + "\n"; } @@ -28,9 +28,9 @@ static void AppendStringHeader(const std::string& header_name, // Appends the header name and the value to |output|, if the value is // nonzero. -static void AppendUint32Header(const std::string& header_name, - uint32 header_value, - std::string* output) { +void AppendUint32Header(const std::string& header_name, + uint32 header_value, + std::string* output) { if (header_value != 0) { *output += (header_name + ": " + base::StringPrintf("%u", header_value) + "\n"); @@ -41,6 +41,12 @@ static void AppendUint32Header(const std::string& header_name, namespace dbus { +bool IsDBusTypeUnixFdSupported() { + int major = 0, minor = 0, micro = 0; + dbus_get_version(&major, &minor, µ); + return major >= 1 && minor >= 4; +} + Message::Message() : raw_message_(NULL) { } @@ -211,7 +217,7 @@ std::string Message::ToStringInternal(const std::string& indent, break; } case UNIX_FD: { - CHECK(kDBusTypeUnixFdIsSupported); + CHECK(IsDBusTypeUnixFdSupported()); FileDescriptor file_descriptor; if (!reader->PopFileDescriptor(&file_descriptor)) @@ -690,7 +696,7 @@ void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) { } void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) { - CHECK(kDBusTypeUnixFdIsSupported); + CHECK(IsDBusTypeUnixFdSupported()); if (!value.is_valid()) { // NB: sending a directory potentially enables sandbox escape @@ -960,7 +966,7 @@ bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) { } bool MessageReader::PopFileDescriptor(FileDescriptor* value) { - CHECK(kDBusTypeUnixFdIsSupported); + CHECK(IsDBusTypeUnixFdSupported()); int fd = -1; const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); diff --git a/dbus/message.h b/dbus/message.h index 4d32cb9..85d045c 100644 --- a/dbus/message.h +++ b/dbus/message.h @@ -28,13 +28,15 @@ class MessageWriter; class MessageReader; // DBUS_TYPE_UNIX_FD was added in D-Bus version 1.4 -#if defined(DBUS_TYPE_UNIX_FD) -const bool kDBusTypeUnixFdIsSupported = true; -#else -const bool kDBusTypeUnixFdIsSupported = false; +#if !defined(DBUS_TYPE_UNIX_FD) #define DBUS_TYPE_UNIX_FD ((int) 'h') #endif +// Returns true if Unix FD passing is supported in libdbus. +// The check is done runtime rather than compile time as the libdbus +// version used at runtime may be different from the one used at compile time. +bool IsDBusTypeUnixFdSupported(); + // Message is the base class of D-Bus message types. Client code must use // sub classes such as MethodCall and Response instead. // diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc index 10835a29..c61f170 100644 --- a/dbus/message_unittest.cc +++ b/dbus/message_unittest.cc @@ -97,7 +97,7 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { // Check all basic types can be properly written and read. TEST(MessageTest, AppendAndPopFileDescriptor) { - if (!dbus::kDBusTypeUnixFdIsSupported) { + if (!dbus::IsDBusTypeUnixFdSupported()) { LOG(WARNING) << "FD passing is not supported"; return; } |