OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/recon_diagnostics.h" | 5 #include "chrome/browser/diagnostics/recon_diagnostics.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <string> | 10 #include <string> |
8 | 11 |
9 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
11 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
| 15 #include "base/macros.h" |
12 #include "base/path_service.h" | 16 #include "base/path_service.h" |
13 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
17 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
| 22 #include "build/build_config.h" |
18 #include "chrome/browser/diagnostics/diagnostics_test.h" | 23 #include "chrome/browser/diagnostics/diagnostics_test.h" |
19 #include "chrome/common/channel_info.h" | 24 #include "chrome/common/channel_info.h" |
20 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
22 #include "components/bookmarks/common/bookmark_constants.h" | 27 #include "components/bookmarks/common/bookmark_constants.h" |
23 #include "components/version_info/version_info.h" | 28 #include "components/version_info/version_info.h" |
24 | 29 |
25 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
26 #include "base/win/windows_version.h" | 31 #include "base/win/windows_version.h" |
27 #include "chrome/browser/enumerate_modules_model_win.h" | 32 #include "chrome/browser/enumerate_modules_model_win.h" |
28 #include "chrome/installer/util/install_util.h" | 33 #include "chrome/installer/util/install_util.h" |
29 #endif | 34 #endif |
30 | 35 |
31 // Reconnaissance diagnostics. These are the first and most critical | 36 // Reconnaissance diagnostics. These are the first and most critical |
32 // diagnostic tests. Here we check for the existence of critical files. | 37 // diagnostic tests. Here we check for the existence of critical files. |
33 // TODO(cpu): Define if it makes sense to localize strings. | 38 // TODO(cpu): Define if it makes sense to localize strings. |
34 | 39 |
35 // TODO(cpu): There are a few maximum file sizes hard-coded in this file | 40 // TODO(cpu): There are a few maximum file sizes hard-coded in this file |
36 // that have little or no theoretical or experimental ground. Find a way | 41 // that have little or no theoretical or experimental ground. Find a way |
37 // to justify them. | 42 // to justify them. |
38 | 43 |
39 namespace diagnostics { | 44 namespace diagnostics { |
40 | 45 |
41 namespace { | 46 namespace { |
42 | 47 |
43 const int64 kOneKilobyte = 1024; | 48 const int64_t kOneKilobyte = 1024; |
44 const int64 kOneMegabyte = 1024 * kOneKilobyte; | 49 const int64_t kOneMegabyte = 1024 * kOneKilobyte; |
45 | 50 |
46 class InstallTypeTest; | 51 class InstallTypeTest; |
47 InstallTypeTest* g_install_type = 0; | 52 InstallTypeTest* g_install_type = 0; |
48 | 53 |
49 // Check if any conflicting DLLs are loaded. | 54 // Check if any conflicting DLLs are loaded. |
50 class ConflictingDllsTest : public DiagnosticsTest { | 55 class ConflictingDllsTest : public DiagnosticsTest { |
51 public: | 56 public: |
52 ConflictingDllsTest() | 57 ConflictingDllsTest() |
53 : DiagnosticsTest(DIAGNOSTICS_CONFLICTING_DLLS_TEST) {} | 58 : DiagnosticsTest(DIAGNOSTICS_CONFLICTING_DLLS_TEST) {} |
54 | 59 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Check that the disk space in the volume where the user data directory | 110 // Check that the disk space in the volume where the user data directory |
106 // normally lives is not dangerously low. | 111 // normally lives is not dangerously low. |
107 class DiskSpaceTest : public DiagnosticsTest { | 112 class DiskSpaceTest : public DiagnosticsTest { |
108 public: | 113 public: |
109 DiskSpaceTest() : DiagnosticsTest(DIAGNOSTICS_DISK_SPACE_TEST) {} | 114 DiskSpaceTest() : DiagnosticsTest(DIAGNOSTICS_DISK_SPACE_TEST) {} |
110 | 115 |
111 bool ExecuteImpl(DiagnosticsModel::Observer* observer) override { | 116 bool ExecuteImpl(DiagnosticsModel::Observer* observer) override { |
112 base::FilePath data_dir; | 117 base::FilePath data_dir; |
113 if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir)) | 118 if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir)) |
114 return false; | 119 return false; |
115 int64 disk_space = base::SysInfo::AmountOfFreeDiskSpace(data_dir); | 120 int64_t disk_space = base::SysInfo::AmountOfFreeDiskSpace(data_dir); |
116 if (disk_space < 0) { | 121 if (disk_space < 0) { |
117 RecordFailure(DIAG_RECON_UNABLE_TO_QUERY, "Unable to query free space"); | 122 RecordFailure(DIAG_RECON_UNABLE_TO_QUERY, "Unable to query free space"); |
118 return true; | 123 return true; |
119 } | 124 } |
120 std::string printable_size = base::Int64ToString(disk_space); | 125 std::string printable_size = base::Int64ToString(disk_space); |
121 if (disk_space < 80 * kOneMegabyte) { | 126 if (disk_space < 80 * kOneMegabyte) { |
122 RecordFailure(DIAG_RECON_LOW_DISK_SPACE, | 127 RecordFailure(DIAG_RECON_LOW_DISK_SPACE, |
123 "Low disk space: " + printable_size); | 128 "Low disk space: " + printable_size); |
124 return true; | 129 return true; |
125 } | 130 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // Checks that a given JSON file can be correctly parsed. | 170 // Checks that a given JSON file can be correctly parsed. |
166 class JSONTest : public DiagnosticsTest { | 171 class JSONTest : public DiagnosticsTest { |
167 public: | 172 public: |
168 enum FileImportance { | 173 enum FileImportance { |
169 NON_CRITICAL, | 174 NON_CRITICAL, |
170 CRITICAL | 175 CRITICAL |
171 }; | 176 }; |
172 | 177 |
173 JSONTest(const base::FilePath& path, | 178 JSONTest(const base::FilePath& path, |
174 DiagnosticsTestId id, | 179 DiagnosticsTestId id, |
175 int64 max_file_size, | 180 int64_t max_file_size, |
176 FileImportance importance) | 181 FileImportance importance) |
177 : DiagnosticsTest(id), | 182 : DiagnosticsTest(id), |
178 path_(path), | 183 path_(path), |
179 max_file_size_(max_file_size), | 184 max_file_size_(max_file_size), |
180 importance_(importance) {} | 185 importance_(importance) {} |
181 | 186 |
182 bool ExecuteImpl(DiagnosticsModel::Observer* observer) override { | 187 bool ExecuteImpl(DiagnosticsModel::Observer* observer) override { |
183 if (!base::PathExists(path_)) { | 188 if (!base::PathExists(path_)) { |
184 if (importance_ == CRITICAL) { | 189 if (importance_ == CRITICAL) { |
185 RecordOutcome(DIAG_RECON_FILE_NOT_FOUND, | 190 RecordOutcome(DIAG_RECON_FILE_NOT_FOUND, |
186 "File not found", | 191 "File not found", |
187 DiagnosticsModel::TEST_FAIL_CONTINUE); | 192 DiagnosticsModel::TEST_FAIL_CONTINUE); |
188 } else { | 193 } else { |
189 RecordOutcome(DIAG_RECON_FILE_NOT_FOUND_OK, | 194 RecordOutcome(DIAG_RECON_FILE_NOT_FOUND_OK, |
190 "File not found (but that is OK)", | 195 "File not found (but that is OK)", |
191 DiagnosticsModel::TEST_OK); | 196 DiagnosticsModel::TEST_OK); |
192 } | 197 } |
193 return true; | 198 return true; |
194 } | 199 } |
195 int64 file_size; | 200 int64_t file_size; |
196 if (!base::GetFileSize(path_, &file_size)) { | 201 if (!base::GetFileSize(path_, &file_size)) { |
197 RecordFailure(DIAG_RECON_CANNOT_OBTAIN_FILE_SIZE, | 202 RecordFailure(DIAG_RECON_CANNOT_OBTAIN_FILE_SIZE, |
198 "Cannot obtain file size"); | 203 "Cannot obtain file size"); |
199 return true; | 204 return true; |
200 } | 205 } |
201 | 206 |
202 if (file_size > max_file_size_) { | 207 if (file_size > max_file_size_) { |
203 RecordFailure(DIAG_RECON_FILE_TOO_BIG, "File too big"); | 208 RecordFailure(DIAG_RECON_FILE_TOO_BIG, "File too big"); |
204 return true; | 209 return true; |
205 } | 210 } |
(...skipping 17 matching lines...) Expand all Loading... |
223 RecordFailure(DIAG_RECON_PARSE_ERROR, error_message); | 228 RecordFailure(DIAG_RECON_PARSE_ERROR, error_message); |
224 return true; | 229 return true; |
225 } | 230 } |
226 | 231 |
227 RecordSuccess("File parsed OK"); | 232 RecordSuccess("File parsed OK"); |
228 return true; | 233 return true; |
229 } | 234 } |
230 | 235 |
231 private: | 236 private: |
232 base::FilePath path_; | 237 base::FilePath path_; |
233 int64 max_file_size_; | 238 int64_t max_file_size_; |
234 FileImportance importance_; | 239 FileImportance importance_; |
235 DISALLOW_COPY_AND_ASSIGN(JSONTest); | 240 DISALLOW_COPY_AND_ASSIGN(JSONTest); |
236 }; | 241 }; |
237 | 242 |
238 // Check that the flavor of the operating system is supported. | 243 // Check that the flavor of the operating system is supported. |
239 class OperatingSystemTest : public DiagnosticsTest { | 244 class OperatingSystemTest : public DiagnosticsTest { |
240 public: | 245 public: |
241 OperatingSystemTest() | 246 OperatingSystemTest() |
242 : DiagnosticsTest(DIAGNOSTICS_OPERATING_SYSTEM_TEST) {} | 247 : DiagnosticsTest(DIAGNOSTICS_OPERATING_SYSTEM_TEST) {} |
243 | 248 |
(...skipping 20 matching lines...) Expand all Loading... |
264 private: | 269 private: |
265 DISALLOW_COPY_AND_ASSIGN(OperatingSystemTest); | 270 DISALLOW_COPY_AND_ASSIGN(OperatingSystemTest); |
266 }; | 271 }; |
267 | 272 |
268 struct TestPathInfo { | 273 struct TestPathInfo { |
269 DiagnosticsTestId test_id; | 274 DiagnosticsTestId test_id; |
270 int path_id; | 275 int path_id; |
271 bool is_directory; | 276 bool is_directory; |
272 bool is_optional; | 277 bool is_optional; |
273 bool test_writable; | 278 bool test_writable; |
274 int64 max_size; | 279 int64_t max_size; |
275 }; | 280 }; |
276 | 281 |
277 const TestPathInfo kPathsToTest[] = { | 282 const TestPathInfo kPathsToTest[] = { |
278 {DIAGNOSTICS_PATH_DICTIONARIES_TEST, chrome::DIR_APP_DICTIONARIES, true, | 283 {DIAGNOSTICS_PATH_DICTIONARIES_TEST, chrome::DIR_APP_DICTIONARIES, true, |
279 true, false, 0}, | 284 true, false, 0}, |
280 {DIAGNOSTICS_PATH_LOCAL_STATE_TEST, chrome::FILE_LOCAL_STATE, false, false, | 285 {DIAGNOSTICS_PATH_LOCAL_STATE_TEST, chrome::FILE_LOCAL_STATE, false, false, |
281 true, 500 * kOneKilobyte}, | 286 true, 500 * kOneKilobyte}, |
282 {DIAGNOSTICS_PATH_RESOURCES_TEST, chrome::FILE_RESOURCES_PACK, false, false, | 287 {DIAGNOSTICS_PATH_RESOURCES_TEST, chrome::FILE_RESOURCES_PACK, false, false, |
283 false, 0}, | 288 false, 0}, |
284 {DIAGNOSTICS_PATH_USER_DATA_TEST, chrome::DIR_USER_DATA, true, false, true, | 289 {DIAGNOSTICS_PATH_USER_DATA_TEST, chrome::DIR_USER_DATA, true, false, true, |
(...skipping 20 matching lines...) Expand all Loading... |
305 return false; | 310 return false; |
306 } | 311 } |
307 if (!base::PathExists(dir_or_file)) { | 312 if (!base::PathExists(dir_or_file)) { |
308 RecordFailure( | 313 RecordFailure( |
309 DIAG_RECON_PATH_NOT_FOUND, | 314 DIAG_RECON_PATH_NOT_FOUND, |
310 "Path not found: " + | 315 "Path not found: " + |
311 base::UTF16ToUTF8(dir_or_file.LossyDisplayName())); | 316 base::UTF16ToUTF8(dir_or_file.LossyDisplayName())); |
312 return true; | 317 return true; |
313 } | 318 } |
314 | 319 |
315 int64 dir_or_file_size = 0; | 320 int64_t dir_or_file_size = 0; |
316 if (path_info_.is_directory) { | 321 if (path_info_.is_directory) { |
317 dir_or_file_size = base::ComputeDirectorySize(dir_or_file); | 322 dir_or_file_size = base::ComputeDirectorySize(dir_or_file); |
318 } else { | 323 } else { |
319 base::GetFileSize(dir_or_file, &dir_or_file_size); | 324 base::GetFileSize(dir_or_file, &dir_or_file_size); |
320 } | 325 } |
321 if (!dir_or_file_size && !path_info_.is_optional) { | 326 if (!dir_or_file_size && !path_info_.is_optional) { |
322 RecordFailure(DIAG_RECON_CANNOT_OBTAIN_SIZE, | 327 RecordFailure(DIAG_RECON_CANNOT_OBTAIN_SIZE, |
323 "Cannot obtain size for: " + | 328 "Cannot obtain size for: " + |
324 base::UTF16ToUTF8(dir_or_file.LossyDisplayName())); | 329 base::UTF16ToUTF8(dir_or_file.LossyDisplayName())); |
325 return true; | 330 return true; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 432 |
428 DiagnosticsTest* MakeResourcesFileTest() { | 433 DiagnosticsTest* MakeResourcesFileTest() { |
429 return new PathTest(kPathsToTest[2]); | 434 return new PathTest(kPathsToTest[2]); |
430 } | 435 } |
431 | 436 |
432 DiagnosticsTest* MakeUserDirTest() { return new PathTest(kPathsToTest[3]); } | 437 DiagnosticsTest* MakeUserDirTest() { return new PathTest(kPathsToTest[3]); } |
433 | 438 |
434 DiagnosticsTest* MakeVersionTest() { return new VersionTest(); } | 439 DiagnosticsTest* MakeVersionTest() { return new VersionTest(); } |
435 | 440 |
436 } // namespace diagnostics | 441 } // namespace diagnostics |
OLD | NEW |