summaryrefslogtreecommitdiffstats
path: root/webkit/appcache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 22:42:01 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 22:42:01 +0000
commitf5ad47a18ebe1dfe2656588776557c3a702faf56 (patch)
tree75e5599ad5d40d9972cf8ae8973df9a9853b316a /webkit/appcache
parentce940f01fdcd216b90e5005f840d3df5d19190cd (diff)
downloadchromium_src-f5ad47a18ebe1dfe2656588776557c3a702faf56.zip
chromium_src-f5ad47a18ebe1dfe2656588776557c3a702faf56.tar.gz
chromium_src-f5ad47a18ebe1dfe2656588776557c3a702faf56.tar.bz2
AppCache: Use a dedicated thread for the disk cache.
BUG=26730 TEST=current tests Review URL: http://codereview.chromium.org/2249005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49111 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r--webkit/appcache/appcache_disk_cache.cc11
-rw-r--r--webkit/appcache/appcache_disk_cache.h4
-rw-r--r--webkit/appcache/appcache_service.cc5
-rw-r--r--webkit/appcache/appcache_service.h7
-rw-r--r--webkit/appcache/appcache_storage_impl.cc9
-rw-r--r--webkit/appcache/appcache_storage_impl.h5
-rw-r--r--webkit/appcache/appcache_storage_impl_unittest.cc2
-rw-r--r--webkit/appcache/appcache_thread.cc1
-rw-r--r--webkit/appcache/appcache_thread.h9
9 files changed, 31 insertions, 22 deletions
diff --git a/webkit/appcache/appcache_disk_cache.cc b/webkit/appcache/appcache_disk_cache.cc
index bdaadfe..3785baf 100644
--- a/webkit/appcache/appcache_disk_cache.cc
+++ b/webkit/appcache/appcache_disk_cache.cc
@@ -25,14 +25,15 @@ AppCacheDiskCache::~AppCacheDiskCache() {
int AppCacheDiskCache::InitWithDiskBackend(
const FilePath& disk_cache_directory, int disk_cache_size, bool force,
- net::CompletionCallback* callback) {
+ base::MessageLoopProxy* cache_thread, net::CompletionCallback* callback) {
return Init(net::APP_CACHE, disk_cache_directory,
- disk_cache_size, force, callback);
+ disk_cache_size, force, cache_thread, callback);
}
int AppCacheDiskCache::InitWithMemBackend(
int mem_cache_size, net::CompletionCallback* callback) {
- return Init(net::MEMORY_CACHE, FilePath(), mem_cache_size, false, callback);
+ return Init(net::MEMORY_CACHE, FilePath(), mem_cache_size, false, NULL,
+ callback);
}
void AppCacheDiskCache::Disable() {
@@ -99,15 +100,15 @@ int AppCacheDiskCache::DoomEntry(int64 key,
int AppCacheDiskCache::Init(net::CacheType cache_type,
const FilePath& cache_directory,
int cache_size, bool force,
+ base::MessageLoopProxy* cache_thread,
net::CompletionCallback* callback) {
DCHECK(!is_initializing() && !disk_cache_.get());
is_disabled_ = false;
create_backend_callback_ = new CreateBackendCallback(
this, &AppCacheDiskCache::OnCreateBackendComplete);
- // TODO(michaeln): Pass a valid cache_thread here.
int rv = disk_cache::CreateCacheBackend(
- cache_type, cache_directory, cache_size, force, NULL,
+ cache_type, cache_directory, cache_size, force, cache_thread,
&(create_backend_callback_->backend_ptr_), create_backend_callback_);
if (rv == net::ERR_IO_PENDING)
init_callback_ = callback;
diff --git a/webkit/appcache/appcache_disk_cache.h b/webkit/appcache/appcache_disk_cache.h
index c295067..f78a607d 100644
--- a/webkit/appcache/appcache_disk_cache.h
+++ b/webkit/appcache/appcache_disk_cache.h
@@ -29,6 +29,7 @@ class AppCacheDiskCache {
// Initializes the object to use disk backed storage.
int InitWithDiskBackend(const FilePath& disk_cache_directory,
int disk_cache_size, bool force,
+ base::MessageLoopProxy* cache_thread,
net::CompletionCallback* callback);
// Initializes the object to use memory only storage.
@@ -85,7 +86,8 @@ class AppCacheDiskCache {
return create_backend_callback_.get() != NULL;
}
int Init(net::CacheType cache_type, const FilePath& directory,
- int cache_size, bool force, net::CompletionCallback* callback);
+ int cache_size, bool force, base::MessageLoopProxy* cache_thread,
+ net::CompletionCallback* callback);
void OnCreateBackendComplete(int rv);
bool is_disabled_;
diff --git a/webkit/appcache/appcache_service.cc b/webkit/appcache/appcache_service.cc
index a6bc24a..bf8fba2 100644
--- a/webkit/appcache/appcache_service.cc
+++ b/webkit/appcache/appcache_service.cc
@@ -143,10 +143,11 @@ AppCacheService::~AppCacheService() {
STLDeleteElements(&pending_helpers_);
}
-void AppCacheService::Initialize(const FilePath& cache_directory) {
+void AppCacheService::Initialize(const FilePath& cache_directory,
+ base::MessageLoopProxy* cache_thread) {
DCHECK(!storage_.get());
AppCacheStorageImpl* storage = new AppCacheStorageImpl(this);
- storage->Initialize(cache_directory);
+ storage->Initialize(cache_directory, cache_thread);
storage_.reset(storage);
}
diff --git a/webkit/appcache/appcache_service.h b/webkit/appcache/appcache_service.h
index 7ccdeea..ac5aa4a 100644
--- a/webkit/appcache/appcache_service.h
+++ b/webkit/appcache/appcache_service.h
@@ -19,6 +19,10 @@
class URLRequestContext;
+namespace base {
+class MessageLoopProxy;
+}
+
namespace appcache {
class AppCacheBackendImpl;
@@ -62,7 +66,8 @@ class AppCacheService {
AppCacheService();
virtual ~AppCacheService();
- void Initialize(const FilePath& cache_directory);
+ void Initialize(const FilePath& cache_directory,
+ base::MessageLoopProxy* cache_thread);
// Purges any memory not needed.
void PurgeMemory() {
diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc
index 051d276..b853a0c 100644
--- a/webkit/appcache/appcache_storage_impl.cc
+++ b/webkit/appcache/appcache_storage_impl.cc
@@ -844,8 +844,10 @@ AppCacheStorageImpl::~AppCacheStorageImpl() {
AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_);
}
-void AppCacheStorageImpl::Initialize(const FilePath& cache_directory) {
+void AppCacheStorageImpl::Initialize(const FilePath& cache_directory,
+ base::MessageLoopProxy* cache_thread) {
cache_directory_ = cache_directory;
+ cache_thread_ = cache_thread;
is_incognito_ = cache_directory_.empty();
FilePath db_file_path;
@@ -1273,9 +1275,12 @@ AppCacheDiskCache* AppCacheStorageImpl::disk_cache() {
} else {
rv = disk_cache_->InitWithDiskBackend(
cache_directory_.Append(kDiskCacheDirectoryName),
- kMaxDiskCacheSize, false, &init_callback_);
+ kMaxDiskCacheSize, false, cache_thread_, &init_callback_);
}
+ // We should not keep this reference around.
+ cache_thread_ = NULL;
+
if (rv != net::ERR_IO_PENDING)
OnDiskCacheInitialized(rv);
}
diff --git a/webkit/appcache/appcache_storage_impl.h b/webkit/appcache/appcache_storage_impl.h
index 5b0c1b3..93abfc64 100644
--- a/webkit/appcache/appcache_storage_impl.h
+++ b/webkit/appcache/appcache_storage_impl.h
@@ -11,6 +11,7 @@
#include <vector>
#include "base/file_path.h"
+#include "base/message_loop_proxy.h"
#include "base/task.h"
#include "webkit/appcache/appcache_database.h"
#include "webkit/appcache/appcache_disk_cache.h"
@@ -23,7 +24,8 @@ class AppCacheStorageImpl : public AppCacheStorage {
explicit AppCacheStorageImpl(AppCacheService* service);
virtual ~AppCacheStorageImpl();
- void Initialize(const FilePath& cache_directory);
+ void Initialize(const FilePath& cache_directory,
+ base::MessageLoopProxy* cache_thread);
void Disable();
bool is_disabled() const { return is_disabled_; }
@@ -113,6 +115,7 @@ class AppCacheStorageImpl : public AppCacheStorage {
// The directory in which we place files in the file system.
FilePath cache_directory_;
+ scoped_refptr<base::MessageLoopProxy> cache_thread_;
bool is_incognito_;
// Structures to keep track of DatabaseTasks that are in-flight.
diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc
index 00342df..627181e 100644
--- a/webkit/appcache/appcache_storage_impl_unittest.cc
+++ b/webkit/appcache/appcache_storage_impl_unittest.cc
@@ -227,7 +227,7 @@ class AppCacheStorageImplTest : public testing::Test {
void SetUpTest() {
DCHECK(MessageLoop::current() == io_thread->message_loop());
service_.reset(new AppCacheService);
- service_->Initialize(FilePath());
+ service_->Initialize(FilePath(), NULL);
delegate_.reset(new MockStorageDelegate(this));
}
diff --git a/webkit/appcache/appcache_thread.cc b/webkit/appcache/appcache_thread.cc
index 56a34e6..579cb53 100644
--- a/webkit/appcache/appcache_thread.cc
+++ b/webkit/appcache/appcache_thread.cc
@@ -9,6 +9,5 @@ namespace appcache {
// static
int AppCacheThread::db_;
int AppCacheThread::io_;
-MessageLoop* AppCacheThread::disk_cache_thread_;
} // namespace appcache
diff --git a/webkit/appcache/appcache_thread.h b/webkit/appcache/appcache_thread.h
index 7a0a70c..b4e46ca 100644
--- a/webkit/appcache/appcache_thread.h
+++ b/webkit/appcache/appcache_thread.h
@@ -11,8 +11,6 @@ namespace tracked_objects {
class Location;
}
-class MessageLoop;
-
namespace appcache {
// The appcache system uses two threads, an IO thread and a DB thread.
@@ -20,18 +18,14 @@ namespace appcache {
// providing them to the appcache library by providing a concrete
// implementation of the PostTask and CurrentlyOn methods declared here,
// and by calling the Init method prior to using the appcache library.
-// The disk_cache also requires the embedder to provide a thread message
-// loop.
class AppCacheThread {
public:
- static void Init(int db, int io, MessageLoop* disk_cache_thread) {
+ static void Init(int db, int io) {
db_ = db;
io_ = io;
- disk_cache_thread_ = disk_cache_thread;
}
static int db() { return db_; }
static int io() { return io_; }
- static MessageLoop* disk_cache_thread() { return disk_cache_thread_; }
static bool PostTask(int id,
const tracked_objects::Location& from_here,
@@ -51,7 +45,6 @@ class AppCacheThread {
static int db_;
static int io_;
- static MessageLoop* disk_cache_thread_;
};
} // namespace appcache