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

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: Address some gabadie feedback 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"
fgorski 2016/05/13 17:39:58 Same here, perhaps you can forward declare some of
dougarnett 2016/05/13 20:58:32 Acknowledged.
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
27 class PrerenderingLoader { 32 // needs to run on BrowserThread::UI to work with the PrerenderManager.
33 class PrerenderingLoader : prerender::PrerenderHandle::Observer {
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 ~PrerenderingLoader() override;
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 bool CanPrerender();
60
61 // Returns whether the loader is idle and able to accept new LoadPage
62 // request.
63 bool IsIdle();
64
65 // Overrides the prerender stack adapter for unit testing.
66 void SetAdapterForTesting(PrerenderAdapter* prerender_adapter);
67
68 private:
69 // PrerenderHandle::Observer overrides:
70 void OnPrerenderStart(prerender::PrerenderHandle* handle) override;
71 void OnPrerenderStopLoading(prerender::PrerenderHandle* handle) override;
72 void OnPrerenderDomContentLoaded(prerender::PrerenderHandle* handle) override;
73 void OnPrerenderStop(prerender::PrerenderHandle* handle) override;
74
75 // Returns the session storage namespace to use for the
76 // prerendering request obtained from [session_contents|.
77 content::SessionStorageNamespace* GetSessionStorageNamespace(
78 content::WebContents* session_contents);
79
80 // Returns the window size to render from |session_contents|.
81 const gfx::Size GetSize(content::WebContents* session_contents);
82
83 // Reports the load result to the LoadPageCallback if load still in progress.
84 void ReportLoadedIfStillLoading();
85
86 // Reports a load failure to the LoadPageCallback if load still in progress.
87 void ReportLoadFailedIfStillLoading();
88
89 // Cancels any current prerender and moves loader to idle state.
90 void CancelPrerender();
91
92 // State of the loader (only one request may be active at a time).
93 enum class State {
fgorski 2016/05/13 17:39:58 define at the beginning of the private block
dougarnett 2016/05/13 20:58:32 Done.
94 IDLE, // No active request.
95 PENDING, // Request pending the start of prerendering.
96 LOADING, // Loading in progress.
97 LOADED, // Loaded and now waiting for requestor to StopLoading().
98 };
99 State state_;
100
101 content::BrowserContext* browser_context_; // Not owned.
102 std::unique_ptr<PrerenderAdapter> adapter_;
103 std::unique_ptr<content::WebContents> session_contents_;
104 LoadPageCallback callback_;
49 }; 105 };
fgorski 2016/05/13 17:39:58 Consider DISALLOW_COPY_AND_ASSIGN...
dougarnett 2016/05/13 20:58:32 Done.
50 106
51 } // namespace offline_pages 107 } // namespace offline_pages
52 108
53 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 109 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698