summaryrefslogtreecommitdiffstats
path: root/webkit/appcache
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 19:40:21 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 19:40:21 +0000
commitc4925d5805396a5e15ae4297b6173b5ed2610a93 (patch)
treee821154e001de7b637657f8f5b096000cb482be2 /webkit/appcache
parent93330676dddfffc05a070df8e7b7e91fd5801ca2 (diff)
downloadchromium_src-c4925d5805396a5e15ae4297b6173b5ed2610a93.zip
chromium_src-c4925d5805396a5e15ae4297b6173b5ed2610a93.tar.gz
chromium_src-c4925d5805396a5e15ae4297b6173b5ed2610a93.tar.bz2
AppCache: If we can't read the existing data delete it and start over.
BUG=38360 TEST=some unit tests apply, but no new tests for this specifically Review URL: http://codereview.chromium.org/1562005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43371 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r--webkit/appcache/appcache_database.cc14
-rw-r--r--webkit/appcache/appcache_histograms.cc18
-rw-r--r--webkit/appcache/appcache_histograms.h21
-rw-r--r--webkit/appcache/appcache_storage_impl.cc22
-rw-r--r--webkit/appcache/webkit_appcache.gypi3
5 files changed, 76 insertions, 2 deletions
diff --git a/webkit/appcache/appcache_database.cc b/webkit/appcache/appcache_database.cc
index a1aa59b..a93b744 100644
--- a/webkit/appcache/appcache_database.cc
+++ b/webkit/appcache/appcache_database.cc
@@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "webkit/appcache/appcache_entry.h"
+#include "webkit/appcache/appcache_histograms.h"
#include "webkit/database/quota_table.h"
// Schema -------------------------------------------------------------------
@@ -994,10 +995,22 @@ bool AppCacheDatabase::LazyOpen(bool create_if_needed) {
}
if (!opened || !EnsureDatabaseVersion()) {
+ LOG(ERROR) << "Failed to open the appcache database.";
+ AppCacheHistograms::CountInitResult(
+ AppCacheHistograms::SQL_DATABASE_ERROR);
+
+ // We're unable to open the database. This is a fatal error
+ // which we can't recover from. We try to handle it by deleting
+ // the existing appcache data and starting with a clean slate in
+ // this browser session.
+ if (!use_in_memory_db && DeleteExistingAndCreateNewDatabase())
+ return true;
+
Disable();
return false;
}
+ AppCacheHistograms::CountInitResult(AppCacheHistograms::INIT_OK);
return true;
}
@@ -1078,6 +1091,7 @@ void AppCacheDatabase::ResetConnectionAndTables() {
bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() {
DCHECK(!db_file_path_.empty());
DCHECK(file_util::PathExists(db_file_path_));
+ LOG(INFO) << "Deleting existing appcache data and starting over.";
ResetConnectionAndTables();
diff --git a/webkit/appcache/appcache_histograms.cc b/webkit/appcache/appcache_histograms.cc
new file mode 100644
index 0000000..9907047
--- /dev/null
+++ b/webkit/appcache/appcache_histograms.cc
@@ -0,0 +1,18 @@
+// 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_histograms.h"
+
+#include "base/histogram.h"
+
+namespace appcache {
+
+// static
+void AppCacheHistograms::CountInitResult(InitResultType init_result) {
+ UMA_HISTOGRAM_ENUMERATION(
+ "appcache.InitResult",
+ init_result, NUM_INIT_RESULT_TYPES);
+}
+
+} // namespace appcache
diff --git a/webkit/appcache/appcache_histograms.h b/webkit/appcache/appcache_histograms.h
new file mode 100644
index 0000000..431c6bd
--- /dev/null
+++ b/webkit/appcache/appcache_histograms.h
@@ -0,0 +1,21 @@
+// 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 WEBKIT_APPCACHE_APPCACHE_HISTOGRAMS_H_
+#define WEBKIT_APPCACHE_APPCACHE_HISTOGRAMS_H_
+
+namespace appcache {
+
+class AppCacheHistograms {
+ public:
+ enum InitResultType {
+ INIT_OK, SQL_DATABASE_ERROR, DISK_CACHE_ERROR,
+ NUM_INIT_RESULT_TYPES
+ };
+ static void CountInitResult(InitResultType init_result);
+};
+
+} // namespace appcache
+
+#endif // WEBKIT_APPCACHE_APPCACHE_HISTOGRAMS_H_
diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc
index d700d24c..10724eb 100644
--- a/webkit/appcache/appcache_storage_impl.cc
+++ b/webkit/appcache/appcache_storage_impl.cc
@@ -17,11 +17,19 @@
#include "webkit/appcache/appcache_database.h"
#include "webkit/appcache/appcache_entry.h"
#include "webkit/appcache/appcache_group.h"
+#include "webkit/appcache/appcache_histograms.h"
#include "webkit/appcache/appcache_policy.h"
#include "webkit/appcache/appcache_response.h"
#include "webkit/appcache/appcache_service.h"
#include "webkit/appcache/appcache_thread.h"
+namespace {
+// Helper with no return value for use with NewRunnableFunction.
+void DeleteDirectory(const FilePath& path) {
+ file_util::Delete(path, true);
+}
+}
+
namespace appcache {
static const char kAppCacheDatabaseName[] = "Index";
@@ -1275,9 +1283,19 @@ AppCacheDiskCache* AppCacheStorageImpl::disk_cache() {
void AppCacheStorageImpl::OnDiskCacheInitialized(int rv) {
if (rv != net::OK) {
- // TODO(michaeln): We're unable to open the disk cache, how
- // do we recover from this error?
+ LOG(ERROR) << "Failed to open the appcache diskcache.";
+ AppCacheHistograms::CountInitResult(AppCacheHistograms::DISK_CACHE_ERROR);
+
+ // We're unable to open the disk cache, this is a fatal error that we can't
+ // really recover from. We handle it by disabling the appcache for this
+ // browser session and deleting the directory on disk. The next browser
+ // session should start with a clean slate.
Disable();
+ if (!is_incognito_) {
+ LOG(INFO) << "Deleting existing appcache data and starting over.";
+ AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE,
+ NewRunnableFunction(DeleteDirectory, cache_directory_));
+ }
}
}
diff --git a/webkit/appcache/webkit_appcache.gypi b/webkit/appcache/webkit_appcache.gypi
index 968c525..e3d5d902 100644
--- a/webkit/appcache/webkit_appcache.gypi
+++ b/webkit/appcache/webkit_appcache.gypi
@@ -27,6 +27,8 @@
'appcache_frontend_impl.h',
'appcache_group.cc',
'appcache_group.h',
+ 'appcache_histograms.cc',
+ 'appcache_histograms.h',
'appcache_host.cc',
'appcache_host.h',
'appcache_interceptor.cc',
@@ -60,6 +62,7 @@
'view_appcache_internals_job.cc',
'web_application_cache_host_impl.cc',
'web_application_cache_host_impl.h',
+ 'webkit_appcache.gypi',
],
'conditions': [
['inside_chromium_build==0', {