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

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: uninlined ObserverDelegate impl 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"
12 #include "chrome/browser/prerender/prerender_handle.h"
13 #include "chrome/browser/prerender/prerender_manager.h"
9 #include "components/offline_pages/background/offliner.h" 14 #include "components/offline_pages/background/offliner.h"
10 15
11 class GURL; 16 class GURL;
12 17
13 namespace content { 18 namespace content {
14 class BrowserContext; 19 class BrowserContext;
15 class WebContents; 20 class WebContents;
16 class SessionStorageNamespace; 21 class SessionStorageNamespace;
17 } // namespace content 22 } // namespace content
18 23
19 namespace gfx { 24 namespace gfx {
20 class Size; 25 class Size;
21 } // namespace gfx 26 } // namespace gfx
22 27
23 namespace offline_pages { 28 namespace offline_pages {
24 29
25 // A client-side page loader that integrates with the PrerenderManager to do 30 // A client-side page loader that integrates with the PrerenderManager to do
26 // the page loading in the background. 31 // the page loading in the background. It operates on a single thread and
32 // needs to run on BrowserThread::UI to work with the PrerenderManager.
27 class PrerenderingLoader { 33 class PrerenderingLoader {
28 public: 34 public:
29 // Reports status of a load page request with loaded contents if available. 35 // Reports status of a load page request with loaded contents if available.
30 typedef base::Callback<void(Offliner::CompletionStatus, 36 typedef base::Callback<void(Offliner::RequestStatus, content::WebContents*)>
31 content::WebContents*)>
32 LoadPageCallback; 37 LoadPageCallback;
33 38
34 explicit PrerenderingLoader(content::BrowserContext* browser_context); 39 explicit PrerenderingLoader(content::BrowserContext* browser_context);
35 virtual ~PrerenderingLoader(); 40 virtual ~PrerenderingLoader();
36 41
37 // Loads a page in the background if possible and returns whether the 42 // Loads a page in the background if possible and returns whether the
38 // request was accepted. If so, the LoadPageCallback will be informed 43 // 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 44 // 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 45 // request is still in progress it must be stopped before a new
41 // request will be accepted. 46 // request will be accepted.
42 virtual bool LoadPage(const GURL& url, const LoadPageCallback& callback); 47 virtual bool LoadPage(const GURL& url, const LoadPageCallback& callback);
43 48
44 // Stops (completes or cancels) the load request. Must be called when 49 // Stops (completes or cancels) the load request. Must be called when
45 // LoadPageCallback is done with consuming the contents. 50 // LoadPageCallback is done with consuming the contents. May be called
51 // prior to LoadPageCallback in order to cancel the current request (in
52 // which case the callback will not be called).
46 // This loader should also be responsible for stopping offline 53 // This loader should also be responsible for stopping offline
47 // prerenders when Chrome is transitioned to foreground. 54 // prerenders when Chrome is transitioned to foreground.
48 virtual void StopLoading(); 55 virtual void StopLoading();
56
57 // Returns whether prerendering is possible for this device's configuration
58 // and the browser context.
59 virtual bool CanPrerender();
60
61 // Returns whether the loader is idle and able to accept new LoadPage
62 // request.
63 virtual bool IsIdle();
64
65 // Returns whether the loader has successfully loaded contents.
fgorski 2016/05/17 05:09:52 nit: web contents.
dougarnett 2016/05/18 00:37:47 Done.
66 // Note that StopLoading() should be used to clear this state once
fgorski 2016/05/17 05:09:52 nit: |StopLoading()|
dougarnett 2016/05/18 00:37:47 Done.
67 // the loaded contents are no longer needed.
fgorski 2016/05/17 05:09:52 the loaded web contents is
dougarnett 2016/05/18 00:37:47 Done.
68 virtual bool IsLoaded();
69
70 // Overrides the prerender stack adapter for unit testing.
71 void SetAdapterForTesting(PrerenderAdapter* prerender_adapter);
72
73 private:
74 friend class ObserverDelegate;
75
76 // Delegating observer for PrerenderHandle events. Used to restrict access
77 // to loader's observer methods.
78 class ObserverDelegate : public prerender::PrerenderHandle::Observer {
fgorski 2016/05/17 05:09:52 Can you name it PrerenderHandleObserver or HandleO
dougarnett 2016/05/18 00:37:47 Done.
79 public:
80 explicit ObserverDelegate(PrerenderingLoader* loader);
81 ~ObserverDelegate() override;
82
83 void OnPrerenderStart(prerender::PrerenderHandle* handle) override;
84 void OnPrerenderStopLoading(prerender::PrerenderHandle* handle) override;
85 void OnPrerenderDomContentLoaded(
86 prerender::PrerenderHandle* handle) override;
87 void OnPrerenderStop(prerender::PrerenderHandle* handle) override;
88
89 private:
90 // Not owned.
91 PrerenderingLoader* loader_;
92 };
93
94 // State of the loader (only one request may be active at a time).
fgorski 2016/05/17 05:09:52 the comment in () should be in the documentation o
dougarnett 2016/05/18 00:37:47 Done.
95 enum class State {
96 IDLE, // No active request.
97 PENDING, // Request pending the start of prerendering.
98 LOADING, // Loading in progress.
99 LOADED, // Loaded and now waiting for requestor to StopLoading().
100 };
101
102 // PrerenderHandle::Observer handling logic:
103 void OnPrerenderStart(prerender::PrerenderHandle* handle);
104 void OnPrerenderStopLoading(prerender::PrerenderHandle* handle);
105 void OnPrerenderDomContentLoaded(prerender::PrerenderHandle* handle);
106 void OnPrerenderStop(prerender::PrerenderHandle* handle);
pasko 2016/05/17 16:26:31 why should PrerenderingLoader know about the handl
dougarnett 2016/05/18 00:37:47 Done.
107
108 // Returns the session storage namespace to use for the prerendering request.
109 content::SessionStorageNamespace* GetSessionStorageNamespace();
110
111 // Returns the window size to render.
112 const gfx::Size GetSize();
113
114 // Reports the load result to the LoadPageCallback if load still in progress.
115 void ReportLoadedIfStillLoading();
116
117 // Reports a load failure to the LoadPageCallback if load still in progress.
118 void ReportLoadFailedIfStillLoading();
119
120 // Cancels any current prerender and moves loader to idle state.
121 void CancelPrerender();
122
123 // Tracks loading state including whether the Loader is idle.
124 State state_;
125
126 content::BrowserContext* browser_context_; // Not owned.
127 std::unique_ptr<PrerenderAdapter> adapter_;
fgorski 2016/05/17 05:09:52 More documentation on each one, please. This is im
dougarnett 2016/05/18 00:37:47 Done.
128 std::unique_ptr<ObserverDelegate> observer_;
129 std::unique_ptr<content::WebContents> session_contents_;
130 LoadPageCallback callback_;
131
132 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader);
49 }; 133 };
50 134
51 } // namespace offline_pages 135 } // namespace offline_pages
52 136
53 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 137 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698