This source file includes following definitions.
- GetInstance
- GetResults
- HasResults
- ClearResults
- RecordRegularStartup
- Run
- RunRecovery
#include "chrome/browser/diagnostics/diagnostics_controller.h"
#include <string>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/time/time.h"
#include "chrome/browser/diagnostics/diagnostics_model.h"
#include "chrome/browser/diagnostics/diagnostics_test.h"
#include "chrome/browser/diagnostics/diagnostics_writer.h"
#include "chrome/common/chrome_switches.h"
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
#endif
namespace diagnostics {
DiagnosticsController* DiagnosticsController::GetInstance() {
return Singleton<DiagnosticsController>::get();
}
DiagnosticsController::DiagnosticsController() : writer_(NULL) {}
DiagnosticsController::~DiagnosticsController() {}
const DiagnosticsModel& DiagnosticsController::GetResults() const {
return *model_;
}
bool DiagnosticsController::HasResults() {
return (model_.get() && model_->GetTestRunCount() > 0);
}
void DiagnosticsController::ClearResults() { model_.reset(); }
void DiagnosticsController::RecordRegularStartup() {
#if defined(OS_CHROMEOS)
UMA_HISTOGRAM_ENUMERATION(
"Diagnostics.RecoveryRun", RECOVERY_NOT_RUN, RECOVERY_RUN_METRICS_COUNT);
for (int i = 0; i < DIAGNOSTICS_TEST_ID_COUNT; ++i) {
RecordUMARecoveryResult(static_cast<DiagnosticsTestId>(i), RESULT_NOT_RUN);
RecordUMATestResult(static_cast<DiagnosticsTestId>(i), RESULT_NOT_RUN);
}
#endif
}
int DiagnosticsController::Run(const CommandLine& command_line,
DiagnosticsWriter* writer) {
writer_ = writer;
model_.reset(MakeDiagnosticsModel(command_line));
model_->RunAll(writer_);
return 0;
}
int DiagnosticsController::RunRecovery(const CommandLine& command_line,
DiagnosticsWriter* writer) {
#if defined(OS_CHROMEOS)
if (command_line.HasSwitch(chromeos::switches::kLoginUser)) {
UMA_HISTOGRAM_ENUMERATION("Diagnostics.RecoveryRun",
diagnostics::RECOVERY_CRASH_RUN,
diagnostics::RECOVERY_RUN_METRICS_COUNT);
} else {
UMA_HISTOGRAM_ENUMERATION("Diagnostics.RecoveryRun",
diagnostics::RECOVERY_USER_RUN,
diagnostics::RECOVERY_RUN_METRICS_COUNT);
}
#endif
if (!HasResults()) {
if (writer) {
writer->WriteInfoLine("No diagnostics have been run.");
writer->OnAllRecoveryDone(model_.get());
}
return -1;
}
writer_ = writer;
model_->RecoverAll(writer_);
return 0;
}
}