Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/observer_list.h" | |
| 10 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 11 #include "chrome/browser/prerender/prerender_manager.h" | 12 #include "chrome/browser/prerender/prerender_manager.h" |
| 12 | 13 |
| 13 class GURL; | 14 class GURL; |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 class SessionStorageNamespace; | 17 class SessionStorageNamespace; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace prerender { | 20 namespace prerender { |
| 20 | 21 |
| 21 class PrerenderContents; | 22 class PrerenderContents; |
| 22 | 23 |
| 23 // A class representing a running prerender to a client of the PrerenderManager. | 24 // A class representing a running prerender to a client of the PrerenderManager. |
| 24 // Methods on PrerenderManager which start prerenders return a caller-owned | 25 // 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 // PrerenderHandle* to the client (or NULL if they are unable to start a |
| 26 // prerender). Because the PrerenderManager can stop running prerenders at any | 27 // prerender). The PrerenderManager can stop running prerenders at any time, |
| 27 // time, callers may wish to check PrerenderHandle::IsValid() before operating | 28 // which will make calls on the handle into no-ops. |
|
mmenke
2012/12/11 19:53:45
They're also no-ops if the prerender has not yet s
gavinp
2012/12/13 13:38:03
Done.
| |
| 28 // on their prerenders. | 29 class PrerenderHandle : public base::NonThreadSafe, |
| 29 class PrerenderHandle : public base::NonThreadSafe { | 30 public PrerenderContents::Observer { |
| 30 public: | 31 public: |
| 32 class Observer { | |
| 33 public: | |
| 34 virtual ~Observer(); | |
| 35 | |
| 36 // Signals that the prerender has started running. | |
| 37 virtual void OnPrerenderStart(PrerenderHandle* handle) = 0; | |
| 38 | |
| 39 // Signals that the prerender has stopped running. | |
| 40 virtual void OnPrerenderStop(PrerenderHandle* handle) = 0; | |
| 41 | |
| 42 // Signals the discovery, through redirects, of a new alias for this | |
| 43 // prerender. | |
| 44 virtual void OnPrerenderAddAlias(PrerenderHandle* handle, | |
| 45 const GURL& alias_url) = 0; | |
| 46 | |
| 47 protected: | |
| 48 Observer(); | |
| 49 }; | |
| 50 | |
| 31 // Before calling the destructor, the caller must invalidate the handle by | 51 // Before calling the destructor, the caller must invalidate the handle by |
| 32 // calling either OnNavigateAway or OnCancel. | 52 // calling either OnNavigateAway or OnCancel. |
| 33 ~PrerenderHandle(); | 53 virtual ~PrerenderHandle(); |
| 54 | |
| 55 void AddObserver(Observer* observer); | |
| 56 void RemoveObserver(Observer* observer); | |
| 34 | 57 |
| 35 // The launcher is navigating away from the context that launched this | 58 // The launcher is navigating away from the context that launched this |
| 36 // prerender. The prerender will likely stay alive briefly though, in case we | 59 // 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 | 60 // are going through a redirect chain that will target it. This call |
| 38 // invalidates the handle. If the prerender handle is already invalid, this | 61 // invalidates the handle. If the prerender handle is already invalid, this |
| 39 // call does nothing. | 62 // call does nothing. |
| 40 void OnNavigateAway(); | 63 void OnNavigateAway(); |
| 41 | 64 |
| 42 // The launcher has taken explicit action to remove this prerender (for | 65 // The launcher has taken explicit action to remove this prerender (for |
| 43 // instance, removing a link element from a document). This call invalidates | 66 // instance, removing a link element from a document). This call invalidates |
| 44 // the handle. If the prerender handle is already invalid, this call does | 67 // the handle. If the prerender handle is already invalid, this call does |
| 45 // nothing. | 68 // nothing. |
| 46 void OnCancel(); | 69 void OnCancel(); |
| 47 | 70 |
| 48 // True if the prerender handle is still connected to a (pending or running) | 71 // True if this prerender handle has been canceled. |
| 49 // prerender. Handles can become invalid through explicit requests by the | 72 bool has_been_canceled() const { |
| 50 // client, such as calling OnCancel() or OnNavigateAway(), and handles | 73 return has_been_canceled_; |
| 51 // also become invalid when the PrerenderManager cancels prerenders. | 74 } |
| 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 | 75 |
| 58 // True if this prerender is currently active. | 76 // True if this prerender is currently active. |
| 59 bool IsPrerendering() const; | 77 bool IsPrerendering() const; |
| 60 | 78 |
| 61 // True if we started a prerender, and it has finished loading. | 79 // True if we started a prerender, and it has finished loading. |
| 62 bool IsFinishedLoading() const; | 80 bool IsFinishedLoading() const; |
| 63 | 81 |
| 64 private: | 82 private: |
| 65 friend class PrerenderManager; | 83 friend class PrerenderManager; |
| 66 | 84 |
| 67 explicit PrerenderHandle(PrerenderManager::PrerenderData* prerender_data); | 85 explicit PrerenderHandle(PrerenderManager::PrerenderData* prerender_data); |
| 68 | 86 |
| 69 void SwapPrerenderDataWith(PrerenderHandle* other_prerender_handle); | 87 void AdoptPrerenderDataFrom(PrerenderHandle* other_handle); |
| 70 | 88 |
| 89 // From PrerenderContents::Observer: | |
| 90 virtual void OnPrerenderStart(PrerenderContents* prerender_contents) OVERRIDE; | |
| 91 virtual void OnPrerenderStop(PrerenderContents* prerender_contents) OVERRIDE; | |
| 92 virtual void OnPrerenderAddAlias(PrerenderContents* prerender_contents, | |
| 93 const GURL& alias_url) OVERRIDE; | |
| 94 virtual void OnPrerenderCreatedMatchCompleteReplacement( | |
| 95 PrerenderContents* contents, PrerenderContents* replacement) OVERRIDE; | |
| 96 | |
| 97 ObserverList<Observer> observer_list_; | |
|
mmenke
2012/12/12 16:54:12
Do we really need an observer list? Seems like in
gavinp
2012/12/13 13:38:03
We can do away with the list. Done.
| |
| 98 | |
| 99 bool has_been_canceled_; | |
| 71 base::WeakPtr<PrerenderManager::PrerenderData> prerender_data_; | 100 base::WeakPtr<PrerenderManager::PrerenderData> prerender_data_; |
| 72 base::WeakPtrFactory<PrerenderHandle> weak_ptr_factory_; | 101 base::WeakPtrFactory<PrerenderHandle> weak_ptr_factory_; |
| 73 | 102 |
| 74 DISALLOW_COPY_AND_ASSIGN(PrerenderHandle); | 103 DISALLOW_COPY_AND_ASSIGN(PrerenderHandle); |
| 75 }; | 104 }; |
| 76 | 105 |
| 77 } // namespace prerender | 106 } // namespace prerender |
| 78 | 107 |
| 79 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_ | 108 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_ |
| OLD | NEW |