Return a FilePath from Settings::file_path().

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
This commit is contained in:
Mark Mentovai 2015-03-10 14:26:24 -04:00
parent e4c8b6cc72
commit bdcc1e7625
3 changed files with 7 additions and 9 deletions

View File

@ -17,15 +17,12 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "build/build_config.h" #include "build/build_config.h"
#include "client/settings.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "util/file/file_io.h" #include "util/file/file_io.h"
#include "util/test/errors.h" #include "util/test/errors.h"
#include "util/test/scoped_temp_dir.h" #include "util/test/scoped_temp_dir.h"
#if !defined(OS_WIN)
#include "client/settings.h"
#endif
namespace crashpad { namespace crashpad {
namespace test { namespace test {
namespace { namespace {

View File

@ -57,7 +57,7 @@ bool Settings::Initialize() {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_); INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
ScopedFileHandle handle(HANDLE_EINTR( ScopedFileHandle handle(HANDLE_EINTR(
open(file_path(), open(file_path().value().c_str(),
O_CREAT | O_EXCL | O_WRONLY | O_EXLOCK, O_CREAT | O_EXCL | O_WRONLY | O_EXLOCK,
0644))); 0644)));
@ -145,14 +145,15 @@ bool Settings::SetLastUploadAttemptTime(time_t time) {
} }
ScopedFileHandle Settings::OpenForReading() { 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"; PLOG_IF(ERROR, !handle.is_valid()) << "open for reading";
return handle.Pass(); return handle.Pass();
} }
ScopedFileHandle Settings::OpenForReadingAndWriting() { ScopedFileHandle Settings::OpenForReadingAndWriting() {
ScopedFileHandle handle(HANDLE_EINTR( 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"; PLOG_IF(ERROR, !handle.is_valid()) << "open for writing";
return handle.Pass(); return handle.Pass();
} }
@ -224,7 +225,7 @@ bool Settings::RecoverSettings(FileHandle handle, Data* out_data) {
return true; return true;
} }
LOG(INFO) << "Recovering settings file " << file_path(); LOG(INFO) << "Recovering settings file " << file_path().value();
if (handle == kInvalidFileHandle) { if (handle == kInvalidFileHandle) {
LOG(ERROR) << "Invalid file handle"; LOG(ERROR) << "Invalid file handle";

View File

@ -133,7 +133,7 @@ class Settings {
// on success and false on failure, with an error logged. // on success and false on failure, with an error logged.
bool InitializeSettings(FileHandle handle); 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_; base::FilePath file_path_;