CrashReportDatabse: set the last upload attempt time from RecordUploadAttempt().

This is only implemented for CrashReportDatabaseMac, because
CrashReportDatabaseWin does not currently have a Settings object. See
bug crashpad:13.

TEST=crashpad_client_test CrashReportDatabaseTest.*
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/995853003
This commit is contained in:
Mark Mentovai 2015-03-10 12:22:31 -04:00
parent c4a8b32495
commit 4ef649d189
4 changed files with 67 additions and 8 deletions

View File

@ -119,12 +119,13 @@ class CrashReportDatabase {
//! will be logged.
kFileSystemError,
//! \brief An error occured while recording metadata for a crash report.
//! \brief An error occured while recording metadata for a crash report or
//! database-wide settings.
//!
//! A database is responsible for managing both the metadata about a report
//! and the actual crash report itself. This error is returned when an
//! error occurred when managing the metadata about a crash report.
//! Additional information will be logged.
//! error occurred when managing the metadata about a crash report or
//! database-wide settings. Additional information will be logged.
kDatabaseError,
//! \brief The operation could not be completed because a concurrent
@ -234,7 +235,8 @@ class CrashReportDatabase {
const Report** report) = 0;
//! \brief Adjusts a crash report records metadata to account for an upload
//! attempt.
//! attempt, and updates the last upload attempt time as returned by
//! Settings::GetLastUploadAttemptTime().
//!
//! After calling this method, the database is permitted to move and rename
//! the file at Report::file_path.

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <uuid/uuid.h>
@ -399,9 +400,9 @@ CrashReportDatabaseMac::RecordUploadAttempt(const Report* report,
if (!WriteXattr(report_path, XattrName(kXattrCollectorID), id)) {
return kDatabaseError;
}
if (!WriteXattrTimeT(report_path,
XattrName(kXattrLastUploadTime),
time(nullptr))) {
time_t now = time(nullptr);
if (!WriteXattrTimeT(report_path, XattrName(kXattrLastUploadTime), now)) {
return kDatabaseError;
}
@ -415,6 +416,10 @@ CrashReportDatabaseMac::RecordUploadAttempt(const Report* report,
return kDatabaseError;
}
if (!settings_.SetLastUploadAttemptTime(now)) {
return kDatabaseError;
}
return kNoError;
}

View File

@ -16,11 +16,16 @@
#include <sys/stat.h>
#include "build/build_config.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 {
@ -74,6 +79,15 @@ class CrashReportDatabaseTest : public testing::Test {
}
void UploadReport(const UUID& uuid, bool successful, const std::string& id) {
#if !defined(OS_WIN)
// Enable when ported to Windows.
// https://code.google.com/p/crashpad/issues/detail?id=13
Settings* const settings = db_->GetSettings();
ASSERT_TRUE(settings);
time_t times[2];
ASSERT_TRUE(settings->GetLastUploadAttemptTime(&times[0]));
#endif
const CrashReportDatabase::Report* report = nullptr;
ASSERT_EQ(CrashReportDatabase::kNoError,
db_->GetReportForUploading(uuid, &report));
@ -84,6 +98,14 @@ class CrashReportDatabaseTest : public testing::Test {
EXPECT_GT(report->creation_time, 0);
EXPECT_EQ(CrashReportDatabase::kNoError,
db_->RecordUploadAttempt(report, successful, id));
#if !defined(OS_WIN)
// Enable when ported to Windows.
// https://code.google.com/p/crashpad/issues/detail?id=13
ASSERT_TRUE(settings->GetLastUploadAttemptTime(&times[1]));
EXPECT_NE(times[1], 0);
EXPECT_GE(times[1], times[0]);
#endif
}
void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) {
@ -112,7 +134,21 @@ class CrashReportDatabaseTest : public testing::Test {
TEST_F(CrashReportDatabaseTest, Initialize) {
// Initialize the database for the first time, creating it.
EXPECT_TRUE(db());
ASSERT_TRUE(db());
#if !defined(OS_WIN)
// Enable when ported to Windows.
// https://code.google.com/p/crashpad/issues/detail?id=13
Settings* settings = db()->GetSettings();
UUID client_ids[2];
ASSERT_TRUE(settings->GetClientID(&client_ids[0]));
EXPECT_NE(client_ids[0], UUID());
time_t last_upload_attempt_time;
ASSERT_TRUE(settings->GetLastUploadAttemptTime(&last_upload_attempt_time));
EXPECT_EQ(0, last_upload_attempt_time);
#endif
// Close and reopen the database at the same path.
ResetDatabase();
@ -120,6 +156,18 @@ TEST_F(CrashReportDatabaseTest, Initialize) {
auto db = CrashReportDatabase::Initialize(path());
ASSERT_TRUE(db);
#if !defined(OS_WIN)
// Enable when ported to Windows.
// https://code.google.com/p/crashpad/issues/detail?id=13
settings = db->GetSettings();
ASSERT_TRUE(settings->GetClientID(&client_ids[1]));
EXPECT_EQ(client_ids[0], client_ids[1]);
ASSERT_TRUE(settings->GetLastUploadAttemptTime(&last_upload_attempt_time));
EXPECT_EQ(0, last_upload_attempt_time);
#endif
std::vector<CrashReportDatabase::Report> reports;
EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports));
EXPECT_TRUE(reports.empty());

View File

@ -708,6 +708,10 @@ OperationStatus CrashReportDatabaseWin::RecordUploadAttempt(
report_disk->state =
successful ? ReportState::kCompleted : ReportState::kPending;
}
// Call Settings::SetLastUploadAttemptTime().
// https://code.google.com/p/crashpad/issues/detail?id=13.
return os;
}