Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / diagnostics / diagnostics_test.h
blobd2e51449fda9d97040a1b4b2ebeba8996cfae7ce
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"
12 namespace base {
13 class FilePath;
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 {
29 public:
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,
37 size_t index);
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,
42 size_t index);
44 void RecordStopFailure(int outcome_code, const std::string& additional_info) {
45 RecordOutcome(
46 outcome_code, additional_info, DiagnosticsModel::TEST_FAIL_STOP);
49 void RecordFailure(int outcome_code, const std::string& additional_info) {
50 RecordOutcome(
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;
74 protected:
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_;
84 int outcome_code_;
85 DiagnosticsModel::TestResult result_;
86 base::Time start_time_;
87 base::Time end_time_;
90 } // namespace diagnostics
91 #endif // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_