diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 21:46:31 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 21:46:31 +0000 |
commit | f430b57130adff68db69f340c68b6afe5746edc5 (patch) | |
tree | 3c1e56173a34f7ea652ebe6c450c22ba9ddce0ae /chrome/common | |
parent | 8177d9bbcda50fdba18f19f131024a4704c376f8 (diff) | |
download | chromium_src-f430b57130adff68db69f340c68b6afe5746edc5.zip chromium_src-f430b57130adff68db69f340c68b6afe5746edc5.tar.gz chromium_src-f430b57130adff68db69f340c68b6afe5746edc5.tar.bz2 |
Retrofit the pre-existing appache message dispatching with the new WebKit APIs and concrete classes defined in our new appcache library, and get rid of the old files.
There are many files in the CL, mostly to pickup constant values now defined in our new appcache library, and to reflect a terminilogy change (from 'context' to 'host').
TEST=some existing unit tests apply
BUG=none
Review URL: http://codereview.chromium.org/170003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
19 files changed, 484 insertions, 346 deletions
diff --git a/chrome/common/app_cache/app_cache_context_impl.cc b/chrome/common/app_cache/app_cache_context_impl.cc deleted file mode 100644 index c622001..0000000 --- a/chrome/common/app_cache/app_cache_context_impl.cc +++ /dev/null @@ -1,84 +0,0 @@ -// 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/app_cache/app_cache_context_impl.h" - -#include "base/logging.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/child_thread.h" -#include "googleurl/src/gurl.h" - -IDMap<AppCacheContextImpl> AppCacheContextImpl::all_contexts; - -// static -AppCacheContextImpl* AppCacheContextImpl::FromContextId(int id) { - return all_contexts.Lookup(id); -} - -AppCacheContextImpl::AppCacheContextImpl(IPC::Message::Sender *sender) - : context_id_(kNoAppCacheContextId), - app_cache_id_(kUnknownAppCacheId), - pending_select_request_id_(0), - sender_(sender) { - DCHECK(sender_); -} - -AppCacheContextImpl::~AppCacheContextImpl() { - UnInitializeContext(); -} - -void AppCacheContextImpl::Initialize(ContextType context_type, - WebAppCacheContext *parent) { - DCHECK(context_id_ == kNoAppCacheContextId); - DCHECK(((context_type == MAIN_FRAME) && !parent) || - ((context_type != MAIN_FRAME) && parent)); - - context_id_ = all_contexts.Add(this); - CHECK(context_id_ != kNoAppCacheContextId); - - sender_->Send(new AppCacheMsg_ContextCreated(context_type, - context_id_, - parent ? parent->GetContextID() - : kNoAppCacheContextId)); -} - -void AppCacheContextImpl::UnInitializeContext() { - if (context_id_ != kNoAppCacheContextId) { - sender_->Send(new AppCacheMsg_ContextDestroyed(context_id_)); - all_contexts.Remove(context_id_); - context_id_ = kNoAppCacheContextId; - } -} - -void AppCacheContextImpl::SelectAppCacheWithoutManifest( - const GURL &document_url, - int64 cache_document_was_loaded_from) { - DCHECK(context_id_ != kNoAppCacheContextId); - app_cache_id_ = kUnknownAppCacheId; // unknown until we get a response - sender_->Send(new AppCacheMsg_SelectAppCache( - context_id_, ++pending_select_request_id_, - document_url, cache_document_was_loaded_from, - GURL::EmptyGURL())); -} - -void AppCacheContextImpl::SelectAppCacheWithManifest( - const GURL &document_url, - int64 cache_document_was_loaded_from, - const GURL &manifest_url) { - DCHECK(context_id_ != kNoAppCacheContextId); - app_cache_id_ = kUnknownAppCacheId; // unknown until we get a response - sender_->Send(new AppCacheMsg_SelectAppCache( - context_id_, ++pending_select_request_id_, - document_url, cache_document_was_loaded_from, - manifest_url)); -} - -void AppCacheContextImpl::OnAppCacheSelected(int select_request_id, - int64 app_cache_id) { - if (select_request_id == pending_select_request_id_) { - DCHECK(app_cache_id_ == kUnknownAppCacheId); - DCHECK(app_cache_id != kUnknownAppCacheId); - app_cache_id_ = app_cache_id; - } -} diff --git a/chrome/common/app_cache/app_cache_context_impl.h b/chrome/common/app_cache/app_cache_context_impl.h deleted file mode 100644 index ec2f25f..0000000 --- a/chrome/common/app_cache/app_cache_context_impl.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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_APP_CACHE_APP_CACHE_CONTEXT_IMPL_H_ -#define CHROME_COMMON_APP_CACHE_APP_CACHE_CONTEXT_IMPL_H_ - -#include "base/id_map.h" -#include "ipc/ipc_message.h" -#include "webkit/glue/webappcachecontext.h" - -// A concrete implemenation of WebAppCacheContext for use in a child process. -class AppCacheContextImpl : public WebAppCacheContext { - public: - // Returns the context having given id or NULL if there is no such context. - static AppCacheContextImpl* FromContextId(int id); - - AppCacheContextImpl(IPC::Message::Sender* sender); - virtual ~AppCacheContextImpl(); - - // WebAppCacheContext implementation - virtual int GetContextID() { return context_id_; } - virtual int64 GetAppCacheID() { return app_cache_id_; } - virtual void Initialize(WebAppCacheContext::ContextType context_type, - WebAppCacheContext* opt_parent); - virtual void SelectAppCacheWithoutManifest( - const GURL& document_url, - int64 cache_document_was_loaded_from); - virtual void SelectAppCacheWithManifest( - const GURL& document_url, - int64 cache_document_was_loaded_from, - const GURL& manifest_url); - - // Called by AppCacheDispatcher when the browser has selected an appcache. - void OnAppCacheSelected(int select_request_id, int64 app_cache_id); - - private: - void UnInitializeContext(); - - int context_id_; - int64 app_cache_id_; - int pending_select_request_id_; - IPC::Message::Sender* sender_; - - static IDMap<AppCacheContextImpl> all_contexts; -}; - -#endif // CHROME_COMMON_APP_CACHE_APP_CACHE_CONTEXT_IMPL_H_ diff --git a/chrome/common/app_cache/app_cache_dispatcher.cc b/chrome/common/app_cache/app_cache_dispatcher.cc deleted file mode 100644 index ba81243..0000000 --- a/chrome/common/app_cache/app_cache_dispatcher.cc +++ /dev/null @@ -1,26 +0,0 @@ -// 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/app_cache/app_cache_dispatcher.h" - -#include "chrome/common/app_cache/app_cache_context_impl.h" -#include "chrome/common/render_messages.h" - -bool AppCacheDispatcher::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcher, msg) - IPC_MESSAGE_HANDLER(AppCacheMsg_AppCacheSelected, OnAppCacheSelected) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void AppCacheDispatcher::OnAppCacheSelected(int context_id, - int select_request_id, - int64 app_cache_id) { - AppCacheContextImpl *context = AppCacheContextImpl::FromContextId(context_id); - if (context) { - context->OnAppCacheSelected(select_request_id, app_cache_id); - } -} diff --git a/chrome/common/app_cache/app_cache_dispatcher.h b/chrome/common/app_cache/app_cache_dispatcher.h deleted file mode 100644 index 3d4cbbd..0000000 --- a/chrome/common/app_cache/app_cache_dispatcher.h +++ /dev/null @@ -1,26 +0,0 @@ -// 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_APP_CACHE_APP_CACHE_DISPATCHER_H_ -#define CHROME_COMMON_APP_CACHE_APP_CACHE_DISPATCHER_H_ - -#include "base/basictypes.h" -#include "ipc/ipc_message.h" - -// Dispatches app cache related messages sent to a child process from the -// main browser process. There is one instance per child process. Messages -// are dispatched on the main child thread. The ChildThread base class -// creates an instance and delegates calls to it. -class AppCacheDispatcher { - public: - bool OnMessageReceived(const IPC::Message& msg); - - private: - // AppCacheContextImpl related messages - void OnAppCacheSelected(int context_id, - int select_request_id, - int64 app_cache_id); -}; - -#endif // CHROME_COMMON_APP_CACHE_APP_CACHE_DISPATCHER_H_ diff --git a/chrome/common/app_cache/app_cache_dispatcher_host.cc b/chrome/common/app_cache/app_cache_dispatcher_host.cc deleted file mode 100644 index 98c774d..0000000 --- a/chrome/common/app_cache/app_cache_dispatcher_host.cc +++ /dev/null @@ -1,60 +0,0 @@ -// 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/app_cache/app_cache_dispatcher_host.h" - -#include "chrome/common/render_messages.h" - -AppCacheDispatcherHost::~AppCacheDispatcherHost() { - if (sender_) { - // TODO(michaeln): plumb to request_context_->app_cache_service - // to remove contexts for the child process that is going away. - } -} - -void AppCacheDispatcherHost::Initialize(IPC::Message::Sender* sender) { - DCHECK(sender); - sender_ = sender; - // TODO(michaeln): plumb to request_context_->app_cache_service to - // tell it about this child process coming into existance -} - -bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& msg, - bool *msg_ok) { - DCHECK(sender_); - *msg_ok = true; - bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, msg, *msg_ok) - IPC_MESSAGE_HANDLER(AppCacheMsg_ContextCreated, OnContextCreated); - IPC_MESSAGE_HANDLER(AppCacheMsg_ContextDestroyed, OnContextDestroyed); - IPC_MESSAGE_HANDLER(AppCacheMsg_SelectAppCache, OnSelectAppCache); - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP_EX() - return handled; -} - -void AppCacheDispatcherHost::OnContextCreated( - WebAppCacheContext::ContextType context_type, - int context_id, - int opt_parent_id) { - // TODO(michaeln): implement me, plumb to request_context->app_cache_service - DCHECK(context_id != WebAppCacheContext::kNoAppCacheContextId); -} - -void AppCacheDispatcherHost::OnContextDestroyed(int context_id) { - // TODO(michaeln): implement me, plumb to request_context->app_cache_service - DCHECK(context_id != WebAppCacheContext::kNoAppCacheContextId); -} - -void AppCacheDispatcherHost::OnSelectAppCache( - int context_id, - int select_request_id, - const GURL& document_url, - int64 cache_document_was_loaded_from, - const GURL& opt_manifest_url) { - // TODO(michaeln): implement me, plumb to request_context->app_cache_service - DCHECK(context_id != WebAppCacheContext::kNoAppCacheContextId); - Send(new AppCacheMsg_AppCacheSelected(context_id, select_request_id, - WebAppCacheContext::kNoAppCacheId)); -} diff --git a/chrome/common/app_cache/app_cache_dispatcher_host.h b/chrome/common/app_cache/app_cache_dispatcher_host.h deleted file mode 100644 index 749e74a..0000000 --- a/chrome/common/app_cache/app_cache_dispatcher_host.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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_APP_CACHE_APP_CACHE_DISPATCHER_HOST_H_ -#define CHROME_COMMON_APP_CACHE_APP_CACHE_DISPATCHER_HOST_H_ - -#include "base/id_map.h" -#include "ipc/ipc_message.h" -#include "webkit/glue/webappcachecontext.h" - -class GURL; - -// Handles app cache 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: - AppCacheDispatcherHost() : sender_(NULL) {} - ~AppCacheDispatcherHost(); - void Initialize(IPC::Message::Sender* sender); - bool OnMessageReceived(const IPC::Message& msg, bool* msg_is_ok); - - private: - // AppCacheContextImpl related messages - void OnContextCreated(WebAppCacheContext::ContextType context_type, - int context_id, int opt_parent_id); - void OnContextDestroyed(int context_id); - void OnSelectAppCache(int context_id, - int select_request_id, - const GURL& document_url, - int64 cache_document_was_loaded_from, - const GURL& opt_manifest_url); - - bool Send(IPC::Message* msg) { - return sender_->Send(msg); - } - - IPC::Message::Sender* sender_; -}; - -#endif // CHROME_COMMON_APP_CACHE_APP_CACHE_DISPATCHER_HOST_H_ diff --git a/chrome/common/appcache/appcache_backend_proxy.cc b/chrome/common/appcache/appcache_backend_proxy.cc new file mode 100644 index 0000000..14b81f1 --- /dev/null +++ b/chrome/common/appcache/appcache_backend_proxy.cc @@ -0,0 +1,53 @@ +// 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/appcache_backend_proxy.h" + +#include "chrome/common/render_messages.h" + +void AppCacheBackendProxy::RegisterHost(int host_id) { + sender_->Send(new AppCacheMsg_RegisterHost(host_id)); +} + +void AppCacheBackendProxy::UnregisterHost(int host_id) { + sender_->Send(new AppCacheMsg_UnregisterHost(host_id)); +} + +void AppCacheBackendProxy::SelectCache( + int host_id, + const GURL& document_url, + const int64 cache_document_was_loaded_from, + const GURL& manifest_url) { + sender_->Send(new AppCacheMsg_SelectCache( + host_id, document_url, + cache_document_was_loaded_from, + manifest_url)); +} + +void AppCacheBackendProxy::MarkAsForeignEntry( + int host_id, const GURL& document_url, + int64 cache_document_was_loaded_from) { + sender_->Send(new AppCacheMsg_MarkAsForeignEntry( + host_id, document_url, + cache_document_was_loaded_from)); +} + +appcache::Status AppCacheBackendProxy::GetStatus(int host_id) { + appcache::Status status; + sender_->Send(new AppCacheMsg_GetStatus(host_id, &status)); + return status; +} + +bool AppCacheBackendProxy::StartUpdate(int host_id) { + bool result; + sender_->Send(new AppCacheMsg_StartUpdate(host_id, &result)); + return result; +} + +bool AppCacheBackendProxy::SwapCache(int host_id) { + bool result; + sender_->Send(new AppCacheMsg_SwapCache(host_id, &result)); + return result; +} + diff --git a/chrome/common/appcache/appcache_backend_proxy.h b/chrome/common/appcache/appcache_backend_proxy.h new file mode 100644 index 0000000..5098336 --- /dev/null +++ b/chrome/common/appcache/appcache_backend_proxy.h @@ -0,0 +1,36 @@ +// 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_APPCACHE_BACKEND_PROXY_H_ +#define CHROME_COMMON_APPCACHE_APPCACHE_BACKEND_PROXY_H_ + +#include "ipc/ipc_message.h" +#include "webkit/appcache/appcache_interfaces.h" + +// Sends appcache related messages to the main process. +class AppCacheBackendProxy : public appcache::AppCacheBackend { + public: + explicit AppCacheBackendProxy(IPC::Message::Sender* sender) + : sender_(sender) {} + + IPC::Message::Sender* sender() const { return sender_; } + + // AppCacheBackend methods + virtual void RegisterHost(int host_id); + virtual void UnregisterHost(int host_id); + virtual void SelectCache(int host_id, + const GURL& document_url, + const int64 cache_document_was_loaded_from, + const GURL& manifest_url); + virtual void MarkAsForeignEntry(int host_id, const GURL& document_url, + int64 cache_document_was_loaded_from); + virtual appcache::Status GetStatus(int host_id); + virtual bool StartUpdate(int host_id); + virtual bool SwapCache(int host_id); + + private: + IPC::Message::Sender* sender_; +}; + +#endif // CHROME_COMMON_APPCACHE_APPCACHE_BACKEND_PROXY_H_ diff --git a/chrome/common/appcache/appcache_dispatcher.cc b/chrome/common/appcache/appcache_dispatcher.cc new file mode 100644 index 0000000..71461ba --- /dev/null +++ b/chrome/common/appcache/appcache_dispatcher.cc @@ -0,0 +1,34 @@ +// 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/appcache_dispatcher.h" + +#include "chrome/common/render_messages.h" +#include "webkit/appcache/web_application_cache_host_impl.h" + +bool AppCacheDispatcher::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcher, msg) + IPC_MESSAGE_HANDLER(AppCacheMsg_CacheSelected, OnCacheSelected) + IPC_MESSAGE_HANDLER(AppCacheMsg_StatusChanged, OnStatusChanged) + IPC_MESSAGE_HANDLER(AppCacheMsg_EventRaised, OnEventRaised) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void AppCacheDispatcher::OnCacheSelected(int host_id, int64 cache_id, + appcache::Status status) { + frontend_impl_.OnCacheSelected(host_id, cache_id, status); +} + +void AppCacheDispatcher::OnStatusChanged(const std::vector<int>& host_ids, + appcache::Status status) { + frontend_impl_.OnStatusChanged(host_ids, status); +} + +void AppCacheDispatcher::OnEventRaised(const std::vector<int>& host_ids, + appcache::EventID event_id) { + frontend_impl_.OnEventRaised(host_ids, event_id); +} diff --git a/chrome/common/appcache/appcache_dispatcher.h b/chrome/common/appcache/appcache_dispatcher.h new file mode 100644 index 0000000..9eaef6a --- /dev/null +++ b/chrome/common/appcache/appcache_dispatcher.h @@ -0,0 +1,39 @@ +// 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_APPCACHE_DISPATCHER_H_ +#define CHROME_COMMON_APPCACHE_APPCACHE_DISPATCHER_H_ + +#include <vector> +#include "chrome/common/appcache/appcache_backend_proxy.h" +#include "ipc/ipc_message.h" +#include "webkit/appcache/appcache_frontend_impl.h" + +// Dispatches appcache related messages sent to a child process from the +// main browser process. There is one instance per child process. Messages +// are dispatched on the main child thread. The ChildThread base class +// creates an instance and delegates calls to it. +class AppCacheDispatcher { + public: + explicit AppCacheDispatcher(IPC::Message::Sender* sender) + : backend_proxy_(sender) {} + + AppCacheBackendProxy* backend_proxy() { return &backend_proxy_; } + + bool OnMessageReceived(const IPC::Message& msg); + + private: + // Ipc message handlers + void OnCacheSelected(int host_id, int64 cache_id, + appcache::Status status); + void OnStatusChanged(const std::vector<int>& host_ids, + appcache::Status status); + void OnEventRaised(const std::vector<int>& host_ids, + appcache::EventID event_id); + + AppCacheBackendProxy backend_proxy_; + appcache::AppCacheFrontendImpl frontend_impl_; +}; + +#endif // CHROME_COMMON_APPCACHE_APPCACHE_DISPATCHER_H_ diff --git a/chrome/common/appcache/appcache_dispatcher_host.cc b/chrome/common/appcache/appcache_dispatcher_host.cc new file mode 100644 index 0000000..b71f2d9 --- /dev/null +++ b/chrome/common/appcache/appcache_dispatcher_host.cc @@ -0,0 +1,79 @@ +// 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/appcache_dispatcher_host.h" + +#include "chrome/common/render_messages.h" + +void AppCacheDispatcherHost::Initialize(IPC::Message::Sender* sender) { + DCHECK(sender); + frontend_proxy_.set_sender(sender); + backend_impl_.Initialize(NULL, &frontend_proxy_); +} + +bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& msg, + bool *msg_ok) { + DCHECK(frontend_proxy_.sender()); + *msg_ok = true; + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, msg, *msg_ok) + IPC_MESSAGE_HANDLER(AppCacheMsg_RegisterHost, OnRegisterHost); + IPC_MESSAGE_HANDLER(AppCacheMsg_UnregisterHost, OnUnregisterHost); + IPC_MESSAGE_HANDLER(AppCacheMsg_SelectCache, OnSelectCache); + IPC_MESSAGE_HANDLER(AppCacheMsg_MarkAsForeignEntry, OnMarkAsForeignEntry); + IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_GetStatus, OnGetStatus); + IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_StartUpdate, OnStartUpdate); + IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_SwapCache, OnSwapCache); + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP_EX() + return handled; +} + +void AppCacheDispatcherHost::OnRegisterHost(int host_id) { + backend_impl_.RegisterHost(host_id); +} + +void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { + 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); +} + +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); +} + +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); +} + +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); +} + +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); + frontend_proxy_.sender()->Send(reply_msg); +} diff --git a/chrome/common/appcache/appcache_dispatcher_host.h b/chrome/common/appcache/appcache_dispatcher_host.h new file mode 100644 index 0000000..f141fdb --- /dev/null +++ b/chrome/common/appcache/appcache_dispatcher_host.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 CHROME_COMMON_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ +#define CHROME_COMMON_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ + +#include <vector> +#include "chrome/common/appcache/appcache_frontend_proxy.h" +#include "ipc/ipc_message.h" +#include "webkit/appcache/appcache_backend_impl.h" + +// 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); + bool OnMessageReceived(const IPC::Message& msg, bool* msg_is_ok); + + // Note: needed to satisfy ipc message dispatching macros. + bool Send(IPC::Message* msg) { + return frontend_proxy_.sender()->Send(msg); + } + + private: + // Ipc message handlers + void OnRegisterHost(int host_id); + void OnUnregisterHost(int host_id); + void OnSelectCache(int host_id, const GURL& document_url, + int64 cache_document_was_loaded_from, + const GURL& opt_manifest_url); + void OnMarkAsForeignEntry(int host_id, const GURL& document_url, + int64 cache_document_was_loaded_from); + void OnGetStatus(int host_id, IPC::Message* reply_msg); + void OnStartUpdate(int host_id, IPC::Message* reply_msg); + void OnSwapCache(int host_id, IPC::Message* reply_msg); + + AppCacheFrontendProxy frontend_proxy_; + appcache::AppCacheBackendImpl backend_impl_; +}; + +#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 new file mode 100644 index 0000000..bf20baa8 --- /dev/null +++ b/chrome/common/appcache/appcache_frontend_proxy.cc @@ -0,0 +1,23 @@ +// 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/appcache_frontend_proxy.h" + +#include "chrome/common/render_messages.h" + +void AppCacheFrontendProxy::OnCacheSelected(int host_id, int64 cache_id , + appcache::Status status) { + sender_->Send(new AppCacheMsg_CacheSelected(host_id, cache_id, status)); +} + +void AppCacheFrontendProxy::OnStatusChanged(const std::vector<int>& host_ids, + appcache::Status status) { + sender_->Send(new AppCacheMsg_StatusChanged(host_ids, status)); +} + +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/appcache_frontend_proxy.h b/chrome/common/appcache/appcache_frontend_proxy.h new file mode 100644 index 0000000..b18f9bb --- /dev/null +++ b/chrome/common/appcache/appcache_frontend_proxy.h @@ -0,0 +1,31 @@ +// 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_APPCACHE_FRONTEND_PROXY_H_ +#define CHROME_COMMON_APPCACHE_APPCACHE_FRONTEND_PROXY_H_ + +#include <vector> +#include "ipc/ipc_message.h" +#include "webkit/appcache/appcache_interfaces.h" + +// Sends appcache related messages to a child process. +class AppCacheFrontendProxy : public appcache::AppCacheFrontend { + public: + AppCacheFrontendProxy() : sender_(NULL) {} + void set_sender(IPC::Message::Sender* sender) { sender_ = sender; } + IPC::Message::Sender* sender() const { return sender_; } + + // AppCacheFrontend methods + virtual void OnCacheSelected(int host_id, int64 cache_id , + appcache::Status); + virtual void OnStatusChanged(const std::vector<int>& host_ids, + appcache::Status status); + virtual void OnEventRaised(const std::vector<int>& host_ids, + appcache::EventID event_id); + + private: + IPC::Message::Sender* sender_; +}; + +#endif // CHROME_COMMON_APPCACHE_APPCACHE_FRONTEND_PROXY_H_ diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index af0e901..fcbf0a4 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -29,6 +29,7 @@ #include "media/audio/audio_output.h" #include "net/base/upload_data.h" #include "net/http/http_response_headers.h" +#include "webkit/appcache/appcache_interfaces.h" #include "webkit/glue/autofill_form.h" #include "webkit/glue/context_menu.h" #include "webkit/glue/form_data.h" @@ -37,7 +38,6 @@ #include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/resource_loader_bridge.h" #include "webkit/glue/webaccessibility.h" -#include "webkit/glue/webappcachecontext.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webmenuitem.h" #include "webkit/glue/webplugin.h" @@ -320,8 +320,8 @@ struct ViewHostMsg_Resource_Request { uint32 request_context; // Indicates which frame (or worker context) the request is being loaded into, - // or kNoAppCacheContextId. - int32 app_cache_context_id; + // or kNoHostId. + int appcache_host_id; // Optional upload data (may be null). scoped_refptr<net::UploadData> upload_data; @@ -1265,7 +1265,7 @@ struct ParamTraits<ViewHostMsg_Resource_Request> { WriteParam(m, p.origin_pid); WriteParam(m, p.resource_type); WriteParam(m, p.request_context); - WriteParam(m, p.app_cache_context_id); + WriteParam(m, p.appcache_host_id); WriteParam(m, p.upload_data); } static bool Read(const Message* m, void** iter, param_type* r) { @@ -1281,7 +1281,7 @@ struct ParamTraits<ViewHostMsg_Resource_Request> { ReadParam(m, iter, &r->origin_pid) && ReadParam(m, iter, &r->resource_type) && ReadParam(m, iter, &r->request_context) && - ReadParam(m, iter, &r->app_cache_context_id) && + ReadParam(m, iter, &r->appcache_host_id) && ReadParam(m, iter, &r->upload_data); } static void Log(const param_type& p, std::wstring* l) { @@ -1304,7 +1304,7 @@ struct ParamTraits<ViewHostMsg_Resource_Request> { l->append(L", "); LogParam(p.request_context, l); l->append(L", "); - LogParam(p.app_cache_context_id, l); + LogParam(p.appcache_host_id, l); l->append(L")"); } }; @@ -1344,7 +1344,8 @@ struct ParamTraits<webkit_glue::ResourceLoaderBridge::ResponseInfo> { WriteParam(m, p.charset); WriteParam(m, p.security_info); WriteParam(m, p.content_length); - WriteParam(m, p.app_cache_id); + WriteParam(m, p.appcache_id); + WriteParam(m, p.appcache_manifest_url); } static bool Read(const Message* m, void** iter, param_type* r) { return @@ -1355,7 +1356,8 @@ struct ParamTraits<webkit_glue::ResourceLoaderBridge::ResponseInfo> { ReadParam(m, iter, &r->charset) && ReadParam(m, iter, &r->security_info) && ReadParam(m, iter, &r->content_length) && - ReadParam(m, iter, &r->app_cache_id); + ReadParam(m, iter, &r->appcache_id) && + ReadParam(m, iter, &r->appcache_manifest_url); } static void Log(const param_type& p, std::wstring* l) { l->append(L"("); @@ -1373,7 +1375,9 @@ struct ParamTraits<webkit_glue::ResourceLoaderBridge::ResponseInfo> { l->append(L", "); LogParam(p.content_length, l); l->append(L", "); - LogParam(p.app_cache_id, l); + LogParam(p.appcache_id, l); + l->append(L", "); + LogParam(p.appcache_manifest_url, l); l->append(L")"); } }; @@ -1848,8 +1852,8 @@ struct ParamTraits<ViewMsg_AudioStreamState> { }; template <> -struct ParamTraits<WebAppCacheContext::ContextType> { - typedef WebAppCacheContext::ContextType param_type; +struct ParamTraits<appcache::Status> { + typedef appcache::Status param_type; static void Write(Message* m, const param_type& p) { m->WriteInt(static_cast<int>(p)); } @@ -1863,17 +1867,75 @@ struct ParamTraits<WebAppCacheContext::ContextType> { static void Log(const param_type& p, std::wstring* l) { std::wstring state; switch (p) { - case WebAppCacheContext::MAIN_FRAME: - state = L"MAIN_FRAME"; + case appcache::UNCACHED: + state = L"UNCACHED"; break; - case WebAppCacheContext::CHILD_FRAME: - state = L"CHILD_FRAME"; + case appcache::IDLE: + state = L"IDLE"; + break; + case appcache::CHECKING: + state = L"CHECKING"; + break; + case appcache::DOWNLOADING: + state = L"DOWNLOADING"; + break; + case appcache::UPDATE_READY: + state = L"UPDATE_READY"; + break; + case appcache::OBSOLETE: + state = L"OBSOLETE"; break; - case WebAppCacheContext::DEDICATED_WORKER: - state = L"DECICATED_WORKER"; - break; default: - state = L"UNKNOWN"; + state = L"InvalidStatusValue"; + break; + } + + LogParam(state, l); + } +}; + +template <> +struct ParamTraits<appcache::EventID> { + typedef appcache::EventID param_type; + static void Write(Message* m, const param_type& p) { + m->WriteInt(static_cast<int>(p)); + } + static bool Read(const Message* m, void** iter, param_type* p) { + int type; + if (!m->ReadInt(iter, &type)) + return false; + *p = static_cast<param_type>(type); + return true; + } + static void Log(const param_type& p, std::wstring* l) { + std::wstring state; + switch (p) { + case appcache::CHECKING_EVENT: + state = L"CHECKING_EVENT"; + break; + case appcache::ERROR_EVENT: + state = L"ERROR_EVENT"; + break; + case appcache::NO_UPDATE_EVENT: + state = L"NO_UPDATE_EVENT"; + break; + case appcache::DOWNLOADING_EVENT: + state = L"DOWNLOADING_EVENT"; + break; + case appcache::PROGRESS_EVENT: + state = L"PROGRESS_EVENT"; + break; + case appcache::UPDATE_READY_EVENT: + state = L"UPDATE_READY_EVENT"; + break; + case appcache::CACHED_EVENT: + state = L"CACHED_EVENT"; + break; + case appcache::OBSOLETE_EVENT: + state = L"OBSOLETE_EVENT"; + break; + default: + state = L"InvalidEventValue"; break; } diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index f94f8e3..6f15991 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -25,8 +25,8 @@ #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "webkit/appcache/appcache_interfaces.h" #include "webkit/glue/dom_operations.h" -#include "webkit/glue/webappcachecontext.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webplugin.h" @@ -518,13 +518,22 @@ IPC_BEGIN_MESSAGES(View) // into a full window). IPC_MESSAGE_ROUTED0(ViewMsg_DisassociateFromPopupCount) - // Notifies the renderer of the AppCache that has been selected for a - // a particular context (or frame). This is sent in reply to - // one of the two AppCacheMsg_SelectAppCache messages. - IPC_MESSAGE_CONTROL3(AppCacheMsg_AppCacheSelected, - int /* context_id */, - int /* select_request_id */, - int64 /* cache_id */) + // Notifies the renderer of the appcache that has been selected for a + // a particular host. This is sent in reply to AppCacheMsg_SelectCache. + IPC_MESSAGE_CONTROL3(AppCacheMsg_CacheSelected, + int /* host_id */, + int64 /* appcache_id */, + appcache::Status) + + // Notifies the renderer of an AppCache status change. + IPC_MESSAGE_CONTROL2(AppCacheMsg_StatusChanged, + std::vector<int> /* host_ids */, + appcache::Status) + + // Notifies the renderer of an AppCache event. + IPC_MESSAGE_CONTROL2(AppCacheMsg_EventRaised, + std::vector<int> /* host_ids */, + appcache::EventID) // Reply to the ViewHostMsg_QueryFormFieldAutofill message with the autofill // suggestions. @@ -1341,34 +1350,49 @@ IPC_BEGIN_MESSAGES(ViewHost) gfx::NativeViewId /* window */, gfx::Rect /* Out: Window location */) - // Informs the browser of a new context. - IPC_MESSAGE_CONTROL3(AppCacheMsg_ContextCreated, - WebAppCacheContext::ContextType, - int /* context_id */, - int /* opt_parent_context_id */) - - // Informs the browser of a context being destroyed. - IPC_MESSAGE_CONTROL1(AppCacheMsg_ContextDestroyed, - int /* context_id */) - - // Initiates the cache selection algorithm for the given context. - // This is sent after new content has been committed, but prior to - // any subresource loads. An AppCacheMsg_AppCacheSelected message will - // be sent in response. - // 'context_id' indentifies a specific frame or worker - // 'select_request_id' indentifies this particular invocation the algorithm - // and will be returned to the caller with the response - // 'document_url' the url of the main resource commited to the frame - // 'cache_document_was_loaded_frame' the id of the appcache the main resource - // was loaded from or kNoAppCacheId + // Informs the browser of a new appcache host. + IPC_MESSAGE_CONTROL1(AppCacheMsg_RegisterHost, + int /* host_id */) + + // Informs the browser of an appcache host being destroyed. + IPC_MESSAGE_CONTROL1(AppCacheMsg_UnregisterHost, + int /* host_id */) + + // Initiates the cache selection algorithm for the given host. + // This is sent prior to any subresource loads. An AppCacheMsg_CacheSelected + // message will be sent in response. + // 'host_id' indentifies a specific document or worker + // 'document_url' the url of the main resource + // 'appcache_document_was_loaded_from' the id of the appcache the main + // resource was loaded from or kNoCacheId // 'opt_manifest_url' the manifest url specified in the <html> tag if any - IPC_MESSAGE_CONTROL5(AppCacheMsg_SelectAppCache, - int /* context_id */, - int /* select_request_id */, + IPC_MESSAGE_CONTROL4(AppCacheMsg_SelectCache, + int /* host_id */, GURL /* document_url */, - int64 /* cache_document_was_loaded_from */, + int64 /* appcache_document_was_loaded_from */, GURL /* opt_manifest_url */) + // Informs the browser of a 'foreign' entry in an appcache. + IPC_MESSAGE_CONTROL3(AppCacheMsg_MarkAsForeignEntry, + int /* host_id */, + GURL /* document_url */, + int64 /* appcache_document_was_loaded_from */) + + // Returns the status of the appcache associated with host_id. + IPC_SYNC_MESSAGE_CONTROL1_1(AppCacheMsg_GetStatus, + int /* host_id */, + appcache::Status) + + // Initiates an update of the appcache associated with host_id. + IPC_SYNC_MESSAGE_CONTROL1_1(AppCacheMsg_StartUpdate, + int /* host_id */, + bool /* success */) + + // Swaps a new pending appcache, if there is one, into use for host_id. + IPC_SYNC_MESSAGE_CONTROL1_1(AppCacheMsg_SwapCache, + int /* host_id */, + bool /* success */) + // Returns the resizer box location in the window this widget is embeded. // Important for Mac OS X, but not Win or Linux. IPC_SYNC_MESSAGE_ROUTED1_1(ViewHostMsg_GetRootWindowResizerRect, diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc index 8167901..d0a90a5 100644 --- a/chrome/common/resource_dispatcher.cc +++ b/chrome/common/resource_dispatcher.cc @@ -55,7 +55,7 @@ class IPCResourceLoaderBridge : public ResourceLoaderBridge { int origin_pid, ResourceType::Type resource_type, uint32 request_context, - int app_cache_context_id, + int appcache_host_id, int routing_id); virtual ~IPCResourceLoaderBridge(); @@ -109,7 +109,7 @@ IPCResourceLoaderBridge::IPCResourceLoaderBridge( int origin_pid, ResourceType::Type resource_type, uint32 request_context, - int app_cache_context_id, + int appcache_host_id, int routing_id) : peer_(NULL), dispatcher_(dispatcher), @@ -127,7 +127,7 @@ IPCResourceLoaderBridge::IPCResourceLoaderBridge( request_.origin_pid = origin_pid; request_.resource_type = resource_type; request_.request_context = request_context; - request_.app_cache_context_id = app_cache_context_id; + request_.appcache_host_id = appcache_host_id; #ifdef LOG_RESOURCE_REQUESTS url_ = url.possibly_invalid_spec(); @@ -543,7 +543,7 @@ webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge( int origin_pid, ResourceType::Type resource_type, uint32 request_context, - int app_cache_context_id, + int appcache_host_id, int route_id) { return new webkit_glue::IPCResourceLoaderBridge(this, method, url, first_party_for_cookies, @@ -552,7 +552,7 @@ webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge( flags, origin_pid, resource_type, request_context, - app_cache_context_id, + appcache_host_id, route_id); } diff --git a/chrome/common/resource_dispatcher.h b/chrome/common/resource_dispatcher.h index a8a9a65..c7a3fa8 100644 --- a/chrome/common/resource_dispatcher.h +++ b/chrome/common/resource_dispatcher.h @@ -45,7 +45,7 @@ class ResourceDispatcher { int origin_pid, ResourceType::Type resource_type, uint32 request_context /* used for plugin->browser requests */, - int app_cache_context_id, + int appcache_host_id, int routing_id); // Adds a request from the pending_requests_ list, returning the new diff --git a/chrome/common/resource_dispatcher_unittest.cc b/chrome/common/resource_dispatcher_unittest.cc index b879670..a270be3 100644 --- a/chrome/common/resource_dispatcher_unittest.cc +++ b/chrome/common/resource_dispatcher_unittest.cc @@ -11,7 +11,7 @@ #include "chrome/common/render_messages.h" #include "chrome/common/resource_dispatcher.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/webappcachecontext.h" +#include "webkit/appcache/appcache_interfaces.h" using webkit_glue::ResourceLoaderBridge; @@ -156,7 +156,7 @@ TEST_F(ResourceDispatcherTest, RoundTrip) { dispatcher_->CreateBridge("GET", GURL(test_page_url), GURL(test_page_url), GURL(), "null", "null", std::string(), 0, 0, ResourceType::SUB_RESOURCE, 0, - WebAppCacheContext::kNoAppCacheContextId, + appcache::kNoHostId, MSG_ROUTING_CONTROL); bridge->Start(&callback); |