summaryrefslogtreecommitdiffstats
path: root/chrome/browser/diagnostics
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 00:59:17 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 00:59:17 +0000
commit36e7669678422402463893b50aa6d6712e37f9e8 (patch)
treeaa4d131871c71ccb645761fc4c85143d65c3dad9 /chrome/browser/diagnostics
parent3ee6112cc9d368ccd11d2cc2eea4f3aca2fd4400 (diff)
downloadchromium_src-36e7669678422402463893b50aa6d6712e37f9e8.zip
chromium_src-36e7669678422402463893b50aa6d6712e37f9e8.tar.gz
chromium_src-36e7669678422402463893b50aa6d6712e37f9e8.tar.bz2
Add diagnostic check for the Preferences file
- Parses the json file BUG=27885 TEST=test modified Review URL: http://codereview.chromium.org/1609022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/diagnostics')
-rw-r--r--chrome/browser/diagnostics/diagnostics_model.cc9
-rw-r--r--chrome/browser/diagnostics/diagnostics_model_unittest.cc4
-rw-r--r--chrome/browser/diagnostics/diagnostics_test.h2
-rw-r--r--chrome/browser/diagnostics/recon_diagnostics.cc76
-rw-r--r--chrome/browser/diagnostics/recon_diagnostics.h3
5 files changed, 90 insertions, 4 deletions
diff --git a/chrome/browser/diagnostics/diagnostics_model.cc b/chrome/browser/diagnostics/diagnostics_model.cc
index eb83537..e7b9f25 100644
--- a/chrome/browser/diagnostics/diagnostics_model.cc
+++ b/chrome/browser/diagnostics/diagnostics_model.cc
@@ -90,6 +90,9 @@ class DiagnosticsModelWin : public DiagnosticsModelImpl {
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
tests_.push_back(MakeDiskSpaceTest());
+ tests_.push_back(MakePreferencesTest());
+ tests_.push_back(MakeLocalStateTest());
+ tests_.push_back(MakeBookMarksTest());
tests_.push_back(MakeSqliteWebDbTest());
tests_.push_back(MakeSqliteCookiesDbTest());
tests_.push_back(MakeSqliteHistoryDbTest());
@@ -113,6 +116,9 @@ class DiagnosticsModelMac : public DiagnosticsModelImpl {
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
tests_.push_back(MakeDiskSpaceTest());
+ tests_.push_back(MakePreferencesTest());
+ tests_.push_back(MakeLocalStateTest());
+ tests_.push_back(MakeBookMarksTest());
tests_.push_back(MakeSqliteWebDbTest());
tests_.push_back(MakeSqliteCookiesDbTest());
tests_.push_back(MakeSqliteHistoryDbTest());
@@ -136,6 +142,9 @@ class DiagnosticsModelPosix : public DiagnosticsModelImpl {
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
tests_.push_back(MakeDiskSpaceTest());
+ tests_.push_back(MakePreferencesTest());
+ tests_.push_back(MakeLocalStateTest());
+ tests_.push_back(MakeBookMarksTest());
tests_.push_back(MakeSqliteWebDbTest());
tests_.push_back(MakeSqliteCookiesDbTest());
tests_.push_back(MakeSqliteHistoryDbTest());
diff --git a/chrome/browser/diagnostics/diagnostics_model_unittest.cc b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
index c12cab9..62dff9d 100644
--- a/chrome/browser/diagnostics/diagnostics_model_unittest.cc
+++ b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
@@ -78,9 +78,9 @@ class UTObserver: public DiagnosticsModel::Observer {
// We currently have more tests operational on windows.
#if defined(OS_WIN)
-const int kDiagnosticsTestCount = 15;
+const int kDiagnosticsTestCount = 18;
#else
-const int kDiagnosticsTestCount = 13;
+const int kDiagnosticsTestCount = 16;
#endif
// Test that the initial state is correct.
diff --git a/chrome/browser/diagnostics/diagnostics_test.h b/chrome/browser/diagnostics/diagnostics_test.h
index 9fdc45e..6e17518 100644
--- a/chrome/browser/diagnostics/diagnostics_test.h
+++ b/chrome/browser/diagnostics/diagnostics_test.h
@@ -72,7 +72,7 @@ class DiagnosticTest : public DiagnosticsModel::TestInfo {
result_ = result;
}
- FilePath GetUserDefaultProfileDir() {
+ static FilePath GetUserDefaultProfileDir() {
FilePath path;
if (!PathService::Get(chrome::DIR_USER_DATA, &path))
return FilePath();
diff --git a/chrome/browser/diagnostics/recon_diagnostics.cc b/chrome/browser/diagnostics/recon_diagnostics.cc
index dc00bb61..e2d214a 100644
--- a/chrome/browser/diagnostics/recon_diagnostics.cc
+++ b/chrome/browser/diagnostics/recon_diagnostics.cc
@@ -4,8 +4,10 @@
#include "chrome/browser/diagnostics/recon_diagnostics.h"
+#include "app/app_paths.h"
#include "base/file_util.h"
#include "base/file_version_info.h"
+#include "base/json/json_reader.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/sys_info.h"
@@ -13,7 +15,7 @@
#include "chrome/browser/diagnostics/diagnostics_test.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/platform_util.h"
-#include "app/app_paths.h"
+#include "chrome/common/json_value_serializer.h"
#if defined(OS_WIN)
#include "base/win_util.h"
@@ -24,6 +26,10 @@
// diagnostic tests. Here we check for the existence of critical files.
// TODO(cpu): Define if it makes sense to localize strings.
+// TODO(cpu): There are a few maxium file sizes hardcoded in this file
+// that have little or no theoretical or experimental ground. Find a way
+// to justify them.
+
namespace {
class InstallTypeTest;
@@ -253,6 +259,56 @@ class DiskSpaceTest : public DiagnosticTest {
DISALLOW_COPY_AND_ASSIGN(DiskSpaceTest);
};
+// Checks that a given json file can be correctly parsed.
+class JSONTest : public DiagnosticTest {
+ public:
+ JSONTest(const FilePath& path, const string16 name, int64 max_file_size)
+ : DiagnosticTest(name), path_(path), max_file_size_(max_file_size) {
+ }
+
+ virtual int GetId() { return 0; }
+
+ virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
+ if (!file_util::PathExists(path_)) {
+ RecordFailure(ASCIIToUTF16("File not found"));
+ return true;
+ }
+ int64 file_size;
+ file_util::GetFileSize(path_, &file_size);
+ if (file_size > max_file_size_) {
+ RecordFailure(ASCIIToUTF16("File too big"));
+ return true;
+ }
+ // Being small enough, we can process it in-memory.
+ std::string json_data;
+ if (!file_util::ReadFileToString(path_, &json_data)) {
+ RecordFailure(ASCIIToUTF16(
+ "Could not open file. Possibly locked by other process"));
+ return true;
+ }
+
+ JSONStringValueSerializer json(json_data);
+ int error_code = base::JSONReader::JSON_NO_ERROR;
+ std::string error_message;
+ scoped_ptr<Value> json_root(json.Deserialize(&error_code, &error_message));
+ if (base::JSONReader::JSON_NO_ERROR != error_code) {
+ if (error_message.empty()) {
+ error_message = "Parse error " + IntToString(error_code);
+ }
+ RecordFailure(UTF8ToUTF16(error_message));
+ return true;
+ }
+
+ RecordSuccess(ASCIIToUTF16("File parsed OK"));
+ return true;
+ }
+
+ private:
+ FilePath path_;
+ int64 max_file_size_;
+ DISALLOW_COPY_AND_ASSIGN(JSONTest);
+};
+
} // namespace
DiagnosticTest* MakeUserDirTest() {
@@ -287,3 +343,21 @@ DiagnosticTest* MakeInstallTypeTest() {
return new InstallTypeTest();
}
+DiagnosticTest* MakePreferencesTest() {
+ FilePath path = DiagnosticTest::GetUserDefaultProfileDir();
+ path = path.Append(chrome::kPreferencesFilename);
+ return new JSONTest(path, ASCIIToUTF16("Profile JSON"), 100 * kOneKilo);
+}
+
+DiagnosticTest* MakeBookMarksTest() {
+ FilePath path = DiagnosticTest::GetUserDefaultProfileDir();
+ path = path.Append(chrome::kBookmarksFileName);
+ return new JSONTest(path, ASCIIToUTF16("BookMarks JSON"), 2 * kOneMeg);
+}
+
+DiagnosticTest* MakeLocalStateTest() {
+ FilePath path;
+ PathService::Get(chrome::DIR_USER_DATA, &path);
+ path = path.Append(chrome::kLocalStateFilename);
+ return new JSONTest(path, ASCIIToUTF16("Local State JSON"), 50 * kOneKilo);
+}
diff --git a/chrome/browser/diagnostics/recon_diagnostics.h b/chrome/browser/diagnostics/recon_diagnostics.h
index 9c0d37d..47f9cc1 100644
--- a/chrome/browser/diagnostics/recon_diagnostics.h
+++ b/chrome/browser/diagnostics/recon_diagnostics.h
@@ -16,5 +16,8 @@ DiagnosticTest* MakeLocalStateFileTest();
DiagnosticTest* MakeDictonaryDirTest();
DiagnosticTest* MakeInspectorDirTest();
DiagnosticTest* MakeDiskSpaceTest();
+DiagnosticTest* MakePreferencesTest();
+DiagnosticTest* MakeBookMarksTest();
+DiagnosticTest* MakeLocalStateTest();
#endif // CHROME_BROWSER_DIAGNOSTICS_RECON_DIAGNOSTICS_H_