summaryrefslogtreecommitdiffstats
path: root/chrome/browser/diagnostics
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 20:40:11 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 20:40:11 +0000
commitba5b708872a57b644f0339f1894e35a4330588c0 (patch)
treeb6aa1a3be023b025ce5249251a212e840ff512c3 /chrome/browser/diagnostics
parentbd48c2b0bdcbb600bd428229c54cbefec46c5014 (diff)
downloadchromium_src-ba5b708872a57b644f0339f1894e35a4330588c0.zip
chromium_src-ba5b708872a57b644f0339f1894e35a4330588c0.tar.gz
chromium_src-ba5b708872a57b644f0339f1894e35a4330588c0.tar.bz2
Allow specifiying a different user-data-dir for diagnostic mode
- Polish the db tests a little bit, now there are critical and non-critical and it handles better is chrome is already running BUG=27885 TEST=none Review URL: http://codereview.chromium.org/1540027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44122 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/diagnostics')
-rw-r--r--chrome/browser/diagnostics/diagnostics_main.cc7
-rw-r--r--chrome/browser/diagnostics/diagnostics_model.cc8
-rw-r--r--chrome/browser/diagnostics/diagnostics_model.h8
-rw-r--r--chrome/browser/diagnostics/diagnostics_model_unittest.cc10
-rw-r--r--chrome/browser/diagnostics/diagnostics_test.h13
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.cc43
6 files changed, 62 insertions, 27 deletions
diff --git a/chrome/browser/diagnostics/diagnostics_main.cc b/chrome/browser/diagnostics/diagnostics_main.cc
index c69172b..f6a03c0 100644
--- a/chrome/browser/diagnostics/diagnostics_main.cc
+++ b/chrome/browser/diagnostics/diagnostics_main.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -190,8 +190,7 @@ class TestController : public DiagnosticsModel::Observer {
DISALLOW_COPY_AND_ASSIGN(TestController);
};
-
-}
+} // namespace
// This entry point is called from ChromeMain() when very few things
// have been initialized. To wit:
@@ -218,7 +217,7 @@ int DiagnosticsMain(const CommandLine& command_line) {
chrome::RegisterPathProvider();
TestWriter writer(&console);
- DiagnosticsModel* model = MakeDiagnosticsModel();
+ DiagnosticsModel* model = MakeDiagnosticsModel(command_line);
TestController controller(&writer);
// Run all the diagnostic tests.
diff --git a/chrome/browser/diagnostics/diagnostics_model.cc b/chrome/browser/diagnostics/diagnostics_model.cc
index cf27ab7..eb83537 100644
--- a/chrome/browser/diagnostics/diagnostics_model.cc
+++ b/chrome/browser/diagnostics/diagnostics_model.cc
@@ -8,6 +8,8 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
#include "base/file_util.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
@@ -16,6 +18,7 @@
#include "chrome/browser/diagnostics/recon_diagnostics.h"
#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
namespace {
@@ -150,7 +153,10 @@ class DiagnosticsModelPosix : public DiagnosticsModelImpl {
} // namespace
-DiagnosticsModel* MakeDiagnosticsModel() {
+DiagnosticsModel* MakeDiagnosticsModel(const CommandLine& cmdline) {
+ FilePath user_data_dir = cmdline.GetSwitchValuePath(switches::kUserDataDir);
+ if (!user_data_dir.empty())
+ PathService::Override(chrome::DIR_USER_DATA, user_data_dir);
#if defined(OS_WIN)
return new DiagnosticsModelWin();
#elif defined(OS_MACOSX)
diff --git a/chrome/browser/diagnostics/diagnostics_model.h b/chrome/browser/diagnostics/diagnostics_model.h
index bb977ef..42d259c 100644
--- a/chrome/browser/diagnostics/diagnostics_model.h
+++ b/chrome/browser/diagnostics/diagnostics_model.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,10 +7,12 @@
#include "base/string16.h"
+class CommandLine;
+
// The chrome diagnostics system is a model-view-controller system. The Model
// responsible for holding and running the individual tests and providing a
// uniform interface for quering the outcome.
-// TODO (CPU): The view and the controller are not yet built.
+// TODO(cpu): The view and the controller are not yet built.
class DiagnosticsModel {
public:
// A particular test can be in one of the following states.
@@ -69,7 +71,7 @@ class DiagnosticsModel {
// The factory for the model. The main purpose is to hide the creation of
// different models for different platforms.
-DiagnosticsModel* MakeDiagnosticsModel();
+DiagnosticsModel* MakeDiagnosticsModel(const CommandLine& cmdline);
#endif // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_MODEL_H_
diff --git a/chrome/browser/diagnostics/diagnostics_model_unittest.cc b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
index c6e3aaf..c12cab9 100644
--- a/chrome/browser/diagnostics/diagnostics_model_unittest.cc
+++ b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
@@ -3,17 +3,22 @@
// found in the LICENSE file.
#include "chrome/browser/diagnostics/diagnostics_model.h"
+
+#include "base/command_line.h"
#include "testing/gtest/include/gtest/gtest.h"
// Basic harness to adquire and release the Diagnostic model object.
class DiagnosticsModelTest : public testing::Test {
protected:
- DiagnosticsModelTest() : model_(NULL) { }
+ DiagnosticsModelTest()
+ : model_(NULL),
+ cmdline_(CommandLine::ARGUMENTS_ONLY) {
+ }
virtual ~DiagnosticsModelTest() { }
virtual void SetUp() {
- model_ = MakeDiagnosticsModel();
+ model_ = MakeDiagnosticsModel(cmdline_);
ASSERT_TRUE(model_ != NULL);
}
@@ -22,6 +27,7 @@ class DiagnosticsModelTest : public testing::Test {
}
DiagnosticsModel* model_;
+ CommandLine cmdline_;
};
// The test observer is used to know if the callbacks are being called.
diff --git a/chrome/browser/diagnostics/diagnostics_test.h b/chrome/browser/diagnostics/diagnostics_test.h
index d0a0947..9fdc45e 100644
--- a/chrome/browser/diagnostics/diagnostics_test.h
+++ b/chrome/browser/diagnostics/diagnostics_test.h
@@ -1,12 +1,16 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_
#define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_
+#include "base/file_path.h"
+#include "base/path_service.h"
#include "base/string16.h"
#include "chrome/browser/diagnostics/diagnostics_model.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
// Represents a single diagnostic test and encapsulates the common
// functionality across platforms as well.
@@ -68,6 +72,13 @@ class DiagnosticTest : public DiagnosticsModel::TestInfo {
result_ = result;
}
+ FilePath GetUserDefaultProfileDir() {
+ FilePath path;
+ if (!PathService::Get(chrome::DIR_USER_DATA, &path))
+ return FilePath();
+ return path.Append(FilePath::FromWStringHack(chrome::kNotSignedInProfile));
+ }
+
protected:
// The id needs to be overriden by derived classes and must uniquely
// identify this test so other test can refer to it.
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc
index 0cdc34c..d7f81fb 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.cc
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc
@@ -16,6 +16,7 @@
#include "base/string_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
+#include "third_party/sqlite/preprocessed/sqlite3.h"
#include "webkit/appcache/appcache_interfaces.h"
#include "webkit/database/database_tracker.h"
@@ -24,20 +25,22 @@ namespace {
// Generic diagnostic test class for checking sqlite db integrity.
class SqliteIntegrityTest : public DiagnosticTest {
public:
- SqliteIntegrityTest(
- const string16& title, const FilePath& profile_relative_db_path)
- : DiagnosticTest(title), db_path_(profile_relative_db_path) {
+ SqliteIntegrityTest(bool critical, const string16& title,
+ const FilePath& profile_relative_db_path)
+ : DiagnosticTest(title),
+ critical_(critical),
+ db_path_(profile_relative_db_path) {
}
virtual int GetId() { return 0; }
virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
- FilePath path;
- PathService::Get(chrome::DIR_USER_DATA, &path);
- path = path.Append(FilePath::FromWStringHack(chrome::kNotSignedInProfile));
+ FilePath path = GetUserDefaultProfileDir();
path = path.Append(db_path_);
if (!file_util::PathExists(path)) {
- RecordSuccess(ASCIIToUTF16("File not found"));
+ RecordOutcome(ASCIIToUTF16("File not found"),
+ critical_ ? DiagnosticsModel::TEST_FAIL_CONTINUE :
+ DiagnosticsModel::TEST_OK);
return true;
}
@@ -46,12 +49,19 @@ class SqliteIntegrityTest : public DiagnosticTest {
sql::Connection db;
db.set_exclusive_locking();
if (!db.Open(path)) {
- RecordFailure(ASCIIToUTF16("Cannot open db. Possibly corrupted"));
+ RecordFailure(ASCIIToUTF16("Cannot open DB. Possibly corrupted"));
return true;
}
sql::Statement s(db.GetUniqueStatement("PRAGMA integrity_check;"));
if (!s) {
- RecordFailure(ASCIIToUTF16("Statement failed"));
+ int error = db.GetErrorCode();
+ if (SQLITE_BUSY == error) {
+ RecordFailure(ASCIIToUTF16("DB locked by another process"));
+ } else {
+ string16 str(ASCIIToUTF16("Pragma failed. Error: "));
+ str += IntToString16(error);
+ RecordFailure(str);
+ }
return false;
}
while (s.Step()) {
@@ -72,6 +82,7 @@ class SqliteIntegrityTest : public DiagnosticTest {
}
private:
+ bool critical_;
FilePath db_path_;
DISALLOW_COPY_AND_ASSIGN(SqliteIntegrityTest);
};
@@ -116,34 +127,34 @@ sql::ErrorDelegate* GetErrorHandlerForWebDb() {
}
DiagnosticTest* MakeSqliteWebDbTest() {
- return new SqliteIntegrityTest(ASCIIToUTF16("Web Database"),
+ return new SqliteIntegrityTest(true, ASCIIToUTF16("Web DB"),
FilePath(chrome::kWebDataFilename));
}
DiagnosticTest* MakeSqliteCookiesDbTest() {
- return new SqliteIntegrityTest(ASCIIToUTF16("Cookies Database"),
+ return new SqliteIntegrityTest(true, ASCIIToUTF16("Cookies DB"),
FilePath(chrome::kCookieFilename));
}
DiagnosticTest* MakeSqliteHistoryDbTest() {
- return new SqliteIntegrityTest(ASCIIToUTF16("History Database"),
+ return new SqliteIntegrityTest(true, ASCIIToUTF16("History DB"),
FilePath(chrome::kHistoryFilename));
}
DiagnosticTest* MakeSqliteArchivedHistoryDbTest() {
- return new SqliteIntegrityTest(ASCIIToUTF16("Archived History Database"),
+ return new SqliteIntegrityTest(false, ASCIIToUTF16("Archived History DB"),
FilePath(chrome::kArchivedHistoryFilename));
}
DiagnosticTest* MakeSqliteThumbnailsDbTest() {
- return new SqliteIntegrityTest(ASCIIToUTF16("Thumbnails Database"),
+ return new SqliteIntegrityTest(false, ASCIIToUTF16("Thumbnails DB"),
FilePath(chrome::kThumbnailsFilename));
}
DiagnosticTest* MakeSqliteAppCacheDbTest() {
FilePath appcache_dir(chrome::kAppCacheDirname);
FilePath appcache_db = appcache_dir.Append(appcache::kAppCacheDatabaseName);
- return new SqliteIntegrityTest(ASCIIToUTF16("AppCache Database"),
+ return new SqliteIntegrityTest(false, ASCIIToUTF16("AppCache DB"),
appcache_db);
}
@@ -151,6 +162,6 @@ DiagnosticTest* MakeSqliteWebDatabaseTrackerDbTest() {
FilePath databases_dir(webkit_database::kDatabaseDirectoryName);
FilePath tracker_db =
databases_dir.Append(webkit_database::kTrackerDatabaseFileName);
- return new SqliteIntegrityTest(ASCIIToUTF16("DatabaseTracker DB"),
+ return new SqliteIntegrityTest(false, ASCIIToUTF16("DatabaseTracker DB"),
tracker_db);
}