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

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

Issue 11348357: Add observer interface to PrerenderContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_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/observer_list.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.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"
(...skipping 16 matching lines...) Expand all
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
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 void AddObserver(Observer* observer);
132 void RemoveObserver(Observer* observer);
133 void ClearObservers();
mmenke 2012/12/03 20:02:47 ClearObservers() doesn't seem to have a function b
gavinp 2012/12/04 18:04:48 Done.
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
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_;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void NotifyPrerenderAddAlias(const GURL& alias_url);
mmenke 2012/12/03 20:02:47 NotifyPrerenderAddAlias is not currently implement
gavinp 2012/12/04 18:04:48 Done.
285
264 // Called whenever a RenderViewHost is created for prerendering. Only called 286 // Called whenever a RenderViewHost is created for prerendering. Only called
265 // once the RenderViewHost has a RenderView and RenderWidgetHostView. 287 // once the RenderViewHost has a RenderView and RenderWidgetHostView.
266 virtual void OnRenderViewHostCreated( 288 virtual void OnRenderViewHostCreated(
267 content::RenderViewHost* new_render_view_host); 289 content::RenderViewHost* new_render_view_host);
268 290
269 content::NotificationRegistrar& notification_registrar() { 291 content::NotificationRegistrar& notification_registrar() {
270 return notification_registrar_; 292 return notification_registrar_;
271 } 293 }
272 294
273 size_t pending_prerender_count() const; 295 size_t pending_prerender_count() const;
(...skipping 22 matching lines...) Expand all
296 318
297 // Message handlers. 319 // Message handlers.
298 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); 320 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls);
299 321
300 // Returns the RenderViewHost Delegate for this prerender. 322 // Returns the RenderViewHost Delegate for this prerender.
301 content::WebContents* GetWebContents(); 323 content::WebContents* GetWebContents();
302 324
303 // Returns the ProcessMetrics for the render process, if it exists. 325 // Returns the ProcessMetrics for the render process, if it exists.
304 base::ProcessMetrics* MaybeGetProcessMetrics(); 326 base::ProcessMetrics* MaybeGetProcessMetrics();
305 327
328 ObserverList<Observer> observer_list_;
329
306 // The prerender manager owning this object. 330 // The prerender manager owning this object.
307 PrerenderManager* prerender_manager_; 331 PrerenderManager* prerender_manager_;
308 332
309 // The prerender tracker tracking prerenders.
310 PrerenderTracker* prerender_tracker_;
311
312 // The URL being prerendered. 333 // The URL being prerendered.
313 GURL prerender_url_; 334 GURL prerender_url_;
314 335
315 // The referrer. 336 // The referrer.
316 content::Referrer referrer_; 337 content::Referrer referrer_;
317 338
318 // The profile being used 339 // The profile being used
319 Profile* profile_; 340 Profile* profile_;
320 341
321 // Information about the title and URL of the page that this class as a 342 // 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
392 413
393 // Caches pages to be added to the history. 414 // Caches pages to be added to the history.
394 AddPageVector add_page_vector_; 415 AddPageVector add_page_vector_;
395 416
396 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); 417 DISALLOW_COPY_AND_ASSIGN(PrerenderContents);
397 }; 418 };
398 419
399 } // namespace prerender 420 } // namespace prerender
400 421
401 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ 422 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698