This source file includes following definitions.
- result_
- Execute
- Recover
- RecordOutcome
- GetUserDefaultProfileDir
- GetId
- GetName
- GetTitle
- GetResult
- GetOutcomeCode
- GetAdditionalInfo
- GetStartTime
- GetEndTime
- RecoveryImpl
#include "chrome/browser/diagnostics/diagnostics_test.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
namespace diagnostics {
DiagnosticsTest::DiagnosticsTest(DiagnosticsTestId id)
: id_(id), outcome_code_(-1), result_(DiagnosticsModel::TEST_NOT_RUN) {}
DiagnosticsTest::~DiagnosticsTest() {}
bool DiagnosticsTest::Execute(DiagnosticsModel::Observer* observer,
DiagnosticsModel* model,
size_t index) {
start_time_ = base::Time::Now();
result_ = DiagnosticsModel::TEST_RUNNING;
bool keep_going = ExecuteImpl(observer);
if (observer)
observer->OnTestFinished(index, model);
return keep_going;
}
bool DiagnosticsTest::Recover(DiagnosticsModel::Observer* observer,
DiagnosticsModel* model,
size_t index) {
result_ = DiagnosticsModel::RECOVERY_RUNNING;
bool keep_going = RecoveryImpl(observer);
result_ = keep_going ? DiagnosticsModel::RECOVERY_OK
: DiagnosticsModel::RECOVERY_FAIL_STOP;
#if defined(OS_CHROMEOS)
if (result_ == DiagnosticsModel::RECOVERY_OK) {
RecordUMARecoveryResult(static_cast<DiagnosticsTestId>(GetId()),
RESULT_SUCCESS);
} else {
RecordUMARecoveryResult(static_cast<DiagnosticsTestId>(GetId()),
RESULT_FAILURE);
}
#endif
if (observer)
observer->OnRecoveryFinished(index, model);
return keep_going;
}
void DiagnosticsTest::RecordOutcome(int outcome_code,
const std::string& additional_info,
DiagnosticsModel::TestResult result) {
end_time_ = base::Time::Now();
outcome_code_ = outcome_code;
additional_info_ = additional_info;
result_ = result;
#if defined(OS_CHROMEOS)
if (result_ == DiagnosticsModel::TEST_OK) {
RecordUMATestResult(static_cast<DiagnosticsTestId>(GetId()),
RESULT_SUCCESS);
} else if (result_ == DiagnosticsModel::TEST_FAIL_CONTINUE ||
result_ == DiagnosticsModel::TEST_FAIL_STOP) {
UMA_HISTOGRAM_ENUMERATION(
"Diagnostics.TestFailures", GetId(), DIAGNOSTICS_TEST_ID_COUNT);
RecordUMATestResult(static_cast<DiagnosticsTestId>(GetId()),
RESULT_FAILURE);
}
#endif
}
base::FilePath DiagnosticsTest::GetUserDefaultProfileDir() {
base::FilePath path;
if (!PathService::Get(chrome::DIR_USER_DATA, &path))
return base::FilePath();
return path.AppendASCII(chrome::kInitialProfile);
}
int DiagnosticsTest::GetId() const { return id_; }
std::string DiagnosticsTest::GetName() const { return GetTestName(id_); }
std::string DiagnosticsTest::GetTitle() const {
return GetTestDescription(id_);
}
DiagnosticsModel::TestResult DiagnosticsTest::GetResult() const {
return result_;
}
int DiagnosticsTest::GetOutcomeCode() const { return outcome_code_; }
std::string DiagnosticsTest::GetAdditionalInfo() const {
return additional_info_;
}
base::Time DiagnosticsTest::GetStartTime() const { return start_time_; }
base::Time DiagnosticsTest::GetEndTime() const { return end_time_; }
bool DiagnosticsTest::RecoveryImpl(DiagnosticsModel::Observer* observer) {
return true;
}
}