Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_FRAME_NODE_NAVIGATION_H_ | |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_FRAME_NODE_NAVIGATION_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "content/browser/appcache/appcache_backend_impl.h" | |
| 17 #include "content/browser/appcache/appcache_frontend_proxy.h" | |
| 18 #include "ipc/ipc_sender.h" | |
| 19 | |
| 20 namespace content { | |
| 21 class ChromeAppCacheService; | |
| 22 struct AppCacheFrameNavigationHandlerDeleter; | |
| 23 | |
| 24 // PlzNavigate: | |
| 25 // 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
| |
| 26 // tree node id, initially. When the navigation is committed, we change the | |
| 27 // mapping for the AppCache backend from a frame tree node id based mapping to | |
| 28 // a renderer process id based mapping. | |
| 29 class AppCacheFrameNavigationHandler | |
| 30 : public base::RefCountedThreadSafe<AppCacheFrameNavigationHandler, | |
| 31 AppCacheFrameNavigationHandlerDeleter>, | |
| 32 public IPC::Sender { | |
| 33 public: | |
| 34 // PlzNavigate: A pending host is registered when a navigation is initiated | |
| 35 // by the browser. The registration completes when the renderer sends the | |
| 36 // AppCacheHostMsg_RegisterHost message to us. The |frame_node_id| parameter | |
| 37 // identifies the frame node who will be a consumer of the cache. | |
| 38 // The function returns the id of the registered host. The actual host | |
| 39 // registration happens on the IO thread in the | |
| 40 // RegisterPendingHostHelper() function. | |
| 41 static int BeginNavigation(AppCacheServiceImpl* appcache_service, | |
| 42 int frame_node_id); | |
| 43 | |
| 44 // Called when the navigation initiated for |frame_node_id| is committed. | |
| 45 // The | process_id | parameter contains the ID of the renderer process. | |
| 46 static void CommitNavigation(int frame_node_id, int process_id); | |
| 47 | |
| 48 // Called when the navigation initiated for |frame_node_id| fails. Cleans | |
| 49 // up any state maintained for the navigation. | |
| 50 static void FailedNavigation(int frame_node_id); | |
| 51 | |
| 52 // IPC::Sender overrides. | |
| 53 // We don't expect to see calls to this function. | |
| 54 bool Send(IPC::Message* msg) override; | |
| 55 | |
| 56 protected: | |
| 57 AppCacheFrameNavigationHandler(ChromeAppCacheService* appcache_service, | |
| 58 int frame_node_id); | |
| 59 ~AppCacheFrameNavigationHandler() override; | |
| 60 | |
| 61 private: | |
| 62 // This function runs on the IO thread and registers the host identified by | |
| 63 // the |host_id| parameter as a pending host. | |
| 64 void RegisterPendingHostHelper(int host_id); | |
| 65 | |
| 66 // This function runs on the IO thread and initializes the | |
| 67 // AppCacheDispatcherHost with the appcache backend information for the | |
| 68 // navigation which was initiated for the frame identified by the | |
| 69 // frame_node_id_ member. The |process_id| parameter contains the ID of | |
| 70 // the renderer process. | |
| 71 void CommitNavigationHelper(int process_id); | |
| 72 | |
| 73 // Ensure that the class is deleted on the IO thread. | |
| 74 void DeleteOnCorrectThread() const; | |
| 75 | |
| 76 int frame_node_id_; | |
| 77 | |
| 78 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
| 79 AppCacheFrontendProxy frontend_proxy_; | |
| 80 std::unique_ptr<AppCacheBackendImpl> backend_impl_; | |
| 81 | |
| 82 content::GetStatusCallback get_status_callback_; | |
| 83 content::StartUpdateCallback start_update_callback_; | |
| 84 content::SwapCacheCallback swap_cache_callback_; | |
| 85 | |
| 86 friend class base::DeleteHelper<AppCacheFrameNavigationHandler>; | |
| 87 friend class base::RefCountedThreadSafe< | |
| 88 AppCacheFrameNavigationHandler, | |
| 89 AppCacheFrameNavigationHandlerDeleter>; | |
| 90 friend struct AppCacheFrameNavigationHandlerDeleter; | |
| 91 | |
| 92 // Set to true when we receive a commit notification for the navigation. | |
| 93 bool commit_received_; | |
| 94 | |
| 95 // WeakPtrFactory for posting tasks back to |this|. | |
| 96 base::WeakPtrFactory<AppCacheFrameNavigationHandler> weak_factory_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(AppCacheFrameNavigationHandler); | |
| 99 }; | |
| 100 | |
| 101 // Weak pointer references to the AppCacheFrameNavigationHandlerDeleter class | |
| 102 // may be active on the IO thread. We have to make sure that we are destroyed | |
| 103 // on the IO thread as well. | |
| 104 struct AppCacheFrameNavigationHandlerDeleter { | |
| 105 static void Destruct(const AppCacheFrameNavigationHandler* handler) { | |
| 106 handler->DeleteOnCorrectThread(); | |
| 107 } | |
| 108 }; | |
| 109 | |
| 110 } // namespace content | |
| 111 | |
| 112 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_FRAME_NODE_NAVIGATION_H_ | |
| OLD | NEW |