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

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

Issue 1968593002: PrerenderingLoader initial integration with PrerenderManager/PrerenderHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: virtual => override nits Created 4 years, 7 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
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>
9
8 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "chrome/browser/android/offline_pages/prerender_adapter.h"
9 #include "components/offline_pages/background/offliner.h" 12 #include "components/offline_pages/background/offliner.h"
10 13
11 class GURL; 14 class GURL;
12 15
13 namespace content { 16 namespace content {
14 class BrowserContext; 17 class BrowserContext;
15 class WebContents; 18 class WebContents;
16 class SessionStorageNamespace; 19 class SessionStorageNamespace;
17 } // namespace content 20 } // namespace content
18 21
19 namespace gfx { 22 namespace gfx {
20 class Size; 23 class Size;
21 } // namespace gfx 24 } // namespace gfx
22 25
23 namespace offline_pages { 26 namespace offline_pages {
24 27
25 // A client-side page loader that integrates with the PrerenderManager to do 28 // A client-side page loader that integrates with the PrerenderManager to do
26 // the page loading in the background. 29 // the page loading in the background. It operates on a single thread and
27 class PrerenderingLoader { 30 // needs to run on BrowserThread::UI to work with the PrerenderManager.
31 // It supports a single load request at a time.
32 class PrerenderingLoader : public PrerenderAdapter::Observer {
28 public: 33 public:
29 // Reports status of a load page request with loaded contents if available. 34 // Reports status of a load page request with loaded contents if available.
30 typedef base::Callback<void(Offliner::CompletionStatus, 35 typedef base::Callback<void(Offliner::RequestStatus, content::WebContents*)>
31 content::WebContents*)>
32 LoadPageCallback; 36 LoadPageCallback;
33 37
34 explicit PrerenderingLoader(content::BrowserContext* browser_context); 38 explicit PrerenderingLoader(content::BrowserContext* browser_context);
35 virtual ~PrerenderingLoader(); 39 ~PrerenderingLoader() override;
36 40
37 // Loads a page in the background if possible and returns whether the 41 // Loads a page in the background if possible and returns whether the
38 // request was accepted. If so, the LoadPageCallback will be informed 42 // request was accepted. If so, the LoadPageCallback will be informed
39 // of status. Only one load request may exist as a time. If a previous 43 // of status. Only one load request may exist as a time. If a previous
40 // request is still in progress it must be canceled before a new 44 // request is still in progress it must be stopped before a new
41 // request will be accepted. 45 // request will be accepted. The callback may be called more than
46 // once - first for a successful load and then if canceled after the
47 // load (which may be from resources being reclaimed) at which point
48 // the retrieved WebContents should no longer be used.
42 virtual bool LoadPage(const GURL& url, const LoadPageCallback& callback); 49 virtual bool LoadPage(const GURL& url, const LoadPageCallback& callback);
43 50
44 // Stops (completes or cancels) the load request. Must be called when 51 // Stops (completes or cancels) the load request. Must be called when
45 // LoadPageCallback is done with consuming the contents. 52 // LoadPageCallback is done with consuming the contents. May be called
53 // prior to LoadPageCallback in order to cancel the current request (in
54 // which case the callback will not be called).
46 // This loader should also be responsible for stopping offline 55 // This loader should also be responsible for stopping offline
47 // prerenders when Chrome is transitioned to foreground. 56 // prerenders when Chrome is transitioned to foreground.
48 virtual void StopLoading(); 57 virtual void StopLoading();
58
59 // Returns whether prerendering is possible for this device's configuration
60 // and the browser context.
61 virtual bool CanPrerender();
62
63 // Returns whether the loader is idle and able to accept new LoadPage
64 // request.
65 virtual bool IsIdle();
66
67 // Returns whether the loader has successfully loaded web contents.
68 // Note that |StopLoading()| should be used to clear this state once
69 // the loaded web contents are no longer needed.
70 virtual bool IsLoaded();
71
72 // Overrides the prerender stack adapter for unit testing.
73 void SetAdapterForTesting(
74 std::unique_ptr<PrerenderAdapter> prerender_adapter);
75
76 // Prerender event handling logic:
pasko 2016/05/20 19:04:53 // PrerenderAdapter::Observer overrides.
dougarnett 2016/05/20 22:21:12 Done.
77 void OnPrerenderStart() override;
78 void OnPrerenderStopLoading() override;
79 void OnPrerenderDomContentLoaded() override;
80 void OnPrerenderStop() override;
81
82 private:
83 // State of the loader (only one request may be active at a time).
84 enum class State {
85 IDLE, // No active load request.
86 PENDING, // Load request is pending the start of prerendering.
87 LOADING, // Loading in progress.
88 LOADED, // Loaded and now waiting for requestor to StopLoading().
89 };
90
91 // Returns the session storage namespace to use for the prerendering request.
92 content::SessionStorageNamespace* GetSessionStorageNamespace();
93
94 // Returns the window size to render.
95 const gfx::Size GetSize();
pasko 2016/05/20 19:04:53 did you mean: gfx::Size GetSize() const; ?
dougarnett 2016/05/20 22:21:12 Done.
96
97 // Reports the loaded result to the LoadPageCallback (if still loading).
98 void ReportLoaded();
99
100 // Reports loading stopped (failure or cancel) to the LoadPageCallback if
101 // load request still active.
102 void ReportLoadingStopped();
103
104 // Cancels any current prerender and moves loader to idle state.
105 void CancelPrerender();
106
107 // Tracks loading state including whether the Loader is idle.
108 State state_;
109
110 // Not owned.
111 content::BrowserContext* browser_context_;
112
113 // Adapter for handling calls to the prerender stack.
114 std::unique_ptr<PrerenderAdapter> adapter_;
115
116 // A WebContents for the active load request that is used to hold the session
117 // storage namespace for rendering. This will NOT have the loaded page.
118 std::unique_ptr<content::WebContents> session_contents_;
119
120 // Callback to call when the active load request completes, fails, or is
121 // canceled.
122 LoadPageCallback callback_;
123
124 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader);
49 }; 125 };
50 126
51 } // namespace offline_pages 127 } // namespace offline_pages
52 128
53 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 129 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698