diagnostics_controller.h revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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_CONTROLLER_H_
6#define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_CONTROLLER_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "base/memory/singleton.h"
10
11class CommandLine;
12
13namespace diagnostics {
14
15class DiagnosticsWriter;
16class DiagnosticsModel;
17
18class DiagnosticsController {
19 public:
20  static DiagnosticsController* GetInstance();
21
22  // Entry point for the diagnostics mode. Returns zero if able to run
23  // diagnostics successfully, regardless of the results of the diagnostics.
24  int Run(const CommandLine& command_line, DiagnosticsWriter* writer);
25
26  // Entry point for running recovery based on diagnostics that have already
27  // been run. In order for this to do anything, Run() must be executed first.
28  int RunRecovery(const CommandLine& command_line, DiagnosticsWriter* writer);
29
30  // Returns a model with the results that have accumulated. They can then be
31  // queried for their attributes for human consumption later.
32  const DiagnosticsModel& GetResults() const;
33
34  // Returns true if there are any results available.
35  bool HasResults();
36
37  // Clears any results that have accumulated. After calling this, do not call
38  // GetResults until after Run is called again.
39  void ClearResults();
40
41  // Records UMA statistics indicating that a regular Chrome startup happened,
42  // with no diagnostics or recovery being run.  This is necessary to provide a
43  // denominator for the diagnostics metrics.
44  void RecordRegularStartup();
45
46 private:
47  friend struct DefaultSingletonTraits<DiagnosticsController>;
48
49  DiagnosticsController();
50  ~DiagnosticsController();
51
52  scoped_ptr<DiagnosticsModel> model_;
53  DiagnosticsWriter* writer_;
54
55  DISALLOW_COPY_AND_ASSIGN(DiagnosticsController);
56};
57
58}  // namespace diagnostics
59
60#endif  // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_CONTROLLER_H_
61