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

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: 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/prerender/prerender_handle.h"
12 #include "chrome/browser/prerender/prerender_manager.h"
9 #include "components/offline_pages/background/offliner.h" 13 #include "components/offline_pages/background/offliner.h"
10 14
11 class GURL; 15 class GURL;
12 class PrerenderManager;
13 16
14 namespace content { 17 namespace content {
18 class BrowserContext;
15 class WebContents; 19 class WebContents;
16 class SessionStorageNamespace; 20 class SessionStorageNamespace;
17 } // namespace content 21 } // namespace content
18 22
19 namespace gfx { 23 namespace gfx {
20 class Size; 24 class Size;
21 } // namespace gfx 25 } // namespace gfx
22 26
23 namespace offline_pages { 27 namespace offline_pages {
24 28
25 // 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
26 // the page loading in the background. 30 // the page loading in the background.
27 class PrerenderingLoader { 31 class PrerenderingLoader : public prerender::PrerenderHandle::Observer {
28 public: 32 public:
33 // Adapter for making prerender stack calls internally. This provides virtual
34 // methods that may be overridden or mocked to allow for unit testing.
35 class PrerenderingAdapter {
Pete Williamson 2016/05/10 20:00:27 Would this be better in its own file? It is start
dougarnett 2016/05/10 21:33:12 Yes, maybe so. Would like to get some review from
fgorski 2016/05/10 21:36:27 +1 what to Pete suggested, and also, PrerenderAdap
dougarnett 2016/05/16 23:51:38 Done.
36 public:
37 PrerenderingAdapter() {}
38 virtual ~PrerenderingAdapter() {}
39
40 // Returns whether prerendering is enabled and configured.
41 virtual bool CanPrerender() const;
42
43 // Requests prerendering of |url|.
44 virtual bool AddPrerenderForOffline(
45 content::BrowserContext* browser_context,
46 const GURL& url,
47 content::SessionStorageNamespace* session_storage_namespace,
48 const gfx::Size& size);
49
50 // Sets an observer on prerendering events.
51 virtual void SetObserver(prerender::PrerenderHandle::Observer* observer);
52
53 // Returns whether actively prerendering.
54 virtual bool IsPrerendering() const;
55
56 // Reports that prerendering should be canceled.
57 virtual void OnCancel();
58
59 // Returns the prerendered WebContents. This should only be called once
60 // prerendering observer events indicate content is loaded. It may be
61 // used for snapshotting the page.
62 virtual content::WebContents* GetPrerenderContents() const;
63
64 // Returns the final status of prerendering.
65 virtual prerender::FinalStatus GetFinalStatus() const;
66
67 // Returns whether there is an active prerendering.
68 virtual bool IsActive() const;
69
70 // Returns whether there is an active prerendering associated with
71 // the |handle|. This may be used to confirm that an observed prerender
72 // event for |handle| applies to the active prerendering.
73 virtual bool IsActive(prerender::PrerenderHandle* handle) const;
74
75 // Destroys and clears any current prerendering operation and state.
76 virtual void DestroyActive();
77
78 private:
79 std::unique_ptr<prerender::PrerenderHandle> active_handle_;
80 };
81
29 // Reports status of a load page request with loaded contents if available. 82 // Reports status of a load page request with loaded contents if available.
30 typedef base::Callback<void(Offliner::CompletionStatus, 83 typedef base::Callback<void(bool /* loaded */, content::WebContents*)>
31 content::WebContents*)>
32 LoadPageCallback; 84 LoadPageCallback;
33 85
34 explicit PrerenderingLoader(PrerenderManager* prerender_manager); 86 explicit PrerenderingLoader(content::BrowserContext* browser_context);
35 ~PrerenderingLoader(); 87 virtual ~PrerenderingLoader();
fgorski 2016/05/10 21:36:27 scratch the virtual, add override;
dougarnett 2016/05/16 23:51:38 Done.
36 88
37 // Loads a page in the background if possible and returns whether the 89 // Loads a page in the background if possible and returns whether the
38 // request was accepted. If so, the LoadPageCallback will be informed 90 // 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 91 // 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 92 // request is still in progress it must be stopped before a new
41 // request will be accepted. 93 // request will be accepted.
42 bool LoadPage(const GURL& url, 94 bool LoadPage(const GURL& url, const LoadPageCallback& callback);
43 content::SessionStorageNamespace* session_storage_namespace,
44 const gfx::Size& size,
45 const LoadPageCallback& callback);
46 95
47 // Stops (completes or cancels) the load request. Must be called when 96 // Stops (completes or cancels) the load request. Must be called when
48 // LoadPageCallback is done with consuming the contents. 97 // LoadPageCallback is done with consuming the contents. May be called
98 // prior to LoadPageCallback in order to cancel the current request (in
99 // which case the callback will not be called).
49 // This loader should also be responsible for stopping offline 100 // This loader should also be responsible for stopping offline
50 // prerenders when Chrome is transitioned to foreground. 101 // prerenders when Chrome is transitioned to foreground.
51 void StopLoading(); 102 void StopLoading();
103
104 // Returns whether prerendering is possible for this device's configuration
105 // and the browser context.
106 bool CanPrerender();
107
108 // Returns whether the loader is idle and able to accept new LoadPage
109 // request.
Pete Williamson 2016/05/10 20:00:27 IsAvailable() may be a better name than IsIdle().
dougarnett 2016/05/10 21:33:12 Maybe, or IsReady
dougarnett 2016/05/16 23:51:38 Kept as IsIdle(). Available and Ready seem more po
110 bool IsIdle();
111
112 // Overrides the prerender stack adapter for unit testing.
113 void SetAdapterForTesting(PrerenderingAdapter* prerendering_adapter);
114
115 private:
116 // Determines and returns the session storage namespace to use for the
117 // prerendering request.
118 content::SessionStorageNamespace* GetSessionStorageNamespace();
119
120 // Determines and returns the window size to use for the prerendering request.
121 const gfx::Size GetSize();
122
123 // Reports the load result to the LoadPageCallback.
124 void ReportLoaded();
125
126 // Reports a load failure to the LoadPageCallback.
127 void ReportLoadFailed();
128
129 // Releases the current load operation resources.
130 void ReleaseCurrentLoad();
131
132 // PrerenderHandle::Observer overrides:
133 void OnPrerenderStart(prerender::PrerenderHandle* handle) override;
134 void OnPrerenderStopLoading(prerender::PrerenderHandle* handle) override;
135 void OnPrerenderDomContentLoaded(prerender::PrerenderHandle* handle) override;
136 void OnPrerenderStop(prerender::PrerenderHandle* handle) override;
137 void OnPrerenderCreatedMatchCompleteReplacement(
138 prerender::PrerenderHandle* handle) override;
139
140 // kIdle - no active request.
141 // kPending - request pending the start of prerendering.
142 // kLoading - loading in progress.
143 // kLoaded - loaded and now waiting for requestor to StopLoading().
144 enum class State { kIdle, kPending, kLoading, kLoaded };
Pete Williamson 2016/05/10 20:00:27 I don't think this is wrong or bad as is, but as I
dougarnett 2016/05/10 21:33:12 Think I saw this style from recent dimich CL so tr
dougarnett 2016/05/16 23:51:38 Revised to other style.
145 State state_;
146
147 // Not owned.
Pete Williamson 2016/05/10 20:00:27 Suggestion to avoid ambiguity: browser_context_ i
dougarnett 2016/05/10 21:33:11 Moved to be a suffix comment. I don't want to set
148 content::BrowserContext* browser_context_;
149 std::unique_ptr<PrerenderingAdapter> adapter_;
150 LoadPageCallback callback_;
52 }; 151 };
53 152
54 } // namespace offline_pages 153 } // namespace offline_pages
55 154
56 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 155 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698