summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 04:01:08 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 04:01:08 +0000
commit31a5d88dfdf8eba77aa2d0a185d90f2f64f4f427 (patch)
treede89c19c8ee3c6a9b176fa74a18e403a1990f17b
parenta38bd5a1867f8b6538ae8e9fefc613ff443c7523 (diff)
downloadchromium_src-31a5d88dfdf8eba77aa2d0a185d90f2f64f4f427.zip
chromium_src-31a5d88dfdf8eba77aa2d0a185d90f2f64f4f427.tar.gz
chromium_src-31a5d88dfdf8eba77aa2d0a185d90f2f64f4f427.tar.bz2
More work on diagnostics mode
- Clean up a bit, reduce windows specific code - Add disk space test - Add Chrome version test - Make OS version readable, cross platform mostly This concludes the minimal sanity tests. BUG=27885 TEST= run chrome with --diagnostics , no test should fail. Review URL: http://codereview.chromium.org/561078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38176 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/diagnostics/diagnostics_model.cc11
-rw-r--r--chrome/browser/diagnostics/diagnostics_model_unittest.cc2
-rw-r--r--chrome/browser/diagnostics/recon_diagnostics.cc129
-rw-r--r--chrome/browser/diagnostics/recon_diagnostics.h7
4 files changed, 106 insertions, 43 deletions
diff --git a/chrome/browser/diagnostics/diagnostics_model.cc b/chrome/browser/diagnostics/diagnostics_model.cc
index 54da906..aa66015 100644
--- a/chrome/browser/diagnostics/diagnostics_model.cc
+++ b/chrome/browser/diagnostics/diagnostics_model.cc
@@ -78,13 +78,14 @@ class DiagnosticsModelImpl : public DiagnosticsModel {
class DiagnosticsModelWin : public DiagnosticsModelImpl {
public:
DiagnosticsModelWin() {
- tests_.push_back(MakeWinOsIdTest());
+ tests_.push_back(MakeOperatingSystemTest());
tests_.push_back(MakeInstallTypeTest());
+ tests_.push_back(MakeVersionTest());
tests_.push_back(MakeUserDirTest());
- tests_.push_back(MakeResourceFileTest());
tests_.push_back(MakeLocalStateFileTest());
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
+ tests_.push_back(MakeDiskSpaceTest());
}
private:
@@ -97,11 +98,12 @@ class DiagnosticsModelMac : public DiagnosticsModelImpl {
DiagnosticsModelMac() {
tests_.push_back(MakeInstallTypeTest());
tests_.push_back(MakeUserDirTest());
- tests_.push_back(MakeResourceFileTest());
tests_.push_back(MakeLocalStateFileTest());
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
+ tests_.push_back(MakeDiskSpaceTest());
}
+
private:
DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelMac);
};
@@ -112,11 +114,12 @@ class DiagnosticsModelLinux : public DiagnosticsModelImpl {
DiagnosticsModelLinux() {
tests_.push_back(MakeInstallTypeTest());
tests_.push_back(MakeUserDirTest());
- tests_.push_back(MakeResourceFileTest());
tests_.push_back(MakeLocalStateFileTest());
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
+ tests_.push_back(MakeDiskSpaceTest());
}
+
private:
DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelLinux);
};
diff --git a/chrome/browser/diagnostics/diagnostics_model_unittest.cc b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
index 5aef7f4..535ee57 100644
--- a/chrome/browser/diagnostics/diagnostics_model_unittest.cc
+++ b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
@@ -72,7 +72,7 @@ class UTObserver: public DiagnosticsModel::Observer {
// We currently have more tests operational on windows.
#if defined(OS_WIN)
-const int kDiagnosticsTestCount = 7;
+const int kDiagnosticsTestCount = 8;
#else
const int kDiagnosticsTestCount = 6;
#endif
diff --git a/chrome/browser/diagnostics/recon_diagnostics.cc b/chrome/browser/diagnostics/recon_diagnostics.cc
index 19afdb0..f16c4a4 100644
--- a/chrome/browser/diagnostics/recon_diagnostics.cc
+++ b/chrome/browser/diagnostics/recon_diagnostics.cc
@@ -2,11 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/diagnostics/recon_diagnostics.h"
+
#include "base/file_util.h"
+#include "base/file_version_info.h"
#include "base/string_util.h"
+#include "base/sys_info.h"
#include "base/path_service.h"
#include "chrome/browser/diagnostics/diagnostics_test.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/platform_util.h"
#include "app/app_paths.h"
#if defined(OS_WIN)
@@ -23,36 +28,40 @@ namespace {
class InstallTypeTest;
InstallTypeTest* g_install_type = 0;
-#if defined(OS_WIN)
-// Check that we know what flavor of windows is and that is not an
-// unsuported operating system.
-class WinOSIdTest : public DiagnosticTest {
+// Check that the flavor of the operating system is supported.
+class OperatingSystemTest : public DiagnosticTest {
public:
- WinOSIdTest() : DiagnosticTest(ASCIIToUTF16("Operating System")) {}
+ OperatingSystemTest() : DiagnosticTest(ASCIIToUTF16("Operating System")) {}
virtual int GetId() { return 0; }
virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
- win_util::WinVersion version = win_util::GetWinVersion();
+ int version = 0;
+ int major = 0;
+ int minor = 0;
+#if defined(OS_WIN)
+ version = win_util::GetWinVersion();
if (version < win_util::WINVERSION_XP) {
RecordFailure(ASCIIToUTF16("Windows 2000 or earlier"));
return false;
}
- int major = 0;
- int minor = 0;
- string16 os_name;
win_util::GetServicePackLevel(&major, &minor);
if ((version == win_util::WINVERSION_XP) && (major < 2)) {
RecordFailure(ASCIIToUTF16("XP Service Pack 1 or earlier"));
return false;
}
- RecordSuccess(ASCIIToUTF16(StringPrintf("Windows %d [%d:%d]",
- version, major, minor)));
+#else
+ // TODO(port): define the OS criteria for linux and mac.
+#endif // defined(OS_WIN)
+ RecordSuccess(ASCIIToUTF16(StringPrintf("%s %s (%d [%d:%d])",
+ base::SysInfo::OperatingSystemName().c_str(),
+ base::SysInfo::OperatingSystemVersion().c_str(),
+ version, major, minor)));
return true;
}
private:
- DISALLOW_COPY_AND_ASSIGN(WinOSIdTest);
+ DISALLOW_COPY_AND_ASSIGN(OperatingSystemTest);
};
// Check if it is system install or per-user install.
@@ -64,6 +73,7 @@ class InstallTypeTest : public DiagnosticTest {
virtual int GetId() { return 0; }
virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
+#if defined(OS_WIN)
FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
RecordFailure(ASCIIToUTF16("Path provider failure"));
@@ -71,8 +81,11 @@ class InstallTypeTest : public DiagnosticTest {
}
user_level_ = InstallUtil::IsPerUserInstall(
chrome_exe.ToWStringHack().c_str());
- string16 install_type(ASCIIToUTF16(user_level_ ? "User Level" :
- "System Level"));
+ const char* type = user_level_ ? "User Level" : "System Level";
+ string16 install_type(ASCIIToUTF16(type));
+#else
+ string16 install_type(ASCIIToUTF16("System Level"));
+#endif // defined(OS_WIN)
RecordSuccess(install_type);
g_install_type = this;
return true;
@@ -85,26 +98,40 @@ class InstallTypeTest : public DiagnosticTest {
DISALLOW_COPY_AND_ASSIGN(InstallTypeTest);
};
-#else
-// For Mac and Linux we just assume is a system level install.
-class InstallTypeTest : public DiagnosticTest {
+// Check the version of Chrome.
+class VersionTest : public DiagnosticTest {
public:
- InstallTypeTest() : DiagnosticTest(ASCIIToUTF16("Install Type")) {}
+ VersionTest() : DiagnosticTest(ASCIIToUTF16("Browser Version")) {}
virtual int GetId() { return 0; }
virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
- g_install_type = this;
- RecordSuccess(ASCIIToUTF16("OK"));
+ scoped_ptr<FileVersionInfo> version_info(
+ FileVersionInfo::CreateFileVersionInfoForCurrentModule());
+ if (!version_info.get()) {
+ RecordFailure(ASCIIToUTF16("No Version"));
+ return true;
+ }
+ string16 current_version = WideToUTF16(version_info->file_version());
+ if (current_version.empty()) {
+ RecordFailure(ASCIIToUTF16("Empty Version"));
+ return true;
+ }
+ string16 version_modifier = platform_util::GetVersionStringModifier();
+ if (!version_modifier.empty()) {
+ current_version += ASCIIToUTF16(" ");
+ current_version += version_modifier;
+ }
+#if defined(GOOGLE_CHROME_BUILD)
+ current_version += ASCIIToUTF16(" GCB");
+#endif // defined(GOOGLE_CHROME_BUILD)
+ RecordSuccess(current_version);
return true;
}
- bool system_level() const { return true; }
-
private:
- DISALLOW_COPY_AND_ASSIGN(InstallTypeTest);
+ DISALLOW_COPY_AND_ASSIGN(VersionTest);
};
-#endif // defined(OS_WIN)
struct TestPathInfo {
const char* test_name;
@@ -119,7 +146,6 @@ const int64 kOneMeg = 1024 * kOneKilo;
const TestPathInfo kPathsToTest[] = {
{"User data Directory", chrome::DIR_USER_DATA, true, 250 * kOneMeg},
{"Local state file", chrome::FILE_LOCAL_STATE, true, 200 * kOneKilo},
- {"Resources module", chrome::FILE_RESOURCE_MODULE, false, 0},
{"Dictionaries Directory", chrome::DIR_APP_DICTIONARIES, false, 0},
{"Inspector Directory", chrome::DIR_INSPECTOR, false, 0}
};
@@ -173,7 +199,8 @@ class PathTest : public DiagnosticTest {
RecordFailure(ASCIIToUTF16("Path is not writable"));
return true;
}
- RecordSuccess(ASCIIToUTF16("Path exists and is writable: ") + printable_size);
+ RecordSuccess(ASCIIToUTF16("Path exists and is writable: ")
+ + printable_size);
return true;
}
@@ -182,6 +209,38 @@ class PathTest : public DiagnosticTest {
DISALLOW_COPY_AND_ASSIGN(PathTest);
};
+// Check that the disk space in the volume where the user data dir normally
+// lives is not dangerosly low.
+class DiskSpaceTest : public DiagnosticTest {
+ public:
+ DiskSpaceTest() : DiagnosticTest(ASCIIToUTF16("Disk Space")) {}
+
+ virtual int GetId() { return 0; }
+
+ virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
+ FilePath data_dir;
+ if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir))
+ return false;
+ int64 disk_space = base::SysInfo::AmountOfFreeDiskSpace(data_dir);
+ if (disk_space < 0) {
+ RecordFailure(ASCIIToUTF16("Unable to query free space"));
+ return true;
+ }
+ DataUnits units = GetByteDisplayUnits(disk_space);
+ string16 printable_size =
+ WideToUTF16(FormatBytes(disk_space, units, true));
+ if (disk_space < 80 * kOneMeg) {
+ RecordFailure(ASCIIToUTF16("Low disk space : ") + printable_size);
+ return true;
+ }
+ RecordSuccess(ASCIIToUTF16("Free space : ") + printable_size);
+ return true;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DiskSpaceTest);
+};
+
} // namespace
DiagnosticTest* MakeUserDirTest() {
@@ -192,23 +251,25 @@ DiagnosticTest* MakeLocalStateFileTest() {
return new PathTest(kPathsToTest[1]);
}
-DiagnosticTest* MakeResourceFileTest() {
+DiagnosticTest* MakeDictonaryDirTest() {
return new PathTest(kPathsToTest[2]);
}
-DiagnosticTest* MakeDictonaryDirTest() {
+DiagnosticTest* MakeInspectorDirTest() {
return new PathTest(kPathsToTest[3]);
}
-DiagnosticTest* MakeInspectorDirTest() {
- return new PathTest(kPathsToTest[4]);
+DiagnosticTest* MakeVersionTest() {
+ return new VersionTest();
}
-#if defined(OS_WIN)
-DiagnosticTest* MakeWinOsIdTest() {
- return new WinOSIdTest();
+DiagnosticTest* MakeDiskSpaceTest() {
+ return new DiskSpaceTest();
+}
+
+DiagnosticTest* MakeOperatingSystemTest() {
+ return new OperatingSystemTest();
}
-#endif // defined(OS_WIN)
DiagnosticTest* MakeInstallTypeTest() {
return new InstallTypeTest();
diff --git a/chrome/browser/diagnostics/recon_diagnostics.h b/chrome/browser/diagnostics/recon_diagnostics.h
index f283e1e..9c0d37d 100644
--- a/chrome/browser/diagnostics/recon_diagnostics.h
+++ b/chrome/browser/diagnostics/recon_diagnostics.h
@@ -8,14 +8,13 @@
#include "base/string16.h"
#include "chrome/browser/diagnostics/diagnostics_test.h"
-#if defined(OS_WIN)
-DiagnosticTest* MakeWinOsIdTest();
-#endif
+DiagnosticTest* MakeOperatingSystemTest();
DiagnosticTest* MakeInstallTypeTest();
+DiagnosticTest* MakeVersionTest();
DiagnosticTest* MakeUserDirTest();
-DiagnosticTest* MakeResourceFileTest();
DiagnosticTest* MakeLocalStateFileTest();
DiagnosticTest* MakeDictonaryDirTest();
DiagnosticTest* MakeInspectorDirTest();
+DiagnosticTest* MakeDiskSpaceTest();
#endif // CHROME_BROWSER_DIAGNOSTICS_RECON_DIAGNOSTICS_H_