summaryrefslogtreecommitdiffstats
path: root/chrome/common/appcache
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 06:33:31 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 06:33:31 +0000
commitbe180c8044f145310f9eb13fd2cab5fd20e88220 (patch)
tree707ac9f3f95f5191664dbdac2ff3f34ab08ad8e7 /chrome/common/appcache
parent4cb1d3be9986c105608991f3dde12c6346335060 (diff)
downloadchromium_src-be180c8044f145310f9eb13fd2cab5fd20e88220.zip
chromium_src-be180c8044f145310f9eb13fd2cab5fd20e88220.tar.gz
chromium_src-be180c8044f145310f9eb13fd2cab5fd20e88220.tar.bz2
Move initialization of ChromeURLRequestContexts to the IO thread.
Before, these URLRequestContexts were lazily created from the UI thread. Unfortunately that model made it easy for consumers on the UI thread to poke at stuff which was being used from the IO thread, and introduce races. So instead of providing a URLRequestContext*, the Profile now vends a URLRequestContextGetter*. The consequence of this is: * Consumers on the UI thread can no longer get access to a URLRequestContext. * Consumers on the IO thread need to call URLRequestContextGetter::GetURLRequestContext() to get at the context. This uses the same style lazy-creation of URLRequestContexts, albeit from the IO thread. OK, so now the smelly part: There were a couple of consumers of URLRequestContext on the UI thread that can't easily be moved to the IO thread -- these are the consumers of the cookie store. Before they could happily mess with the cookie store from the UI thread, and this was fine since CookieStore is threadsafe. However under the new model, they have no way to get at the URLRequestContext from the UI thread, hence can't get a pointer to the cookie store. To support that use-cases, I bastardized the API some by adding a URLRequestContextGetter::GetCookieStore() method that lets UI thread consumers get a pointer to the cookie store, since we know this particular cross-thread usage is safe. BUG=http://crbug.com/22294 Review URL: http://codereview.chromium.org/258008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/appcache')
-rw-r--r--chrome/common/appcache/appcache_dispatcher_host.cc13
-rw-r--r--chrome/common/appcache/appcache_dispatcher_host.h11
-rw-r--r--chrome/common/appcache/chrome_appcache_service.h43
3 files changed, 28 insertions, 39 deletions
diff --git a/chrome/common/appcache/appcache_dispatcher_host.cc b/chrome/common/appcache/appcache_dispatcher_host.cc
index 91a181f..d609858 100644
--- a/chrome/common/appcache/appcache_dispatcher_host.cc
+++ b/chrome/common/appcache/appcache_dispatcher_host.cc
@@ -5,12 +5,14 @@
#include "chrome/common/appcache/appcache_dispatcher_host.h"
#include "chrome/browser/renderer_host/browser_render_process_host.h"
+// TODO(eroman): uh oh, depending on stuff outside of common/
+#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/common/appcache/chrome_appcache_service.h"
#include "chrome/common/render_messages.h"
AppCacheDispatcherHost::AppCacheDispatcherHost(
- ChromeAppCacheService* appcache_service)
- : appcache_service_(appcache_service),
+ URLRequestContextGetter* request_context_getter)
+ : request_context_getter_(request_context_getter),
process_handle_(0) {
}
@@ -19,6 +21,13 @@ void AppCacheDispatcherHost::Initialize(IPC::Message::Sender* sender,
DCHECK(sender);
DCHECK(process_handle && !process_handle_);
process_handle_ = process_handle;
+
+ // Get the AppCacheService (it can only be accessed from IO thread).
+ URLRequestContext* context = request_context_getter_->GetURLRequestContext();
+ appcache_service_ =
+ static_cast<ChromeURLRequestContext*>(context)->appcache_service();
+ request_context_getter_ = NULL;
+
frontend_proxy_.set_sender(sender);
if (appcache_service_.get()) {
backend_impl_.Initialize(
diff --git a/chrome/common/appcache/appcache_dispatcher_host.h b/chrome/common/appcache/appcache_dispatcher_host.h
index 31adcdf..7b04b9c 100644
--- a/chrome/common/appcache/appcache_dispatcher_host.h
+++ b/chrome/common/appcache/appcache_dispatcher_host.h
@@ -15,6 +15,7 @@
#include "webkit/appcache/appcache_backend_impl.h"
class ChromeAppCacheService;
+class URLRequestContextGetter;
// Handles appcache related messages sent to the main browser process from
// its child processes. There is a distinct host for each child process.
@@ -22,7 +23,8 @@ class ChromeAppCacheService;
// an instance and delegates calls to it.
class AppCacheDispatcherHost {
public:
- explicit AppCacheDispatcherHost(ChromeAppCacheService* appcache_service);
+ explicit AppCacheDispatcherHost(
+ URLRequestContextGetter* request_context_getter);
void Initialize(IPC::Message::Sender* sender, int process_id,
base::ProcessHandle process_handle);
@@ -56,7 +58,14 @@ class AppCacheDispatcherHost {
AppCacheFrontendProxy frontend_proxy_;
appcache::AppCacheBackendImpl backend_impl_;
+
+ // Temporary until Initialize() can be called from the IO thread,
+ // which will extract the AppCacheService from the URLRequestContext.
+ scoped_refptr<URLRequestContextGetter> request_context_getter_;
+
+ // This is only valid once Initialize() has been called.
scoped_refptr<ChromeAppCacheService> appcache_service_;
+
scoped_ptr<appcache::GetStatusCallback> get_status_callback_;
scoped_ptr<appcache::StartUpdateCallback> start_update_callback_;
scoped_ptr<appcache::SwapCacheCallback> swap_cache_callback_;
diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h
index 213a347..37e0dcb 100644
--- a/chrome/common/appcache/chrome_appcache_service.h
+++ b/chrome/common/appcache/chrome_appcache_service.h
@@ -20,52 +20,23 @@
// 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
-// except for the ctor and the init method which are expected to be called on
-// the UI thread.
+// All methods, including the dtor, are expected to be called on the IO thread.
class ChromeAppCacheService
- : public base::RefCountedThreadSafe<ChromeAppCacheService>,
+ : public base::RefCounted<ChromeAppCacheService>,
public appcache::AppCacheService {
public:
- explicit ChromeAppCacheService()
- : is_initialized_(false), was_initialized_with_io_thread_(false) {
- }
-
- bool is_initialized() const { return is_initialized_; }
-
- void InitializeOnUIThread(const FilePath& data_directory,
- bool is_incognito) {
- DCHECK(!is_initialized_);
- is_initialized_ = true;
-
- // The I/O thread may be NULL during testing.
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread) {
- was_initialized_with_io_thread_ = true;
- io_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &ChromeAppCacheService::InitializeOnIOThread,
- data_directory, is_incognito));
- }
+ ChromeAppCacheService(const FilePath& data_directory,
+ bool is_incognito) {
+ Initialize(is_incognito ? FilePath()
+ : data_directory.Append(chrome::kAppCacheDirname));
}
-
private:
- friend class base::RefCountedThreadSafe<ChromeAppCacheService>;
+ friend class base::RefCounted<ChromeAppCacheService>;
virtual ~ChromeAppCacheService() {
- DCHECK(!was_initialized_with_io_thread_ ||
- ChromeThread::CurrentlyOn(ChromeThread::IO));
- }
-
- void InitializeOnIOThread(const FilePath& data_directory,
- bool is_incognito) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- Initialize(is_incognito ? FilePath()
- : data_directory.Append(chrome::kAppCacheDirname));
}
-
- bool is_initialized_;
- bool was_initialized_with_io_thread_;
};
#endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_