Rename vector icon header files.
[chromium-blink-merge.git] / chrome / browser / diagnostics / diagnostics_test.cc
blob65482daf8060f8c9107dd5d9c66f9ca132c28ad6
1 // Copyright (c) 2011 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_test.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
10 #include "base/path_service.h"
11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/chrome_paths.h"
14 namespace diagnostics {
16 DiagnosticsTest::DiagnosticsTest(DiagnosticsTestId id)
17 : id_(id), outcome_code_(-1), result_(DiagnosticsModel::TEST_NOT_RUN) {}
19 DiagnosticsTest::~DiagnosticsTest() {}
21 bool DiagnosticsTest::Execute(DiagnosticsModel::Observer* observer,
22 DiagnosticsModel* model,
23 size_t index) {
24 start_time_ = base::Time::Now();
25 result_ = DiagnosticsModel::TEST_RUNNING;
26 bool keep_going = ExecuteImpl(observer);
27 if (observer)
28 observer->OnTestFinished(index, model);
29 return keep_going;
32 bool DiagnosticsTest::Recover(DiagnosticsModel::Observer* observer,
33 DiagnosticsModel* model,
34 size_t index) {
35 result_ = DiagnosticsModel::RECOVERY_RUNNING;
36 bool keep_going = RecoveryImpl(observer);
37 result_ = keep_going ? DiagnosticsModel::RECOVERY_OK
38 : DiagnosticsModel::RECOVERY_FAIL_STOP;
39 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS
40 if (result_ == DiagnosticsModel::RECOVERY_OK) {
41 RecordUMARecoveryResult(static_cast<DiagnosticsTestId>(GetId()),
42 RESULT_SUCCESS);
43 } else {
44 RecordUMARecoveryResult(static_cast<DiagnosticsTestId>(GetId()),
45 RESULT_FAILURE);
47 #endif
48 if (observer)
49 observer->OnRecoveryFinished(index, model);
50 return keep_going;
53 void DiagnosticsTest::RecordOutcome(int outcome_code,
54 const std::string& additional_info,
55 DiagnosticsModel::TestResult result) {
56 end_time_ = base::Time::Now();
57 outcome_code_ = outcome_code;
58 additional_info_ = additional_info;
59 result_ = result;
60 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS
61 if (result_ == DiagnosticsModel::TEST_OK) {
62 // Record individual test success.
63 RecordUMATestResult(static_cast<DiagnosticsTestId>(GetId()),
64 RESULT_SUCCESS);
65 } else if (result_ == DiagnosticsModel::TEST_FAIL_CONTINUE ||
66 result_ == DiagnosticsModel::TEST_FAIL_STOP) {
67 // Record test failure in summary histogram.
68 UMA_HISTOGRAM_ENUMERATION(
69 "Diagnostics.TestFailures", GetId(), DIAGNOSTICS_TEST_ID_COUNT);
70 // Record individual test failure.
71 RecordUMATestResult(static_cast<DiagnosticsTestId>(GetId()),
72 RESULT_FAILURE);
74 #endif
77 // static
78 base::FilePath DiagnosticsTest::GetUserDefaultProfileDir() {
79 base::FilePath path;
80 if (!PathService::Get(chrome::DIR_USER_DATA, &path))
81 return base::FilePath();
82 return path.AppendASCII(chrome::kInitialProfile);
85 int DiagnosticsTest::GetId() const { return id_; }
87 std::string DiagnosticsTest::GetName() const { return GetTestName(id_); }
89 std::string DiagnosticsTest::GetTitle() const {
90 return GetTestDescription(id_);
93 DiagnosticsModel::TestResult DiagnosticsTest::GetResult() const {
94 return result_;
97 int DiagnosticsTest::GetOutcomeCode() const { return outcome_code_; }
99 std::string DiagnosticsTest::GetAdditionalInfo() const {
100 return additional_info_;
103 base::Time DiagnosticsTest::GetStartTime() const { return start_time_; }
105 base::Time DiagnosticsTest::GetEndTime() const { return end_time_; }
107 bool DiagnosticsTest::RecoveryImpl(DiagnosticsModel::Observer* observer) {
108 return true;
111 } // namespace diagnostics