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

Unified Diff: chrome/browser/android/offline_pages/prerender_adapter.h

Issue 2015603002: PrerenderingLoader initial integration with PrerenderManager/PrerenderHandle and make it unit-testa… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds mock adapter member initialization in constructor 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/prerender_adapter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/offline_pages/prerender_adapter.h
diff --git a/chrome/browser/android/offline_pages/prerender_adapter.h b/chrome/browser/android/offline_pages/prerender_adapter.h
new file mode 100644
index 0000000000000000000000000000000000000000..1382170565df9b1bab5da23d274f07d8365de9e3
--- /dev/null
+++ b/chrome/browser/android/offline_pages/prerender_adapter.h
@@ -0,0 +1,106 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_
+#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_
+
+#include <memory>
+
+#include "chrome/browser/prerender/prerender_handle.h"
+
+class GURL;
+
+namespace content {
+class BrowserContext;
+class WebContents;
+class SessionStorageNamespace;
+} // namespace content
+
+namespace gfx {
+class Size;
+} // namespace gfx
+
+namespace offline_pages {
+
+// An adapter for managing a prerendering request for offlining. This handles
+// all calls into the prerender stack and tracks the active prerender handle.
+class PrerenderAdapter : public prerender::PrerenderHandle::Observer {
+ public:
+ // An observer of PrerenderHandle events that does not expose the handle.
+ class Observer {
+ public:
+ // Signals that the prerender has started running.
+ virtual void OnPrerenderStart() = 0;
+
+ // Signals that the prerender has had its load event.
+ virtual void OnPrerenderStopLoading() = 0;
+
+ // Signals that the prerender has had its 'DOMContentLoaded' event.
+ virtual void OnPrerenderDomContentLoaded() = 0;
+
+ // Signals that the prerender has stopped running and any retrieved
+ // WebContents (via |GetWebContents()|) have become invalidated.
+ virtual void OnPrerenderStop() = 0;
+
+ protected:
+ Observer();
+ virtual ~Observer();
+ };
+
+ explicit PrerenderAdapter(PrerenderAdapter::Observer* observer);
+ ~PrerenderAdapter() override;
+
+ // Returns whether prerendering is enabled and configured.
+ virtual bool CanPrerender() const;
+
+ // Starts prerendering |url| for offlining. There must be no active
+ // prerender request when calling this. Returns whether it was able
+ // to start the prerendering operation.
+ virtual bool StartPrerender(
+ content::BrowserContext* browser_context,
+ const GURL& url,
+ content::SessionStorageNamespace* session_storage_namespace,
+ const gfx::Size& size);
+
+ // Returns a pointer to the prerendered WebContents. This should only be
+ // called once prerendering observer events indicate content is loaded.
+ // It may be used for snapshotting the page. The caller does NOT get
+ // ownership on the contents and must call |DestroyActive()|
+ // to report when it no longer needs the web contents. The caller should
+ // watch for its |PrerenderAdapter::Observer::OnPrerenderStop()| to
+ // learn that the web contents should no longer be used.
+ virtual content::WebContents* GetWebContents() const;
+
+ // Returns the final status of prerendering.
+ virtual prerender::FinalStatus GetFinalStatus() const;
+
+ // Returns whether this adapter has an active prerender request. This
+ // adapter supports one request at a time. DestroyActive() may be used
+ // to clear an active request (which will allow StartPrerender() to be
+ // called to request a new one).
+ virtual bool IsActive() const;
+
+ // Cancels any current prerendering operation and destroys its local handle.
+ virtual void DestroyActive();
+
+ // PrerenderHandle::Observer interface:
+ 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:
+ // At most one prerender request may be active for this adapter and this
+ // holds its handle if one is active.
+ std::unique_ptr<prerender::PrerenderHandle> active_handle_;
+
+ // Observer of active handle events. Not owned.
+ PrerenderAdapter::Observer* observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrerenderAdapter);
+};
+
+} // namespace offline_pages
+
+#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/prerender_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698