OLD | NEW |
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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // 2- Overriding RunTest() to wrap it with the appropriate fatal exception | 44 // 2- Overriding RunTest() to wrap it with the appropriate fatal exception |
45 // handler for the OS. | 45 // handler for the OS. |
46 // 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 |
47 // destruction. | 47 // destruction. |
48 class DiagnosticsModelImpl : public DiagnosticsModel { | 48 class DiagnosticsModelImpl : public DiagnosticsModel { |
49 public: | 49 public: |
50 DiagnosticsModelImpl() : tests_run_(0) {} | 50 DiagnosticsModelImpl() : tests_run_(0) {} |
51 | 51 |
52 virtual ~DiagnosticsModelImpl() { STLDeleteElements(&tests_); } | 52 virtual ~DiagnosticsModelImpl() { STLDeleteElements(&tests_); } |
53 | 53 |
54 virtual int GetTestRunCount() const OVERRIDE { return tests_run_; } | 54 virtual int GetTestRunCount() const override { return tests_run_; } |
55 | 55 |
56 virtual int GetTestAvailableCount() const OVERRIDE { return tests_.size(); } | 56 virtual int GetTestAvailableCount() const override { return tests_.size(); } |
57 | 57 |
58 virtual void RunAll(DiagnosticsModel::Observer* observer) OVERRIDE { | 58 virtual void RunAll(DiagnosticsModel::Observer* observer) override { |
59 size_t test_count = tests_.size(); | 59 size_t test_count = tests_.size(); |
60 bool continue_running = true; | 60 bool continue_running = true; |
61 for (size_t i = 0; i != test_count; ++i) { | 61 for (size_t i = 0; i != test_count; ++i) { |
62 // If one of the diagnostic steps returns false, we want to | 62 // If one of the diagnostic steps returns false, we want to |
63 // mark the rest of them as "skipped" in the UMA stats. | 63 // mark the rest of them as "skipped" in the UMA stats. |
64 if (continue_running) { | 64 if (continue_running) { |
65 continue_running = RunTest(tests_[i], observer, i); | 65 continue_running = RunTest(tests_[i], observer, i); |
66 ++tests_run_; | 66 ++tests_run_; |
67 } else { | 67 } else { |
68 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS | 68 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS |
69 RecordUMATestResult(static_cast<DiagnosticsTestId>(tests_[i]->GetId()), | 69 RecordUMATestResult(static_cast<DiagnosticsTestId>(tests_[i]->GetId()), |
70 RESULT_SKIPPED); | 70 RESULT_SKIPPED); |
71 #else | 71 #else |
72 // On other platforms, we can just bail out if a diagnostic step returns | 72 // On other platforms, we can just bail out if a diagnostic step returns |
73 // false. | 73 // false. |
74 break; | 74 break; |
75 #endif | 75 #endif |
76 } | 76 } |
77 } | 77 } |
78 if (observer) | 78 if (observer) |
79 observer->OnAllTestsDone(this); | 79 observer->OnAllTestsDone(this); |
80 } | 80 } |
81 | 81 |
82 virtual void RecoverAll(DiagnosticsModel::Observer* observer) OVERRIDE { | 82 virtual void RecoverAll(DiagnosticsModel::Observer* observer) override { |
83 size_t test_count = tests_.size(); | 83 size_t test_count = tests_.size(); |
84 bool continue_running = true; | 84 bool continue_running = true; |
85 for (size_t i = 0; i != test_count; ++i) { | 85 for (size_t i = 0; i != test_count; ++i) { |
86 // If one of the recovery steps returns false, we want to | 86 // If one of the recovery steps returns false, we want to |
87 // mark the rest of them as "skipped" in the UMA stats. | 87 // mark the rest of them as "skipped" in the UMA stats. |
88 if (continue_running) { | 88 if (continue_running) { |
89 continue_running = RunRecovery(tests_[i], observer, i); | 89 continue_running = RunRecovery(tests_[i], observer, i); |
90 } else { | 90 } else { |
91 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS | 91 #if defined(OS_CHROMEOS) // Only collecting UMA stats on ChromeOS |
92 RecordUMARecoveryResult( | 92 RecordUMARecoveryResult( |
93 static_cast<DiagnosticsTestId>(tests_[i]->GetId()), RESULT_SKIPPED); | 93 static_cast<DiagnosticsTestId>(tests_[i]->GetId()), RESULT_SKIPPED); |
94 #else | 94 #else |
95 // On other platforms, we can just bail out if a recovery step returns | 95 // On other platforms, we can just bail out if a recovery step returns |
96 // false. | 96 // false. |
97 break; | 97 break; |
98 #endif | 98 #endif |
99 } | 99 } |
100 } | 100 } |
101 if (observer) | 101 if (observer) |
102 observer->OnAllRecoveryDone(this); | 102 observer->OnAllRecoveryDone(this); |
103 } | 103 } |
104 | 104 |
105 virtual const TestInfo& GetTest(size_t index) const OVERRIDE { | 105 virtual const TestInfo& GetTest(size_t index) const override { |
106 return *tests_[index]; | 106 return *tests_[index]; |
107 } | 107 } |
108 | 108 |
109 virtual bool GetTestInfo(int id, const TestInfo** result) const OVERRIDE { | 109 virtual bool GetTestInfo(int id, const TestInfo** result) const override { |
110 DCHECK(id < DIAGNOSTICS_TEST_ID_COUNT); | 110 DCHECK(id < DIAGNOSTICS_TEST_ID_COUNT); |
111 DCHECK(id >= 0); | 111 DCHECK(id >= 0); |
112 for (size_t i = 0; i < tests_.size(); i++) { | 112 for (size_t i = 0; i < tests_.size(); i++) { |
113 if (tests_[i]->GetId() == id) { | 113 if (tests_[i]->GetId() == id) { |
114 *result = tests_[i]; | 114 *result = tests_[i]; |
115 return true; | 115 return true; |
116 } | 116 } |
117 } | 117 } |
118 return false; | 118 return false; |
119 } | 119 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 #if defined(OS_WIN) | 236 #if defined(OS_WIN) |
237 return new DiagnosticsModelWin(); | 237 return new DiagnosticsModelWin(); |
238 #elif defined(OS_MACOSX) | 238 #elif defined(OS_MACOSX) |
239 return new DiagnosticsModelMac(); | 239 return new DiagnosticsModelMac(); |
240 #elif defined(OS_POSIX) | 240 #elif defined(OS_POSIX) |
241 return new DiagnosticsModelPosix(); | 241 return new DiagnosticsModelPosix(); |
242 #endif | 242 #endif |
243 } | 243 } |
244 | 244 |
245 } // namespace diagnostics | 245 } // namespace diagnostics |
OLD | NEW |