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 #ifndef CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_
6 #define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/diagnostics/diagnostics_metrics.h"
10 #include "chrome/browser/diagnostics/diagnostics_model.h"
16 namespace diagnostics
{
18 // Represents a single diagnostic test and encapsulates the common
19 // functionality across platforms as well.
20 // It also implements the TestInfo interface providing the storage
21 // for the outcome of the test.
22 // Specific tests need (minimally) only to:
23 // 1- override ExecuteImpl() to implement the test.
24 // 2- call RecordStopFailure() or RecordFailure() or RecordSuccess()
25 // at the end of the test.
26 // 3- Optionally call observer->OnProgress() if the test is long.
27 // 4- Optionally call observer->OnSkipped() if the test cannot be run.
28 class DiagnosticsTest
: public DiagnosticsModel::TestInfo
{
30 explicit DiagnosticsTest(DiagnosticsTestId id
);
32 ~DiagnosticsTest() override
;
34 // Runs the test. Returning false signals that no more tests should be run.
35 // The actual outcome of the test should be set using the RecordXX functions.
36 bool Execute(DiagnosticsModel::Observer
* observer
, DiagnosticsModel
* model
,
39 // Runs any recovery steps for the test. Returning false signals that no more
40 // recovery should be attempted.
41 bool Recover(DiagnosticsModel::Observer
* observer
, DiagnosticsModel
* model
,
44 void RecordStopFailure(int outcome_code
, const std::string
& additional_info
) {
46 outcome_code
, additional_info
, DiagnosticsModel::TEST_FAIL_STOP
);
49 void RecordFailure(int outcome_code
, const std::string
& additional_info
) {
51 outcome_code
, additional_info
, DiagnosticsModel::TEST_FAIL_CONTINUE
);
54 void RecordSuccess(const std::string
& additional_info
) {
55 RecordOutcome(0, additional_info
, DiagnosticsModel::TEST_OK
);
58 void RecordOutcome(int outcome_code
,
59 const std::string
& additional_info
,
60 DiagnosticsModel::TestResult result
);
62 static base::FilePath
GetUserDefaultProfileDir();
64 // DiagnosticsModel::TestInfo overrides
65 int GetId() const override
;
66 std::string
GetName() const override
;
67 std::string
GetTitle() const override
;
68 DiagnosticsModel::TestResult
GetResult() const override
;
69 std::string
GetAdditionalInfo() const override
;
70 int GetOutcomeCode() const override
;
71 base::Time
GetStartTime() const override
;
72 base::Time
GetEndTime() const override
;
75 // Derived classes override this method do perform the actual test.
76 virtual bool ExecuteImpl(DiagnosticsModel::Observer
* observer
) = 0;
78 // Derived classes may override this method to perform a recovery, if recovery
79 // makes sense for the diagnostics test.
80 virtual bool RecoveryImpl(DiagnosticsModel::Observer
* observer
);
82 const DiagnosticsTestId id_
;
83 std::string additional_info_
;
85 DiagnosticsModel::TestResult result_
;
86 base::Time start_time_
;
90 } // namespace diagnostics
91 #endif // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_