OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_ |
| 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_ |
| 7 |
| 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" |
| 12 |
| 13 class GURL; |
| 14 |
| 15 namespace content { |
| 16 class SessionStorageNamespace; |
| 17 } |
| 18 |
| 19 namespace prerender { |
| 20 |
| 21 class PrerenderContents; |
| 22 |
| 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). Because the PrerenderManager can stop running prerenders at any |
| 27 // time, callers may wish to check PrerenderHandle::IsValid() before operating |
| 28 // on their prerenders. |
| 29 class PrerenderHandle : public base::NonThreadSafe { |
| 30 public: |
| 31 // Before calling the destructor, the caller must invalidate the handle by |
| 32 // calling either OnNavigateAway or OnCancel. |
| 33 ~PrerenderHandle(); |
| 34 |
| 35 // The launcher is navigating away from the context that launched this |
| 36 // 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 |
| 38 // invalidates the handle. If the prerender handle is already invalid, this |
| 39 // call does nothing. |
| 40 void OnNavigateAway(); |
| 41 |
| 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. |
| 59 bool IsPrerendering() const; |
| 60 |
| 61 // True if we started a prerender, and it has finished loading. |
| 62 bool IsFinishedLoading() const; |
| 63 |
| 64 private: |
| 65 friend class PrerenderManager; |
| 66 |
| 67 explicit PrerenderHandle(PrerenderManager::PrerenderData* prerender_data); |
| 68 |
| 69 void SwapPrerenderDataWith(PrerenderHandle* other_prerender_handle); |
| 70 |
| 71 base::WeakPtr<PrerenderManager::PrerenderData> prerender_data_; |
| 72 base::WeakPtrFactory<PrerenderHandle> weak_ptr_factory_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(PrerenderHandle); |
| 75 }; |
| 76 |
| 77 } // namespace prerender |
| 78 |
| 79 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HANDLE_H_ |
OLD | NEW |