aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2017-07-26 20:19:18 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-07-26 20:19:18 +0000
commit548b90b26b43f5766297e4395da5bc9819a096ab (patch)
treefe141152985eaf7c1b10e4b7df4e15f7d98a3214
parent92e0fd9dc313afc0bec3fa62efb4c174d28146bf (diff)
parent54b117b3a26eb90fb5526162e8a4304a7ced07f3 (diff)
downloadlibbrillo-548b90b26b43f5766297e4395da5bc9819a096ab.tar.gz
Revert "libbrillo: Update libchrome APIS to r456626."android-o-mr1-preview-2android-o-mr1-preview-1
am: 54b117b3a2 Change-Id: Ibc96ee3b286568abb08d80bd19420ba7b19de8d5
-rw-r--r--brillo/dbus/data_serialization.cc10
-rw-r--r--brillo/dbus/data_serialization.h15
-rw-r--r--brillo/dbus/data_serialization_unittest.cc13
-rw-r--r--brillo/dbus/dbus_method_invoker.h26
-rw-r--r--brillo/dbus/dbus_method_invoker_unittest.cc13
-rw-r--r--brillo/file_utils_unittest.cc6
-rw-r--r--brillo/http/http_form_data_unittest.cc10
-rw-r--r--brillo/http/http_transport_curl.cc11
-rw-r--r--brillo/http/http_transport_curl_unittest.cc5
-rw-r--r--brillo/key_value_store_unittest.cc4
-rw-r--r--brillo/location_logging.h2
-rw-r--r--brillo/message_loops/base_message_loop.cc3
-rw-r--r--brillo/minijail/minijail.cc5
-rw-r--r--brillo/minijail/minijail.h6
-rw-r--r--brillo/osrelease_reader_unittest.cc12
-rw-r--r--brillo/process_unittest.cc4
-rw-r--r--brillo/streams/file_stream_unittest.cc20
-rw-r--r--brillo/value_conversion.cc10
18 files changed, 97 insertions, 78 deletions
diff --git a/brillo/dbus/data_serialization.cc b/brillo/dbus/data_serialization.cc
index 746b241..86d1c63 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 base::ScopedFD& value) {
- writer->AppendFileDescriptor(value.get());
+ const dbus::FileDescriptor& value) {
+ writer->AppendFileDescriptor(value);
}
void AppendValueToWriter(dbus::MessageWriter* writer,
@@ -140,10 +140,12 @@ bool PopValueFromReader(dbus::MessageReader* reader, dbus::ObjectPath* value) {
}
bool PopValueFromReader(dbus::MessageReader* reader,
- base::ScopedFD* value) {
+ dbus::FileDescriptor* value) {
dbus::MessageReader variant_reader(nullptr);
bool ok = details::DescendIntoVariantIfPresent(&reader, &variant_reader) &&
reader->PopFileDescriptor(value);
+ if (ok)
+ value->CheckValidity();
return ok;
}
@@ -307,7 +309,7 @@ bool PopValueFromReader(dbus::MessageReader* reader, brillo::Any* value) {
return false;
case dbus::Message::UNIX_FD:
CHECK(dbus::IsDBusTypeUnixFdSupported()) << "UNIX_FD data not supported";
- // base::ScopedFD is not a copyable type. Cannot be returned via
+ // dbus::FileDescriptor 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 6919b19..46da165 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 | base::ScopedFD
+// UNIX_FD | h | dbus::FileDescriptor
// SIGNATURE | g | (unsupported)
//
// Additional overloads/specialization can be provided for custom types.
@@ -58,7 +58,6 @@
#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>
@@ -412,23 +411,23 @@ struct DBusType<dbus::ObjectPath> {
}
};
-// base::ScopedFD -------------------------------------------------------------
+// dbus::FileDescriptor -------------------------------------------------------
BRILLO_EXPORT void AppendValueToWriter(dbus::MessageWriter* writer,
- const base::ScopedFD& value);
+ const dbus::FileDescriptor& value);
BRILLO_EXPORT bool PopValueFromReader(dbus::MessageReader* reader,
- base::ScopedFD* value);
+ dbus::FileDescriptor* value);
template<>
-struct DBusType<base::ScopedFD> {
+struct DBusType<dbus::FileDescriptor> {
inline static std::string GetSignature() {
return DBUS_TYPE_UNIX_FD_AS_STRING;
}
inline static void Write(dbus::MessageWriter* writer,
- const base::ScopedFD& value) {
+ const dbus::FileDescriptor& value) {
AppendValueToWriter(writer, value);
}
inline static bool Read(dbus::MessageReader* reader,
- base::ScopedFD* value) {
+ dbus::FileDescriptor* value) {
return PopValueFromReader(reader, value);
}
};
diff --git a/brillo/dbus/data_serialization_unittest.cc b/brillo/dbus/data_serialization_unittest.cc
index 8771fe9..585f20b 100644
--- a/brillo/dbus/data_serialization_unittest.cc
+++ b/brillo/dbus/data_serialization_unittest.cc
@@ -6,13 +6,12 @@
#include <limits>
-#include <base/files/scoped_file.h>
#include <brillo/variant_dictionary.h>
#include <gtest/gtest.h>
#include "brillo/dbus/test.pb.h"
-using base::ScopedFD;
+using dbus::FileDescriptor;
using dbus::Message;
using dbus::MessageReader;
using dbus::MessageWriter;
@@ -34,7 +33,7 @@ TEST(DBusUtils, Supported_BasicTypes) {
EXPECT_TRUE(IsTypeSupported<double>::value);
EXPECT_TRUE(IsTypeSupported<std::string>::value);
EXPECT_TRUE(IsTypeSupported<ObjectPath>::value);
- EXPECT_TRUE(IsTypeSupported<ScopedFD>::value);
+ EXPECT_TRUE(IsTypeSupported<FileDescriptor>::value);
EXPECT_TRUE(IsTypeSupported<Any>::value);
EXPECT_TRUE(IsTypeSupported<google::protobuf::MessageLite>::value);
EXPECT_TRUE(IsTypeSupported<dbus_utils_test::TestMessage>::value);
@@ -90,7 +89,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<ScopedFD>());
+ EXPECT_EQ("h", GetDBusSignature<FileDescriptor>());
EXPECT_EQ("v", GetDBusSignature<Any>());
}
@@ -106,7 +105,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<ScopedFD>>());
+ EXPECT_EQ("ah", GetDBusSignature<std::vector<FileDescriptor>>());
EXPECT_EQ("av", GetDBusSignature<std::vector<Any>>());
EXPECT_EQ("a(is)",
(GetDBusSignature<std::vector<std::pair<int, std::string>>>()));
@@ -239,7 +238,7 @@ TEST(DBusUtils, AppendAndPopFileDescriptor) {
MessageWriter writer(message.get());
// Append stdout.
- ScopedFD temp(1);
+ FileDescriptor temp(1);
// Descriptor should not be valid until checked.
EXPECT_FALSE(temp.is_valid());
// NB: thread IO requirements not relevant for unit tests.
@@ -249,7 +248,7 @@ TEST(DBusUtils, AppendAndPopFileDescriptor) {
EXPECT_EQ("h", message->GetSignature());
- ScopedFD fd_value;
+ FileDescriptor 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 2a8708b..f3d0e6b 100644
--- a/brillo/dbus/dbus_method_invoker.h
+++ b/brillo/dbus/dbus_method_invoker.h
@@ -73,6 +73,7 @@
#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>
@@ -140,6 +141,27 @@ 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.
@@ -149,7 +171,7 @@ inline bool ExtractMessageParametersAsTuple(
ErrorPtr* error,
std::tuple<ResultTypes...>* val_tuple) {
auto callback = [val_tuple](const ResultTypes&... params) {
- *val_tuple = std::forward_as_tuple(params...);
+ *val_tuple = std::forward_as_tuple(internal::HackMove(params)...);
};
return DBusParamReader<false, ResultTypes...>::Invoke(
callback, reader, error);
@@ -162,7 +184,7 @@ inline bool ExtractMessageParametersAsTuple(
ErrorPtr* error,
std::tuple<ResultTypes&...>* ref_tuple) {
auto callback = [ref_tuple](const ResultTypes&... params) {
- *ref_tuple = std::forward_as_tuple(params...);
+ *ref_tuple = std::forward_as_tuple(internal::HackMove(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 dfd10c4..f24f03e 100644
--- a/brillo/dbus/dbus_method_invoker_unittest.cc
+++ b/brillo/dbus/dbus_method_invoker_unittest.cc
@@ -6,7 +6,6 @@
#include <string>
-#include <base/files/scoped_file.h>
#include <brillo/bind_lambda.h>
#include <dbus/mock_bus.h>
#include <dbus/mock_object_proxy.h>
@@ -91,7 +90,7 @@ class DBusMethodInvokerTest : public testing::Test {
} else if (method_call->GetMember() == kTestMethod4) {
method_call->SetSerial(123);
MessageReader reader(method_call);
- base::ScopedFD fd;
+ dbus::FileDescriptor fd;
if (reader.PopFileDescriptor(&fd)) {
auto response = Response::CreateEmpty();
MessageWriter writer(response.get());
@@ -132,13 +131,13 @@ class DBusMethodInvokerTest : public testing::Test {
}
// Sends a file descriptor received over D-Bus back to the caller.
- base::ScopedFD EchoFD(const base::ScopedFD& fd_in) {
+ dbus::FileDescriptor EchoFD(const dbus::FileDescriptor& 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());
- base::ScopedFD fd_out;
+ dbus::FileDescriptor fd_out;
using brillo::dbus_utils::ExtractMethodCallResults;
EXPECT_TRUE(ExtractMethodCallResults(response.get(), nullptr, &fd_out));
return fd_out;
@@ -180,13 +179,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.
- base::ScopedFD fd_stdin(0);
+ dbus::FileDescriptor fd_stdin(0);
fd_stdin.CheckValidity();
EXPECT_NE(fd_stdin.value(), EchoFD(fd_stdin).value());
- base::ScopedFD fd_stdout(1);
+ dbus::FileDescriptor fd_stdout(1);
fd_stdout.CheckValidity();
EXPECT_NE(fd_stdout.value(), EchoFD(fd_stdout).value());
- base::ScopedFD fd_stderr(2);
+ dbus::FileDescriptor fd_stderr(2);
fd_stderr.CheckValidity();
EXPECT_NE(fd_stderr.value(), EchoFD(fd_stderr).value());
}
diff --git a/brillo/file_utils_unittest.cc b/brillo/file_utils_unittest.cc
index e906db7..f8898a0 100644
--- a/brillo/file_utils_unittest.cc
+++ b/brillo/file_utils_unittest.cc
@@ -19,7 +19,7 @@ class FileUtilsTest : public testing::Test {
public:
FileUtilsTest() {
CHECK(temp_dir_.CreateUniqueTempDir());
- file_path_ = temp_dir_.GetPath().Append("test.temp");
+ file_path_ = temp_dir_.path().Append("test.temp");
}
protected:
@@ -75,7 +75,7 @@ TEST_F(FileUtilsTest, TouchFileCreateThroughUmask) {
}
TEST_F(FileUtilsTest, TouchFileCreateDirectoryStructure) {
- file_path_ = temp_dir_.GetPath().Append("foo/bar/baz/test.temp");
+ file_path_ = temp_dir_.path().Append("foo/bar/baz/test.temp");
EXPECT_TRUE(TouchFile(file_path_));
ExpectFileContains("");
}
@@ -94,7 +94,7 @@ TEST_F(FileUtilsTest, TouchFileReplaceDirectory) {
}
TEST_F(FileUtilsTest, TouchFileReplaceSymlink) {
- base::FilePath symlink_target = temp_dir_.GetPath().Append("target.temp");
+ base::FilePath symlink_target = temp_dir_.path().Append("target.temp");
EXPECT_TRUE(base::CreateSymbolicLink(symlink_target, file_path_));
EXPECT_TRUE(TouchFile(file_path_));
EXPECT_FALSE(base::IsLink(file_path_));
diff --git a/brillo/http/http_form_data_unittest.cc b/brillo/http/http_form_data_unittest.cc
index 34288d0..842225d 100644
--- a/brillo/http/http_form_data_unittest.cc
+++ b/brillo/http/http_form_data_unittest.cc
@@ -42,7 +42,7 @@ TEST(HttpFormData, FileFormField) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
std::string file_content{"text line1\ntext line2\n"};
- base::FilePath file_name = dir.GetPath().Append("sample.txt");
+ base::FilePath file_name = dir.path().Append("sample.txt");
ASSERT_EQ(file_content.size(),
static_cast<size_t>(base::WriteFile(
file_name, file_content.data(), file_content.size())));
@@ -70,12 +70,12 @@ TEST(HttpFormData, MultiPartFormField) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
std::string file1{"text line1\ntext line2\n"};
- base::FilePath filename1 = dir.GetPath().Append("sample.txt");
+ base::FilePath filename1 = dir.path().Append("sample.txt");
ASSERT_EQ(file1.size(),
static_cast<size_t>(
base::WriteFile(filename1, file1.data(), file1.size())));
std::string file2{"\x01\x02\x03\x04\x05"};
- base::FilePath filename2 = dir.GetPath().Append("test.bin");
+ base::FilePath filename2 = dir.path().Append("test.bin");
ASSERT_EQ(file2.size(),
static_cast<size_t>(
base::WriteFile(filename2, file2.data(), file2.size())));
@@ -145,12 +145,12 @@ TEST(HttpFormData, FormData) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
std::string file1{"text line1\ntext line2\n"};
- base::FilePath filename1 = dir.GetPath().Append("sample.txt");
+ base::FilePath filename1 = dir.path().Append("sample.txt");
ASSERT_EQ(file1.size(),
static_cast<size_t>(
base::WriteFile(filename1, file1.data(), file1.size())));
std::string file2{"\x01\x02\x03\x04\x05"};
- base::FilePath filename2 = dir.GetPath().Append("test.bin");
+ base::FilePath filename2 = dir.path().Append("test.bin");
ASSERT_EQ(file2.size(),
static_cast<size_t>(
base::WriteFile(filename2, file2.data(), file2.size())));
diff --git a/brillo/http/http_transport_curl.cc b/brillo/http/http_transport_curl.cc
index 109d2c1..f7e3b71 100644
--- a/brillo/http/http_transport_curl.cc
+++ b/brillo/http/http_transport_curl.cc
@@ -40,8 +40,7 @@ class Transport::SocketPollData : public base::MessageLoopForIO::Watcher {
: curl_interface_(curl_interface),
curl_multi_handle_(curl_multi_handle),
transport_(transport),
- socket_fd_(socket_fd),
- file_descriptor_watcher_(FROM_HERE) {}
+ socket_fd_(socket_fd) {}
// Returns the pointer for the socket-specific file descriptor watcher.
base::MessageLoopForIO::FileDescriptorWatcher* GetWatcher() {
@@ -204,8 +203,7 @@ std::shared_ptr<http::Connection> Transport::CreateConnection(
void Transport::RunCallbackAsync(const tracked_objects::Location& from_here,
const base::Closure& callback) {
- base::MessageLoopForIO::current()->task_runner()->PostTask(
- from_here, callback);
+ base::MessageLoopForIO::current()->PostTask(from_here, callback);
}
RequestID Transport::StartAsyncTransfer(http::Connection* connection,
@@ -354,8 +352,7 @@ int Transport::MultiSocketCallback(CURL* easy,
poll_data->GetWatcher()->StopWatchingFileDescriptor();
// This method can be called indirectly from SocketPollData::OnSocketReady,
// so delay destruction of SocketPollData object till the next loop cycle.
- base::MessageLoopForIO::current()->task_runner()->
- DeleteSoon(FROM_HERE, poll_data);
+ base::MessageLoopForIO::current()->DeleteSoon(FROM_HERE, poll_data);
return 0;
}
@@ -398,7 +395,7 @@ int Transport::MultiTimerCallback(CURLM* /* multi */,
// Cancel any previous timer callbacks.
transport->weak_ptr_factory_for_timer_.InvalidateWeakPtrs();
if (timeout_ms >= 0) {
- base::MessageLoopForIO::current()->task_runner()->PostDelayedTask(
+ base::MessageLoopForIO::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&Transport::OnTimer,
transport->weak_ptr_factory_for_timer_.GetWeakPtr()),
diff --git a/brillo/http/http_transport_curl_unittest.cc b/brillo/http/http_transport_curl_unittest.cc
index 1937e73..702c9d9 100644
--- a/brillo/http/http_transport_curl_unittest.cc
+++ b/brillo/http/http_transport_curl_unittest.cc
@@ -209,8 +209,7 @@ TEST_F(HttpCurlTransportAsyncTest, StartAsyncTransfer) {
base::RunLoop* run_loop,
RequestID /* request_id */,
std::unique_ptr<http::Response> /* resp */) {
- base::MessageLoop::current()->task_runner()->PostTask(
- FROM_HERE, run_loop->QuitClosure());
+ base::MessageLoop::current()->PostTask(FROM_HERE, run_loop->QuitClosure());
(*success_call_count)++;
};
@@ -278,7 +277,7 @@ TEST_F(HttpCurlTransportAsyncTest, StartAsyncTransfer) {
// Just in case something goes wrong and |success_callback| isn't called,
// post a time-out quit closure to abort the message loop after 1 second.
- message_loop.task_runner()->PostDelayedTask(
+ message_loop.PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(1));
run_loop.Run();
EXPECT_EQ(1, success_call_count);
diff --git a/brillo/key_value_store_unittest.cc b/brillo/key_value_store_unittest.cc
index 04af5fd..cd18e89 100644
--- a/brillo/key_value_store_unittest.cc
+++ b/brillo/key_value_store_unittest.cc
@@ -40,8 +40,8 @@ class KeyValueStoreTest : public ::testing::Test {
TEST_F(KeyValueStoreTest, LoadAndSaveFromFile) {
base::ScopedTempDir temp_dir_;
CHECK(temp_dir_.CreateUniqueTempDir());
- base::FilePath temp_file_ = temp_dir_.GetPath().Append("temp.conf");
- base::FilePath saved_temp_file_ = temp_dir_.GetPath().Append("saved_temp.conf");
+ base::FilePath temp_file_ = temp_dir_.path().Append("temp.conf");
+ base::FilePath saved_temp_file_ = temp_dir_.path().Append("saved_temp.conf");
string blob = "A=B\n# Comment\n";
ASSERT_EQ(blob.size(), base::WriteFile(temp_file_, blob.data(), blob.size()));
diff --git a/brillo/location_logging.h b/brillo/location_logging.h
index 9fb3716..8e18c05 100644
--- a/brillo/location_logging.h
+++ b/brillo/location_logging.h
@@ -19,6 +19,6 @@
#define DVLOG_LOC(from_here, verbose_level) \
LAZY_STREAM(VLOG_LOC_STREAM(from_here, verbose_level), \
- DCHECK_IS_ON() && VLOG_IS_ON(verbose_level))
+ ::logging::DEBUG_MODE && VLOG_IS_ON(verbose_level))
#endif // LIBBRILLO_BRILLO_LOCATION_LOGGING_H_
diff --git a/brillo/message_loops/base_message_loop.cc b/brillo/message_loops/base_message_loop.cc
index 500c29b..ac57cb3 100644
--- a/brillo/message_loops/base_message_loop.cc
+++ b/brillo/message_loops/base_message_loop.cc
@@ -315,8 +315,7 @@ BaseMessageLoop::IOTask::IOTask(const tracked_objects::Location& location,
bool persistent,
const Closure& task)
: location_(location), loop_(loop), task_id_(task_id),
- fd_(fd), base_mode_(base_mode), persistent_(persistent), closure_(task),
- fd_watcher_(FROM_HERE) {}
+ fd_(fd), base_mode_(base_mode), persistent_(persistent), closure_(task) {}
bool BaseMessageLoop::IOTask::StartWatching() {
return loop_->base_loop_->WatchFileDescriptor(
diff --git a/brillo/minijail/minijail.cc b/brillo/minijail/minijail.cc
index 305f073..4d47c05 100644
--- a/brillo/minijail/minijail.cc
+++ b/brillo/minijail/minijail.cc
@@ -11,14 +11,15 @@ using std::vector;
namespace brillo {
+static base::LazyInstance<Minijail> g_minijail = LAZY_INSTANCE_INITIALIZER;
+
Minijail::Minijail() {}
Minijail::~Minijail() {}
// static
Minijail* Minijail::GetInstance() {
- static Minijail* minijail = new Minijail();
- return minijail;
+ return g_minijail.Pointer();
}
struct minijail* Minijail::New() {
diff --git a/brillo/minijail/minijail.h b/brillo/minijail/minijail.h
index 15167cf..4c1431d 100644
--- a/brillo/minijail/minijail.h
+++ b/brillo/minijail/minijail.h
@@ -12,9 +12,9 @@ extern "C" {
#include <sys/types.h>
}
-#include <libminijail.h>
+#include <base/lazy_instance.h>
-#include "base/macros.h"
+#include <libminijail.h>
namespace brillo {
@@ -108,6 +108,8 @@ class Minijail {
Minijail();
private:
+ friend struct base::DefaultLazyInstanceTraits<Minijail>;
+
DISALLOW_COPY_AND_ASSIGN(Minijail);
};
diff --git a/brillo/osrelease_reader_unittest.cc b/brillo/osrelease_reader_unittest.cc
index 9381367..88185a0 100644
--- a/brillo/osrelease_reader_unittest.cc
+++ b/brillo/osrelease_reader_unittest.cc
@@ -16,8 +16,8 @@ class OsReleaseReaderTest : public ::testing::Test {
public:
void SetUp() override {
CHECK(temp_dir_.CreateUniqueTempDir());
- osreleased_ = temp_dir_.GetPath().Append("etc").Append("os-release.d");
- osrelease_ = temp_dir_.GetPath().Append("etc").Append("os-release");
+ osreleased_ = temp_dir_.path().Append("etc").Append("os-release.d");
+ osrelease_ = temp_dir_.path().Append("etc").Append("os-release");
base::CreateDirectory(osreleased_);
}
@@ -28,12 +28,12 @@ class OsReleaseReaderTest : public ::testing::Test {
};
TEST_F(OsReleaseReaderTest, MissingOsReleaseTest) {
- store_.LoadTestingOnly(temp_dir_.GetPath());
+ store_.LoadTestingOnly(temp_dir_.path());
}
TEST_F(OsReleaseReaderTest, MissingOsReleaseDTest) {
base::DeleteFile(osreleased_, true);
- store_.LoadTestingOnly(temp_dir_.GetPath());
+ store_.LoadTestingOnly(temp_dir_.path());
}
TEST_F(OsReleaseReaderTest, CompleteTest) {
@@ -46,7 +46,7 @@ TEST_F(OsReleaseReaderTest, CompleteTest) {
base::WriteFile(osreleased_.Append("GREETINGS"), ola.data(), ola.size());
base::WriteFile(osrelease_, osreleasecontent.data(), osreleasecontent.size());
- store_.LoadTestingOnly(temp_dir_.GetPath());
+ store_.LoadTestingOnly(temp_dir_.path());
string test_key_value;
ASSERT_TRUE(store_.GetString("TEST_KEY", &test_key_value));
@@ -80,7 +80,7 @@ TEST_F(OsReleaseReaderTest, NoNewLine) {
base::WriteFile(
osreleased_.Append("BONJOUR"), bonjour.data(), bonjour.size());
- store_.LoadTestingOnly(temp_dir_.GetPath());
+ store_.LoadTestingOnly(temp_dir_.path());
string hello_value;
string bonjour_value;
diff --git a/brillo/process_unittest.cc b/brillo/process_unittest.cc
index 20ccf2e..d2c92e6 100644
--- a/brillo/process_unittest.cc
+++ b/brillo/process_unittest.cc
@@ -107,7 +107,7 @@ class ProcessTest : public ::testing::Test {
public:
void SetUp() {
CHECK(temp_dir_.CreateUniqueTempDir());
- output_file_ = temp_dir_.GetPath().Append("fork_out").value();
+ output_file_ = temp_dir_.path().Append("fork_out").value();
process_.RedirectOutput(output_file_);
ClearLog();
}
@@ -324,7 +324,7 @@ TEST_F(ProcessTest, ProcessExists) {
}
TEST_F(ProcessTest, ResetPidByFile) {
- FilePath pid_path = temp_dir_.GetPath().Append("pid");
+ FilePath pid_path = temp_dir_.path().Append("pid");
EXPECT_FALSE(process_.ResetPidByFile(pid_path.value()));
EXPECT_TRUE(base::WriteFile(pid_path, "456\n", 4));
EXPECT_TRUE(process_.ResetPidByFile(pid_path.value()));
diff --git a/brillo/streams/file_stream_unittest.cc b/brillo/streams/file_stream_unittest.cc
index aa1ce43..4554ede 100644
--- a/brillo/streams/file_stream_unittest.cc
+++ b/brillo/streams/file_stream_unittest.cc
@@ -715,7 +715,7 @@ TEST_F(FileStreamTest, CreateTemporary) {
TEST_F(FileStreamTest, OpenRead) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
std::vector<char> buffer(1024 * 1024);
base::RandBytes(buffer.data(), buffer.size());
int file_size = buffer.size(); // Stupid base::WriteFile taking "int" size.
@@ -743,7 +743,7 @@ TEST_F(FileStreamTest, OpenRead) {
TEST_F(FileStreamTest, OpenWrite) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
std::vector<char> buffer(1024 * 1024);
base::RandBytes(buffer.data(), buffer.size());
@@ -772,7 +772,7 @@ TEST_F(FileStreamTest, OpenWrite) {
TEST_F(FileStreamTest, Open_OpenExisting) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
std::string data{"Lorem ipsum dolor sit amet ..."};
int data_size = data.size(); // I hate ints for data size...
ASSERT_EQ(data_size, base::WriteFile(path, data.data(), data_size));
@@ -794,7 +794,7 @@ TEST_F(FileStreamTest, Open_OpenExisting) {
TEST_F(FileStreamTest, Open_OpenExisting_Fail) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
ErrorPtr error;
StreamPtr stream = FileStream::Open(path,
@@ -809,7 +809,7 @@ TEST_F(FileStreamTest, Open_OpenExisting_Fail) {
TEST_F(FileStreamTest, Open_CreateAlways_New) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
StreamPtr stream = FileStream::Open(path,
Stream::AccessMode::READ_WRITE,
@@ -828,7 +828,7 @@ TEST_F(FileStreamTest, Open_CreateAlways_New) {
TEST_F(FileStreamTest, Open_CreateAlways_Existing) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
std::string data{"Lorem ipsum dolor sit amet ..."};
int data_size = data.size(); // I hate ints for data size...
ASSERT_EQ(data_size, base::WriteFile(path, data.data(), data_size));
@@ -850,7 +850,7 @@ TEST_F(FileStreamTest, Open_CreateAlways_Existing) {
TEST_F(FileStreamTest, Open_CreateNewOnly_New) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
StreamPtr stream = FileStream::Open(path,
Stream::AccessMode::READ_WRITE,
@@ -869,7 +869,7 @@ TEST_F(FileStreamTest, Open_CreateNewOnly_New) {
TEST_F(FileStreamTest, Open_CreateNewOnly_Existing) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
std::string data{"Lorem ipsum dolor sit amet ..."};
int data_size = data.size(); // I hate ints for data size...
ASSERT_EQ(data_size, base::WriteFile(path, data.data(), data_size));
@@ -887,7 +887,7 @@ TEST_F(FileStreamTest, Open_CreateNewOnly_Existing) {
TEST_F(FileStreamTest, Open_TruncateExisting_New) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
ErrorPtr error;
StreamPtr stream = FileStream::Open(
@@ -903,7 +903,7 @@ TEST_F(FileStreamTest, Open_TruncateExisting_New) {
TEST_F(FileStreamTest, Open_TruncateExisting_Existing) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath path = temp_dir.GetPath().Append(base::FilePath{"test.dat"});
+ base::FilePath path = temp_dir.path().Append(base::FilePath{"test.dat"});
std::string data{"Lorem ipsum dolor sit amet ..."};
int data_size = data.size(); // I hate ints for data size...
ASSERT_EQ(data_size, base::WriteFile(path, data.data(), data_size));
diff --git a/brillo/value_conversion.cc b/brillo/value_conversion.cc
index 8aab94c..aa5135b 100644
--- a/brillo/value_conversion.cc
+++ b/brillo/value_conversion.cc
@@ -38,23 +38,23 @@ bool FromValue(const base::Value& in_value,
}
std::unique_ptr<base::Value> ToValue(int value) {
- return std::unique_ptr<base::Value>(new base::Value(value));
+ return std::unique_ptr<base::Value>{new base::FundamentalValue{value}};
}
std::unique_ptr<base::Value> ToValue(bool value) {
- return std::unique_ptr<base::Value>(new base::Value(value));
+ return std::unique_ptr<base::Value>{new base::FundamentalValue{value}};
}
std::unique_ptr<base::Value> ToValue(double value) {
- return std::unique_ptr<base::Value>(new base::Value(value));
+ return std::unique_ptr<base::Value>{new base::FundamentalValue{value}};
}
std::unique_ptr<base::Value> ToValue(const char* value) {
- return std::unique_ptr<base::Value>(new base::Value(value));
+ return std::unique_ptr<base::Value>{new base::StringValue{value}};
}
std::unique_ptr<base::Value> ToValue(const std::string& value) {
- return std::unique_ptr<base::Value>(new base::Value(value));
+ return std::unique_ptr<base::Value>{new base::StringValue{value}};
}
} // namespace brillo