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_CONTENTS_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "chrome/browser/prerender/prerender_final_status.h" | 18 #include "chrome/browser/prerender/prerender_final_status.h" |
18 #include "chrome/browser/prerender/prerender_origin.h" | 19 #include "chrome/browser/prerender/prerender_origin.h" |
19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
21 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
22 #include "content/public/common/referrer.h" | 23 #include "content/public/common/referrer.h" |
23 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
24 | 25 |
(...skipping 13 matching lines...) Expand all Loading... |
38 | 39 |
39 namespace history { | 40 namespace history { |
40 struct HistoryAddPageArgs; | 41 struct HistoryAddPageArgs; |
41 } | 42 } |
42 | 43 |
43 namespace prerender { | 44 namespace prerender { |
44 | 45 |
45 class PrerenderHandle; | 46 class PrerenderHandle; |
46 class PrerenderManager; | 47 class PrerenderManager; |
47 class PrerenderRenderViewHostObserver; | 48 class PrerenderRenderViewHostObserver; |
48 class PrerenderTracker; | |
49 | 49 |
50 class PrerenderContents : public content::NotificationObserver, | 50 class PrerenderContents : public content::NotificationObserver, |
51 public content::WebContentsObserver { | 51 public content::WebContentsObserver { |
52 public: | 52 public: |
53 // PrerenderContents::Create uses the currently registered Factory to create | 53 // PrerenderContents::Create uses the currently registered Factory to create |
54 // the PrerenderContents. Factory is intended for testing. | 54 // the PrerenderContents. Factory is intended for testing. |
55 class Factory { | 55 class Factory { |
56 public: | 56 public: |
57 Factory() {} | 57 Factory() {} |
58 virtual ~Factory() {} | 58 virtual ~Factory() {} |
59 | 59 |
60 // Ownership is not transfered through this interface as prerender_manager, | 60 // Ownership is not transfered through this interface as prerender_manager, |
61 // prerender_tracker, and profile are stored as weak pointers. | 61 // prerender_tracker, and profile are stored as weak pointers. |
62 virtual PrerenderContents* CreatePrerenderContents( | 62 virtual PrerenderContents* CreatePrerenderContents( |
63 PrerenderManager* prerender_manager, | 63 PrerenderManager* prerender_manager, |
64 PrerenderTracker* prerender_tracker, | |
65 Profile* profile, | 64 Profile* profile, |
66 const GURL& url, | 65 const GURL& url, |
67 const content::Referrer& referrer, | 66 const content::Referrer& referrer, |
68 Origin origin, | 67 Origin origin, |
69 uint8 experiment_id) = 0; | 68 uint8 experiment_id) = 0; |
70 | 69 |
71 private: | 70 private: |
72 DISALLOW_COPY_AND_ASSIGN(Factory); | 71 DISALLOW_COPY_AND_ASSIGN(Factory); |
73 }; | 72 }; |
74 | 73 |
| 74 class Observer { |
| 75 public: |
| 76 // Signals that the prerender has started running. |
| 77 virtual void OnPrerenderStart(PrerenderContents* contents) = 0; |
| 78 |
| 79 // Signals that the prerender has stopped running. |
| 80 virtual void OnPrerenderStop(PrerenderContents* contents) = 0; |
| 81 |
| 82 protected: |
| 83 Observer(); |
| 84 virtual ~Observer() = 0; |
| 85 }; |
| 86 |
75 // A container for extra data on pending prerenders. | 87 // A container for extra data on pending prerenders. |
76 struct PendingPrerenderInfo { | 88 struct PendingPrerenderInfo { |
77 public: | 89 public: |
78 PendingPrerenderInfo( | 90 PendingPrerenderInfo( |
79 base::WeakPtr<PrerenderHandle> weak_prerender_handle, | 91 base::WeakPtr<PrerenderHandle> weak_prerender_handle, |
80 Origin origin, | 92 Origin origin, |
81 const GURL& url, | 93 const GURL& url, |
82 const content::Referrer& referrer, | 94 const content::Referrer& referrer, |
83 const gfx::Size& size); | 95 const gfx::Size& size); |
84 | 96 |
(...skipping 24 matching lines...) Expand all Loading... |
109 // we record in MatchComplete but not Match. | 121 // we record in MatchComplete but not Match. |
110 MATCH_COMPLETE_REPLACEMENT, | 122 MATCH_COMPLETE_REPLACEMENT, |
111 // A prerender that is a MatchComplete dummy, early in the process of being | 123 // A prerender that is a MatchComplete dummy, early in the process of being |
112 // created. This prerender should not fail. Record for MatchComplete, but | 124 // created. This prerender should not fail. Record for MatchComplete, but |
113 // not Match. | 125 // not Match. |
114 MATCH_COMPLETE_REPLACEMENT_PENDING, | 126 MATCH_COMPLETE_REPLACEMENT_PENDING, |
115 }; | 127 }; |
116 | 128 |
117 virtual ~PrerenderContents(); | 129 virtual ~PrerenderContents(); |
118 | 130 |
| 131 // All observers of a PrerenderContents are removed after the OnPrerenderStop |
| 132 // event is sent, so there is no need for a RemoveObserver() method. |
| 133 void AddObserver(Observer* observer); |
| 134 |
119 // For MatchComplete correctness, create a dummy replacement prerender | 135 // For MatchComplete correctness, create a dummy replacement prerender |
120 // contents to stand in for this prerender contents that (which we are about | 136 // contents to stand in for this prerender contents that (which we are about |
121 // to destroy). | 137 // to destroy). |
122 PrerenderContents* CreateMatchCompleteReplacement() const; | 138 PrerenderContents* CreateMatchCompleteReplacement() const; |
123 | 139 |
124 bool Init(); | 140 bool Init(); |
125 | 141 |
126 static Factory* CreateFactory(); | 142 static Factory* CreateFactory(); |
127 | 143 |
128 // Start rendering the contents in the prerendered state. If | 144 // Start rendering the contents in the prerendered state. If |
(...skipping 11 matching lines...) Expand all Loading... |
140 content::SessionStorageNamespace* session_storage_namespace, | 156 content::SessionStorageNamespace* session_storage_namespace, |
141 bool is_control_group); | 157 bool is_control_group); |
142 | 158 |
143 // Verifies that the prerendering is not using too many resources, and kills | 159 // Verifies that the prerendering is not using too many resources, and kills |
144 // it if not. | 160 // it if not. |
145 void DestroyWhenUsingTooManyResources(); | 161 void DestroyWhenUsingTooManyResources(); |
146 | 162 |
147 content::RenderViewHost* GetRenderViewHostMutable(); | 163 content::RenderViewHost* GetRenderViewHostMutable(); |
148 const content::RenderViewHost* GetRenderViewHost() const; | 164 const content::RenderViewHost* GetRenderViewHost() const; |
149 | 165 |
| 166 PrerenderManager* prerender_manager() { return prerender_manager_; } |
| 167 |
150 string16 title() const { return title_; } | 168 string16 title() const { return title_; } |
151 int32 page_id() const { return page_id_; } | 169 int32 page_id() const { return page_id_; } |
152 GURL icon_url() const { return icon_url_; } | 170 GURL icon_url() const { return icon_url_; } |
153 const GURL& prerender_url() const { return prerender_url_; } | 171 const GURL& prerender_url() const { return prerender_url_; } |
154 const content::Referrer& referrer() const { return referrer_; } | 172 const content::Referrer& referrer() const { return referrer_; } |
155 bool has_stopped_loading() const { return has_stopped_loading_; } | 173 bool has_stopped_loading() const { return has_stopped_loading_; } |
156 bool has_finished_loading() const { return has_finished_loading_; } | 174 bool has_finished_loading() const { return has_finished_loading_; } |
157 bool prerendering_has_started() const { return prerendering_has_started_; } | 175 bool prerendering_has_started() const { return prerendering_has_started_; } |
158 MatchCompleteStatus match_complete_status() const { | 176 MatchCompleteStatus match_complete_status() const { |
159 return match_complete_status_; | 177 return match_complete_status_; |
160 } | 178 } |
161 void set_match_complete_status(MatchCompleteStatus status) { | 179 void set_match_complete_status(MatchCompleteStatus status) { |
162 match_complete_status_ = status; | 180 match_complete_status_ = status; |
163 } | 181 } |
164 | 182 |
165 // Sets the parameter to the value of the associated RenderViewHost's child id | 183 // Sets the parameter to the value of the associated RenderViewHost's child id |
166 // and returns a boolean indicating the validity of that id. | 184 // and returns a boolean indicating the validity of that id. |
167 virtual bool GetChildId(int* child_id) const; | 185 virtual bool GetChildId(int* child_id) const; |
168 | 186 |
169 // Sets the parameter to the value of the associated RenderViewHost's route id | 187 // Sets the parameter to the value of the associated RenderViewHost's route id |
170 // and returns a boolean indicating the validity of that id. | 188 // and returns a boolean indicating the validity of that id. |
171 virtual bool GetRouteId(int* route_id) const; | 189 virtual bool GetRouteId(int* route_id) const; |
172 | 190 |
173 // Set the final status for how the PrerenderContents was used. This | 191 // Set the final status for how the PrerenderContents was used. This |
174 // should only be called once, and should be called before the prerender | 192 // should only be called once, and should be called before the prerender |
175 // contents are destroyed. | 193 // contents are destroyed. |
176 void set_final_status(FinalStatus final_status); | 194 void SetFinalStatus(FinalStatus final_status); |
177 FinalStatus final_status() const { return final_status_; } | 195 FinalStatus final_status() const { return final_status_; } |
178 | 196 |
179 Origin origin() const { return origin_; } | 197 Origin origin() const { return origin_; } |
180 uint8 experiment_id() const { return experiment_id_; } | 198 uint8 experiment_id() const { return experiment_id_; } |
181 | 199 |
182 base::TimeTicks load_start_time() const { return load_start_time_; } | 200 base::TimeTicks load_start_time() const { return load_start_time_; } |
183 | 201 |
184 // Indicates whether this prerendered page can be used for the provided | 202 // Indicates whether this prerendered page can be used for the provided |
185 // |url| and |session_storage_namespace|. | 203 // |url| and |session_storage_namespace|. |
186 bool Matches( | 204 bool Matches( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // exists when this page is made visible, it will be launched. | 265 // exists when this page is made visible, it will be launched. |
248 virtual void AddPendingPrerender( | 266 virtual void AddPendingPrerender( |
249 scoped_ptr<PendingPrerenderInfo> pending_prerender_info); | 267 scoped_ptr<PendingPrerenderInfo> pending_prerender_info); |
250 | 268 |
251 // Reissues any pending prerender requests from the prerendered page. Also | 269 // Reissues any pending prerender requests from the prerendered page. Also |
252 // clears the list of pending requests. | 270 // clears the list of pending requests. |
253 void StartPendingPrerenders(); | 271 void StartPendingPrerenders(); |
254 | 272 |
255 protected: | 273 protected: |
256 PrerenderContents(PrerenderManager* prerender_manager, | 274 PrerenderContents(PrerenderManager* prerender_manager, |
257 PrerenderTracker* prerender_tracker, | |
258 Profile* profile, | 275 Profile* profile, |
259 const GURL& url, | 276 const GURL& url, |
260 const content::Referrer& referrer, | 277 const content::Referrer& referrer, |
261 Origin origin, | 278 Origin origin, |
262 uint8 experiment_id); | 279 uint8 experiment_id); |
263 | 280 |
| 281 // These call out to methods on our Observers, using our observer_list_. |
| 282 void NotifyPrerenderStart(); |
| 283 void NotifyPrerenderStop(); |
| 284 |
264 // Called whenever a RenderViewHost is created for prerendering. Only called | 285 // Called whenever a RenderViewHost is created for prerendering. Only called |
265 // once the RenderViewHost has a RenderView and RenderWidgetHostView. | 286 // once the RenderViewHost has a RenderView and RenderWidgetHostView. |
266 virtual void OnRenderViewHostCreated( | 287 virtual void OnRenderViewHostCreated( |
267 content::RenderViewHost* new_render_view_host); | 288 content::RenderViewHost* new_render_view_host); |
268 | 289 |
269 content::NotificationRegistrar& notification_registrar() { | 290 content::NotificationRegistrar& notification_registrar() { |
270 return notification_registrar_; | 291 return notification_registrar_; |
271 } | 292 } |
272 | 293 |
273 size_t pending_prerender_count() const; | 294 size_t pending_prerender_count() const; |
(...skipping 22 matching lines...) Expand all Loading... |
296 | 317 |
297 // Message handlers. | 318 // Message handlers. |
298 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); | 319 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); |
299 | 320 |
300 // Returns the RenderViewHost Delegate for this prerender. | 321 // Returns the RenderViewHost Delegate for this prerender. |
301 content::WebContents* GetWebContents(); | 322 content::WebContents* GetWebContents(); |
302 | 323 |
303 // Returns the ProcessMetrics for the render process, if it exists. | 324 // Returns the ProcessMetrics for the render process, if it exists. |
304 base::ProcessMetrics* MaybeGetProcessMetrics(); | 325 base::ProcessMetrics* MaybeGetProcessMetrics(); |
305 | 326 |
| 327 ObserverList<Observer> observer_list_; |
| 328 |
306 // The prerender manager owning this object. | 329 // The prerender manager owning this object. |
307 PrerenderManager* prerender_manager_; | 330 PrerenderManager* prerender_manager_; |
308 | 331 |
309 // The prerender tracker tracking prerenders. | |
310 PrerenderTracker* prerender_tracker_; | |
311 | |
312 // The URL being prerendered. | 332 // The URL being prerendered. |
313 GURL prerender_url_; | 333 GURL prerender_url_; |
314 | 334 |
315 // The referrer. | 335 // The referrer. |
316 content::Referrer referrer_; | 336 content::Referrer referrer_; |
317 | 337 |
318 // The profile being used | 338 // The profile being used |
319 Profile* profile_; | 339 Profile* profile_; |
320 | 340 |
321 // Information about the title and URL of the page that this class as a | 341 // Information about the title and URL of the page that this class as a |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 412 |
393 // Caches pages to be added to the history. | 413 // Caches pages to be added to the history. |
394 AddPageVector add_page_vector_; | 414 AddPageVector add_page_vector_; |
395 | 415 |
396 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); | 416 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); |
397 }; | 417 }; |
398 | 418 |
399 } // namespace prerender | 419 } // namespace prerender |
400 | 420 |
401 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ | 421 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ |
OLD | NEW |