summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/appcache/chrome_appcache_service.cc46
-rw-r--r--chrome/browser/appcache/chrome_appcache_service.h11
-rw-r--r--chrome/browser/appcache/chrome_appcache_service_unittest.cc99
-rw-r--r--chrome/browser/browser_process_impl.cc2
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc5
-rw-r--r--chrome/browser/profiles/profile.cc5
-rw-r--r--chrome/browser/profiles/profile_impl.cc12
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--webkit/appcache/appcache_storage_impl.h5
9 files changed, 165 insertions, 21 deletions
diff --git a/chrome/browser/appcache/chrome_appcache_service.cc b/chrome/browser/appcache/chrome_appcache_service.cc
index c01b1d7..6c84999 100644
--- a/chrome/browser/appcache/chrome_appcache_service.cc
+++ b/chrome/browser/appcache/chrome_appcache_service.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -15,6 +15,20 @@
static bool has_initialized_thread_ids;
+namespace {
+
+// Used to defer deleting of local storage until the destructor has finished.
+void DeleteLocalStateOnIOThread(FilePath cache_path) {
+ // Post the actual deletion to the DB thread to ensure it happens after the
+ // database file has been closed.
+ BrowserThread::PostTask(
+ BrowserThread::DB, FROM_HERE,
+ NewRunnableFunction<bool(*)(const FilePath&, bool), FilePath, bool>(
+ &file_util::Delete, cache_path, true));
+}
+
+} // namespace
+
// ----------------------------------------------------------------------------
ChromeAppCacheService::ChromeAppCacheService() {
@@ -22,7 +36,8 @@ ChromeAppCacheService::ChromeAppCacheService() {
void ChromeAppCacheService::InitializeOnIOThread(
const FilePath& profile_path, bool is_incognito,
- scoped_refptr<HostContentSettingsMap> content_settings_map) {
+ scoped_refptr<HostContentSettingsMap> content_settings_map,
+ bool clear_local_state_on_exit) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!has_initialized_thread_ids) {
@@ -33,16 +48,24 @@ void ChromeAppCacheService::InitializeOnIOThread(
host_contents_settings_map_ = content_settings_map;
registrar_.Add(
this, NotificationType::PURGE_MEMORY, NotificationService::AllSources());
+ SetClearLocalStateOnExit(clear_local_state_on_exit);
+ if (!is_incognito)
+ cache_path_ = profile_path.Append(chrome::kAppCacheDirname);
// Init our base class.
- Initialize(
- is_incognito ? FilePath() : profile_path.Append(chrome::kAppCacheDirname),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
+ Initialize(cache_path_,
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
set_appcache_policy(this);
}
ChromeAppCacheService::~ChromeAppCacheService() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (clear_local_state_on_exit_ && !cache_path_.empty()) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(DeleteLocalStateOnIOThread, cache_path_));
+ }
}
void ChromeAppCacheService::SetOriginQuotaInMemory(
@@ -58,9 +81,16 @@ void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) {
storage()->ResetOriginQuotaInMemory(origin);
}
-// static
-void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) {
- file_util::Delete(profile_path.Append(chrome::kAppCacheDirname), true);
+void ChromeAppCacheService::SetClearLocalStateOnExit(bool clear_local_state) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &ChromeAppCacheService::SetClearLocalStateOnExit,
+ clear_local_state));
+ return;
+ }
+ clear_local_state_on_exit_ = clear_local_state;
}
bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) {
diff --git a/chrome/browser/appcache/chrome_appcache_service.h b/chrome/browser/appcache/chrome_appcache_service.h
index dbc0616..0b43759 100644
--- a/chrome/browser/appcache/chrome_appcache_service.h
+++ b/chrome/browser/appcache/chrome_appcache_service.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -35,14 +35,15 @@ class ChromeAppCacheService
void InitializeOnIOThread(
const FilePath& profile_path, bool is_incognito,
- scoped_refptr<HostContentSettingsMap> content_settings_map);
+ scoped_refptr<HostContentSettingsMap> content_settings_map,
+ bool clear_local_state_on_exit);
// Helpers used by the extension service to grant and revoke
// unlimited storage to app extensions.
void SetOriginQuotaInMemory(const GURL& origin, int64 quota);
void ResetOriginQuotaInMemory(const GURL& origin);
- static void ClearLocalState(const FilePath& profile_path);
+ void SetClearLocalStateOnExit(bool clear_local_state);
private:
friend class BrowserThread;
@@ -62,6 +63,10 @@ class ChromeAppCacheService
scoped_refptr<HostContentSettingsMap> host_contents_settings_map_;
NotificationRegistrar registrar_;
+ bool clear_local_state_on_exit_;
+ FilePath cache_path_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService);
};
#endif // CHROME_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_
diff --git a/chrome/browser/appcache/chrome_appcache_service_unittest.cc b/chrome/browser/appcache/chrome_appcache_service_unittest.cc
new file mode 100644
index 0000000..0cb5090
--- /dev/null
+++ b/chrome/browser/appcache/chrome_appcache_service_unittest.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2011 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 "base/file_util.h"
+#include "base/message_loop.h"
+#include "base/ref_counted.h"
+#include "base/scoped_temp_dir.h"
+#include "chrome/browser/appcache/chrome_appcache_service.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/test/thread_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/appcache/appcache_storage_impl.h"
+
+namespace appcache {
+
+class ChromeAppCacheServiceTest : public testing::Test {
+ public:
+ ChromeAppCacheServiceTest()
+ : message_loop_(MessageLoop::TYPE_IO),
+ db_thread_(BrowserThread::DB, &message_loop_),
+ file_thread_(BrowserThread::FILE, &message_loop_),
+ cache_thread_(BrowserThread::CACHE, &message_loop_),
+ io_thread_(BrowserThread::IO, &message_loop_) {
+ }
+
+ protected:
+ MessageLoop message_loop_;
+ ScopedTempDir temp_dir_;
+
+ private:
+ BrowserThread db_thread_;
+ BrowserThread file_thread_;
+ BrowserThread cache_thread_;
+ BrowserThread io_thread_;
+};
+
+TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname);
+ scoped_refptr<ChromeAppCacheService> appcache_service =
+ new ChromeAppCacheService;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(appcache_service.get(),
+ &ChromeAppCacheService::InitializeOnIOThread,
+ temp_dir_.path(), false,
+ scoped_refptr<HostContentSettingsMap>(NULL),
+ false));
+ // Make the steps needed to initialize the storage of AppCache data.
+ message_loop_.RunAllPending();
+ appcache::AppCacheStorageImpl* storage =
+ static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage());
+ ASSERT_TRUE(storage->database_->db_connection());
+ ASSERT_EQ(1, storage->NewCacheId());
+ storage->disk_cache();
+ message_loop_.RunAllPending();
+
+ ASSERT_TRUE(file_util::PathExists(appcache_path));
+ ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
+
+ appcache_service = NULL;
+ message_loop_.RunAllPending();
+
+ ASSERT_TRUE(file_util::PathExists(appcache_path));
+}
+
+TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname);
+ scoped_refptr<ChromeAppCacheService> appcache_service =
+ new ChromeAppCacheService;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(appcache_service.get(),
+ &ChromeAppCacheService::InitializeOnIOThread,
+ temp_dir_.path(), false,
+ scoped_refptr<HostContentSettingsMap>(NULL),
+ true));
+ // Make the steps needed to initialize the storage of AppCache data.
+ message_loop_.RunAllPending();
+ appcache::AppCacheStorageImpl* storage =
+ static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage());
+ ASSERT_TRUE(storage->database_->db_connection());
+ ASSERT_EQ(1, storage->NewCacheId());
+ storage->disk_cache();
+ message_loop_.RunAllPending();
+
+ ASSERT_TRUE(file_util::PathExists(appcache_path));
+ ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
+
+ appcache_service = NULL;
+ message_loop_.RunAllPending();
+
+ ASSERT_FALSE(file_util::PathExists(appcache_path));
+}
+
+} // namespace appcache
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 222ee28..d6228eb 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -15,7 +15,6 @@
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/synchronization/waitable_event.h"
-#include "chrome/browser/appcache/chrome_appcache_service.h"
#include "chrome/browser/automation/automation_provider_list.h"
#include "chrome/browser/browser_child_process_host.h"
#include "chrome/browser/browser_list.h"
@@ -576,7 +575,6 @@ bool BrowserProcessImpl::have_inspector_files() const {
void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
webkit_database::DatabaseTracker::ClearLocalState(profile_path);
- ChromeAppCacheService::ClearLocalState(profile_path);
}
bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 7f052b6..d9f8596 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -312,7 +312,8 @@ class ExtensionTestingProfile : public TestingProfile {
NewRunnableMethod(appcache_service_.get(),
&ChromeAppCacheService::InitializeOnIOThread,
GetPath(), IsOffTheRecord(),
- make_scoped_refptr(GetHostContentSettingsMap())));
+ make_scoped_refptr(GetHostContentSettingsMap()),
+ false));
}
return appcache_service_;
}
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index 1e2bba4..692012a 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -196,7 +196,8 @@ class OffTheRecordProfileImpl : public Profile,
NewRunnableMethod(appcache_service_.get(),
&ChromeAppCacheService::InitializeOnIOThread,
GetPath(), IsOffTheRecord(),
- make_scoped_refptr(GetHostContentSettingsMap())));
+ make_scoped_refptr(GetHostContentSettingsMap()),
+ false));
}
return appcache_service_;
}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 34a50fc..0f2bf3c 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -575,7 +575,8 @@ ChromeAppCacheService* ProfileImpl::GetAppCacheService() {
NewRunnableMethod(appcache_service_.get(),
&ChromeAppCacheService::InitializeOnIOThread,
GetPath(), IsOffTheRecord(),
- make_scoped_refptr(GetHostContentSettingsMap())));
+ make_scoped_refptr(GetHostContentSettingsMap()),
+ clear_local_state_on_exit_));
}
return appcache_service_;
}
@@ -1214,9 +1215,14 @@ void ProfileImpl::Observe(NotificationType type,
} else if (*pref_name_in == prefs::kClearSiteDataOnExit) {
clear_local_state_on_exit_ =
prefs->GetBoolean(prefs::kClearSiteDataOnExit);
- if (webkit_context_)
+ if (webkit_context_) {
webkit_context_->set_clear_local_state_on_exit(
clear_local_state_on_exit_);
+ }
+ if (appcache_service_) {
+ appcache_service_->SetClearLocalStateOnExit(
+ clear_local_state_on_exit_);
+ }
}
} else if (NotificationType::THEME_INSTALLED == type) {
DCHECK_EQ(Source<Profile>(source).ptr(), GetOriginalProfile());
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index eb41a66..e76848c 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1025,6 +1025,7 @@
'browser/about_flags_unittest.cc',
'browser/accessibility/browser_accessibility_mac_unittest.mm',
'browser/accessibility/browser_accessibility_win_unittest.cc',
+ 'browser/appcache/chrome_appcache_service_unittest.cc',
'browser/app_controller_mac_unittest.mm',
'browser/autocomplete_history_manager_unittest.cc',
'browser/autocomplete/autocomplete_edit_unittest.cc',
diff --git a/webkit/appcache/appcache_storage_impl.h b/webkit/appcache/appcache_storage_impl.h
index 584862a..dc49053d 100644
--- a/webkit/appcache/appcache_storage_impl.h
+++ b/webkit/appcache/appcache_storage_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -151,6 +151,9 @@ class AppCacheStorageImpl : public AppCacheStorage {
std::set<GURL> origins_with_groups_;
std::deque<Task*> pending_simple_tasks_;
ScopedRunnableMethodFactory<AppCacheStorageImpl> method_factory_;
+
+ FRIEND_TEST_ALL_PREFIXES(ChromeAppCacheServiceTest, KeepOnDestruction);
+ FRIEND_TEST_ALL_PREFIXES(ChromeAppCacheServiceTest, RemoveOnDestruction);
};
} // namespace appcache