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