blob: df5ae196a72c7a0304647fd7ecd448ff6a1bba8b [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"
asvitkineaa060312016-09-01 22:44:139#include "base/metrics/histogram_macros.h"
[email protected]e4be2dd2010-12-14 00:44:3910#include "base/path_service.h"
avie4d7b6f2015-12-26 00:59:1811#include "build/build_config.h"
[email protected]e4be2dd2010-12-14 00:44:3912#include "chrome/common/chrome_constants.h"
13#include "chrome/common/chrome_paths.h"
14
[email protected]f22fae42013-07-09 21:11:1115namespace diagnostics {
[email protected]e4be2dd2010-12-14 00:44:3916
[email protected]0c38b262013-08-23 23:34:2417DiagnosticsTest::DiagnosticsTest(DiagnosticsTestId id)
18 : id_(id), outcome_code_(-1), result_(DiagnosticsModel::TEST_NOT_RUN) {}
[email protected]e4be2dd2010-12-14 00:44:3919
[email protected]f22fae42013-07-09 21:11:1120DiagnosticsTest::~DiagnosticsTest() {}
21
22bool DiagnosticsTest::Execute(DiagnosticsModel::Observer* observer,
23 DiagnosticsModel* model,
24 size_t index) {
25 start_time_ = base::Time::Now();
[email protected]e4be2dd2010-12-14 00:44:3926 result_ = DiagnosticsModel::TEST_RUNNING;
[email protected]e4be2dd2010-12-14 00:44:3927 bool keep_going = ExecuteImpl(observer);
[email protected]f22fae42013-07-09 21:11:1128 if (observer)
[email protected]60756be2013-08-07 05:20:2629 observer->OnTestFinished(index, model);
30 return keep_going;
31}
32
33bool DiagnosticsTest::Recover(DiagnosticsModel::Observer* observer,
34 DiagnosticsModel* model,
35 size_t index) {
36 result_ = DiagnosticsModel::RECOVERY_RUNNING;
37 bool keep_going = RecoveryImpl(observer);
38 result_ = keep_going ? DiagnosticsModel::RECOVERY_OK
39 : DiagnosticsModel::RECOVERY_FAIL_STOP;
[email protected]0c38b262013-08-23 23:34:2440#if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS
41 if (result_ == DiagnosticsModel::RECOVERY_OK) {
42 RecordUMARecoveryResult(static_cast<DiagnosticsTestId>(GetId()),
43 RESULT_SUCCESS);
44 } else {
45 RecordUMARecoveryResult(static_cast<DiagnosticsTestId>(GetId()),
46 RESULT_FAILURE);
47 }
48#endif
[email protected]60756be2013-08-07 05:20:2649 if (observer)
50 observer->OnRecoveryFinished(index, model);
[email protected]e4be2dd2010-12-14 00:44:3951 return keep_going;
52}
53
[email protected]f22fae42013-07-09 21:11:1154void DiagnosticsTest::RecordOutcome(int outcome_code,
55 const std::string& additional_info,
56 DiagnosticsModel::TestResult result) {
57 end_time_ = base::Time::Now();
58 outcome_code_ = outcome_code;
[email protected]e4be2dd2010-12-14 00:44:3959 additional_info_ = additional_info;
60 result_ = result;
[email protected]0c38b262013-08-23 23:34:2461#if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS
62 if (result_ == DiagnosticsModel::TEST_OK) {
63 // Record individual test success.
64 RecordUMATestResult(static_cast<DiagnosticsTestId>(GetId()),
65 RESULT_SUCCESS);
66 } else if (result_ == DiagnosticsModel::TEST_FAIL_CONTINUE ||
67 result_ == DiagnosticsModel::TEST_FAIL_STOP) {
68 // Record test failure in summary histogram.
69 UMA_HISTOGRAM_ENUMERATION(
70 "Diagnostics.TestFailures", GetId(), DIAGNOSTICS_TEST_ID_COUNT);
71 // Record individual test failure.
72 RecordUMATestResult(static_cast<DiagnosticsTestId>(GetId()),
73 RESULT_FAILURE);
74 }
75#endif
[email protected]e4be2dd2010-12-14 00:44:3976}
77
78// static
[email protected]f22fae42013-07-09 21:11:1179base::FilePath DiagnosticsTest::GetUserDefaultProfileDir() {
[email protected]650b2d52013-02-10 03:41:4580 base::FilePath path;
[email protected]e4be2dd2010-12-14 00:44:3981 if (!PathService::Get(chrome::DIR_USER_DATA, &path))
[email protected]650b2d52013-02-10 03:41:4582 return base::FilePath();
[email protected]d778d6e2011-08-12 09:47:0583 return path.AppendASCII(chrome::kInitialProfile);
[email protected]e4be2dd2010-12-14 00:44:3984}
[email protected]f22fae42013-07-09 21:11:1185
[email protected]0c38b262013-08-23 23:34:2486int DiagnosticsTest::GetId() const { return id_; }
[email protected]f22fae42013-07-09 21:11:1187
[email protected]0c38b262013-08-23 23:34:2488std::string DiagnosticsTest::GetName() const { return GetTestName(id_); }
89
90std::string DiagnosticsTest::GetTitle() const {
91 return GetTestDescription(id_);
92}
[email protected]f22fae42013-07-09 21:11:1193
94DiagnosticsModel::TestResult DiagnosticsTest::GetResult() const {
95 return result_;
96}
97
98int DiagnosticsTest::GetOutcomeCode() const { return outcome_code_; }
99
100std::string DiagnosticsTest::GetAdditionalInfo() const {
101 return additional_info_;
102}
103
104base::Time DiagnosticsTest::GetStartTime() const { return start_time_; }
105
106base::Time DiagnosticsTest::GetEndTime() const { return end_time_; }
107
[email protected]60756be2013-08-07 05:20:26108bool DiagnosticsTest::RecoveryImpl(DiagnosticsModel::Observer* observer) {
109 return true;
[email protected]0c38b262013-08-23 23:34:24110}
[email protected]60756be2013-08-07 05:20:26111
[email protected]f22fae42013-07-09 21:11:11112} // namespace diagnostics