Index: content/browser/appcache/appcache_frame_node_navigation.h |
diff --git a/content/browser/appcache/appcache_frame_node_navigation.h b/content/browser/appcache/appcache_frame_node_navigation.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6ca28444dff1f5f27474f8e59208808313b1ec93 |
--- /dev/null |
+++ b/content/browser/appcache/appcache_frame_node_navigation.h |
@@ -0,0 +1,112 @@ |
+// Copyright 2016 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 CONTENT_BROWSER_APPCACHE_APPCACHE_FRAME_NODE_NAVIGATION_H_ |
+#define CONTENT_BROWSER_APPCACHE_APPCACHE_FRAME_NODE_NAVIGATION_H_ |
+ |
+#include <stdint.h> |
+ |
+#include <memory> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/weak_ptr.h" |
+#include "content/browser/appcache/appcache_backend_impl.h" |
+#include "content/browser/appcache/appcache_frontend_proxy.h" |
+#include "ipc/ipc_sender.h" |
+ |
+namespace content { |
+class ChromeAppCacheService; |
+struct AppCacheFrameNavigationHandlerDeleter; |
+ |
+// PlzNavigate: |
+// Handles navigations for a frame. Sets up the AppCache backend for the frame |
michaeln
2016/11/22 00:17:27
Do we ever get multiple hosts in this backend inst
ananta
2016/11/23 04:05:14
Reverted
|
+// tree node id, initially. When the navigation is committed, we change the |
+// mapping for the AppCache backend from a frame tree node id based mapping to |
+// a renderer process id based mapping. |
+class AppCacheFrameNavigationHandler |
+ : public base::RefCountedThreadSafe<AppCacheFrameNavigationHandler, |
+ AppCacheFrameNavigationHandlerDeleter>, |
+ public IPC::Sender { |
+ public: |
+ // PlzNavigate: A pending host is registered when a navigation is initiated |
+ // by the browser. The registration completes when the renderer sends the |
+ // AppCacheHostMsg_RegisterHost message to us. The |frame_node_id| parameter |
+ // identifies the frame node who will be a consumer of the cache. |
+ // The function returns the id of the registered host. The actual host |
+ // registration happens on the IO thread in the |
+ // RegisterPendingHostHelper() function. |
+ static int BeginNavigation(AppCacheServiceImpl* appcache_service, |
+ int frame_node_id); |
+ |
+ // Called when the navigation initiated for |frame_node_id| is committed. |
+ // The | process_id | parameter contains the ID of the renderer process. |
+ static void CommitNavigation(int frame_node_id, int process_id); |
+ |
+ // Called when the navigation initiated for |frame_node_id| fails. Cleans |
+ // up any state maintained for the navigation. |
+ static void FailedNavigation(int frame_node_id); |
+ |
+ // IPC::Sender overrides. |
+ // We don't expect to see calls to this function. |
+ bool Send(IPC::Message* msg) override; |
+ |
+ protected: |
+ AppCacheFrameNavigationHandler(ChromeAppCacheService* appcache_service, |
+ int frame_node_id); |
+ ~AppCacheFrameNavigationHandler() override; |
+ |
+ private: |
+ // This function runs on the IO thread and registers the host identified by |
+ // the |host_id| parameter as a pending host. |
+ void RegisterPendingHostHelper(int host_id); |
+ |
+ // This function runs on the IO thread and initializes the |
+ // AppCacheDispatcherHost with the appcache backend information for the |
+ // navigation which was initiated for the frame identified by the |
+ // frame_node_id_ member. The |process_id| parameter contains the ID of |
+ // the renderer process. |
+ void CommitNavigationHelper(int process_id); |
+ |
+ // Ensure that the class is deleted on the IO thread. |
+ void DeleteOnCorrectThread() const; |
+ |
+ int frame_node_id_; |
+ |
+ scoped_refptr<ChromeAppCacheService> appcache_service_; |
+ AppCacheFrontendProxy frontend_proxy_; |
+ std::unique_ptr<AppCacheBackendImpl> backend_impl_; |
+ |
+ content::GetStatusCallback get_status_callback_; |
+ content::StartUpdateCallback start_update_callback_; |
+ content::SwapCacheCallback swap_cache_callback_; |
+ |
+ friend class base::DeleteHelper<AppCacheFrameNavigationHandler>; |
+ friend class base::RefCountedThreadSafe< |
+ AppCacheFrameNavigationHandler, |
+ AppCacheFrameNavigationHandlerDeleter>; |
+ friend struct AppCacheFrameNavigationHandlerDeleter; |
+ |
+ // Set to true when we receive a commit notification for the navigation. |
+ bool commit_received_; |
+ |
+ // WeakPtrFactory for posting tasks back to |this|. |
+ base::WeakPtrFactory<AppCacheFrameNavigationHandler> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AppCacheFrameNavigationHandler); |
+}; |
+ |
+// Weak pointer references to the AppCacheFrameNavigationHandlerDeleter class |
+// may be active on the IO thread. We have to make sure that we are destroyed |
+// on the IO thread as well. |
+struct AppCacheFrameNavigationHandlerDeleter { |
+ static void Destruct(const AppCacheFrameNavigationHandler* handler) { |
+ handler->DeleteOnCorrectThread(); |
+ } |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_FRAME_NODE_NAVIGATION_H_ |