summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-23 20:40:57 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-23 20:40:57 +0000
commit8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7 (patch)
treedd56c3b7fb32d93154b58616e4e8368cc2702341 /webkit
parentd6b7266a83b8fffe30fd79c9ebe7c155cb5b687d (diff)
downloadchromium_src-8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7.zip
chromium_src-8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7.tar.gz
chromium_src-8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7.tar.bz2
The appcache system uses two threads, an IO thread and a DB thread.
It does not create these threads, the embedder is responsible for providing them to the appcache library by implementing the class declared in appcache_thread.h. Also in this CL are two implementations, one for Chrome and another for test_shell. TEST=none BUG=none Review URL: http://codereview.chromium.org/409005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32846 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/appcache/appcache_thread.cc13
-rw-r--r--webkit/appcache/appcache_thread.h44
-rw-r--r--webkit/tools/test_shell/simple_appcache_system.cc27
-rw-r--r--webkit/tools/test_shell/simple_appcache_system.h25
-rw-r--r--webkit/webkit.gyp2
5 files changed, 108 insertions, 3 deletions
diff --git a/webkit/appcache/appcache_thread.cc b/webkit/appcache/appcache_thread.cc
new file mode 100644
index 0000000..579cb53
--- /dev/null
+++ b/webkit/appcache/appcache_thread.cc
@@ -0,0 +1,13 @@
+// Copyright (c) 2009 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_thread.h"
+
+namespace appcache {
+
+// static
+int AppCacheThread::db_;
+int AppCacheThread::io_;
+
+} // namespace appcache
diff --git a/webkit/appcache/appcache_thread.h b/webkit/appcache/appcache_thread.h
new file mode 100644
index 0000000..9f14b1c
--- /dev/null
+++ b/webkit/appcache/appcache_thread.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2009 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_THREAD_H_
+#define WEBKIT_APPCACHE_APPCACHE_THREAD_H_
+
+namespace tracked_objects {
+class Location;
+}
+class Task;
+
+namespace appcache {
+
+// The appcache system uses two threads, an IO thread and a DB thread.
+// It does not create these threads, the embedder is responsible for
+// providing them to the appcache library by providing a concrete
+// implementation of the PostTask and CurrentlyOn methods declared here,
+// and by calling the InitIDs method prior to using the appcache library.
+class AppCacheThread {
+ public:
+ static void InitIDs(int db, int io) {
+ db_ = db;
+ io_ = io;
+ }
+ static int db() { return db_; }
+ static int io() { return io_; }
+
+ static bool PostTask(int id,
+ const tracked_objects::Location& from_here,
+ Task* task);
+ static bool CurrentlyOn(int id);
+
+ private:
+ AppCacheThread();
+ ~AppCacheThread();
+
+ static int db_;
+ static int io_;
+};
+
+} // namespace appcache
+
+#endif // WEBKIT_APPCACHE_APPCACHE_THREAD_H_
diff --git a/webkit/tools/test_shell/simple_appcache_system.cc b/webkit/tools/test_shell/simple_appcache_system.cc
index 297005a..0f9d452 100644
--- a/webkit/tools/test_shell/simple_appcache_system.cc
+++ b/webkit/tools/test_shell/simple_appcache_system.cc
@@ -16,7 +16,28 @@ using WebKit::WebApplicationCacheHostClient;
using appcache::WebApplicationCacheHostImpl;
using appcache::AppCacheBackendImpl;
using appcache::AppCacheInterceptor;
+using appcache::AppCacheThread;
+namespace appcache {
+
+// An impl of AppCacheThread we need to provide to the appcache lib.
+
+bool AppCacheThread::PostTask(
+ int id,
+ const tracked_objects::Location& from_here,
+ Task* task) {
+ scoped_ptr<Task> task_ptr(task);
+ MessageLoop* loop = SimpleAppCacheSystem::GetMessageLoop(id);
+ if (loop)
+ loop->PostTask(from_here, task_ptr.release());
+ return loop ? true : false;
+}
+
+bool AppCacheThread::CurrentlyOn(int id) {
+ return MessageLoop::current() == SimpleAppCacheSystem::GetMessageLoop(id);
+}
+
+} // namespace appcache
// SimpleFrontendProxy --------------------------------------------------------
// Proxies method calls from the backend IO thread to the frontend UI thread.
@@ -247,7 +268,7 @@ SimpleAppCacheSystem::SimpleAppCacheSystem()
backend_proxy_(new SimpleBackendProxy(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(
frontend_proxy_(new SimpleFrontendProxy(this))),
- backend_impl_(NULL), service_(NULL) {
+ backend_impl_(NULL), service_(NULL), db_thread_("AppCacheDBThread") {
DCHECK(!instance_);
instance_ = this;
}
@@ -262,6 +283,7 @@ void SimpleAppCacheSystem::InitOnUIThread(
const FilePath& cache_directory) {
DCHECK(!ui_message_loop_);
DCHECK(!cache_directory.empty());
+ AppCacheThread::InitIDs(DB_THREAD_ID, IO_THREAD_ID);
ui_message_loop_ = MessageLoop::current();
cache_directory_ = cache_directory;
}
@@ -274,6 +296,9 @@ void SimpleAppCacheSystem::InitOnIOThread(URLRequestContext* request_context) {
io_message_loop_ = MessageLoop::current();
io_message_loop_->AddDestructionObserver(this);
+ if (!db_thread_.IsRunning())
+ db_thread_.Start();
+
// Recreate and initialize per each IO thread.
service_ = new appcache::AppCacheService();
backend_impl_ = new appcache::AppCacheBackendImpl();
diff --git a/webkit/tools/test_shell/simple_appcache_system.h b/webkit/tools/test_shell/simple_appcache_system.h
index c029051..adeedd6 100644
--- a/webkit/tools/test_shell/simple_appcache_system.h
+++ b/webkit/tools/test_shell/simple_appcache_system.h
@@ -7,9 +7,11 @@
#include "base/file_path.h"
#include "base/message_loop.h"
+#include "base/thread.h"
#include "webkit/appcache/appcache_backend_impl.h"
#include "webkit/appcache/appcache_frontend_impl.h"
#include "webkit/appcache/appcache_service.h"
+#include "webkit/appcache/appcache_thread.h"
#include "webkit/glue/resource_type.h"
namespace WebKit {
@@ -74,9 +76,12 @@ class SimpleAppCacheSystem : public MessageLoop::DestructionObserver {
private:
friend class SimpleBackendProxy;
friend class SimpleFrontendProxy;
+ friend class appcache::AppCacheThread;
- // A low-tech singleton.
- static SimpleAppCacheSystem* instance_;
+ enum AppCacheThreadID {
+ DB_THREAD_ID,
+ IO_THREAD_ID,
+ };
// Instance methods called by our static public methods
void InitOnUIThread(const FilePath& cache_directory);
@@ -101,6 +106,16 @@ class SimpleAppCacheSystem : public MessageLoop::DestructionObserver {
bool is_initailized_on_ui_thread() {
return ui_message_loop_ && !cache_directory_.empty();
}
+ static MessageLoop* GetMessageLoop(int id) {
+ if (instance_) {
+ if (id == IO_THREAD_ID)
+ return instance_->io_message_loop_;
+ if (id == DB_THREAD_ID)
+ return instance_->db_thread_.message_loop();
+ NOTREACHED() << "Invalid AppCacheThreadID value";
+ }
+ return NULL;
+ }
// IOThread DestructionObserver
virtual void WillDestroyCurrentMessageLoop();
@@ -117,6 +132,12 @@ class SimpleAppCacheSystem : public MessageLoop::DestructionObserver {
// is started new instances will be created.
appcache::AppCacheBackendImpl* backend_impl_;
appcache::AppCacheService* service_;
+
+ // We start a thread for use as the DB thread.
+ base::Thread db_thread_;
+
+ // A low-tech singleton.
+ static SimpleAppCacheSystem* instance_;
};
#endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 972d734..8fed312 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -166,6 +166,8 @@
'appcache/appcache_storage.h',
'appcache/appcache_storage_impl.cc',
'appcache/appcache_storage_impl.h',
+ 'appcache/appcache_thread.cc',
+ 'appcache/appcache_thread.h',
'appcache/appcache_working_set.cc',
'appcache/appcache_working_set.h',
'appcache/appcache_update_job.cc',