summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/appcache/chrome_appcache_service.cc6
-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
-rw-r--r--webkit/tools/test_shell/simple_appcache_system.cc9
-rw-r--r--webkit/tools/test_shell/simple_resource_loader_bridge.cc18
-rw-r--r--webkit/tools/test_shell/simple_resource_loader_bridge.h4
-rw-r--r--webkit/tools/test_shell/test_shell.gypi1
-rw-r--r--webkit/tools/test_shell/test_shell_request_context.cc11
-rw-r--r--webkit/tools/test_shell/test_shell_request_context.h2
-rw-r--r--webkit/tools/test_shell/test_shell_webkit_init.cc107
-rw-r--r--webkit/tools/test_shell/test_shell_webkit_init.h111
18 files changed, 176 insertions, 146 deletions
diff --git a/chrome/browser/appcache/chrome_appcache_service.cc b/chrome/browser/appcache/chrome_appcache_service.cc
index 6e94f25..1939a16 100644
--- a/chrome/browser/appcache/chrome_appcache_service.cc
+++ b/chrome/browser/appcache/chrome_appcache_service.cc
@@ -53,8 +53,7 @@ ChromeAppCacheService::ChromeAppCacheService(
if (!has_initialized_thread_ids) {
has_initialized_thread_ids = true;
- appcache::AppCacheThread::Init(ChromeThread::DB, ChromeThread::IO,
- NULL); // TODO(michaeln): cache_thread
+ appcache::AppCacheThread::Init(ChromeThread::DB, ChromeThread::IO);
}
host_contents_settings_map_ = request_context->host_content_settings_map();
@@ -63,7 +62,8 @@ ChromeAppCacheService::ChromeAppCacheService(
// Init our base class.
Initialize(request_context->is_off_the_record() ?
- FilePath() : profile_path.Append(chrome::kAppCacheDirname));
+ FilePath() : profile_path.Append(chrome::kAppCacheDirname),
+ ChromeThread::GetMessageLoopProxyForThread(ChromeThread::CACHE));
set_request_context(request_context);
set_appcache_policy(this);
}
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
diff --git a/webkit/tools/test_shell/simple_appcache_system.cc b/webkit/tools/test_shell/simple_appcache_system.cc
index 49b4881..81efb98 100644
--- a/webkit/tools/test_shell/simple_appcache_system.cc
+++ b/webkit/tools/test_shell/simple_appcache_system.cc
@@ -331,11 +331,9 @@ SimpleAppCacheSystem::~SimpleAppCacheSystem() {
}
}
-void SimpleAppCacheSystem::InitOnUIThread(
- const FilePath& cache_directory) {
+void SimpleAppCacheSystem::InitOnUIThread(const FilePath& cache_directory) {
DCHECK(!ui_message_loop_);
- // TODO(michaeln): provide a cache_thread message loop
- AppCacheThread::Init(DB_THREAD_ID, IO_THREAD_ID, NULL);
+ AppCacheThread::Init(DB_THREAD_ID, IO_THREAD_ID);
ui_message_loop_ = MessageLoop::current();
cache_directory_ = cache_directory;
}
@@ -354,7 +352,8 @@ void SimpleAppCacheSystem::InitOnIOThread(URLRequestContext* request_context) {
// Recreate and initialize per each IO thread.
service_ = new appcache::AppCacheService();
backend_impl_ = new appcache::AppCacheBackendImpl();
- service_->Initialize(cache_directory_);
+ service_->Initialize(cache_directory_,
+ SimpleResourceLoaderBridge::GetCacheThread());
service_->set_request_context(request_context);
backend_impl_->Initialize(service_, frontend_proxy_.get(), kSingleProcessId);
diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
index ffa0d81..d76a5fe 100644
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
@@ -86,6 +86,7 @@ struct TestShellRequestContextParams {
TestShellRequestContextParams* g_request_context_params = NULL;
URLRequestContext* g_request_context = NULL;
+base::Thread* g_cache_thread = NULL;
//-----------------------------------------------------------------------------
@@ -733,6 +734,10 @@ void SimpleResourceLoaderBridge::Shutdown() {
delete g_io_thread;
g_io_thread = NULL;
+ DCHECK(g_cache_thread);
+ delete g_cache_thread;
+ g_cache_thread = NULL;
+
DCHECK(!g_request_context) << "should have been nulled by thread dtor";
} else {
delete g_request_context_params;
@@ -788,6 +793,13 @@ bool SimpleResourceLoaderBridge::EnsureIOThread() {
base::EnsureNSPRInit();
#endif
+ // Create the cache thread. We want the cache thread to outlive the IO thread,
+ // so its lifetime is bonded to the IO thread lifetime.
+ DCHECK(!g_cache_thread);
+ g_cache_thread = new base::Thread("cache");
+ CHECK(g_cache_thread->StartWithOptions(
+ base::Thread::Options(MessageLoop::TYPE_IO, 0)));
+
g_io_thread = new IOThread();
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
@@ -804,3 +816,9 @@ void SimpleResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) {
g_io_thread->SetAcceptAllCookies(accept_all_cookies);
}
}
+
+// static
+scoped_refptr<base::MessageLoopProxy>
+ SimpleResourceLoaderBridge::GetCacheThread() {
+ return g_cache_thread->message_loop_proxy();
+}
diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.h b/webkit/tools/test_shell/simple_resource_loader_bridge.h
index 1bcfe07..cea8001 100644
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.h
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.h
@@ -6,6 +6,7 @@
#define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_RESOURCE_LOADER_BRIDGE_H__
#include <string>
+#include "base/message_loop_proxy.h"
#include "base/file_path.h"
#include "net/http/http_cache.h"
@@ -35,6 +36,9 @@ class SimpleResourceLoaderBridge {
const GURL& first_party_for_cookies);
static bool EnsureIOThread();
static void SetAcceptAllCookies(bool accept_all_cookies);
+
+ // This method should only be called after Init(), and before Shutdown().
+ static scoped_refptr<base::MessageLoopProxy> GetCacheThread();
};
#endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_RESOURCE_LOADER_BRIDGE_H__
diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi
index 5b83a349..4e5c6fa 100644
--- a/webkit/tools/test_shell/test_shell.gypi
+++ b/webkit/tools/test_shell/test_shell.gypi
@@ -94,6 +94,7 @@
'test_shell_switches.cc',
'test_shell_switches.h',
'test_shell_win.cc',
+ 'test_shell_webkit_init.cc',
'test_shell_webkit_init.h',
'test_shell_webthemecontrol.h',
'test_shell_webthemecontrol.cc',
diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc
index d76c6c5..a688c13 100644
--- a/webkit/tools/test_shell/test_shell_request_context.cc
+++ b/webkit/tools/test_shell/test_shell_request_context.cc
@@ -17,15 +17,16 @@
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/proxy/proxy_service.h"
#include "webkit/glue/webkit_glue.h"
+#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
-TestShellRequestContext::TestShellRequestContext() : cache_thread_("cache") {
+TestShellRequestContext::TestShellRequestContext() {
Init(FilePath(), net::HttpCache::NORMAL, false);
}
TestShellRequestContext::TestShellRequestContext(
const FilePath& cache_path,
net::HttpCache::Mode cache_mode,
- bool no_proxy) : cache_thread_("cache") {
+ bool no_proxy) {
Init(cache_path, cache_mode, no_proxy);
}
@@ -63,13 +64,9 @@ void TestShellRequestContext::Init(
http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault();
- if (!cache_path.empty())
- CHECK(cache_thread_.StartWithOptions(
- base::Thread::Options(MessageLoop::TYPE_IO, 0)));
-
net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend(
cache_path.empty() ? net::MEMORY_CACHE : net::DISK_CACHE,
- cache_path, 0, cache_thread_.message_loop_proxy());
+ cache_path, 0, SimpleResourceLoaderBridge::GetCacheThread());
net::HttpCache* cache =
new net::HttpCache(NULL, host_resolver_, proxy_service_,
diff --git a/webkit/tools/test_shell/test_shell_request_context.h b/webkit/tools/test_shell/test_shell_request_context.h
index 1bba2f0..c03d7909 100644
--- a/webkit/tools/test_shell/test_shell_request_context.h
+++ b/webkit/tools/test_shell/test_shell_request_context.h
@@ -30,8 +30,6 @@ class TestShellRequestContext : public URLRequestContext {
void Init(const FilePath& cache_path, net::HttpCache::Mode cache_mode,
bool no_proxy);
-
- base::Thread cache_thread_;
};
#endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_REQUEST_CONTEXT_H__
diff --git a/webkit/tools/test_shell/test_shell_webkit_init.cc b/webkit/tools/test_shell/test_shell_webkit_init.cc
new file mode 100644
index 0000000..6da3962
--- /dev/null
+++ b/webkit/tools/test_shell/test_shell_webkit_init.cc
@@ -0,0 +1,107 @@
+// 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/tools/test_shell/test_shell_webkit_init.h"
+
+#include "base/path_service.h"
+#include "base/stats_counters.h"
+#include "media/base/media.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h"
+#include "webkit/extensions/v8/gears_extension.h"
+#include "webkit/extensions/v8/interval_extension.h"
+#include "webkit/tools/test_shell/test_shell.h"
+
+#if defined(OS_WIN)
+#include "webkit/tools/test_shell/test_shell_webthemeengine.h"
+#endif
+
+TestShellWebKitInit::TestShellWebKitInit(bool layout_test_mode) {
+ v8::V8::SetCounterFunction(StatsTable::FindLocation);
+
+ WebKit::initialize(this);
+ WebKit::setLayoutTestMode(layout_test_mode);
+ WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(
+ WebKit::WebString::fromUTF8("test-shell-resource"));
+ WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess(
+ WebKit::WebString::fromUTF8("test-shell-resource"));
+ WebKit::WebScriptController::enableV8SingleThreadMode();
+ WebKit::WebScriptController::registerExtension(
+ extensions_v8::GearsExtension::Get());
+ WebKit::WebScriptController::registerExtension(
+ extensions_v8::IntervalExtension::Get());
+ WebKit::WebRuntimeFeatures::enableSockets(true);
+ WebKit::WebRuntimeFeatures::enableApplicationCache(true);
+ WebKit::WebRuntimeFeatures::enableDatabase(true);
+ WebKit::WebRuntimeFeatures::enableWebGL(true);
+ WebKit::WebRuntimeFeatures::enablePushState(true);
+ WebKit::WebRuntimeFeatures::enableNotifications(true);
+ WebKit::WebRuntimeFeatures::enableTouch(true);
+ WebKit::WebRuntimeFeatures::enableIndexedDatabase(true);
+
+ // Load libraries for media and enable the media player.
+ FilePath module_path;
+ WebKit::WebRuntimeFeatures::enableMediaPlayer(
+ PathService::Get(base::DIR_MODULE, &module_path) &&
+ media::InitializeMediaLibrary(module_path));
+
+ WebKit::WebRuntimeFeatures::enableGeolocation(true);
+
+ // Construct and initialize an appcache system for this scope.
+ // A new empty temp directory is created to house any cached
+ // content during the run. Upon exit that directory is deleted.
+ // If we can't create a tempdir, we'll use in-memory storage.
+ if (!appcache_dir_.CreateUniqueTempDir()) {
+ LOG(WARNING) << "Failed to create a temp dir for the appcache, "
+ "using in-memory storage.";
+ DCHECK(appcache_dir_.path().empty());
+ }
+ SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path());
+
+ WebKit::WebDatabase::setObserver(&database_system_);
+
+ file_system_.set_sandbox_enabled(false);
+
+#if defined(OS_WIN)
+ // Ensure we pick up the default theme engine.
+ SetThemeEngine(NULL);
+#endif
+}
+
+TestShellWebKitInit::~TestShellWebKitInit() {
+ WebKit::shutdown();
+}
+
+WebKit::WebClipboard* TestShellWebKitInit::clipboard() {
+ // Mock out clipboard calls in layout test mode so that tests don't mess
+ // with each other's copies/pastes when running in parallel.
+ if (TestShell::layout_test_mode()) {
+ return &mock_clipboard_;
+ } else {
+ return &real_clipboard_;
+ }
+}
+
+WebKit::WebData TestShellWebKitInit::loadResource(const char* name) {
+ if (!strcmp(name, "deleteButton")) {
+ // Create a red 30x30 square.
+ const char red_square[] =
+ "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
+ "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3"
+ "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00"
+ "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80"
+ "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff"
+ "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00"
+ "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a"
+ "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a"
+ "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d"
+ "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60"
+ "\x82";
+ return WebKit::WebData(red_square, arraysize(red_square));
+ }
+ return webkit_glue::WebKitClientImpl::loadResource(name);
+}
diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h
index cc66afc..6cd62a6 100644
--- a/webkit/tools/test_shell/test_shell_webkit_init.h
+++ b/webkit/tools/test_shell/test_shell_webkit_init.h
@@ -5,32 +5,9 @@
#ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_
#define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_
-#include "base/file_util.h"
-#include "base/path_service.h"
-#include "base/platform_file.h"
-#include "base/scoped_temp_dir.h"
-#include "base/stats_counters.h"
-#include "base/string_util.h"
-#include "media/base/media.h"
-#include "net/base/file_stream.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebData.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebGeolocationServiceMock.h"
#include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebStorageArea.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebStorageEventDispatcher.h"
#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebThemeEngine.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
-#include "webkit/database/vfs_backend.h"
-#include "webkit/extensions/v8/gears_extension.h"
-#include "webkit/extensions/v8/interval_extension.h"
#include "webkit/glue/webclipboard_impl.h"
#include "webkit/glue/webfilesystem_impl.h"
#include "webkit/glue/webkit_glue.h"
@@ -41,7 +18,6 @@
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/simple_webcookiejar_impl.h"
#include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h"
-#include "v8/include/v8.h"
#if defined(OS_WIN)
#include "webkit/tools/test_shell/test_shell_webthemeengine.h"
@@ -49,75 +25,14 @@
class TestShellWebKitInit : public webkit_glue::WebKitClientImpl {
public:
- explicit TestShellWebKitInit(bool layout_test_mode) {
- v8::V8::SetCounterFunction(StatsTable::FindLocation);
-
- WebKit::initialize(this);
- WebKit::setLayoutTestMode(layout_test_mode);
- WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(
- WebKit::WebString::fromUTF8("test-shell-resource"));
- WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess(
- WebKit::WebString::fromUTF8("test-shell-resource"));
- WebKit::WebScriptController::enableV8SingleThreadMode();
- WebKit::WebScriptController::registerExtension(
- extensions_v8::GearsExtension::Get());
- WebKit::WebScriptController::registerExtension(
- extensions_v8::IntervalExtension::Get());
- WebKit::WebRuntimeFeatures::enableSockets(true);
- WebKit::WebRuntimeFeatures::enableApplicationCache(true);
- WebKit::WebRuntimeFeatures::enableDatabase(true);
- WebKit::WebRuntimeFeatures::enableWebGL(true);
- WebKit::WebRuntimeFeatures::enablePushState(true);
- WebKit::WebRuntimeFeatures::enableNotifications(true);
- WebKit::WebRuntimeFeatures::enableTouch(true);
- WebKit::WebRuntimeFeatures::enableIndexedDatabase(true);
-
- // Load libraries for media and enable the media player.
- FilePath module_path;
- WebKit::WebRuntimeFeatures::enableMediaPlayer(
- PathService::Get(base::DIR_MODULE, &module_path) &&
- media::InitializeMediaLibrary(module_path));
-
- WebKit::WebRuntimeFeatures::enableGeolocation(true);
-
- // Construct and initialize an appcache system for this scope.
- // A new empty temp directory is created to house any cached
- // content during the run. Upon exit that directory is deleted.
- // If we can't create a tempdir, we'll use in-memory storage.
- if (!appcache_dir_.CreateUniqueTempDir()) {
- LOG(WARNING) << "Failed to create a temp dir for the appcache, "
- "using in-memory storage.";
- DCHECK(appcache_dir_.path().empty());
- }
- SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path());
-
- WebKit::WebDatabase::setObserver(&database_system_);
-
- file_system_.set_sandbox_enabled(false);
-
-#if defined(OS_WIN)
- // Ensure we pick up the default theme engine.
- SetThemeEngine(NULL);
-#endif
- }
-
- ~TestShellWebKitInit() {
- WebKit::shutdown();
- }
+ explicit TestShellWebKitInit(bool layout_test_mode);
+ ~TestShellWebKitInit();
virtual WebKit::WebMimeRegistry* mimeRegistry() {
return &mime_registry_;
}
- WebKit::WebClipboard* clipboard() {
- // Mock out clipboard calls in layout test mode so that tests don't mess
- // with each other's copies/pastes when running in parallel.
- if (TestShell::layout_test_mode()) {
- return &mock_clipboard_;
- } else {
- return &real_clipboard_;
- }
- }
+ WebKit::WebClipboard* clipboard();
virtual WebKit::WebFileSystem* fileSystem() {
return &file_system_;
@@ -174,25 +89,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl {
virtual void prefetchHostName(const WebKit::WebString&) {
}
- virtual WebKit::WebData loadResource(const char* name) {
- if (!strcmp(name, "deleteButton")) {
- // Create a red 30x30 square.
- const char red_square[] =
- "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
- "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3"
- "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00"
- "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80"
- "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff"
- "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00"
- "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a"
- "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a"
- "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d"
- "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60"
- "\x82";
- return WebKit::WebData(red_square, arraysize(red_square));
- }
- return webkit_glue::WebKitClientImpl::loadResource(name);
- }
+ virtual WebKit::WebData loadResource(const char* name);
virtual WebKit::WebString defaultLocale() {
return ASCIIToUTF16("en-US");