• 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_MODEL_H_
6 #define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_
7 
8 #include <string>
9 #include "base/time/time.h"
10 
11 class CommandLine;
12 
13 namespace diagnostics {
14 
15 // The chrome diagnostics system is a model-view-controller system. The Model
16 // responsible for holding and running the individual tests and providing a
17 // uniform interface for querying the outcome.
18 class DiagnosticsModel {
19  public:
20   // A particular test can be in one of the following states.
21   enum TestResult {
22     TEST_NOT_RUN,
23     TEST_RUNNING,
24     TEST_OK,
25     TEST_FAIL_CONTINUE,
26     TEST_FAIL_STOP,
27     RECOVERY_RUNNING,
28     RECOVERY_OK,
29     RECOVERY_FAIL_STOP,
30   };
31 
32   // Number of diagnostic tests available on the current platform. To be used
33   // only by tests to verify that the right number of tests were run.
34   static const int kDiagnosticsTestCount;
35 
36   // Observer derived form this class which provides a way to be notified of
37   // changes to the model as the tests are run. For all the callbacks |id|
38   // is the index of the test in question and information can be obtained by
39   // calling model->GetTest(id).
40   class Observer {
41    public:
~Observer()42     virtual ~Observer() {}
43     // Called when a test has finished, regardless of outcome.
44     virtual void OnTestFinished(int index, DiagnosticsModel* model) = 0;
45     // Called once all the test are run.
46     virtual void OnAllTestsDone(DiagnosticsModel* model) = 0;
47     // Called when a recovery has finished regardless of outcome.
48     virtual void OnRecoveryFinished(int index, DiagnosticsModel* model) = 0;
49     // Called once all the recoveries are run.
50     virtual void OnAllRecoveryDone(DiagnosticsModel* model) = 0;
51   };
52 
53   // Encapsulates what you can know about a given test.
54   class TestInfo {
55    public:
~TestInfo()56     virtual ~TestInfo() {}
57     // A numerical id for this test. Must be a unique number among all the
58     // tests.
59     virtual int GetId() const = 0;
60     // A parse-able ASCII string that indicates what is being tested.
61     virtual std::string GetName() const = 0;
62     // A human readable string that tells you what is being tested.
63     // This is not localized: it is only meant for developer consumption.
64     virtual std::string GetTitle() const = 0;
65     // The result of running the test. If called before the test is ran the
66     // answer is TEST_NOT_RUN.
67     virtual TestResult GetResult() const = 0;
68     // A human readable string that tells you more about what happened. If
69     // called before the test is run it returns the empty string.
70     // This is not localized: it is only meant for developer consumption.
71     virtual std::string GetAdditionalInfo() const = 0;
72     // A test-specific code representing what happened. If called before the
73     // test is run, it should return -1.
74     virtual int GetOutcomeCode() const = 0;
75     // Returns the system time when the test was performed.
76     virtual base::Time GetStartTime() const = 0;
77     // Returns the system time when the test was finished.
78     virtual base::Time GetEndTime() const = 0;
79   };
80 
~DiagnosticsModel()81   virtual ~DiagnosticsModel() {}
82   // Returns how many tests have been run.
83   virtual int GetTestRunCount() const = 0;
84   // Returns how many tests are available. This value never changes.
85   virtual int GetTestAvailableCount() const = 0;
86   // Runs all the available tests, the |observer| callbacks will be called as
87   // the diagnostics progress. |observer| maybe NULL if no observation is
88   // needed.
89   virtual void RunAll(DiagnosticsModel::Observer* observer) = 0;
90   // Attempt to recover from any failures discovered by testing.
91   virtual void RecoverAll(DiagnosticsModel::Observer* observer) = 0;
92   // Get the information for a particular test. Lifetime of returned object is
93   // limited to the lifetime of this model.
94   virtual const TestInfo& GetTest(size_t index) const = 0;
95   // Get the information for a test with given numerical |id|. Lifetime of
96   // returned object is limited to the lifetime of this model. Returns false if
97   // there is no such id. |result| may not be NULL.
98   virtual bool GetTestInfo(int id, const TestInfo** result) const = 0;
99 };
100 
101 // The factory for the model. The main purpose is to hide the creation of
102 // different models for different platforms.
103 DiagnosticsModel* MakeDiagnosticsModel(const CommandLine& cmdline);
104 
105 }  // namespace diagnostics
106 
107 #endif  // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_
108