Home | History | Annotate | Download | only in diagnostics
      1 // Copyright 2013 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_WRITER_H_
      6 #define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_WRITER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "chrome/browser/diagnostics/diagnostics_model.h"
     11 
     12 namespace diagnostics {
     13 
     14 // Console base class used internally.
     15 class SimpleConsole;
     16 
     17 class DiagnosticsWriter : public DiagnosticsModel::Observer {
     18  public:
     19   // The type of formatting done by this writer.
     20   enum FormatType {
     21     MACHINE,
     22     LOG,
     23     HUMAN
     24   };
     25 
     26   explicit DiagnosticsWriter(FormatType format);
     27   virtual ~DiagnosticsWriter();
     28 
     29   // How many tests reported failure.
     30   int failures() { return failures_; }
     31 
     32   // What format are we writing things in.
     33   FormatType format() const { return format_; }
     34 
     35   // Write an informational line of text in white over black. String must be
     36   // UTF8 encoded. A newline will be added for non-LOG output formats.
     37   bool WriteInfoLine(const std::string& info_text);
     38 
     39   // DiagnosticsModel::Observer overrides
     40   virtual void OnTestFinished(int index, DiagnosticsModel* model) OVERRIDE;
     41   virtual void OnAllTestsDone(DiagnosticsModel* model) OVERRIDE;
     42   virtual void OnRecoveryFinished(int index, DiagnosticsModel* model) OVERRIDE;
     43   virtual void OnAllRecoveryDone(DiagnosticsModel* model) OVERRIDE;
     44 
     45  private:
     46   // Write a result block. For humans, it consists of two lines. The first line
     47   // has [PASS] or [FAIL] with |name| and the second line has the text in
     48   // |extra|. For machine and log formats, we just have [PASS] or [FAIL],
     49   // followed by the exact error code and the id. Name and extra strings must be
     50   // UTF8 encoded, as they are user-facing strings.
     51   bool WriteResult(bool success,
     52                    const std::string& id,
     53                    const std::string& name,
     54                    int outcome_code,
     55                    const std::string& extra);
     56 
     57   scoped_ptr<SimpleConsole> console_;
     58 
     59   // Keeps track of how many tests reported failure.
     60   int failures_;
     61   FormatType format_;
     62 
     63   DISALLOW_COPY_AND_ASSIGN(DiagnosticsWriter);
     64 };
     65 
     66 }  // namespace diagnostics
     67 
     68 #endif  // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_WRITER_H_
     69