• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_
6 #define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_
7 
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/diagnostics/diagnostics_metrics.h"
10 #include "chrome/browser/diagnostics/diagnostics_model.h"
11 
12 namespace base {
13 class FilePath;
14 }
15 
16 namespace diagnostics {
17 
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);
31 
32   virtual ~DiagnosticsTest();
33 
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);
38 
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);
43 
RecordStopFailure(int outcome_code,const std::string & additional_info)44   void RecordStopFailure(int outcome_code, const std::string& additional_info) {
45     RecordOutcome(
46         outcome_code, additional_info, DiagnosticsModel::TEST_FAIL_STOP);
47   }
48 
RecordFailure(int outcome_code,const std::string & additional_info)49   void RecordFailure(int outcome_code, const std::string& additional_info) {
50     RecordOutcome(
51         outcome_code, additional_info, DiagnosticsModel::TEST_FAIL_CONTINUE);
52   }
53 
RecordSuccess(const std::string & additional_info)54   void RecordSuccess(const std::string& additional_info) {
55     RecordOutcome(0, additional_info, DiagnosticsModel::TEST_OK);
56   }
57 
58   void RecordOutcome(int outcome_code,
59                      const std::string& additional_info,
60                      DiagnosticsModel::TestResult result);
61 
62   static base::FilePath GetUserDefaultProfileDir();
63 
64   // DiagnosticsModel::TestInfo overrides
65   virtual int GetId() const OVERRIDE;
66   virtual std::string GetName() const OVERRIDE;
67   virtual std::string GetTitle() const OVERRIDE;
68   virtual DiagnosticsModel::TestResult GetResult() const OVERRIDE;
69   virtual std::string GetAdditionalInfo() const OVERRIDE;
70   virtual int GetOutcomeCode() const OVERRIDE;
71   virtual base::Time GetStartTime() const OVERRIDE;
72   virtual base::Time GetEndTime() const OVERRIDE;
73  protected:
74   // Derived classes override this method do perform the actual test.
75   virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) = 0;
76 
77   // Derived classes may override this method to perform a recovery, if recovery
78   // makes sense for the diagnostics test.
79   virtual bool RecoveryImpl(DiagnosticsModel::Observer* observer);
80 
81   const DiagnosticsTestId id_;
82   std::string additional_info_;
83   int outcome_code_;
84   DiagnosticsModel::TestResult result_;
85   base::Time start_time_;
86   base::Time end_time_;
87 };
88 
89 }  // namespace diagnostics
90 #endif  // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_
91