From bdcc1e76257f5578d765dc8577a229b4f43b0a8e Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 10 Mar 2015 14:26:24 -0400 Subject: [PATCH] Return a FilePath from Settings::file_path(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it possible to #include "client/settings.h" for the interface even on Windows. Although Settings is not currently implemented on Windows (bug crashpad:13), it’s easier to have the interface declaration available without having to have it be guarded. TEST=crashpad_client_test SettingsTest.* BUG= R=rsesek@chromium.org Review URL: https://codereview.chromium.org/987383002 --- client/crash_report_database_test.cc | 5 +---- client/settings.cc | 9 +++++---- client/settings.h | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/client/crash_report_database_test.cc b/client/crash_report_database_test.cc index 4b7db856..44fde917 100644 --- a/client/crash_report_database_test.cc +++ b/client/crash_report_database_test.cc @@ -17,15 +17,12 @@ #include #include "build/build_config.h" +#include "client/settings.h" #include "gtest/gtest.h" #include "util/file/file_io.h" #include "util/test/errors.h" #include "util/test/scoped_temp_dir.h" -#if !defined(OS_WIN) -#include "client/settings.h" -#endif - namespace crashpad { namespace test { namespace { diff --git a/client/settings.cc b/client/settings.cc index f10421a8..ca101d2d 100644 --- a/client/settings.cc +++ b/client/settings.cc @@ -57,7 +57,7 @@ bool Settings::Initialize() { INITIALIZATION_STATE_SET_INITIALIZING(initialized_); ScopedFileHandle handle(HANDLE_EINTR( - open(file_path(), + open(file_path().value().c_str(), O_CREAT | O_EXCL | O_WRONLY | O_EXLOCK, 0644))); @@ -145,14 +145,15 @@ bool Settings::SetLastUploadAttemptTime(time_t time) { } ScopedFileHandle Settings::OpenForReading() { - ScopedFileHandle handle(HANDLE_EINTR(open(file_path(), O_RDONLY | O_SHLOCK))); + ScopedFileHandle handle(HANDLE_EINTR( + open(file_path().value().c_str(), O_RDONLY | O_SHLOCK))); PLOG_IF(ERROR, !handle.is_valid()) << "open for reading"; return handle.Pass(); } ScopedFileHandle Settings::OpenForReadingAndWriting() { ScopedFileHandle handle(HANDLE_EINTR( - open(file_path(), O_RDWR | O_EXLOCK | O_CREAT, 0644))); + open(file_path().value().c_str(), O_RDWR | O_EXLOCK | O_CREAT, 0644))); PLOG_IF(ERROR, !handle.is_valid()) << "open for writing"; return handle.Pass(); } @@ -224,7 +225,7 @@ bool Settings::RecoverSettings(FileHandle handle, Data* out_data) { return true; } - LOG(INFO) << "Recovering settings file " << file_path(); + LOG(INFO) << "Recovering settings file " << file_path().value(); if (handle == kInvalidFileHandle) { LOG(ERROR) << "Invalid file handle"; diff --git a/client/settings.h b/client/settings.h index 741561be..bab5186a 100644 --- a/client/settings.h +++ b/client/settings.h @@ -133,7 +133,7 @@ class Settings { // on success and false on failure, with an error logged. bool InitializeSettings(FileHandle handle); - const char* file_path() { return file_path_.value().c_str(); } + const base::FilePath& file_path() const { return file_path_; } base::FilePath file_path_;