1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/diagnostics/diagnostics_controller.h"
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/diagnostics/diagnostics_model.h"
15 #include "chrome/browser/diagnostics/diagnostics_test.h"
16 #include "chrome/browser/diagnostics/diagnostics_writer.h"
17 #include "chrome/common/chrome_switches.h"
19 #if defined(OS_CHROMEOS)
20 #include "chromeos/chromeos_switches.h"
23 namespace diagnostics
{
25 DiagnosticsController
* DiagnosticsController::GetInstance() {
26 return Singleton
<DiagnosticsController
>::get();
29 DiagnosticsController::DiagnosticsController() : writer_(NULL
) {}
31 DiagnosticsController::~DiagnosticsController() {}
33 const DiagnosticsModel
& DiagnosticsController::GetResults() const {
37 bool DiagnosticsController::HasResults() {
38 return (model_
.get() && model_
->GetTestRunCount() > 0);
41 void DiagnosticsController::ClearResults() { model_
.reset(); }
43 void DiagnosticsController::RecordRegularStartup() {
44 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS
45 // Count the number of normal starts, so we can compare that with the number
46 // of recovery runs to get a percentage.
47 UMA_HISTOGRAM_ENUMERATION(
48 "Diagnostics.RecoveryRun", RECOVERY_NOT_RUN
, RECOVERY_RUN_METRICS_COUNT
);
50 // For each of the test types, record a normal start (no diagnostics run), so
51 // we have a common denominator.
52 for (int i
= 0; i
< DIAGNOSTICS_TEST_ID_COUNT
; ++i
) {
53 RecordUMARecoveryResult(static_cast<DiagnosticsTestId
>(i
), RESULT_NOT_RUN
);
54 RecordUMATestResult(static_cast<DiagnosticsTestId
>(i
), RESULT_NOT_RUN
);
59 // This entry point is called from early in startup when very few things have
60 // been initialized, so be careful what you use.
61 int DiagnosticsController::Run(const CommandLine
& command_line
,
62 DiagnosticsWriter
* writer
) {
65 model_
.reset(MakeDiagnosticsModel(command_line
));
66 model_
->RunAll(writer_
);
71 // This entry point is called from early in startup when very few things have
72 // been initialized, so be careful what you use.
73 int DiagnosticsController::RunRecovery(const CommandLine
& command_line
,
74 DiagnosticsWriter
* writer
) {
75 // Separate out recoveries that we execute automatically as a result of a
76 // crash from user-run recoveries.
77 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS
78 if (command_line
.HasSwitch(chromeos::switches::kLoginUser
)) {
79 UMA_HISTOGRAM_ENUMERATION("Diagnostics.RecoveryRun",
80 diagnostics::RECOVERY_CRASH_RUN
,
81 diagnostics::RECOVERY_RUN_METRICS_COUNT
);
83 UMA_HISTOGRAM_ENUMERATION("Diagnostics.RecoveryRun",
84 diagnostics::RECOVERY_USER_RUN
,
85 diagnostics::RECOVERY_RUN_METRICS_COUNT
);
91 writer
->WriteInfoLine("No diagnostics have been run.");
92 writer
->OnAllRecoveryDone(model_
.get());
99 model_
->RecoverAll(writer_
);
103 } // namespace diagnostics