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

Side by Side Diff: chrome/browser/prerender/prerender_handle.h

Issue 11316311: Make PrerenderHandle an observer of PrerenderContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: signal stop on match complete Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_PRERENDER_PRERENDER_HANDLE_H_ 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/non_thread_safe.h" 10 #include "base/threading/non_thread_safe.h"
11 #include "chrome/browser/prerender/prerender_manager.h" 11 #include "chrome/browser/prerender/prerender_manager.h"
12 12
13 class GURL; 13 class GURL;
14 14
15 namespace content { 15 namespace content {
16 class SessionStorageNamespace; 16 class SessionStorageNamespace;
17 } 17 }
18 18
19 namespace prerender { 19 namespace prerender {
20 20
21 class PrerenderContents; 21 class PrerenderContents;
22 22
23 // A class representing a running prerender to a client of the PrerenderManager. 23 // A class representing a running prerender to a client of the PrerenderManager.
24 // Methods on PrerenderManager which start prerenders return a caller-owned 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 25 // PrerenderHandle* to the client (or NULL if they are unable to start a
26 // prerender). Because the PrerenderManager can stop running prerenders at any 26 // prerender). Calls on the handle of a prerender that is not running at no-ops.
27 // time, callers may wish to check PrerenderHandle::IsValid() before operating 27 // Destroying a handle before a prerender starts will prevent it from ever
28 // on their prerenders. 28 // starting. Destroying a handle while a prerendering is running will stop the
29 class PrerenderHandle : public base::NonThreadSafe { 29 // prerender.
mmenke 2012/12/13 18:27:16 Think it's worth mentioning that destroying "will
gavinp 2012/12/13 20:45:34 Done.
30 class PrerenderHandle : public base::NonThreadSafe,
31 public PrerenderContents::Observer {
30 public: 32 public:
33 class Observer {
34 public:
35 virtual ~Observer();
mmenke 2012/12/13 18:27:16 Could make this protected as well - mostly as a pr
gavinp 2012/12/13 20:45:34 Done.
36
37 // Signals that the prerender has started running.
38 virtual void OnPrerenderStart(PrerenderHandle* handle) = 0;
39
40 // Signals that the prerender has stopped running.
41 virtual void OnPrerenderStop(PrerenderHandle* handle) = 0;
42
43 // Signals the discovery, through redirects, of a new alias for this
44 // prerender.
45 virtual void OnPrerenderAddAlias(PrerenderHandle* handle,
46 const GURL& alias_url) = 0;
47
48 protected:
49 Observer();
50 };
51
31 // Before calling the destructor, the caller must invalidate the handle by 52 // Before calling the destructor, the caller must invalidate the handle by
32 // calling either OnNavigateAway or OnCancel. 53 // calling either OnNavigateAway or OnCancel.
33 ~PrerenderHandle(); 54 virtual ~PrerenderHandle();
55
56 void set_observer(Observer* observer) {
57 DCHECK(!observer_);
mmenke 2012/12/13 18:27:16 We need to include "base/logging.h" for DCHECK. W
gavinp 2012/12/13 20:45:34 Done.
58 observer_ = observer;
59 }
34 60
35 // The launcher is navigating away from the context that launched this 61 // The launcher is navigating away from the context that launched this
36 // prerender. The prerender will likely stay alive briefly though, in case we 62 // prerender. The prerender will likely stay alive briefly though, in case we
37 // are going through a redirect chain that will target it. This call 63 // are going through a redirect chain that will target it. This call
38 // invalidates the handle. If the prerender handle is already invalid, this 64 // invalidates the handle. If the prerender handle is already invalid, this
39 // call does nothing. 65 // call does nothing.
40 void OnNavigateAway(); 66 void OnNavigateAway();
41 67
42 // The launcher has taken explicit action to remove this prerender (for
43 // instance, removing a link element from a document). This call invalidates
44 // the handle. If the prerender handle is already invalid, this call does
45 // nothing.
46 void OnCancel();
47
48 // True if the prerender handle is still connected to a (pending or running)
49 // prerender. Handles can become invalid through explicit requests by the
50 // client, such as calling OnCancel() or OnNavigateAway(), and handles
51 // also become invalid when the PrerenderManager cancels prerenders.
52 bool IsValid() const;
53
54 // True if this prerender was launched by a page that was itself being
55 // prerendered, and so has not yet been started.
56 bool IsPending() const;
57
58 // True if this prerender is currently active. 68 // True if this prerender is currently active.
59 bool IsPrerendering() const; 69 bool IsPrerendering() const;
60 70
61 // True if we started a prerender, and it has finished loading. 71 // True if we started a prerender, and it has finished loading.
62 bool IsFinishedLoading() const; 72 bool IsFinishedLoading() const;
63 73
64 private: 74 private:
65 friend class PrerenderManager; 75 friend class PrerenderManager;
66 76
67 explicit PrerenderHandle(PrerenderManager::PrerenderData* prerender_data); 77 explicit PrerenderHandle(PrerenderManager::PrerenderData* prerender_data);
68 78
69 void SwapPrerenderDataWith(PrerenderHandle* other_prerender_handle); 79 void AdoptPrerenderDataFrom(PrerenderHandle* other_handle);
80
81 // From PrerenderContents::Observer:
82 virtual void OnPrerenderStart(PrerenderContents* prerender_contents) OVERRIDE;
83 virtual void OnPrerenderStop(PrerenderContents* prerender_contents) OVERRIDE;
84 virtual void OnPrerenderAddAlias(PrerenderContents* prerender_contents,
85 const GURL& alias_url) OVERRIDE;
86 virtual void OnPrerenderCreatedMatchCompleteReplacement(
87 PrerenderContents* contents, PrerenderContents* replacement) OVERRIDE;
88
89 Observer* observer_;
70 90
71 base::WeakPtr<PrerenderManager::PrerenderData> prerender_data_; 91 base::WeakPtr<PrerenderManager::PrerenderData> prerender_data_;
72 base::WeakPtrFactory<PrerenderHandle> weak_ptr_factory_; 92 base::WeakPtrFactory<PrerenderHandle> weak_ptr_factory_;
73 93
74 DISALLOW_COPY_AND_ASSIGN(PrerenderHandle); 94 DISALLOW_COPY_AND_ASSIGN(PrerenderHandle);
75 }; 95 };
76 96
77 } // namespace prerender 97 } // namespace prerender
78 98
79 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_ 99 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698