summaryrefslogtreecommitdiffstats
path: root/chrome/common/app_cache
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common/app_cache')
-rw-r--r--chrome/common/app_cache/app_cache_context_impl.cc84
-rw-r--r--chrome/common/app_cache/app_cache_context_impl.h48
-rw-r--r--chrome/common/app_cache/app_cache_dispatcher.cc26
-rw-r--r--chrome/common/app_cache/app_cache_dispatcher.h26
-rw-r--r--chrome/common/app_cache/app_cache_dispatcher_host.cc60
-rw-r--r--chrome/common/app_cache/app_cache_dispatcher_host.h43
6 files changed, 287 insertions, 0 deletions
diff --git a/chrome/common/app_cache/app_cache_context_impl.cc b/chrome/common/app_cache/app_cache_context_impl.cc
new file mode 100644
index 0000000..d50b467
--- /dev/null
+++ b/chrome/common/app_cache/app_cache_context_impl.cc
@@ -0,0 +1,84 @@
+// 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->context_id()
+ : 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
new file mode 100644
index 0000000..7ca7ee3
--- /dev/null
+++ b/chrome/common/app_cache/app_cache_context_impl.h
@@ -0,0 +1,48 @@
+// 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 "chrome/common/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 context_id() { return context_id_; }
+ virtual int64 app_cache_id() { 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
new file mode 100644
index 0000000..ba81243
--- /dev/null
+++ b/chrome/common/app_cache/app_cache_dispatcher.cc
@@ -0,0 +1,26 @@
+// 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
new file mode 100644
index 0000000..c8baf28
--- /dev/null
+++ b/chrome/common/app_cache/app_cache_dispatcher.h
@@ -0,0 +1,26 @@
+// 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 "chrome/common/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
new file mode 100644
index 0000000..98c774d
--- /dev/null
+++ b/chrome/common/app_cache/app_cache_dispatcher_host.cc
@@ -0,0 +1,60 @@
+// 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
new file mode 100644
index 0000000..e84a7fd
--- /dev/null
+++ b/chrome/common/app_cache/app_cache_dispatcher_host.h
@@ -0,0 +1,43 @@
+// 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 "chrome/common/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_