OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_ | 5 #ifndef CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_ |
6 #define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_ | 6 #define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 | 10 |
11 class CommandLine; | 11 class CommandLine; |
12 | 12 |
13 namespace diagnostics { | 13 namespace diagnostics { |
14 | 14 |
15 // The chrome diagnostics system is a model-view-controller system. The Model | 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 | 16 // responsible for holding and running the individual tests and providing a |
17 // uniform interface for querying the outcome. | 17 // uniform interface for querying the outcome. |
18 class DiagnosticsModel { | 18 class DiagnosticsModel { |
19 public: | 19 public: |
20 // A particular test can be in one of the following states. | 20 // A particular test can be in one of the following states. |
21 enum TestResult { | 21 enum TestResult { |
22 TEST_NOT_RUN, | 22 TEST_NOT_RUN, |
23 TEST_RUNNING, | 23 TEST_RUNNING, |
24 TEST_OK, | 24 TEST_OK, |
25 TEST_FAIL_CONTINUE, | 25 TEST_FAIL_CONTINUE, |
26 TEST_FAIL_STOP, | 26 TEST_FAIL_STOP, |
| 27 RECOVERY_RUNNING, |
| 28 RECOVERY_OK, |
| 29 RECOVERY_FAIL_STOP, |
27 }; | 30 }; |
28 | 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 |
29 // Observer derived form this class which provides a way to be notified of | 36 // Observer derived form this class which provides a way to be notified of |
30 // changes to the model as the tests are run. For all the callbacks |id| | 37 // changes to the model as the tests are run. For all the callbacks |id| |
31 // is the index of the test in question and information can be obtained by | 38 // is the index of the test in question and information can be obtained by |
32 // calling model->GetTest(id). | 39 // calling model->GetTest(id). |
33 class Observer { | 40 class Observer { |
34 public: | 41 public: |
35 virtual ~Observer() {} | 42 virtual ~Observer() {} |
36 // Called when a test has finished regardless of outcome. | 43 // Called when a test has finished, regardless of outcome. |
37 virtual void OnFinished(int index, DiagnosticsModel* model) = 0; | 44 virtual void OnTestFinished(int index, DiagnosticsModel* model) = 0; |
38 // Called once all the test are run. | 45 // Called once all the test are run. |
39 virtual void OnDoneAll(DiagnosticsModel* model) = 0; | 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; |
40 }; | 51 }; |
41 | 52 |
42 // Encapsulates what you can know about a given test. | 53 // Encapsulates what you can know about a given test. |
43 class TestInfo { | 54 class TestInfo { |
44 public: | 55 public: |
45 virtual ~TestInfo() {} | 56 virtual ~TestInfo() {} |
46 // A parse-able ASCII string that indicates what is being tested. | 57 // A parse-able ASCII string that indicates what is being tested. |
47 virtual std::string GetId() const = 0; | 58 virtual std::string GetId() const = 0; |
48 // A human readable string that tells you what is being tested. | 59 // A human readable string that tells you what is being tested. |
49 // This is not localized: it is only meant for developer consumption. | 60 // This is not localized: it is only meant for developer consumption. |
(...skipping 16 matching lines...) Expand all Loading... |
66 | 77 |
67 virtual ~DiagnosticsModel() {} | 78 virtual ~DiagnosticsModel() {} |
68 // Returns how many tests have been run. | 79 // Returns how many tests have been run. |
69 virtual int GetTestRunCount() const = 0; | 80 virtual int GetTestRunCount() const = 0; |
70 // Returns how many tests are available. This value never changes. | 81 // Returns how many tests are available. This value never changes. |
71 virtual int GetTestAvailableCount() const = 0; | 82 virtual int GetTestAvailableCount() const = 0; |
72 // Runs all the available tests, the |observer| callbacks will be called as | 83 // Runs all the available tests, the |observer| callbacks will be called as |
73 // the diagnostics progress. |observer| maybe NULL if no observation is | 84 // the diagnostics progress. |observer| maybe NULL if no observation is |
74 // needed. | 85 // needed. |
75 virtual void RunAll(DiagnosticsModel::Observer* observer) = 0; | 86 virtual void RunAll(DiagnosticsModel::Observer* observer) = 0; |
| 87 // Attempt to recover from any failures discovered by testing. |
| 88 virtual void RecoverAll(DiagnosticsModel::Observer* observer) = 0; |
76 // Get the information for a particular test. Lifetime of returned object is | 89 // Get the information for a particular test. Lifetime of returned object is |
77 // limited to the lifetime of this model. | 90 // limited to the lifetime of this model. |
78 virtual const TestInfo& GetTest(size_t index) = 0; | 91 virtual const TestInfo& GetTest(size_t index) const = 0; |
| 92 // Get the information for a test with given |id|. Lifetime of returned object |
| 93 // is limited to the lifetime of this model. Returns false if there is no such |
| 94 // id. |result| may not be NULL. |
| 95 virtual bool GetTestInfo(const std::string& id, |
| 96 const TestInfo** result) const = 0; |
79 }; | 97 }; |
80 | 98 |
81 // The factory for the model. The main purpose is to hide the creation of | 99 // The factory for the model. The main purpose is to hide the creation of |
82 // different models for different platforms. | 100 // different models for different platforms. |
83 DiagnosticsModel* MakeDiagnosticsModel(const CommandLine& cmdline); | 101 DiagnosticsModel* MakeDiagnosticsModel(const CommandLine& cmdline); |
84 | 102 |
85 } // namespace diagnostics | 103 } // namespace diagnostics |
86 | 104 |
87 #endif // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_ | 105 #endif // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_ |
OLD | NEW |