| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 11 #include "chrome/browser/android/offline_pages/prerender_adapter.h" | 13 #include "chrome/browser/android/offline_pages/prerender_adapter.h" |
| 12 #include "components/offline_pages/core/background/offliner.h" | 14 #include "components/offline_pages/core/background/offliner.h" |
| 13 #include "components/offline_pages/core/snapshot_controller.h" | 15 #include "components/offline_pages/core/snapshot_controller.h" |
| 14 | 16 |
| 15 class GURL; | 17 class GURL; |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 class BrowserContext; | 20 class BrowserContext; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 void OnPrerenderDomContentLoaded() override; | 77 void OnPrerenderDomContentLoaded() override; |
| 76 void OnPrerenderStop() override; | 78 void OnPrerenderStop() override; |
| 77 void OnPrerenderNetworkBytesChanged(int64_t bytes) override; | 79 void OnPrerenderNetworkBytesChanged(int64_t bytes) override; |
| 78 | 80 |
| 79 // SnapshotController::Client implementation: | 81 // SnapshotController::Client implementation: |
| 80 void StartSnapshot() override; | 82 void StartSnapshot() override; |
| 81 | 83 |
| 82 // Returns true if the lowbar of snapshotting a page is met. | 84 // Returns true if the lowbar of snapshotting a page is met. |
| 83 virtual bool IsLowbarMet(); | 85 virtual bool IsLowbarMet(); |
| 84 | 86 |
| 87 // Returns a vector of strings for analysis of loading progress. |
| 88 const std::vector<std::string>& GetLoadingSignalData() { |
| 89 return signal_data_; |
| 90 } |
| 91 |
| 85 private: | 92 private: |
| 86 // State of the loader (only one request may be active at a time). | 93 // State of the loader (only one request may be active at a time). |
| 87 enum class State { | 94 enum class State { |
| 88 IDLE, // No active load request. | 95 IDLE, // No active load request. |
| 89 PENDING, // Load request is pending the start of prerendering. | 96 PENDING, // Load request is pending the start of prerendering. |
| 90 LOADING, // Loading in progress. | 97 LOADING, // Loading in progress. |
| 91 LOADED, // Loaded and now waiting for requestor to StopLoading(). | 98 LOADED, // Loaded and now waiting for requestor to StopLoading(). |
| 92 }; | 99 }; |
| 93 | 100 |
| 94 // Handles some event/signal that the load request has succeeded or failed. | 101 // Handles some event/signal that the load request has succeeded or failed. |
| 95 // It may be due to some asynchronous trigger that occurs after the request | 102 // It may be due to some asynchronous trigger that occurs after the request |
| 96 // has completed for some other reason/event. | 103 // has completed for some other reason/event. |
| 97 void HandleLoadEvent(); | 104 void HandleLoadEvent(); |
| 98 | 105 |
| 99 // Handles some event/signal that loading has stopped (whether due to a | 106 // Handles some event/signal that loading has stopped (whether due to a |
| 100 // failure, cancel, or stop request). It may be due to some asynchronous | 107 // failure, cancel, or stop request). It may be due to some asynchronous |
| 101 // trigger that occurs after the request has stopped for some other reason. | 108 // trigger that occurs after the request has stopped for some other reason. |
| 102 void HandleLoadingStopped(); | 109 void HandleLoadingStopped(); |
| 103 | 110 |
| 104 // Cancels any current prerender and moves loader to idle state. | 111 // Cancels any current prerender and moves loader to idle state. |
| 105 void CancelPrerender(); | 112 void CancelPrerender(); |
| 106 | 113 |
| 114 // Add a signal to the signal data. |
| 115 void AddLoadingSignal(const char* signal_name); |
| 116 |
| 107 // Tracks loading state including whether the Loader is idle. | 117 // Tracks loading state including whether the Loader is idle. |
| 108 State state_; | 118 State state_; |
| 109 | 119 |
| 110 // Handles determining when to report page is LOADED. | 120 // Handles determining when to report page is LOADED. |
| 111 std::unique_ptr<SnapshotController> snapshot_controller_; | 121 std::unique_ptr<SnapshotController> snapshot_controller_; |
| 112 | 122 |
| 113 // Not owned. | 123 // Not owned. |
| 114 content::BrowserContext* browser_context_; | 124 content::BrowserContext* browser_context_; |
| 115 | 125 |
| 116 // Adapter for handling calls to the prerender stack. | 126 // Adapter for handling calls to the prerender stack. |
| 117 std::unique_ptr<PrerenderAdapter> adapter_; | 127 std::unique_ptr<PrerenderAdapter> adapter_; |
| 118 | 128 |
| 119 // A WebContents for the active load request that is used to hold the session | 129 // A WebContents for the active load request that is used to hold the session |
| 120 // storage namespace for rendering. This will NOT have the loaded page. | 130 // storage namespace for rendering. This will NOT have the loaded page. |
| 121 std::unique_ptr<content::WebContents> session_contents_; | 131 std::unique_ptr<content::WebContents> session_contents_; |
| 122 | 132 |
| 133 // Signal data collected for this rendering attempt |
| 134 std::vector<std::string> signal_data_; |
| 135 |
| 123 // Callback to call when the active load request completes, fails, or is | 136 // Callback to call when the active load request completes, fails, or is |
| 124 // canceled. | 137 // canceled. |
| 125 LoadPageCallback load_done_callback_; | 138 LoadPageCallback load_done_callback_; |
| 126 | 139 |
| 127 // Callback to call when we know more bytes have loaded from the network. | 140 // Callback to call when we know more bytes have loaded from the network. |
| 128 ProgressCallback progress_callback_; | 141 ProgressCallback progress_callback_; |
| 129 | 142 |
| 130 // True if the lowbar of snapshotting a page is met. | 143 // True if the lowbar of snapshotting a page is met. |
| 131 bool is_lowbar_met_; | 144 bool is_lowbar_met_; |
| 132 | 145 |
| 133 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader); | 146 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader); |
| 134 }; | 147 }; |
| 135 | 148 |
| 136 } // namespace offline_pages | 149 } // namespace offline_pages |
| 137 | 150 |
| 138 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ | 151 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ |
| OLD | NEW |