diff options
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/appcache/appcache_dispatcher_host.cc | 13 | ||||
-rw-r--r-- | chrome/common/appcache/appcache_dispatcher_host.h | 11 | ||||
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.h | 43 | ||||
-rw-r--r-- | chrome/common/chrome_plugin_unittest.cc | 18 |
4 files changed, 43 insertions, 42 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_ diff --git a/chrome/common/chrome_plugin_unittest.cc b/chrome/common/chrome_plugin_unittest.cc index b9aac5d..537c585 100644 --- a/chrome/common/chrome_plugin_unittest.cc +++ b/chrome/common/chrome_plugin_unittest.cc @@ -7,6 +7,7 @@ #include "base/path_service.h" #include "base/string_util.h" #include "chrome/browser/chrome_plugin_host.h" +#include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_plugin_lib.h" #include "chrome/test/chrome_plugin/test_chrome_plugin.h" @@ -22,6 +23,17 @@ const wchar_t kDocRoot[] = L"chrome/test/data"; const char kPluginFilename[] = "test_chrome_plugin.dll"; const int kResponseBufferSize = 4096; +class TestURLRequestContextGetter : public URLRequestContextGetter { + public: + virtual URLRequestContext* GetURLRequestContext() { + if (!context_) + context_ = new TestURLRequestContext(); + return context_; + } + private: + scoped_refptr<URLRequestContext> context_; +}; + class ChromePluginTest : public testing::Test, public URLRequest::Delegate { public: ChromePluginTest() @@ -29,7 +41,7 @@ class ChromePluginTest : public testing::Test, public URLRequest::Delegate { response_buffer_(new net::IOBuffer(kResponseBufferSize)), plugin_(NULL), expected_payload_(NULL), - request_context_(new TestURLRequestContext()) { + request_context_getter_(new TestURLRequestContextGetter()) { test_funcs_.test_make_request = NULL; } @@ -56,7 +68,7 @@ class ChromePluginTest : public testing::Test, public URLRequest::Delegate { // We need to setup a default request context in order to issue HTTP // requests. DCHECK(!Profile::GetDefaultRequestContext()); - Profile::set_default_request_context(request_context_.get()); + Profile::set_default_request_context(request_context_getter_.get()); } virtual void TearDown() { UnloadPlugin(); @@ -83,7 +95,7 @@ class ChromePluginTest : public testing::Test, public URLRequest::Delegate { ChromePluginLib* plugin_; TestFuncParams::PluginFuncs test_funcs_; const TestResponsePayload* expected_payload_; - scoped_refptr<URLRequestContext> request_context_; + scoped_refptr<URLRequestContextGetter> request_context_getter_; }; static void STDCALL CPT_Complete(CPRequest* request, bool success, |