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

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

Issue 16948012: This adds a recovery mode to the diagnostics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload after merge Created 7 years, 4 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/diagnostics/diagnostics_model.h" 5 #include "chrome/browser/diagnostics/diagnostics_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "chrome/browser/diagnostics/diagnostics_test.h" 16 #include "chrome/browser/diagnostics/diagnostics_test.h"
17 #include "chrome/browser/diagnostics/recon_diagnostics.h" 17 #include "chrome/browser/diagnostics/recon_diagnostics.h"
18 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" 18 #include "chrome/browser/diagnostics/sqlite_diagnostics.h"
19 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 21
22 namespace diagnostics { 22 namespace diagnostics {
23 23
24 // This is the count of diagnostic tests on each platform. This should
25 // only be used by testing code.
26 #if defined(OS_WIN)
27 const int DiagnosticsModel::kDiagnosticsTestCount = 19;
28 #elif defined(OS_MACOSX)
29 const int DiagnosticsModel::kDiagnosticsTestCount = 15;
30 #elif defined(OS_POSIX)
31 #if defined(OS_CHROMEOS)
32 const int DiagnosticsModel::kDiagnosticsTestCount = 19;
33 #else
34 const int DiagnosticsModel::kDiagnosticsTestCount = 17;
35 #endif
36 #endif
37
24 namespace { 38 namespace {
25 39
26 // Embodies the commonalities of the model across platforms. It manages the 40 // Embodies the commonalities of the model across platforms. It manages the
27 // list of tests and can loop over them. The main job of the platform specific 41 // list of tests and can loop over them. The main job of the platform specific
28 // code becomes: 42 // code becomes:
29 // 1- Inserting the appropriate tests into |tests_| 43 // 1- Inserting the appropriate tests into |tests_|
30 // 2- Overriding RunTest() to wrap it with the appropriate fatal exception 44 // 2- Overriding RunTest() to wrap it with the appropriate fatal exception
31 // handler for the OS. 45 // handler for the OS.
32 // This class owns the all the tests and will only delete them upon 46 // This class owns the all the tests and will only delete them upon
33 // destruction. 47 // destruction.
(...skipping 15 matching lines...) Expand all
49 63
50 virtual void RunAll(DiagnosticsModel::Observer* observer) OVERRIDE { 64 virtual void RunAll(DiagnosticsModel::Observer* observer) OVERRIDE {
51 size_t test_count = tests_.size(); 65 size_t test_count = tests_.size();
52 for (size_t ix = 0; ix != test_count; ++ix) { 66 for (size_t ix = 0; ix != test_count; ++ix) {
53 bool do_next = RunTest(tests_[ix], observer, ix); 67 bool do_next = RunTest(tests_[ix], observer, ix);
54 ++tests_run_; 68 ++tests_run_;
55 if (!do_next) 69 if (!do_next)
56 break; 70 break;
57 } 71 }
58 if (observer) 72 if (observer)
59 observer->OnDoneAll(this); 73 observer->OnAllTestsDone(this);
60 } 74 }
61 75
62 virtual const TestInfo& GetTest(size_t index) OVERRIDE { 76 virtual void RecoverAll(DiagnosticsModel::Observer* observer) OVERRIDE {
77 size_t test_count = tests_.size();
78 for (size_t i = 0; i != test_count; ++i) {
79 bool do_next = RunRecovery(tests_[i], observer, i);
80 if (!do_next)
81 break;
82 }
83 if (observer)
84 observer->OnAllRecoveryDone(this);
85 }
86
87 virtual const TestInfo& GetTest(size_t index) const OVERRIDE {
63 return *tests_[index]; 88 return *tests_[index];
64 } 89 }
65 90
91 virtual bool GetTestInfo(const std::string& id,
92 const TestInfo** result) const OVERRIDE {
93 for (size_t i = 0; i < tests_.size(); i++) {
94 if (tests_[i]->GetId() == id) {
95 *result = tests_[i];
96 return true;
97 }
98 }
99 return false;
100 }
101
66 protected: 102 protected:
67 // Run a particular test. Return false if no other tests should be run. 103 // Run a particular diagnostic test. Return false if no other tests should be
104 // run.
68 virtual bool RunTest(DiagnosticsTest* test, 105 virtual bool RunTest(DiagnosticsTest* test,
69 Observer* observer, 106 Observer* observer,
70 size_t index) { 107 size_t index) {
71 return test->Execute(observer, this, index); 108 return test->Execute(observer, this, index);
72 } 109 }
73 110
111 // Recover from a particular diagnostic test. Return false if no further
112 // recovery should be run.
113 virtual bool RunRecovery(DiagnosticsTest* test,
114 Observer* observer,
115 size_t index) {
116 return test->Recover(observer, this, index);
117 }
118
74 typedef std::vector<DiagnosticsTest*> TestArray; 119 typedef std::vector<DiagnosticsTest*> TestArray;
75 TestArray tests_; 120 TestArray tests_;
76 int tests_run_; 121 int tests_run_;
77 122
78 private: 123 private:
79 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelImpl); 124 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelImpl);
80 }; 125 };
81 126
82 // Each platform can have their own tests. For the time being there is only 127 // Each platform can have their own tests. For the time being there is only
83 // one test that works on all platforms. 128 // one test that works on all platforms.
(...skipping 27 matching lines...) Expand all
111 }; 156 };
112 157
113 #elif defined(OS_MACOSX) 158 #elif defined(OS_MACOSX)
114 class DiagnosticsModelMac : public DiagnosticsModelImpl { 159 class DiagnosticsModelMac : public DiagnosticsModelImpl {
115 public: 160 public:
116 DiagnosticsModelMac() { 161 DiagnosticsModelMac() {
117 tests_.push_back(MakeInstallTypeTest()); 162 tests_.push_back(MakeInstallTypeTest());
118 tests_.push_back(MakeUserDirTest()); 163 tests_.push_back(MakeUserDirTest());
119 tests_.push_back(MakeLocalStateFileTest()); 164 tests_.push_back(MakeLocalStateFileTest());
120 tests_.push_back(MakeDictonaryDirTest()); 165 tests_.push_back(MakeDictonaryDirTest());
121 tests_.push_back(MakeResourcesFileTest());
122 tests_.push_back(MakeDiskSpaceTest()); 166 tests_.push_back(MakeDiskSpaceTest());
123 tests_.push_back(MakePreferencesTest()); 167 tests_.push_back(MakePreferencesTest());
124 tests_.push_back(MakeLocalStateTest()); 168 tests_.push_back(MakeLocalStateTest());
125 tests_.push_back(MakeBookMarksTest()); 169 tests_.push_back(MakeBookMarksTest());
126 tests_.push_back(MakeSqliteWebDbTest()); 170 tests_.push_back(MakeSqliteWebDbTest());
127 tests_.push_back(MakeSqliteCookiesDbTest()); 171 tests_.push_back(MakeSqliteCookiesDbTest());
128 tests_.push_back(MakeSqliteHistoryDbTest()); 172 tests_.push_back(MakeSqliteHistoryDbTest());
129 tests_.push_back(MakeSqliteArchivedHistoryDbTest()); 173 tests_.push_back(MakeSqliteArchivedHistoryDbTest());
130 tests_.push_back(MakeSqliteThumbnailsDbTest()); 174 tests_.push_back(MakeSqliteThumbnailsDbTest());
131 tests_.push_back(MakeSqliteAppCacheDbTest()); 175 tests_.push_back(MakeSqliteAppCacheDbTest());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 #if defined(OS_WIN) 223 #if defined(OS_WIN)
180 return new DiagnosticsModelWin(); 224 return new DiagnosticsModelWin();
181 #elif defined(OS_MACOSX) 225 #elif defined(OS_MACOSX)
182 return new DiagnosticsModelMac(); 226 return new DiagnosticsModelMac();
183 #elif defined(OS_POSIX) 227 #elif defined(OS_POSIX)
184 return new DiagnosticsModelPosix(); 228 return new DiagnosticsModelPosix();
185 #endif 229 #endif
186 } 230 }
187 231
188 } // namespace diagnostics 232 } // namespace diagnostics
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