summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/app_base.gypi1
-rw-r--r--app/sql/diagnostic_error_delegate.h44
-rw-r--r--chrome/browser/diagnostics/diagnostics_model.cc8
-rw-r--r--chrome/browser/diagnostics/diagnostics_model_unittest.cc6
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.cc122
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.h4
-rw-r--r--webkit/appcache/appcache_database.cc14
-rw-r--r--webkit/appcache/appcache_interfaces.cc4
-rw-r--r--webkit/appcache/appcache_interfaces.h5
-rw-r--r--webkit/appcache/appcache_storage_impl.cc8
-rw-r--r--webkit/database/database_tracker.cc16
11 files changed, 154 insertions, 78 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi
index 07d5f3c..2eaa8f6 100644
--- a/app/app_base.gypi
+++ b/app/app_base.gypi
@@ -151,6 +151,7 @@
'slide_animation.h',
'sql/connection.cc',
'sql/connection.h',
+ 'sql/diagnostic_error_delegate.h',
'sql/init_status.h',
'sql/meta_table.cc',
'sql/meta_table.h',
diff --git a/app/sql/diagnostic_error_delegate.h b/app/sql/diagnostic_error_delegate.h
new file mode 100644
index 0000000..e62bba2
--- /dev/null
+++ b/app/sql/diagnostic_error_delegate.h
@@ -0,0 +1,44 @@
+// 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 APP_SQL_DIAGNOSTIC_ERROR_DELEGATE_H_
+#define APP_SQL_DIAGNOSTIC_ERROR_DELEGATE_H_
+
+#include "app/sql/connection.h"
+#include "base/histogram.h"
+#include "base/logging.h"
+
+namespace sql {
+
+// This class handles the exceptional sqlite errors that we might encounter
+// if for example the db is corrupted. Right now we just generate a UMA
+// histogram for release and an assert for debug builds.
+//
+// Why is it a template you ask? well, that is a funny story. The histograms
+// need to be singletons that is why they are always static at the function
+// scope, but we cannot use the Singleton class because they are not default
+// constructible. The template parameter makes the compiler to create unique
+// classes that don't share the same static variable.
+template <class UniqueT>
+class DiagnosticErrorDelegate : public ErrorDelegate {
+ public:
+
+ virtual int OnError(int error, Connection* connection,
+ Statement* stmt) {
+ NOTREACHED() << "sqlite error " << error;
+ RecordErrorInHistogram(error);
+ return error;
+ }
+
+ private:
+ static void RecordErrorInHistogram(int error) {
+ // The histogram values from sqlite result codes go currently from 1 to
+ // 26 currently but 50 gives them room to grow.
+ UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error, 50);
+ }
+};
+
+} // namespace sql
+
+#endif // APP_SQL_DIAGNOSTIC_ERROR_DELEGATE_H_
diff --git a/chrome/browser/diagnostics/diagnostics_model.cc b/chrome/browser/diagnostics/diagnostics_model.cc
index b7a1bc3..cf27ab7 100644
--- a/chrome/browser/diagnostics/diagnostics_model.cc
+++ b/chrome/browser/diagnostics/diagnostics_model.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.
@@ -92,6 +92,8 @@ class DiagnosticsModelWin : public DiagnosticsModelImpl {
tests_.push_back(MakeSqliteHistoryDbTest());
tests_.push_back(MakeSqliteArchivedHistoryDbTest());
tests_.push_back(MakeSqliteThumbnailsDbTest());
+ tests_.push_back(MakeSqliteAppCacheDbTest());
+ tests_.push_back(MakeSqliteWebDatabaseTrackerDbTest());
}
private:
@@ -113,6 +115,8 @@ class DiagnosticsModelMac : public DiagnosticsModelImpl {
tests_.push_back(MakeSqliteHistoryDbTest());
tests_.push_back(MakeSqliteArchivedHistoryDbTest());
tests_.push_back(MakeSqliteThumbnailsDbTest());
+ tests_.push_back(MakeSqliteAppCacheDbTest());
+ tests_.push_back(MakeSqliteWebDatabaseTrackerDbTest());
}
private:
@@ -134,6 +138,8 @@ class DiagnosticsModelPosix : public DiagnosticsModelImpl {
tests_.push_back(MakeSqliteHistoryDbTest());
tests_.push_back(MakeSqliteArchivedHistoryDbTest());
tests_.push_back(MakeSqliteThumbnailsDbTest());
+ tests_.push_back(MakeSqliteAppCacheDbTest());
+ tests_.push_back(MakeSqliteWebDatabaseTrackerDbTest());
}
private:
diff --git a/chrome/browser/diagnostics/diagnostics_model_unittest.cc b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
index 3db4912..c6e3aaf 100644
--- a/chrome/browser/diagnostics/diagnostics_model_unittest.cc
+++ b/chrome/browser/diagnostics/diagnostics_model_unittest.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.
@@ -72,9 +72,9 @@ class UTObserver: public DiagnosticsModel::Observer {
// We currently have more tests operational on windows.
#if defined(OS_WIN)
-const int kDiagnosticsTestCount = 13;
+const int kDiagnosticsTestCount = 15;
#else
-const int kDiagnosticsTestCount = 11;
+const int kDiagnosticsTestCount = 13;
#endif
// Test that the initial state is correct.
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc
index e0eeab3..0cdc34c 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.cc
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc
@@ -1,10 +1,11 @@
-// 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.
#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
#include "app/sql/connection.h"
+#include "app/sql/diagnostic_error_delegate.h"
#include "app/sql/init_status.h"
#include "app/sql/statement.h"
#include "base/file_util.h"
@@ -15,64 +16,17 @@
#include "base/string_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
+#include "webkit/appcache/appcache_interfaces.h"
+#include "webkit/database/database_tracker.h"
namespace {
-const char* kHistogramNames[] = {
- "Sqlite.Cookie.Error",
- "Sqlite.History.Error",
- "Sqlite.Thumbnail.Error",
- "Sqlite.Text.Error",
- "Sqlite.Web.Error"
-};
-
-// This class handles the exceptional sqlite errors that we might encounter
-// if for example the db is corrupted. Right now we just generate a UMA
-// histogram for release and an assert for debug builds.
-//
-// Why is it a template you ask? well, that is a funny story. The histograms
-// need to be singletons that is why they are always static at the function
-// scope, but we cannot use the Singleton class because they are not default
-// constructible. The template parameter makes the compiler to create unique
-// classes that don't share the same static variable.
-template <size_t unique>
-class BasicSqliteErrrorHandler : public sql::ErrorDelegate {
- public:
-
- virtual int OnError(int error, sql::Connection* connection,
- sql::Statement* stmt) {
- NOTREACHED() << "sqlite error " << error;
- RecordErrorInHistogram(error);
- return error;
- }
-
- private:
- static void RecordErrorInHistogram(int error) {
- // The histogram values from sqlite result codes go currently from 1 to
- // 26 currently but 50 gives them room to grow.
- UMA_HISTOGRAM_ENUMERATION(kHistogramNames[unique], error, 50);
- }
-};
-
-struct DbTestInfo {
- const char* test_name;
- const FilePath::CharType* db_name;
-};
-
-static const DbTestInfo kTestInfo[] = {
- {"Web Database", chrome::kWebDataFilename},
- {"Cookies Database", chrome::kCookieFilename},
- {"History Database", chrome::kHistoryFilename},
- {"Archived history Database", chrome::kArchivedHistoryFilename},
- {"Thumbnails Database", chrome::kThumbnailsFilename}
-};
-
// Generic diagnostic test class for checking sqlite db integrity.
class SqliteIntegrityTest : public DiagnosticTest {
public:
- explicit SqliteIntegrityTest(int index)
- : DiagnosticTest(ASCIIToUTF16(kTestInfo[index].test_name)),
- index_(index) {
+ SqliteIntegrityTest(
+ const string16& title, const FilePath& profile_relative_db_path)
+ : DiagnosticTest(title), db_path_(profile_relative_db_path) {
}
virtual int GetId() { return 0; }
@@ -81,9 +35,9 @@ class SqliteIntegrityTest : public DiagnosticTest {
FilePath path;
PathService::Get(chrome::DIR_USER_DATA, &path);
path = path.Append(FilePath::FromWStringHack(chrome::kNotSignedInProfile));
- path = path.Append(kTestInfo[index_].db_name);
+ path = path.Append(db_path_);
if (!file_util::PathExists(path)) {
- RecordFailure(ASCIIToUTF16("File not found"));
+ RecordSuccess(ASCIIToUTF16("File not found"));
return true;
}
@@ -118,49 +72,85 @@ class SqliteIntegrityTest : public DiagnosticTest {
}
private:
- int index_;
+ FilePath db_path_;
DISALLOW_COPY_AND_ASSIGN(SqliteIntegrityTest);
};
+// Uniquifier to use the sql::DiagnosticErrorDelegate template which
+// requires a static name() method.
+template <size_t unique>
+class HistogramUniquifier {
+ public:
+ static const char* name() {
+ const char* kHistogramNames[] = {
+ "Sqlite.Cookie.Error",
+ "Sqlite.History.Error",
+ "Sqlite.Thumbnail.Error",
+ "Sqlite.Text.Error",
+ "Sqlite.Web.Error"
+ };
+ return kHistogramNames[unique];
+ }
+};
+
} // namespace
sql::ErrorDelegate* GetErrorHandlerForCookieDb() {
- return new BasicSqliteErrrorHandler<0>();
+ return new sql::DiagnosticErrorDelegate<HistogramUniquifier<0> >();
}
sql::ErrorDelegate* GetErrorHandlerForHistoryDb() {
- return new BasicSqliteErrrorHandler<1>();
+ return new sql::DiagnosticErrorDelegate<HistogramUniquifier<1> >();
}
sql::ErrorDelegate* GetErrorHandlerForThumbnailDb() {
- return new BasicSqliteErrrorHandler<2>();
+ return new sql::DiagnosticErrorDelegate<HistogramUniquifier<2> >();
}
sql::ErrorDelegate* GetErrorHandlerForTextDb() {
- return new BasicSqliteErrrorHandler<3>();
+ return new sql::DiagnosticErrorDelegate<HistogramUniquifier<3> >();
}
sql::ErrorDelegate* GetErrorHandlerForWebDb() {
- return new BasicSqliteErrrorHandler<4>();
+ return new sql::DiagnosticErrorDelegate<HistogramUniquifier<4> >();
}
DiagnosticTest* MakeSqliteWebDbTest() {
- return new SqliteIntegrityTest(0);
+ return new SqliteIntegrityTest(ASCIIToUTF16("Web Database"),
+ FilePath(chrome::kWebDataFilename));
}
DiagnosticTest* MakeSqliteCookiesDbTest() {
- return new SqliteIntegrityTest(1);
+ return new SqliteIntegrityTest(ASCIIToUTF16("Cookies Database"),
+ FilePath(chrome::kCookieFilename));
}
DiagnosticTest* MakeSqliteHistoryDbTest() {
- return new SqliteIntegrityTest(2);
+ return new SqliteIntegrityTest(ASCIIToUTF16("History Database"),
+ FilePath(chrome::kHistoryFilename));
}
DiagnosticTest* MakeSqliteArchivedHistoryDbTest() {
- return new SqliteIntegrityTest(3);
+ return new SqliteIntegrityTest(ASCIIToUTF16("Archived History Database"),
+ FilePath(chrome::kArchivedHistoryFilename));
}
DiagnosticTest* MakeSqliteThumbnailsDbTest() {
- return new SqliteIntegrityTest(4);
+ return new SqliteIntegrityTest(ASCIIToUTF16("Thumbnails Database"),
+ FilePath(chrome::kThumbnailsFilename));
}
+DiagnosticTest* MakeSqliteAppCacheDbTest() {
+ FilePath appcache_dir(chrome::kAppCacheDirname);
+ FilePath appcache_db = appcache_dir.Append(appcache::kAppCacheDatabaseName);
+ return new SqliteIntegrityTest(ASCIIToUTF16("AppCache Database"),
+ appcache_db);
+}
+
+DiagnosticTest* MakeSqliteWebDatabaseTrackerDbTest() {
+ FilePath databases_dir(webkit_database::kDatabaseDirectoryName);
+ FilePath tracker_db =
+ databases_dir.Append(webkit_database::kTrackerDatabaseFileName);
+ return new SqliteIntegrityTest(ASCIIToUTF16("DatabaseTracker DB"),
+ tracker_db);
+}
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.h b/chrome/browser/diagnostics/sqlite_diagnostics.h
index 1618a07..c416e88 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.h
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.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.
@@ -25,5 +25,7 @@ DiagnosticTest* MakeSqliteCookiesDbTest();
DiagnosticTest* MakeSqliteHistoryDbTest();
DiagnosticTest* MakeSqliteArchivedHistoryDbTest();
DiagnosticTest* MakeSqliteThumbnailsDbTest();
+DiagnosticTest* MakeSqliteAppCacheDbTest();
+DiagnosticTest* MakeSqliteWebDatabaseTrackerDbTest();
#endif // CHROME_BROWSER_DIAGNOSTICS_SQLITE_DIAGNOSTICS_H_
diff --git a/webkit/appcache/appcache_database.cc b/webkit/appcache/appcache_database.cc
index a93b744..42af3dbc 100644
--- a/webkit/appcache/appcache_database.cc
+++ b/webkit/appcache/appcache_database.cc
@@ -1,10 +1,11 @@
-// 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.
#include "webkit/appcache/appcache_database.h"
#include "app/sql/connection.h"
+#include "app/sql/diagnostic_error_delegate.h"
#include "app/sql/meta_table.h"
#include "app/sql/statement.h"
#include "app/sql/transaction.h"
@@ -133,6 +134,15 @@ const struct {
const int kTableCount = ARRAYSIZE_UNSAFE(kTables);
const int kIndexCount = ARRAYSIZE_UNSAFE(kIndexes);
+class HistogramUniquifier {
+ public:
+ static const char* name() { return "Sqlite.AppCache.Error"; }
+};
+
+sql::ErrorDelegate* GetErrorHandlerForAppCacheDb() {
+ return new sql::DiagnosticErrorDelegate<HistogramUniquifier>();
+}
+
} // anon namespace
@@ -983,6 +993,8 @@ bool AppCacheDatabase::LazyOpen(bool create_if_needed) {
meta_table_.reset(new sql::MetaTable);
quota_table_.reset(new webkit_database::QuotaTable(db_.get()));
+ db_->set_error_delegate(GetErrorHandlerForAppCacheDb());
+
bool opened = false;
if (use_in_memory_db) {
opened = db_->OpenInMemory();
diff --git a/webkit/appcache/appcache_interfaces.cc b/webkit/appcache/appcache_interfaces.cc
index 4ee686a..b70cadf 100644
--- a/webkit/appcache/appcache_interfaces.cc
+++ b/webkit/appcache/appcache_interfaces.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.
@@ -19,6 +19,8 @@ const char kHttpsScheme[] = "https";
const char kHttpGETMethod[] = "GET";
const char kHttpHEADMethod[] = "HEAD";
+const FilePath::CharType kAppCacheDatabaseName[] = FILE_PATH_LITERAL("Index");
+
bool IsSchemeSupported(const GURL& url) {
bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme);
#ifndef NDEBUG
diff --git a/webkit/appcache/appcache_interfaces.h b/webkit/appcache/appcache_interfaces.h
index 223e560..b5d6424 100644
--- a/webkit/appcache/appcache_interfaces.h
+++ b/webkit/appcache/appcache_interfaces.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.
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/basictypes.h"
+#include "base/file_path.h"
class GURL;
class URLRequest;
@@ -87,6 +88,8 @@ bool IsSchemeSupported(const GURL& url);
bool IsMethodSupported(const std::string& method);
bool IsSchemeAndMethodSupported(const URLRequest* request);
+extern const FilePath::CharType kAppCacheDatabaseName[];
+
} // namespace
#endif // WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_
diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc
index 10724eb..69701e6 100644
--- a/webkit/appcache/appcache_storage_impl.cc
+++ b/webkit/appcache/appcache_storage_impl.cc
@@ -32,10 +32,10 @@ void DeleteDirectory(const FilePath& path) {
namespace appcache {
-static const char kAppCacheDatabaseName[] = "Index";
-static const char kDiskCacheDirectoryName[] = "Cache";
static const int kMaxDiskCacheSize = 250 * 1024 * 1024;
static const int kMaxMemDiskCacheSize = 10 * 1024 * 1024;
+static const FilePath::CharType kDiskCacheDirectoryName[] =
+ FILE_PATH_LITERAL("Cache");
// DatabaseTask -----------------------------------------
@@ -849,7 +849,7 @@ void AppCacheStorageImpl::Initialize(const FilePath& cache_directory) {
FilePath db_file_path;
if (!is_incognito_)
- db_file_path = cache_directory_.AppendASCII(kAppCacheDatabaseName);
+ db_file_path = cache_directory_.Append(kAppCacheDatabaseName);
database_ = new AppCacheDatabase(db_file_path);
scoped_refptr<InitTask> task = new InitTask(this);
@@ -1271,7 +1271,7 @@ AppCacheDiskCache* AppCacheStorageImpl::disk_cache() {
kMaxMemDiskCacheSize, &init_callback_);
} else {
rv = disk_cache_->InitWithDiskBackend(
- cache_directory_.AppendASCII(kDiskCacheDirectoryName),
+ cache_directory_.Append(kDiskCacheDirectoryName),
kMaxDiskCacheSize, false, &init_callback_);
}
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc
index e64f118..c184c8b 100644
--- a/webkit/database/database_tracker.cc
+++ b/webkit/database/database_tracker.cc
@@ -7,6 +7,7 @@
#include <vector>
#include "app/sql/connection.h"
+#include "app/sql/diagnostic_error_delegate.h"
#include "app/sql/meta_table.h"
#include "app/sql/statement.h"
#include "app/sql/transaction.h"
@@ -18,6 +19,19 @@
#include "webkit/database/databases_table.h"
#include "webkit/database/quota_table.h"
+namespace {
+
+class HistogramUniquifier {
+ public:
+ static const char* name() { return "Sqlite.DatabaseTracker.Error"; }
+};
+
+sql::ErrorDelegate* GetErrorHandlerForTrackerDb() {
+ return new sql::DiagnosticErrorDelegate<HistogramUniquifier>();
+}
+
+} // anon namespace
+
namespace webkit_database {
const FilePath::CharType kDatabaseDirectoryName[] =
@@ -304,6 +318,8 @@ bool DatabaseTracker::LazyInit() {
return false;
}
+ db_->set_error_delegate(GetErrorHandlerForTrackerDb());
+
databases_table_.reset(new DatabasesTable(db_.get()));
quota_table_.reset(new QuotaTable(db_.get()));
meta_table_.reset(new sql::MetaTable());