Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_handle.h
blobe28bcf5ead63f19ac69f320c06967a2b741cfe63
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "chrome/browser/prerender/prerender_manager.h"
13 class GURL;
15 namespace content {
16 class SessionStorageNamespace;
19 namespace prerender {
21 class PrerenderContents;
23 // A class representing a running prerender to a client of the PrerenderManager.
24 // Methods on PrerenderManager which start prerenders return a caller-owned
25 // PrerenderHandle* to the client (or NULL if they are unable to start a
26 // prerender). Calls on the handle of a prerender that is not running at no-ops.
27 // Destroying a handle before a prerender starts will prevent it from ever
28 // starting. Destroying a handle while a prerendering is running will stop the
29 // prerender, without making any calls to the observer.
30 class PrerenderHandle : public base::NonThreadSafe,
31 public PrerenderContents::Observer {
32 public:
33 class Observer {
34 public:
35 // Signals that the prerender has started running.
36 virtual void OnPrerenderStart(PrerenderHandle* handle) = 0;
38 // Signals that the prerender has had its load event.
39 virtual void OnPrerenderStopLoading(PrerenderHandle* handle) = 0;
41 // Signals that the prerender has had its 'DOMContentLoaded' event.
42 virtual void OnPrerenderDomContentLoaded(PrerenderHandle* handle) = 0;
44 // Signals that the prerender has stopped running.
45 virtual void OnPrerenderStop(PrerenderHandle* handle) = 0;
47 // Signals that this prerender has just become a MatchComplete replacement.
48 virtual void OnPrerenderCreatedMatchCompleteReplacement(
49 PrerenderHandle* handle) = 0;
51 protected:
52 Observer();
53 virtual ~Observer();
56 // Before calling the destructor, the caller must invalidate the handle by
57 // calling either OnNavigateAway or OnCancel.
58 ~PrerenderHandle() override;
60 void SetObserver(Observer* observer);
62 // The launcher is navigating away from the context that launched this
63 // prerender. The prerender will likely stay alive briefly though, in case we
64 // are going through a redirect chain that will target it.
65 void OnNavigateAway();
67 // The launcher has taken explicit action to remove this prerender (for
68 // instance, removing a link element from a document). This call invalidates
69 // the handle. If the prerender handle is already invalid, this call does
70 // nothing.
71 void OnCancel();
73 // True if this prerender is currently active.
74 bool IsPrerendering() const;
76 // True if we started a prerender, and it has finished loading.
77 bool IsFinishedLoading() const;
79 // True if the prerender is currently active, but is abandoned.
80 bool IsAbandoned() const;
82 PrerenderContents* contents() const;
84 // Returns whether the prerender matches the URL provided.
85 bool Matches(
86 const GURL& url,
87 const content::SessionStorageNamespace* session_storage_namespace) const;
89 // Returns whether this PrerenderHandle represents the same prerender as
90 // the other PrerenderHandle object specified.
91 bool RepresentingSamePrerenderAs(PrerenderHandle* other) const;
93 private:
94 friend class PrerenderManager;
96 explicit PrerenderHandle(PrerenderManager::PrerenderData* prerender_data);
98 // From PrerenderContents::Observer:
99 void OnPrerenderStart(PrerenderContents* prerender_contents) override;
100 void OnPrerenderStopLoading(PrerenderContents* prerender_contents) override;
101 void OnPrerenderDomContentLoaded(
102 PrerenderContents* prerender_contents) override;
103 void OnPrerenderStop(PrerenderContents* prerender_contents) override;
104 void OnPrerenderCreatedMatchCompleteReplacement(
105 PrerenderContents* contents,
106 PrerenderContents* replacement) override;
108 Observer* observer_;
110 base::WeakPtr<PrerenderManager::PrerenderData> prerender_data_;
111 base::WeakPtrFactory<PrerenderHandle> weak_ptr_factory_;
113 DISALLOW_COPY_AND_ASSIGN(PrerenderHandle);
116 } // namespace prerender
118 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_