| OLD | NEW |
| 1 // Copyright (c) 2010 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/recon_diagnostics.h" | 5 #include "chrome/browser/diagnostics/recon_diagnostics.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "chrome/browser/diagnostics/diagnostics_test.h" | 16 #include "chrome/browser/diagnostics/diagnostics_test.h" |
| 17 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
| 18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
| 21 #include "chrome/common/json_value_serializer.h" | 21 #include "chrome/common/json_value_serializer.h" |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 25 #include "chrome/browser/enumerate_modules_model_win.h" |
| 25 #include "chrome/installer/util/install_util.h" | 26 #include "chrome/installer/util/install_util.h" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 // Reconnaissance diagnostics. These are the first and most critical | 29 // Reconnaissance diagnostics. These are the first and most critical |
| 29 // diagnostic tests. Here we check for the existence of critical files. | 30 // diagnostic tests. Here we check for the existence of critical files. |
| 30 // TODO(cpu): Define if it makes sense to localize strings. | 31 // TODO(cpu): Define if it makes sense to localize strings. |
| 31 | 32 |
| 32 // TODO(cpu): There are a few maxium file sizes hardcoded in this file | 33 // TODO(cpu): There are a few maximum file sizes hardcoded in this file |
| 33 // that have little or no theoretical or experimental ground. Find a way | 34 // that have little or no theoretical or experimental ground. Find a way |
| 34 // to justify them. | 35 // to justify them. |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 class InstallTypeTest; | 39 class InstallTypeTest; |
| 39 InstallTypeTest* g_install_type = 0; | 40 InstallTypeTest* g_install_type = 0; |
| 40 | 41 |
| 41 // Check that the flavor of the operating system is supported. | 42 // Check that the flavor of the operating system is supported. |
| 42 class OperatingSystemTest : public DiagnosticTest { | 43 class OperatingSystemTest : public DiagnosticTest { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 if (version < base::win::VERSION_XP) { | 55 if (version < base::win::VERSION_XP) { |
| 55 RecordFailure(ASCIIToUTF16("Windows 2000 or earlier")); | 56 RecordFailure(ASCIIToUTF16("Windows 2000 or earlier")); |
| 56 return false; | 57 return false; |
| 57 } | 58 } |
| 58 base::win::GetServicePackLevel(&major, &minor); | 59 base::win::GetServicePackLevel(&major, &minor); |
| 59 if ((version == base::win::VERSION_XP) && (major < 2)) { | 60 if ((version == base::win::VERSION_XP) && (major < 2)) { |
| 60 RecordFailure(ASCIIToUTF16("XP Service Pack 1 or earlier")); | 61 RecordFailure(ASCIIToUTF16("XP Service Pack 1 or earlier")); |
| 61 return false; | 62 return false; |
| 62 } | 63 } |
| 63 #else | 64 #else |
| 64 // TODO(port): define the OS criteria for linux and mac. | 65 // TODO(port): define the OS criteria for Linux and Mac. |
| 65 #endif // defined(OS_WIN) | 66 #endif // defined(OS_WIN) |
| 66 RecordSuccess(ASCIIToUTF16(StringPrintf("%s %s (%d [%d:%d])", | 67 RecordSuccess(ASCIIToUTF16(StringPrintf("%s %s (%d [%d:%d])", |
| 67 base::SysInfo::OperatingSystemName().c_str(), | 68 base::SysInfo::OperatingSystemName().c_str(), |
| 68 base::SysInfo::OperatingSystemVersion().c_str(), | 69 base::SysInfo::OperatingSystemVersion().c_str(), |
| 69 version, major, minor))); | 70 version, major, minor))); |
| 70 return true; | 71 return true; |
| 71 } | 72 } |
| 72 | 73 |
| 73 private: | 74 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(OperatingSystemTest); | 75 DISALLOW_COPY_AND_ASSIGN(OperatingSystemTest); |
| 75 }; | 76 }; |
| 76 | 77 |
| 78 // Check if any conflicting DLLs are loaded. |
| 79 class ConflictingDllsTest : public DiagnosticTest { |
| 80 public: |
| 81 ConflictingDllsTest() : DiagnosticTest(ASCIIToUTF16("Conflicting modules")) {} |
| 82 |
| 83 virtual int GetId() { return 0; } |
| 84 |
| 85 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { |
| 86 #if defined(OS_WIN) |
| 87 EnumerateModulesModel* model = EnumerateModulesModel::GetInstance(); |
| 88 model->set_limited_mode(true); |
| 89 model->ScanNow(); |
| 90 ListValue* list = model->GetModuleList(); |
| 91 if (!model->confirmed_bad_modules_detected() && |
| 92 !model->suspected_bad_modules_detected()) { |
| 93 RecordSuccess(ASCIIToUTF16("No conflicting modules found")); |
| 94 return true; |
| 95 } |
| 96 |
| 97 string16 failures = ASCIIToUTF16("Possibly conflicting modules:"); |
| 98 DictionaryValue* dictionary; |
| 99 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 100 list->GetDictionary(i, &dictionary); |
| 101 int status; |
| 102 string16 location; |
| 103 string16 name; |
| 104 if (!dictionary->GetInteger("status", &status)) |
| 105 RecordFailure(ASCIIToUTF16("No 'status' field found")); |
| 106 if (status < ModuleEnumerator::SUSPECTED_BAD) |
| 107 continue; |
| 108 |
| 109 if (!dictionary->GetString("location", &location)) { |
| 110 RecordFailure(ASCIIToUTF16("No 'location' field found")); |
| 111 return true; |
| 112 } |
| 113 if (!dictionary->GetString("name", &name)) { |
| 114 RecordFailure(ASCIIToUTF16("No 'name' field found")); |
| 115 return true; |
| 116 } |
| 117 |
| 118 failures += ASCIIToUTF16("\n") + location + name; |
| 119 } |
| 120 RecordFailure(failures); |
| 121 return true; |
| 122 #else |
| 123 RecordFailure(ASCIIToUTF16("Not implemented")); |
| 124 return true; |
| 125 #endif // defined(OS_WIN) |
| 126 } |
| 127 |
| 128 private: |
| 129 DISALLOW_COPY_AND_ASSIGN(ConflictingDllsTest); |
| 130 }; |
| 131 |
| 77 // Check if it is system install or per-user install. | 132 // Check if it is system install or per-user install. |
| 78 class InstallTypeTest : public DiagnosticTest { | 133 class InstallTypeTest : public DiagnosticTest { |
| 79 public: | 134 public: |
| 80 InstallTypeTest() : DiagnosticTest(ASCIIToUTF16("Install Type")), | 135 InstallTypeTest() : DiagnosticTest(ASCIIToUTF16("Install Type")), |
| 81 user_level_(false) {} | 136 user_level_(false) {} |
| 82 | 137 |
| 83 virtual int GetId() { return 0; } | 138 virtual int GetId() { return 0; } |
| 84 | 139 |
| 85 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { | 140 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { |
| 86 #if defined(OS_WIN) | 141 #if defined(OS_WIN) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 {"User data Directory", chrome::DIR_USER_DATA, | 211 {"User data Directory", chrome::DIR_USER_DATA, |
| 157 true, false, true, 850 * kOneMeg}, | 212 true, false, true, 850 * kOneMeg}, |
| 158 {"Local state file", chrome::FILE_LOCAL_STATE, | 213 {"Local state file", chrome::FILE_LOCAL_STATE, |
| 159 false, false, true, 500 * kOneKilo}, | 214 false, false, true, 500 * kOneKilo}, |
| 160 {"Dictionaries Directory", chrome::DIR_APP_DICTIONARIES, | 215 {"Dictionaries Directory", chrome::DIR_APP_DICTIONARIES, |
| 161 true, true, false, 0}, | 216 true, true, false, 0}, |
| 162 {"Inspector Directory", chrome::DIR_INSPECTOR, | 217 {"Inspector Directory", chrome::DIR_INSPECTOR, |
| 163 true, false, false, 0} | 218 true, false, false, 0} |
| 164 }; | 219 }; |
| 165 | 220 |
| 166 // Check that the user's data directory exists and the paths are writeable. | 221 // Check that the user's data directory exists and the paths are writable. |
| 167 // If it is a systemwide install some paths are not expected to be writeable. | 222 // If it is a systemwide install some paths are not expected to be writable. |
| 168 // This test depends on |InstallTypeTest| having run succesfuly. | 223 // This test depends on |InstallTypeTest| having run successfully. |
| 169 class PathTest : public DiagnosticTest { | 224 class PathTest : public DiagnosticTest { |
| 170 public: | 225 public: |
| 171 explicit PathTest(const TestPathInfo& path_info) | 226 explicit PathTest(const TestPathInfo& path_info) |
| 172 : DiagnosticTest(ASCIIToUTF16(path_info.test_name)), | 227 : DiagnosticTest(ASCIIToUTF16(path_info.test_name)), |
| 173 path_info_(path_info) {} | 228 path_info_(path_info) {} |
| 174 | 229 |
| 175 virtual int GetId() { return 0; } | 230 virtual int GetId() { return 0; } |
| 176 | 231 |
| 177 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { | 232 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { |
| 178 if (!g_install_type) { | 233 if (!g_install_type) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 + printable_size); | 275 + printable_size); |
| 221 return true; | 276 return true; |
| 222 } | 277 } |
| 223 | 278 |
| 224 private: | 279 private: |
| 225 TestPathInfo path_info_; | 280 TestPathInfo path_info_; |
| 226 DISALLOW_COPY_AND_ASSIGN(PathTest); | 281 DISALLOW_COPY_AND_ASSIGN(PathTest); |
| 227 }; | 282 }; |
| 228 | 283 |
| 229 // Check that the disk space in the volume where the user data dir normally | 284 // Check that the disk space in the volume where the user data dir normally |
| 230 // lives is not dangerosly low. | 285 // lives is not dangerously low. |
| 231 class DiskSpaceTest : public DiagnosticTest { | 286 class DiskSpaceTest : public DiagnosticTest { |
| 232 public: | 287 public: |
| 233 DiskSpaceTest() : DiagnosticTest(ASCIIToUTF16("Disk Space")) {} | 288 DiskSpaceTest() : DiagnosticTest(ASCIIToUTF16("Disk Space")) {} |
| 234 | 289 |
| 235 virtual int GetId() { return 0; } | 290 virtual int GetId() { return 0; } |
| 236 | 291 |
| 237 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { | 292 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { |
| 238 FilePath data_dir; | 293 FilePath data_dir; |
| 239 if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir)) | 294 if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir)) |
| 240 return false; | 295 return false; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 385 } |
| 331 | 386 |
| 332 DiagnosticTest* MakeDiskSpaceTest() { | 387 DiagnosticTest* MakeDiskSpaceTest() { |
| 333 return new DiskSpaceTest(); | 388 return new DiskSpaceTest(); |
| 334 } | 389 } |
| 335 | 390 |
| 336 DiagnosticTest* MakeOperatingSystemTest() { | 391 DiagnosticTest* MakeOperatingSystemTest() { |
| 337 return new OperatingSystemTest(); | 392 return new OperatingSystemTest(); |
| 338 } | 393 } |
| 339 | 394 |
| 395 DiagnosticTest* MakeConflictingDllsTest() { |
| 396 return new ConflictingDllsTest(); |
| 397 } |
| 398 |
| 340 DiagnosticTest* MakeInstallTypeTest() { | 399 DiagnosticTest* MakeInstallTypeTest() { |
| 341 return new InstallTypeTest(); | 400 return new InstallTypeTest(); |
| 342 } | 401 } |
| 343 | 402 |
| 344 DiagnosticTest* MakePreferencesTest() { | 403 DiagnosticTest* MakePreferencesTest() { |
| 345 FilePath path = DiagnosticTest::GetUserDefaultProfileDir(); | 404 FilePath path = DiagnosticTest::GetUserDefaultProfileDir(); |
| 346 path = path.Append(chrome::kPreferencesFilename); | 405 path = path.Append(chrome::kPreferencesFilename); |
| 347 return new JSONTest(path, ASCIIToUTF16("Profile JSON"), 100 * kOneKilo); | 406 return new JSONTest(path, ASCIIToUTF16("Profile JSON"), 100 * kOneKilo); |
| 348 } | 407 } |
| 349 | 408 |
| 350 DiagnosticTest* MakeBookMarksTest() { | 409 DiagnosticTest* MakeBookMarksTest() { |
| 351 FilePath path = DiagnosticTest::GetUserDefaultProfileDir(); | 410 FilePath path = DiagnosticTest::GetUserDefaultProfileDir(); |
| 352 path = path.Append(chrome::kBookmarksFileName); | 411 path = path.Append(chrome::kBookmarksFileName); |
| 353 return new JSONTest(path, ASCIIToUTF16("BookMarks JSON"), 2 * kOneMeg); | 412 return new JSONTest(path, ASCIIToUTF16("BookMarks JSON"), 2 * kOneMeg); |
| 354 } | 413 } |
| 355 | 414 |
| 356 DiagnosticTest* MakeLocalStateTest() { | 415 DiagnosticTest* MakeLocalStateTest() { |
| 357 FilePath path; | 416 FilePath path; |
| 358 PathService::Get(chrome::DIR_USER_DATA, &path); | 417 PathService::Get(chrome::DIR_USER_DATA, &path); |
| 359 path = path.Append(chrome::kLocalStateFilename); | 418 path = path.Append(chrome::kLocalStateFilename); |
| 360 return new JSONTest(path, ASCIIToUTF16("Local State JSON"), 50 * kOneKilo); | 419 return new JSONTest(path, ASCIIToUTF16("Local State JSON"), 50 * kOneKilo); |
| 361 } | 420 } |
| OLD | NEW |