| Index: chrome/browser/android/offline_pages/prerendering_loader.h
|
| diff --git a/chrome/browser/android/offline_pages/prerendering_loader.h b/chrome/browser/android/offline_pages/prerendering_loader.h
|
| index f4af6a2b7a2e0b37892acaf3ec965e59df8f1a2e..0729843a116443014f3b28a49b7394f22ccf3e98 100644
|
| --- a/chrome/browser/android/offline_pages/prerendering_loader.h
|
| +++ b/chrome/browser/android/offline_pages/prerendering_loader.h
|
| @@ -5,7 +5,12 @@
|
| #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
|
| #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
|
|
|
| +#include <memory>
|
| +
|
| #include "base/callback.h"
|
| +#include "chrome/browser/android/offline_pages/prerender_adapter.h"
|
| +#include "chrome/browser/prerender/prerender_handle.h"
|
| +#include "chrome/browser/prerender/prerender_manager.h"
|
| #include "components/offline_pages/background/offliner.h"
|
|
|
| class GURL;
|
| @@ -23,8 +28,9 @@ class Size;
|
| namespace offline_pages {
|
|
|
| // A client-side page loader that integrates with the PrerenderManager to do
|
| -// the page loading in the background.
|
| -class PrerenderingLoader {
|
| +// the page loading in the background. It operates on a single thread and
|
| +// needs to run on BrowserThread::UI to work with the PrerenderManager.
|
| +class PrerenderingLoader : public prerender::PrerenderHandle::Observer {
|
| public:
|
| // Reports status of a load page request with loaded contents if available.
|
| typedef base::Callback<void(Offliner::CompletionStatus,
|
| @@ -32,20 +38,71 @@ class PrerenderingLoader {
|
| LoadPageCallback;
|
|
|
| explicit PrerenderingLoader(content::BrowserContext* browser_context);
|
| - virtual ~PrerenderingLoader();
|
| + ~PrerenderingLoader() override;
|
|
|
| // Loads a page in the background if possible and returns whether the
|
| // request was accepted. If so, the LoadPageCallback will be informed
|
| // of status. Only one load request may exist as a time. If a previous
|
| - // request is still in progress it must be canceled before a new
|
| + // request is still in progress it must be stopped before a new
|
| // request will be accepted.
|
| virtual bool LoadPage(const GURL& url, const LoadPageCallback& callback);
|
|
|
| // Stops (completes or cancels) the load request. Must be called when
|
| - // LoadPageCallback is done with consuming the contents.
|
| + // LoadPageCallback is done with consuming the contents. May be called
|
| + // prior to LoadPageCallback in order to cancel the current request (in
|
| + // which case the callback will not be called).
|
| // This loader should also be responsible for stopping offline
|
| // prerenders when Chrome is transitioned to foreground.
|
| virtual void StopLoading();
|
| +
|
| + // Returns whether prerendering is possible for this device's configuration
|
| + // and the browser context.
|
| + bool CanPrerender();
|
| +
|
| + // Returns whether the loader is idle and able to accept new LoadPage
|
| + // request.
|
| + bool IsIdle();
|
| +
|
| + // Overrides the prerender stack adapter for unit testing.
|
| + void SetAdapterForTesting(PrerenderAdapter* prerender_adapter);
|
| +
|
| + // PrerenderHandle::Observer overrides:
|
| + void OnPrerenderStart(prerender::PrerenderHandle* handle) override;
|
| + void OnPrerenderStopLoading(prerender::PrerenderHandle* handle) override;
|
| + void OnPrerenderDomContentLoaded(prerender::PrerenderHandle* handle) override;
|
| + void OnPrerenderStop(prerender::PrerenderHandle* handle) override;
|
| +
|
| + private:
|
| + // Returns the session storage namespace to use for the
|
| + // prerendering request obtained from [session_contents|.
|
| + content::SessionStorageNamespace* GetSessionStorageNamespace(
|
| + content::WebContents* session_contents);
|
| +
|
| + // Returns the window size to render from |session_contents|.
|
| + const gfx::Size GetSize(content::WebContents* session_contents);
|
| +
|
| + // Reports the load result to the LoadPageCallback.
|
| + void ReportLoaded();
|
| +
|
| + // Reports a load failure to the LoadPageCallback.
|
| + void ReportLoadFailed();
|
| +
|
| + // Cancels any current prerender and moves loader to idle state.
|
| + void CancelPrerender();
|
| +
|
| + // State of the loader (only one request may be active at a time).
|
| + enum class State {
|
| + kIdle, // No active request.
|
| + kPending, // Request pending the start of prerendering.
|
| + kLoading, // Loading in progress.
|
| + kLoaded, // Loaded and now waiting for requestor to StopLoading().
|
| + };
|
| + State state_;
|
| +
|
| + content::BrowserContext* browser_context_; // Not owned.
|
| + std::unique_ptr<PrerenderAdapter> adapter_;
|
| + std::unique_ptr<content::WebContents> session_contents_;
|
| + LoadPageCallback callback_;
|
| };
|
|
|
| } // namespace offline_pages
|
|
|