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_NAVIGATION_HANDLE_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_NAVIGATION_HANDLE_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 class AppCacheNavigationHandleCore; |
| 15 class ChromeAppCacheService; |
| 16 |
| 17 // This class is used to manage the lifetime of AppCacheHosts created during |
| 18 // navigation. This is a UI thread class, with a pendant class on the IO |
| 19 // thread, the AppCacheNavigationHandleCore. |
| 20 // |
| 21 // The lifetime of the AppCacheNavigationHandle, the |
| 22 // AppCacheNavigationHandleCore and the AppCacheHost are the following : |
| 23 // 1) We create a AppCacheNavigationHandle on the UI thread with a |
| 24 // app cache host id of -1. This also leads to the creation of a |
| 25 // AppCacheNavigationHandleCore with an id of -1. Every time |
| 26 // an AppCacheNavigationHandle instance is created the global host id is |
| 27 // decremented by 1. |
| 28 // |
| 29 // 2) When the navigation request is sent to the IO thread, we include a |
| 30 // pointer to the AppCacheNavigationHandleCore. |
| 31 // |
| 32 // 3. The AppCacheHost instance is created and its ownership is passed to the |
| 33 // AppCacheNavigationHandleCore instance. Now the app cache host id is |
| 34 // updated. |
| 35 // |
| 36 // 4) The AppCacheNavigationHandleCore instance informs the |
| 37 // AppCacheNavigationHandle instance on the UI thread that the app cache |
| 38 // host id was updated. |
| 39 // |
| 40 // 5) When the navigation is ready to commit, the NavigationRequest will |
| 41 // update the RequestNavigationParams based on the id from the |
| 42 // AppCacheNavigationHandle. |
| 43 // |
| 44 // 6. The commit leads to AppCache registrations happening from the renderer. |
| 45 // This is via the IPC message AppCacheHostMsg_RegisterHost. The |
| 46 // AppCacheDispatcherHost class which handles these IPCs will be informed |
| 47 // about these hosts when the navigation commits. It will ignore the |
| 48 // host registrations as they have already been registered. The |
| 49 // ownership of the AppCacheHost is passed from the |
| 50 // AppCacheNavigationHandle core to the AppCacheBackend. |
| 51 |
| 52 // 7) When the navigation finishes, the AppCacheNavigationHandle is |
| 53 // destroyed. The destructor of the AppCacheNavigationHandle posts a |
| 54 // task to destroy the AppacheNavigationHandleCore on the IO thread. |
| 55 |
| 56 class AppCacheNavigationHandle { |
| 57 public: |
| 58 AppCacheNavigationHandle(ChromeAppCacheService* appcache_service); |
| 59 ~AppCacheNavigationHandle(); |
| 60 |
| 61 int appcache_host_id() const { |
| 62 return appcache_host_id_; |
| 63 } |
| 64 AppCacheNavigationHandleCore* core() const { return core_; } |
| 65 |
| 66 // Called when a navigation is committed. The |process_id| parameter is |
| 67 // is the process id of the renderer. |
| 68 void CommitNavigation(int process_id); |
| 69 |
| 70 private: |
| 71 int appcache_host_id_; |
| 72 AppCacheNavigationHandleCore* core_; |
| 73 base::WeakPtrFactory<AppCacheNavigationHandle> weak_factory_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(AppCacheNavigationHandle); |
| 76 }; |
| 77 |
| 78 } // namespace content |
| 79 |
| 80 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_NAVIGATION_HANDLE_H_ |
OLD | NEW |