diff options
author | Jay Civelli <jcivelli@google.com> | 2017-03-27 09:36:42 -0700 |
---|---|---|
committer | Hidehiko Abe <hidehiko@google.com> | 2017-12-12 03:12:44 +0900 |
commit | 324b9515118eca1ac9b579af6dd4d9ffc33a023c (patch) | |
tree | 0509206f97501283e49b3a19abee98008a3cd72f /brillo/dbus | |
parent | 1015853ceea363bb0c5979748fa53985657323af (diff) | |
download | platform_external_libbrillo-324b9515118eca1ac9b579af6dd4d9ffc33a023c.tar.gz platform_external_libbrillo-324b9515118eca1ac9b579af6dd4d9ffc33a023c.tar.bz2 platform_external_libbrillo-324b9515118eca1ac9b579af6dd4d9ffc33a023c.zip |
libbrillo: Update libchrome APIS to r456626.
The new libchrome has been ported from Chromium and some APIs have
changed. Make necessary changes at call sites.
Notable changes from libchrome:
- FOR_EACH_OBSERVER macro removed (replaced by use of C++ 11 range-base
for loop)
- base::Values no more FundamentalValue
- stl_util moved to base namespace
- some scoped pointers removed in crypto/ in favor of BoringSSL
UniquePtr.
- path() accessor renamed to GetPath() in ScopedTempDir (and other
classes)
BUG: 37434548
Test: All tests in libbrillo_test pass on aosp_arm-eng build
Change-Id: I2379bb5bcea54b8343936aecd4f8a4da06f99f5a
Diffstat (limited to 'brillo/dbus')
-rw-r--r-- | brillo/dbus/data_serialization.cc | 10 | ||||
-rw-r--r-- | brillo/dbus/data_serialization.h | 15 | ||||
-rw-r--r-- | brillo/dbus/data_serialization_unittest.cc | 13 | ||||
-rw-r--r-- | brillo/dbus/dbus_method_invoker.h | 26 | ||||
-rw-r--r-- | brillo/dbus/dbus_method_invoker_unittest.cc | 13 |
5 files changed, 28 insertions, 49 deletions
diff --git a/brillo/dbus/data_serialization.cc b/brillo/dbus/data_serialization.cc index 86d1c63..746b241 100644 --- a/brillo/dbus/data_serialization.cc +++ b/brillo/dbus/data_serialization.cc @@ -62,8 +62,8 @@ void AppendValueToWriter(dbus::MessageWriter* writer, } void AppendValueToWriter(dbus::MessageWriter* writer, - const dbus::FileDescriptor& value) { - writer->AppendFileDescriptor(value); + const base::ScopedFD& value) { + writer->AppendFileDescriptor(value.get()); } void AppendValueToWriter(dbus::MessageWriter* writer, @@ -140,12 +140,10 @@ bool PopValueFromReader(dbus::MessageReader* reader, dbus::ObjectPath* value) { } bool PopValueFromReader(dbus::MessageReader* reader, - dbus::FileDescriptor* value) { + base::ScopedFD* value) { dbus::MessageReader variant_reader(nullptr); bool ok = details::DescendIntoVariantIfPresent(&reader, &variant_reader) && reader->PopFileDescriptor(value); - if (ok) - value->CheckValidity(); return ok; } @@ -309,7 +307,7 @@ bool PopValueFromReader(dbus::MessageReader* reader, brillo::Any* value) { return false; case dbus::Message::UNIX_FD: CHECK(dbus::IsDBusTypeUnixFdSupported()) << "UNIX_FD data not supported"; - // dbus::FileDescriptor is not a copyable type. Cannot be returned via + // base::ScopedFD is not a copyable type. Cannot be returned via // brillo::Any. Fail here. LOG(ERROR) << "Cannot return FileDescriptor via Any"; return false; diff --git a/brillo/dbus/data_serialization.h b/brillo/dbus/data_serialization.h index 46da165..6919b19 100644 --- a/brillo/dbus/data_serialization.h +++ b/brillo/dbus/data_serialization.h @@ -36,7 +36,7 @@ // | (UVW...) | std::tuple<U,V,W,...> // DICT | a{KV} | std::map<K,V> // VARIANT | v | brillo::Any -// UNIX_FD | h | dbus::FileDescriptor +// UNIX_FD | h | base::ScopedFD // SIGNATURE | g | (unsupported) // // Additional overloads/specialization can be provided for custom types. @@ -58,6 +58,7 @@ #include <vector> #include <base/logging.h> +#include <base/files/scoped_file.h> #include <brillo/brillo_export.h> #include <brillo/type_name_undecorate.h> #include <dbus/message.h> @@ -411,23 +412,23 @@ struct DBusType<dbus::ObjectPath> { } }; -// dbus::FileDescriptor ------------------------------------------------------- +// base::ScopedFD ------------------------------------------------------------- BRILLO_EXPORT void AppendValueToWriter(dbus::MessageWriter* writer, - const dbus::FileDescriptor& value); + const base::ScopedFD& value); BRILLO_EXPORT bool PopValueFromReader(dbus::MessageReader* reader, - dbus::FileDescriptor* value); + base::ScopedFD* value); template<> -struct DBusType<dbus::FileDescriptor> { +struct DBusType<base::ScopedFD> { inline static std::string GetSignature() { return DBUS_TYPE_UNIX_FD_AS_STRING; } inline static void Write(dbus::MessageWriter* writer, - const dbus::FileDescriptor& value) { + const base::ScopedFD& value) { AppendValueToWriter(writer, value); } inline static bool Read(dbus::MessageReader* reader, - dbus::FileDescriptor* value) { + base::ScopedFD* value) { return PopValueFromReader(reader, value); } }; diff --git a/brillo/dbus/data_serialization_unittest.cc b/brillo/dbus/data_serialization_unittest.cc index 585f20b..8771fe9 100644 --- a/brillo/dbus/data_serialization_unittest.cc +++ b/brillo/dbus/data_serialization_unittest.cc @@ -6,12 +6,13 @@ #include <limits> +#include <base/files/scoped_file.h> #include <brillo/variant_dictionary.h> #include <gtest/gtest.h> #include "brillo/dbus/test.pb.h" -using dbus::FileDescriptor; +using base::ScopedFD; using dbus::Message; using dbus::MessageReader; using dbus::MessageWriter; @@ -33,7 +34,7 @@ TEST(DBusUtils, Supported_BasicTypes) { EXPECT_TRUE(IsTypeSupported<double>::value); EXPECT_TRUE(IsTypeSupported<std::string>::value); EXPECT_TRUE(IsTypeSupported<ObjectPath>::value); - EXPECT_TRUE(IsTypeSupported<FileDescriptor>::value); + EXPECT_TRUE(IsTypeSupported<ScopedFD>::value); EXPECT_TRUE(IsTypeSupported<Any>::value); EXPECT_TRUE(IsTypeSupported<google::protobuf::MessageLite>::value); EXPECT_TRUE(IsTypeSupported<dbus_utils_test::TestMessage>::value); @@ -89,7 +90,7 @@ TEST(DBusUtils, Signatures_BasicTypes) { EXPECT_EQ("d", GetDBusSignature<double>()); EXPECT_EQ("s", GetDBusSignature<std::string>()); EXPECT_EQ("o", GetDBusSignature<ObjectPath>()); - EXPECT_EQ("h", GetDBusSignature<FileDescriptor>()); + EXPECT_EQ("h", GetDBusSignature<ScopedFD>()); EXPECT_EQ("v", GetDBusSignature<Any>()); } @@ -105,7 +106,7 @@ TEST(DBusUtils, Signatures_Arrays) { EXPECT_EQ("ad", GetDBusSignature<std::vector<double>>()); EXPECT_EQ("as", GetDBusSignature<std::vector<std::string>>()); EXPECT_EQ("ao", GetDBusSignature<std::vector<ObjectPath>>()); - EXPECT_EQ("ah", GetDBusSignature<std::vector<FileDescriptor>>()); + EXPECT_EQ("ah", GetDBusSignature<std::vector<ScopedFD>>()); EXPECT_EQ("av", GetDBusSignature<std::vector<Any>>()); EXPECT_EQ("a(is)", (GetDBusSignature<std::vector<std::pair<int, std::string>>>())); @@ -238,7 +239,7 @@ TEST(DBusUtils, AppendAndPopFileDescriptor) { MessageWriter writer(message.get()); // Append stdout. - FileDescriptor temp(1); + ScopedFD temp(1); // Descriptor should not be valid until checked. EXPECT_FALSE(temp.is_valid()); // NB: thread IO requirements not relevant for unit tests. @@ -248,7 +249,7 @@ TEST(DBusUtils, AppendAndPopFileDescriptor) { EXPECT_EQ("h", message->GetSignature()); - FileDescriptor fd_value; + ScopedFD fd_value; MessageReader reader(message.get()); EXPECT_TRUE(reader.HasMoreData()); diff --git a/brillo/dbus/dbus_method_invoker.h b/brillo/dbus/dbus_method_invoker.h index f3d0e6b..2a8708b 100644 --- a/brillo/dbus/dbus_method_invoker.h +++ b/brillo/dbus/dbus_method_invoker.h @@ -73,7 +73,6 @@ #include <brillo/errors/error.h> #include <brillo/errors/error_codes.h> #include <brillo/brillo_export.h> -#include <dbus/file_descriptor.h> #include <dbus/message.h> #include <dbus/object_proxy.h> @@ -141,27 +140,6 @@ inline std::unique_ptr<dbus::Response> CallMethodAndBlock( args...); } -namespace internal { -// In order to support non-copyable dbus::FileDescriptor, we have this -// internal::HackMove() helper function that does really nothing for normal -// types but uses Pass() for file descriptors so we can move them out from -// the temporaries created inside DBusParamReader<...>::Invoke(). -// If only libchrome supported real rvalues so we can just do std::move() and -// be done with it. -template <typename T> -inline const T& HackMove(const T& val) { - return val; -} - -// Even though |val| here is passed as const&, the actual value is created -// inside DBusParamReader<...>::Invoke() and is temporary in nature, so it is -// safe to move the file descriptor out of |val|. That's why we are doing -// const_cast here. It is a bit hacky, but there is no negative side effects. -inline dbus::FileDescriptor HackMove(const dbus::FileDescriptor& val) { - return std::move(const_cast<dbus::FileDescriptor&>(val)); -} -} // namespace internal - // Extracts the parameters of |ResultTypes...| types from the message reader // and puts the values in the resulting |tuple|. Returns false on error and // provides additional error details in |error| object. @@ -171,7 +149,7 @@ inline bool ExtractMessageParametersAsTuple( ErrorPtr* error, std::tuple<ResultTypes...>* val_tuple) { auto callback = [val_tuple](const ResultTypes&... params) { - *val_tuple = std::forward_as_tuple(internal::HackMove(params)...); + *val_tuple = std::forward_as_tuple(params...); }; return DBusParamReader<false, ResultTypes...>::Invoke( callback, reader, error); @@ -184,7 +162,7 @@ inline bool ExtractMessageParametersAsTuple( ErrorPtr* error, std::tuple<ResultTypes&...>* ref_tuple) { auto callback = [ref_tuple](const ResultTypes&... params) { - *ref_tuple = std::forward_as_tuple(internal::HackMove(params)...); + *ref_tuple = std::forward_as_tuple(params...); }; return DBusParamReader<false, ResultTypes...>::Invoke( callback, reader, error); diff --git a/brillo/dbus/dbus_method_invoker_unittest.cc b/brillo/dbus/dbus_method_invoker_unittest.cc index f24f03e..dfd10c4 100644 --- a/brillo/dbus/dbus_method_invoker_unittest.cc +++ b/brillo/dbus/dbus_method_invoker_unittest.cc @@ -6,6 +6,7 @@ #include <string> +#include <base/files/scoped_file.h> #include <brillo/bind_lambda.h> #include <dbus/mock_bus.h> #include <dbus/mock_object_proxy.h> @@ -90,7 +91,7 @@ class DBusMethodInvokerTest : public testing::Test { } else if (method_call->GetMember() == kTestMethod4) { method_call->SetSerial(123); MessageReader reader(method_call); - dbus::FileDescriptor fd; + base::ScopedFD fd; if (reader.PopFileDescriptor(&fd)) { auto response = Response::CreateEmpty(); MessageWriter writer(response.get()); @@ -131,13 +132,13 @@ class DBusMethodInvokerTest : public testing::Test { } // Sends a file descriptor received over D-Bus back to the caller. - dbus::FileDescriptor EchoFD(const dbus::FileDescriptor& fd_in) { + base::ScopedFD EchoFD(const base::ScopedFD& fd_in) { std::unique_ptr<dbus::Response> response = brillo::dbus_utils::CallMethodAndBlock(mock_object_proxy_.get(), kTestInterface, kTestMethod4, nullptr, fd_in); EXPECT_NE(nullptr, response.get()); - dbus::FileDescriptor fd_out; + base::ScopedFD fd_out; using brillo::dbus_utils::ExtractMethodCallResults; EXPECT_TRUE(ExtractMethodCallResults(response.get(), nullptr, &fd_out)); return fd_out; @@ -179,13 +180,13 @@ TEST_F(DBusMethodInvokerTest, TestFileDescriptors) { // Passing a file descriptor over D-Bus would effectively duplicate the fd. // So the resulting file descriptor value would be different but it still // should be valid. - dbus::FileDescriptor fd_stdin(0); + base::ScopedFD fd_stdin(0); fd_stdin.CheckValidity(); EXPECT_NE(fd_stdin.value(), EchoFD(fd_stdin).value()); - dbus::FileDescriptor fd_stdout(1); + base::ScopedFD fd_stdout(1); fd_stdout.CheckValidity(); EXPECT_NE(fd_stdout.value(), EchoFD(fd_stdout).value()); - dbus::FileDescriptor fd_stderr(2); + base::ScopedFD fd_stderr(2); fd_stderr.CheckValidity(); EXPECT_NE(fd_stderr.value(), EchoFD(fd_stderr).value()); } |