Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_loader.h

Issue 2049743004: Integrates the SnapshotController into the PrerenderingLoader to provide logic for determining when… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@turnon
Patch Set: Replaces Stop() calls with unique_ptr.reset for better instance handling Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/prerendering_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "chrome/browser/android/offline_pages/prerender_adapter.h" 11 #include "chrome/browser/android/offline_pages/prerender_adapter.h"
12 #include "components/offline_pages/background/offliner.h" 12 #include "components/offline_pages/background/offliner.h"
13 #include "components/offline_pages/snapshot_controller.h"
13 14
14 class GURL; 15 class GURL;
15 16
16 namespace content { 17 namespace content {
17 class BrowserContext; 18 class BrowserContext;
18 class WebContents; 19 class WebContents;
19 class SessionStorageNamespace; 20 class SessionStorageNamespace;
20 } // namespace content 21 } // namespace content
21 22
22 namespace gfx { 23 namespace gfx {
23 class Size; 24 class Size;
24 } // namespace gfx 25 } // namespace gfx
25 26
26 namespace offline_pages { 27 namespace offline_pages {
27 28
28 // A client-side page loader that integrates with the PrerenderManager to do 29 // A client-side page loader that integrates with the PrerenderManager to do
29 // the page loading in the background. It operates on a single thread and 30 // the page loading in the background. It operates on a single thread and
30 // needs to run on BrowserThread::UI to work with the PrerenderManager. 31 // needs to run on BrowserThread::UI to work with the PrerenderManager.
31 // It supports a single load request at a time. 32 // It supports a single load request at a time.
32 class PrerenderingLoader : public PrerenderAdapter::Observer { 33 class PrerenderingLoader : public PrerenderAdapter::Observer,
34 public SnapshotController::Client {
33 public: 35 public:
34 // Reports status of a load page request with loaded contents if available. 36 // Reports status of a load page request with loaded contents if available.
35 typedef base::Callback<void(Offliner::RequestStatus, content::WebContents*)> 37 typedef base::Callback<void(Offliner::RequestStatus, content::WebContents*)>
36 LoadPageCallback; 38 LoadPageCallback;
37 39
38 explicit PrerenderingLoader(content::BrowserContext* browser_context); 40 explicit PrerenderingLoader(content::BrowserContext* browser_context);
39 ~PrerenderingLoader() override; 41 ~PrerenderingLoader() override;
40 42
41 // Loads a page in the background if possible and returns whether the 43 // Loads a page in the background if possible and returns whether the
42 // request was accepted. If so, the LoadPageCallback will be informed 44 // request was accepted. If so, the LoadPageCallback will be informed
(...skipping 29 matching lines...) Expand all
72 // Overrides the prerender stack adapter for unit testing. 74 // Overrides the prerender stack adapter for unit testing.
73 void SetAdapterForTesting( 75 void SetAdapterForTesting(
74 std::unique_ptr<PrerenderAdapter> prerender_adapter); 76 std::unique_ptr<PrerenderAdapter> prerender_adapter);
75 77
76 // PrerenderAdapter::Observer implementation: 78 // PrerenderAdapter::Observer implementation:
77 void OnPrerenderStart() override; 79 void OnPrerenderStart() override;
78 void OnPrerenderStopLoading() override; 80 void OnPrerenderStopLoading() override;
79 void OnPrerenderDomContentLoaded() override; 81 void OnPrerenderDomContentLoaded() override;
80 void OnPrerenderStop() override; 82 void OnPrerenderStop() override;
81 83
84 // SnapshotController::Client implementation:
85 void StartSnapshot() override;
86
82 private: 87 private:
83 // State of the loader (only one request may be active at a time). 88 // State of the loader (only one request may be active at a time).
84 enum class State { 89 enum class State {
85 IDLE, // No active load request. 90 IDLE, // No active load request.
86 PENDING, // Load request is pending the start of prerendering. 91 PENDING, // Load request is pending the start of prerendering.
87 LOADING, // Loading in progress. 92 LOADING, // Loading in progress.
88 LOADED, // Loaded and now waiting for requestor to StopLoading(). 93 LOADED, // Loaded and now waiting for requestor to StopLoading().
89 }; 94 };
90 95
91 // Handles some event/signal that the load request has succeeded or failed. 96 // Handles some event/signal that the load request has succeeded or failed.
92 // It may be due to some asynchronous trigger that occurs after the request 97 // It may be due to some asynchronous trigger that occurs after the request
93 // has completed for some other reason/event. 98 // has completed for some other reason/event.
94 void HandleLoadEvent(); 99 void HandleLoadEvent();
95 100
96 // Handles some event/signal that loading has stopped (whether due to a 101 // Handles some event/signal that loading has stopped (whether due to a
97 // failure, cancel, or stop request). It may be due to some asynchronous 102 // failure, cancel, or stop request). It may be due to some asynchronous
98 // trigger that occurs after the request has stopped for some other reason. 103 // trigger that occurs after the request has stopped for some other reason.
99 void HandleLoadingStopped(); 104 void HandleLoadingStopped();
100 105
101 // Cancels any current prerender and moves loader to idle state. 106 // Cancels any current prerender and moves loader to idle state.
102 void CancelPrerender(); 107 void CancelPrerender();
103 108
104 // Tracks loading state including whether the Loader is idle. 109 // Tracks loading state including whether the Loader is idle.
105 State state_; 110 State state_;
106 111
112 // Handles determining when to report page is LOADED.
113 std::unique_ptr<SnapshotController> snapshot_controller_;
114
107 // Not owned. 115 // Not owned.
108 content::BrowserContext* browser_context_; 116 content::BrowserContext* browser_context_;
109 117
110 // Adapter for handling calls to the prerender stack. 118 // Adapter for handling calls to the prerender stack.
111 std::unique_ptr<PrerenderAdapter> adapter_; 119 std::unique_ptr<PrerenderAdapter> adapter_;
112 120
113 // A WebContents for the active load request that is used to hold the session 121 // A WebContents for the active load request that is used to hold the session
114 // storage namespace for rendering. This will NOT have the loaded page. 122 // storage namespace for rendering. This will NOT have the loaded page.
115 std::unique_ptr<content::WebContents> session_contents_; 123 std::unique_ptr<content::WebContents> session_contents_;
116 124
117 // Callback to call when the active load request completes, fails, or is 125 // Callback to call when the active load request completes, fails, or is
118 // canceled. 126 // canceled.
119 LoadPageCallback callback_; 127 LoadPageCallback callback_;
120 128
121 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader); 129 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader);
122 }; 130 };
123 131
124 } // namespace offline_pages 132 } // namespace offline_pages
125 133
126 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 134 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/prerendering_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698