blob: 65482daf8060f8c9107dd5d9c66f9ca132c28ad6 [file] [log] [blame]
[email protected]d778d6e2011-08-12 09:47:051// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]e4be2dd2010-12-14 00:44:392// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/diagnostics/diagnostics_test.h"
6
[email protected]57999812013-02-24 05:40:527#include "base/files/file_path.h"
[email protected]0c38b262013-08-23 23:34:248#include "base/logging.h"
9#include "base/metrics/histogram.h"
[email protected]e4be2dd2010-12-14 00:44:3910#include "base/path_service.h"
11#include "chrome/common/chrome_constants.h"
12#include "chrome/common/chrome_paths.h"
13
[email protected]f22fae42013-07-09 21:11:1114namespace diagnostics {
[email protected]e4be2dd2010-12-14 00:44:3915
[email protected]0c38b262013-08-23 23:34:2416DiagnosticsTest::DiagnosticsTest(DiagnosticsTestId id)
17 : id_(id), outcome_code_(-1), result_(DiagnosticsModel::TEST_NOT_RUN) {}
[email protected]e4be2dd2010-12-14 00:44:3918
[email protected]f22fae42013-07-09 21:11:1119DiagnosticsTest::~DiagnosticsTest() {}
20
21bool DiagnosticsTest::Execute(DiagnosticsModel::Observer* observer,
22 DiagnosticsModel* model,
23 size_t index) {
24 start_time_ = base::Time::Now();
[email protected]e4be2dd2010-12-14 00:44:3925 result_ = DiagnosticsModel::TEST_RUNNING;
[email protected]e4be2dd2010-12-14 00:44:3926 bool keep_going = ExecuteImpl(observer);
[email protected]f22fae42013-07-09 21:11:1127 if (observer)
[email protected]60756be2013-08-07 05:20:2628 observer->OnTestFinished(index, model);
29 return keep_going;
30}
31
32bool 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;
[email protected]0c38b262013-08-23 23:34:2439#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);
46 }
47#endif
[email protected]60756be2013-08-07 05:20:2648 if (observer)
49 observer->OnRecoveryFinished(index, model);
[email protected]e4be2dd2010-12-14 00:44:3950 return keep_going;
51}
52
[email protected]f22fae42013-07-09 21:11:1153void 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;
[email protected]e4be2dd2010-12-14 00:44:3958 additional_info_ = additional_info;
59 result_ = result;
[email protected]0c38b262013-08-23 23:34:2460#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);
73 }
74#endif
[email protected]e4be2dd2010-12-14 00:44:3975}
76
77// static
[email protected]f22fae42013-07-09 21:11:1178base::FilePath DiagnosticsTest::GetUserDefaultProfileDir() {
[email protected]650b2d52013-02-10 03:41:4579 base::FilePath path;
[email protected]e4be2dd2010-12-14 00:44:3980 if (!PathService::Get(chrome::DIR_USER_DATA, &path))
[email protected]650b2d52013-02-10 03:41:4581 return base::FilePath();
[email protected]d778d6e2011-08-12 09:47:0582 return path.AppendASCII(chrome::kInitialProfile);
[email protected]e4be2dd2010-12-14 00:44:3983}
[email protected]f22fae42013-07-09 21:11:1184
[email protected]0c38b262013-08-23 23:34:2485int DiagnosticsTest::GetId() const { return id_; }
[email protected]f22fae42013-07-09 21:11:1186
[email protected]0c38b262013-08-23 23:34:2487std::string DiagnosticsTest::GetName() const { return GetTestName(id_); }
88
89std::string DiagnosticsTest::GetTitle() const {
90 return GetTestDescription(id_);
91}
[email protected]f22fae42013-07-09 21:11:1192
93DiagnosticsModel::TestResult DiagnosticsTest::GetResult() const {
94 return result_;
95}
96
97int DiagnosticsTest::GetOutcomeCode() const { return outcome_code_; }
98
99std::string DiagnosticsTest::GetAdditionalInfo() const {
100 return additional_info_;
101}
102
103base::Time DiagnosticsTest::GetStartTime() const { return start_time_; }
104
105base::Time DiagnosticsTest::GetEndTime() const { return end_time_; }
106
[email protected]60756be2013-08-07 05:20:26107bool DiagnosticsTest::RecoveryImpl(DiagnosticsModel::Observer* observer) {
108 return true;
[email protected]0c38b262013-08-23 23:34:24109}
[email protected]60756be2013-08-07 05:20:26110
[email protected]f22fae42013-07-09 21:11:11111} // namespace diagnostics