diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 22:30:30 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 22:30:30 +0000 |
commit | 23f1ef1a445a53bcefc8ddab9f4184b1db7321c5 (patch) | |
tree | c9f17a33025ed5b5c5dee76a7b4fef9104e9a995 /chrome/common/appcache | |
parent | e143c823ce66af5a83a9a17b6f5938eb16e49392 (diff) | |
download | chromium_src-23f1ef1a445a53bcefc8ddab9f4184b1db7321c5.zip chromium_src-23f1ef1a445a53bcefc8ddab9f4184b1db7321c5.tar.gz chromium_src-23f1ef1a445a53bcefc8ddab9f4184b1db7321c5.tar.bz2 |
Plumb request interception into the appcache library for both chrome and test_shell.
AppCache library:
* Added AppCacheInterceptor, which is derived from URLRequest::Interceptor.
Chrome:
* Each UserProfile instantiates a ChromeAppCacheService, which is derived from an appcache library class.
* Each ChromeURLRequestContext associated with that profile has a reference to that instance.
* ResourceDispatcherHost pokes AppCacheInterceptor when initiating URLRequests and when returning the response head.
TestShell:
* Added SimpleAppCacheSystem which bundles together appcache lib components for use in a single process with an UI and IO thread.
* TestShellWebKit instantiates and initializes an instance of the above, aimed at at temp directory that will get cleaned up when the test run is over.
* SimpleResourceLoaderBridge pokes the system when initiating URLRequests and when returning the response head.
TEST=none, although many existing tests exercise this stuff
BUG=none
Review URL: http://codereview.chromium.org/173406
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/appcache')
-rw-r--r-- | chrome/common/appcache/appcache_backend_proxy.cc | 7 | ||||
-rw-r--r-- | chrome/common/appcache/appcache_dispatcher_host.cc | 85 | ||||
-rw-r--r-- | chrome/common/appcache/appcache_dispatcher_host.h | 20 | ||||
-rw-r--r-- | chrome/common/appcache/appcache_frontend_proxy.cc | 1 | ||||
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.h | 67 |
5 files changed, 154 insertions, 26 deletions
diff --git a/chrome/common/appcache/appcache_backend_proxy.cc b/chrome/common/appcache/appcache_backend_proxy.cc index 14b81f1..25c77f7 100644 --- a/chrome/common/appcache/appcache_backend_proxy.cc +++ b/chrome/common/appcache/appcache_backend_proxy.cc @@ -34,20 +34,19 @@ void AppCacheBackendProxy::MarkAsForeignEntry( } appcache::Status AppCacheBackendProxy::GetStatus(int host_id) { - appcache::Status status; + appcache::Status status = appcache::UNCACHED; sender_->Send(new AppCacheMsg_GetStatus(host_id, &status)); return status; } bool AppCacheBackendProxy::StartUpdate(int host_id) { - bool result; + bool result = false; sender_->Send(new AppCacheMsg_StartUpdate(host_id, &result)); return result; } bool AppCacheBackendProxy::SwapCache(int host_id) { - bool result; + bool result = false; sender_->Send(new AppCacheMsg_SwapCache(host_id, &result)); return result; } - diff --git a/chrome/common/appcache/appcache_dispatcher_host.cc b/chrome/common/appcache/appcache_dispatcher_host.cc index b71f2d9..ee0265f 100644 --- a/chrome/common/appcache/appcache_dispatcher_host.cc +++ b/chrome/common/appcache/appcache_dispatcher_host.cc @@ -4,12 +4,28 @@ #include "chrome/common/appcache/appcache_dispatcher_host.h" +#include "chrome/common/appcache/chrome_appcache_service.h" #include "chrome/common/render_messages.h" -void AppCacheDispatcherHost::Initialize(IPC::Message::Sender* sender) { +AppCacheDispatcherHost::AppCacheDispatcherHost( + ChromeAppCacheService* appcache_service) + : appcache_service_(appcache_service) { +} + +void AppCacheDispatcherHost::Initialize(IPC::Message::Sender* sender, + int process_id) { DCHECK(sender); frontend_proxy_.set_sender(sender); - backend_impl_.Initialize(NULL, &frontend_proxy_); + if (appcache_service_.get()) { + backend_impl_.Initialize( + appcache_service_.get(), &frontend_proxy_, process_id); + get_status_callback_.reset( + NewCallback(this, &AppCacheDispatcherHost::GetStatusCallback)); + start_update_callback_.reset( + NewCallback(this, &AppCacheDispatcherHost::StartUpdateCallback)); + swap_cache_callback_.reset( + NewCallback(this, &AppCacheDispatcherHost::SwapCacheCallback)); + } } bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& msg, @@ -31,49 +47,78 @@ bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& msg, } void AppCacheDispatcherHost::OnRegisterHost(int host_id) { - backend_impl_.RegisterHost(host_id); + if (appcache_service_.get()) + backend_impl_.RegisterHost(host_id); } void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { - backend_impl_.UnregisterHost(host_id); + if (appcache_service_.get()) + backend_impl_.UnregisterHost(host_id); } void AppCacheDispatcherHost::OnSelectCache( int host_id, const GURL& document_url, int64 cache_document_was_loaded_from, const GURL& opt_manifest_url) { - backend_impl_.SelectCache(host_id, document_url, - cache_document_was_loaded_from, - opt_manifest_url); + if (appcache_service_.get()) + backend_impl_.SelectCache(host_id, document_url, + cache_document_was_loaded_from, + opt_manifest_url); + else + frontend_proxy_.OnCacheSelected( + host_id, appcache::kNoCacheId, appcache::UNCACHED); } void AppCacheDispatcherHost::OnMarkAsForeignEntry( int host_id, const GURL& document_url, int64 cache_document_was_loaded_from) { - backend_impl_.MarkAsForeignEntry(host_id, document_url, - cache_document_was_loaded_from); + if (appcache_service_.get()) + backend_impl_.MarkAsForeignEntry(host_id, document_url, + cache_document_was_loaded_from); } void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { - // TODO(michaeln): Handle the case where cache selection is not yet complete. - appcache::Status status = backend_impl_.GetStatus(host_id); - AppCacheMsg_GetStatus::WriteReplyParams(reply_msg, status); - frontend_proxy_.sender()->Send(reply_msg); + if (appcache_service_.get()) + backend_impl_.GetStatusWithCallback( + host_id, get_status_callback_.get(), reply_msg); + else + GetStatusCallback(appcache::UNCACHED, reply_msg); } void AppCacheDispatcherHost::OnStartUpdate(int host_id, IPC::Message* reply_msg) { - // TODO(michaeln): Handle the case where cache selection is not yet complete. - bool success = backend_impl_.StartUpdate(host_id); - AppCacheMsg_StartUpdate::WriteReplyParams(reply_msg, success); - frontend_proxy_.sender()->Send(reply_msg); + if (appcache_service_.get()) + backend_impl_.StartUpdateWithCallback( + host_id, start_update_callback_.get(), reply_msg); + else + StartUpdateCallback(false, reply_msg); } void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { - // TODO(michaeln): Handle the case where cache selection is not yet complete. - bool success = backend_impl_.SwapCache(host_id); - AppCacheMsg_SwapCache::WriteReplyParams(reply_msg, success); + if (appcache_service_.get()) + backend_impl_.SwapCacheWithCallback( + host_id, swap_cache_callback_.get(), reply_msg); + else + SwapCacheCallback(false, reply_msg); +} + +void AppCacheDispatcherHost::GetStatusCallback( + appcache::Status status, void* param) { + IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); + AppCacheMsg_GetStatus::WriteReplyParams(reply_msg, status); + frontend_proxy_.sender()->Send(reply_msg); +} + +void AppCacheDispatcherHost::StartUpdateCallback(bool result, void* param) { + IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); + AppCacheMsg_StartUpdate::WriteReplyParams(reply_msg, result); + frontend_proxy_.sender()->Send(reply_msg); +} + +void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { + IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); + AppCacheMsg_SwapCache::WriteReplyParams(reply_msg, result); frontend_proxy_.sender()->Send(reply_msg); } diff --git a/chrome/common/appcache/appcache_dispatcher_host.h b/chrome/common/appcache/appcache_dispatcher_host.h index f141fdb..47f245a 100644 --- a/chrome/common/appcache/appcache_dispatcher_host.h +++ b/chrome/common/appcache/appcache_dispatcher_host.h @@ -6,19 +6,27 @@ #define CHROME_COMMON_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ #include <vector> +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "chrome/common/appcache/appcache_frontend_proxy.h" #include "ipc/ipc_message.h" #include "webkit/appcache/appcache_backend_impl.h" +class ChromeAppCacheService; + // Handles appcache related messages sent to the main browser process from // its child processes. There is a distinct host for each child process. // Messages are handled on the IO thread. The ResourceMessageFilter creates // an instance and delegates calls to it. class AppCacheDispatcherHost { public: - void Initialize(IPC::Message::Sender* sender); + explicit AppCacheDispatcherHost(ChromeAppCacheService* appcache_service); + + void Initialize(IPC::Message::Sender* sender, int process_id); bool OnMessageReceived(const IPC::Message& msg, bool* msg_is_ok); + int process_id() const { return backend_impl_.process_id(); } + // Note: needed to satisfy ipc message dispatching macros. bool Send(IPC::Message* msg) { return frontend_proxy_.sender()->Send(msg); @@ -37,8 +45,18 @@ class AppCacheDispatcherHost { void OnStartUpdate(int host_id, IPC::Message* reply_msg); void OnSwapCache(int host_id, IPC::Message* reply_msg); + void GetStatusCallback(appcache::Status status, void* param); + void StartUpdateCallback(bool result, void* param); + void SwapCacheCallback(bool result, void* param); + AppCacheFrontendProxy frontend_proxy_; appcache::AppCacheBackendImpl backend_impl_; + 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_; + + DISALLOW_COPY_AND_ASSIGN(AppCacheDispatcherHost); }; #endif // CHROME_COMMON_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ diff --git a/chrome/common/appcache/appcache_frontend_proxy.cc b/chrome/common/appcache/appcache_frontend_proxy.cc index bf20baa8..08c8510 100644 --- a/chrome/common/appcache/appcache_frontend_proxy.cc +++ b/chrome/common/appcache/appcache_frontend_proxy.cc @@ -20,4 +20,3 @@ void AppCacheFrontendProxy::OnEventRaised(const std::vector<int>& host_ids, appcache::EventID event_id) { sender_->Send(new AppCacheMsg_EventRaised(host_ids, event_id)); } - diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h new file mode 100644 index 0000000..63736da --- /dev/null +++ b/chrome/common/appcache/chrome_appcache_service.h @@ -0,0 +1,67 @@ +// 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 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/chrome_thread.h" +#include "chrome/common/chrome_constants.h" +#include "webkit/appcache/appcache_service.h" + +// 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 +// except for the ctor and the init method which are expected to be called on +// the UI thread. +class ChromeAppCacheService + : public base::RefCountedThreadSafe<ChromeAppCacheService>, + public appcache::AppCacheService { + public: + + explicit ChromeAppCacheService() + : was_initialized_with_io_thread_(false) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + } + + void InitializeOnUIThread(const FilePath& data_directory, + bool is_incognito) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + + // Some test cases run without an IO thread. + MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO); + if (io_thread) { + was_initialized_with_io_thread_ = true; + io_thread->PostTask(FROM_HERE, + NewRunnableMethod(this, &ChromeAppCacheService::InitializeOnIOThread, + data_directory, is_incognito)); + } + } + + private: + friend class base::RefCountedThreadSafe<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 was_initialized_with_io_thread_; +}; + +#endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |