diff options
-rw-r--r-- | chrome/browser/profile.cc | 1 | ||||
-rwxr-xr-x | chrome/chrome.gyp | 1 | ||||
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.cc | 50 | ||||
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.h | 22 | ||||
-rw-r--r-- | webkit/appcache/appcache_thread.cc | 13 | ||||
-rw-r--r-- | webkit/appcache/appcache_thread.h | 44 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_appcache_system.cc | 27 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_appcache_system.h | 25 | ||||
-rw-r--r-- | webkit/webkit.gyp | 2 |
9 files changed, 166 insertions, 19 deletions
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index f522360..a60b7fc 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -14,6 +14,7 @@ #include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/ntp_resource_cache.h" diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index f9bebb4..c80bc21 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -578,6 +578,7 @@ 'common/appcache/appcache_dispatcher_host.h', 'common/appcache/appcache_frontend_proxy.cc', 'common/appcache/appcache_frontend_proxy.h', + 'common/appcache/chrome_appcache_service.cc', 'common/appcache/chrome_appcache_service.h', 'common/automation_constants.cc', 'common/automation_constants.h', diff --git a/chrome/common/appcache/chrome_appcache_service.cc b/chrome/common/appcache/chrome_appcache_service.cc new file mode 100644 index 0000000..c1016cb --- /dev/null +++ b/chrome/common/appcache/chrome_appcache_service.cc @@ -0,0 +1,50 @@ +// 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 "chrome/common/appcache/chrome_appcache_service.h" + +#include "base/file_path.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/common/chrome_constants.h" +#include "webkit/appcache/appcache_thread.h" + +static bool has_initialized_thread_ids; + +ChromeAppCacheService::ChromeAppCacheService(const FilePath& data_directory, + bool is_incognito) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + if (!has_initialized_thread_ids) { + has_initialized_thread_ids = true; + appcache::AppCacheThread::InitIDs(ChromeThread::DB, ChromeThread::IO); + } + Initialize(is_incognito ? FilePath() + : data_directory.Append(chrome::kAppCacheDirname)); +} + +ChromeAppCacheService::~ChromeAppCacheService() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); +} + +static ChromeThread::ID ToChromeThreadID(int id) { + DCHECK(has_initialized_thread_ids); + DCHECK(id == ChromeThread::DB || id == ChromeThread::IO); + return static_cast<ChromeThread::ID>(id); +} + +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) { + return ChromeThread::PostTask(ToChromeThreadID(id), from_here, task); +} + +bool AppCacheThread::CurrentlyOn(int id) { + return ChromeThread::CurrentlyOn(ToChromeThreadID(id)); +} + +} // namespace appcache diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h index 37e0dcb..509afd2 100644 --- a/chrome/common/appcache/chrome_appcache_service.h +++ b/chrome/common/appcache/chrome_appcache_service.h @@ -5,38 +5,28 @@ #ifndef CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ #define CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ -#include "base/file_path.h" -#include "base/message_loop.h" #include "base/ref_counted.h" -#include "base/task.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/common/chrome_constants.h" #include "webkit/appcache/appcache_service.h" +class FilePath; + // An AppCacheService subclass used by the chrome. There is an instance // associated with each Profile. This derivation adds refcounting semantics // since a profile has multiple URLRequestContexts which refer to the same // object, and those URLRequestContexts are refcounted independently of the // owning profile. // -// All methods, including the dtor, are expected to be called on the IO thread. +// All methods, including the ctor and dtor, are expected to be called on +// the IO thread. class ChromeAppCacheService : public base::RefCounted<ChromeAppCacheService>, public appcache::AppCacheService { public: - ChromeAppCacheService(const FilePath& data_directory, - bool is_incognito) { - Initialize(is_incognito ? FilePath() - : data_directory.Append(chrome::kAppCacheDirname)); - } + bool is_incognito); private: friend class base::RefCounted<ChromeAppCacheService>; - - virtual ~ChromeAppCacheService() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - } + virtual ~ChromeAppCacheService(); }; #endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 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', |