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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/prerender_adapter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_
7
8 #include <memory>
9
10 #include "chrome/browser/prerender/prerender_handle.h"
11
12 class GURL;
13
14 namespace content {
15 class BrowserContext;
16 class WebContents;
17 class SessionStorageNamespace;
18 } // namespace content
19
20 namespace gfx {
21 class Size;
22 } // namespace gfx
23
24 namespace offline_pages {
25
26 // An adapter for managing a prerendering request for offlining. This handles
27 // all calls into the prerender stack and tracks the active prerender handle.
28 class PrerenderAdapter : public prerender::PrerenderHandle::Observer {
29 public:
30 // An observer of PrerenderHandle events that does not expose the handle.
31 class Observer {
32 public:
33 // Signals that the prerender has started running.
34 virtual void OnPrerenderStart() = 0;
35
36 // Signals that the prerender has had its load event.
37 virtual void OnPrerenderStopLoading() = 0;
38
39 // Signals that the prerender has had its 'DOMContentLoaded' event.
40 virtual void OnPrerenderDomContentLoaded() = 0;
41
42 // Signals that the prerender has stopped running and any retrieved
43 // WebContents (via |GetWebContents()|) have become invalidated.
44 virtual void OnPrerenderStop() = 0;
45
46 protected:
47 Observer();
48 virtual ~Observer();
49 };
50
51 explicit PrerenderAdapter(PrerenderAdapter::Observer* observer);
52 ~PrerenderAdapter() override;
53
54 // Returns whether prerendering is enabled and configured.
55 virtual bool CanPrerender() const;
56
57 // Starts prerendering |url| for offlining. There must be no active
58 // prerender request when calling this. Returns whether it was able
59 // to start the prerendering operation.
60 virtual bool StartPrerender(
61 content::BrowserContext* browser_context,
62 const GURL& url,
63 content::SessionStorageNamespace* session_storage_namespace,
64 const gfx::Size& size);
65
66 // Returns a pointer to the prerendered WebContents. This should only be
67 // called once prerendering observer events indicate content is loaded.
68 // It may be used for snapshotting the page. The caller does NOT get
69 // ownership on the contents and must call |DestroyActive()|
70 // to report when it no longer needs the web contents. The caller should
71 // watch for its |PrerenderAdapter::Observer::OnPrerenderStop()| to
72 // learn that the web contents should no longer be used.
73 virtual content::WebContents* GetWebContents() const;
74
75 // Returns the final status of prerendering.
76 virtual prerender::FinalStatus GetFinalStatus() const;
77
78 // Returns whether this adapter has an active prerender request. This
79 // adapter supports one request at a time. DestroyActive() may be used
80 // to clear an active request (which will allow StartPrerender() to be
81 // called to request a new one).
82 virtual bool IsActive() const;
83
84 // Cancels any current prerendering operation and destroys its local handle.
85 virtual void DestroyActive();
86
87 // PrerenderHandle::Observer interface:
88 void OnPrerenderStart(prerender::PrerenderHandle* handle) override;
89 void OnPrerenderStopLoading(prerender::PrerenderHandle* handle) override;
90 void OnPrerenderDomContentLoaded(prerender::PrerenderHandle* handle) override;
91 void OnPrerenderStop(prerender::PrerenderHandle* handle) override;
92
93 private:
94 // At most one prerender request may be active for this adapter and this
95 // holds its handle if one is active.
96 std::unique_ptr<prerender::PrerenderHandle> active_handle_;
97
98 // Observer of active handle events. Not owned.
99 PrerenderAdapter::Observer* observer_;
100
101 DISALLOW_COPY_AND_ASSIGN(PrerenderAdapter);
102 };
103
104 } // namespace offline_pages
105
106 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_
OLDNEW
« 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