Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: chrome/browser/diagnostics/diagnostics_model.cc

Issue 385144: Introducing the diagnostic model classes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 #include "chrome/browser/diagnostics/diagnostics_model.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/file_util.h"
12 #include "base/stl_util-inl.h"
13 #include "base/string_util.h"
14 #include "base/path_service.h"
15 #include "chrome/browser/diagnostics/diagnostics_test.h"
16 #include "chrome/common/chrome_paths.h"
17
18 namespace {
19
20 // Embodies the commonalities of the model across platforms. It manages the
21 // list of tests and can loop over them. The main job of the platform specific
22 // code becomes:
23 // 1- Inserting the appropiate tests into |tests_|
24 // 2- Overriding RunTest() to wrap it with the appropiate fatal exception
25 // handler for the OS.
26 // This class owns the all the tests and will only delete them upon
27 // destruction.
28 class DiagnosticsModelImpl : public DiagnosticsModel {
29 public:
30 DiagnosticsModelImpl() : tests_run_(0) {
31 }
32
33 ~DiagnosticsModelImpl() {
34 STLDeleteElements(&tests_);
35 }
36
37 virtual int GetTestRunCount() {
38 return tests_run_;
39 }
40
41 virtual int GetTestAvailableCount() {
42 return tests_.size();
43 }
44
45 virtual void RunAll(DiagnosticsModel::Observer* observer) {
46 size_t test_count = tests_.size();
47 for (size_t ix = 0; ix != test_count; ++ix) {
48 bool do_next = RunTest(tests_[ix], observer);
49 ++tests_run_;
50 if (!do_next)
51 break;
52 }
53 observer->OnDoneAll(this);
54 }
55
56 virtual TestInfo& GetTest(size_t id) {
57 return *tests_[id];
58 }
59
60 protected:
61 // Run a particular test. Return false if no other tests should be run.
62 virtual bool RunTest(DiagnosticTest* test, Observer* observer) {
63 return test->Execute(observer, this);
64 }
65
66 typedef std::vector<DiagnosticTest*> TestArray;
67 TestArray tests_;
68 int tests_run_;
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelImpl);
72 };
73
74 // Simple basic diagnostic test. Check that the user's data directory
75 // exists. This test works for all platforms.
76 // TODO(cpu): Move to its final place.
77 // TODO(cpu): Localize strings.
78 class UserPathsTest : public DiagnosticTest {
79 public:
80 UserPathsTest() : DiagnosticTest(ASCIIToUTF16("User Directory")) {}
81
82 // Not used at the moment but it allows one test to query the status
83 // of another test so we can build test dependencies.
84 virtual int GetId() { return 0; }
85
86 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
87 FilePath data_dir;
88 if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir)) {
89 RecordStopFailure(ASCIIToUTF16("Path provider failure"));
90 return false;
91 }
92 if (!file_util::PathExists(data_dir)) {
93 RecordFailure(ASCIIToUTF16("No user data dir found"));
94 return true;
95 }
96 RecordSuccess(ASCIIToUTF16("Directory found"));
97 return true;
98 }
99
100 private:
101 DISALLOW_COPY_AND_ASSIGN(UserPathsTest);
102 };
103
104 // Each platform can have their own tests. For the time being there is only
105 // one test that works on all platforms.
106 #if defined(OS_WIN)
107 class DiagnosticsModelWin : public DiagnosticsModelImpl {
108 public:
109 DiagnosticsModelWin() {
110 tests_.push_back(new UserPathsTest());
111 }
112
113 private:
114 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelWin);
115 };
116
117 #elif defined(OS_MACOSX)
118 class DiagnosticsModelMac : public DiagnosticsModelImpl {
119 public:
120 DiagnosticsModelMac() {
121 tests_.push_back(new UserPathsTest());
122 }
123 private:
124 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelMac);
125 };
126
127 #elif defined(OS_LINUX)
128 class DiagnosticsModelLinux : public DiagnosticsModelImpl {
129 public:
130 DiagnosticsModelLinux() {
131 tests_.push_back(new UserPathsTest());
132 }
133 private:
134 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelLinux);
135 };
136
137 #endif
138
139 } // namespace
140
141 DiagnosticsModel* MakeDiagnosticsModel() {
142 #if defined(OS_WIN)
143 return new DiagnosticsModelWin();
144 #elif defined(OS_MACOSX)
145 return new DiagnosticsModelMac();
146 #elif defined(OS_LINUX)
147 return new DiagnosticsModelLinux();
148 #endif
149 }
OLDNEW
« no previous file with comments | « chrome/browser/diagnostics/diagnostics_model.h ('k') | chrome/browser/diagnostics/diagnostics_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698