Home | History | Annotate | Download | only in diagnostics
      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 #pragma once
      8 
      9 #include "base/string16.h"
     10 
     11 class CommandLine;
     12 
     13 // The chrome diagnostics system is a model-view-controller system. The Model
     14 // responsible for holding and running the individual tests and providing a
     15 // uniform interface for querying the outcome.
     16 // TODO(cpu): The view and the controller are not yet built.
     17 class DiagnosticsModel {
     18  public:
     19   // A particular test can be in one of the following states.
     20   enum TestResult {
     21     TEST_NOT_RUN,
     22     TEST_RUNNING,
     23     TEST_OK,
     24     TEST_FAIL_CONTINUE,
     25     TEST_FAIL_STOP,
     26   };
     27 
     28   // Observer derived form this class which provides a way to be notified of
     29   // changes to the model as the tests are run. For all the callbacks |id|
     30   // is the index of the test in question and information can be obtained by
     31   // calling model->GetTest(id).
     32   class Observer {
     33    public:
     34     virtual ~Observer() {}
     35     // Called once upon test start with |percent| = 0 and periodically as the
     36     // test progresses. There is no cancellation method.
     37     virtual void OnProgress(int id, int percent, DiagnosticsModel* model) = 0;
     38     // Called if the test in question cannot be run.
     39     virtual void OnSkipped(int id, DiagnosticsModel* model) = 0;
     40     // Called when the test has finished regardless of outcome.
     41     virtual void OnFinished(int id, DiagnosticsModel* model) = 0;
     42     // Called once all the test are run.
     43     virtual void OnDoneAll(DiagnosticsModel* model) = 0;
     44   };
     45 
     46   // Encapsulates what you can know about a given test.
     47   class TestInfo {
     48    public:
     49     virtual ~TestInfo() {}
     50     // A human readable, localized string that tells you what is being tested.
     51     virtual string16 GetTitle() = 0;
     52     // The result of running the test. If called before the test is ran the
     53     // answer is TEST_NOT_RUN.
     54     virtual TestResult GetResult() = 0;
     55     // A human readable, localized string that tells you what happened. If
     56     // called before the test is run it returns the empty string.
     57     virtual string16 GetAdditionalInfo() = 0;
     58   };
     59 
     60   virtual ~DiagnosticsModel() {}
     61   // Returns how many tests have been run.
     62   virtual int GetTestRunCount() = 0;
     63   // Returns how many tests are available. This value never changes.
     64   virtual int GetTestAvailableCount() =0;
     65   // Runs all the available tests, the |observer| callbacks will be called as
     66   // the test progress and thus cannot be null.
     67   virtual void RunAll(DiagnosticsModel::Observer* observer) = 0;
     68   // Get the information for a particular test. Do not keep a pointer to the
     69   // returned object.
     70   virtual TestInfo& GetTest(size_t id) = 0;
     71 };
     72 
     73 // The factory for the model. The main purpose is to hide the creation of
     74 // different models for different platforms.
     75 DiagnosticsModel* MakeDiagnosticsModel(const CommandLine& cmdline);
     76 
     77 
     78 #endif  // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_
     79