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

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

Issue 6966017: Remove a chrome dependency by removing Prerender from ResourceDispatcherHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 7 months 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
27 #include "chrome/common/extensions/extension_messages.h" 27 #include "chrome/common/extensions/extension_messages.h"
28 #include "chrome/common/icon_messages.h" 28 #include "chrome/common/icon_messages.h"
29 #include "chrome/common/render_messages.h" 29 #include "chrome/common/render_messages.h"
30 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
31 #include "content/browser/browsing_instance.h" 31 #include "content/browser/browsing_instance.h"
32 #include "content/browser/renderer_host/render_view_host.h" 32 #include "content/browser/renderer_host/render_view_host.h"
33 #include "content/browser/renderer_host/resource_dispatcher_host.h" 33 #include "content/browser/renderer_host/resource_dispatcher_host.h"
34 #include "content/browser/renderer_host/resource_request_details.h" 34 #include "content/browser/renderer_host/resource_request_details.h"
35 #include "content/browser/resource_context.h"
35 #include "content/browser/site_instance.h" 36 #include "content/browser/site_instance.h"
36 #include "content/browser/tab_contents/tab_contents_delegate.h" 37 #include "content/browser/tab_contents/tab_contents_delegate.h"
37 #include "content/browser/tab_contents/tab_contents_view.h" 38 #include "content/browser/tab_contents/tab_contents_view.h"
38 #include "content/common/notification_service.h" 39 #include "content/common/notification_service.h"
39 #include "content/common/view_messages.h" 40 #include "content/common/view_messages.h"
40 #include "ui/gfx/rect.h" 41 #include "ui/gfx/rect.h"
41 42
42 #if defined(OS_MACOSX) 43 #if defined(OS_MACOSX)
43 #include "chrome/browser/mach_broker_mac.h" 44 #include "chrome/browser/mach_broker_mac.h"
44 #endif 45 #endif
(...skipping 17 matching lines...) Expand all
62 url.query() == url_.query(); 63 url.query() == url_.query();
63 } 64 }
64 GURL url_; 65 GURL url_;
65 }; 66 };
66 67
67 } // end namespace 68 } // end namespace
68 69
69 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { 70 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory {
70 public: 71 public:
71 virtual PrerenderContents* CreatePrerenderContents( 72 virtual PrerenderContents* CreatePrerenderContents(
72 PrerenderManager* prerender_manager, Profile* profile, const GURL& url, 73 PrerenderManager* prerender_manager, PrerenderTracker* prerender_tracker,
73 const GURL& referrer) OVERRIDE { 74 Profile* profile, const GURL& url, const GURL& referrer) OVERRIDE {
74 return new PrerenderContents(prerender_manager, profile, url, referrer); 75 return new PrerenderContents(prerender_manager, prerender_tracker, profile,
76 url, referrer);
75 } 77 }
76 }; 78 };
77 79
78 // TabContentsDelegateImpl ----------------------------------------------------- 80 // TabContentsDelegateImpl -----------------------------------------------------
79 81
80 class PrerenderContents::TabContentsDelegateImpl 82 class PrerenderContents::TabContentsDelegateImpl
81 : public TabContentsDelegate { 83 : public TabContentsDelegate {
82 public: 84 public:
83 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) : 85 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) :
84 prerender_contents_(prerender_contents) { 86 prerender_contents_(prerender_contents) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > 120 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> >
119 AddPageVector; 121 AddPageVector;
120 122
121 // Caches pages to be added to the history. 123 // Caches pages to be added to the history.
122 AddPageVector add_page_vector_; 124 AddPageVector add_page_vector_;
123 125
124 PrerenderContents* prerender_contents_; 126 PrerenderContents* prerender_contents_;
125 }; 127 };
126 128
127 PrerenderContents::PrerenderContents(PrerenderManager* prerender_manager, 129 PrerenderContents::PrerenderContents(PrerenderManager* prerender_manager,
130 PrerenderTracker* prerender_tracker,
128 Profile* profile, 131 Profile* profile,
129 const GURL& url, 132 const GURL& url,
130 const GURL& referrer) 133 const GURL& referrer)
131 : prerender_manager_(prerender_manager), 134 : prerender_manager_(prerender_manager),
135 prerender_tracker_(prerender_tracker),
132 render_view_host_(NULL), 136 render_view_host_(NULL),
133 prerender_url_(url), 137 prerender_url_(url),
134 referrer_(referrer), 138 referrer_(referrer),
135 profile_(profile), 139 profile_(profile),
136 page_id_(0), 140 page_id_(0),
137 ALLOW_THIS_IN_INITIALIZER_LIST(tab_contents_observer_registrar_(this)), 141 ALLOW_THIS_IN_INITIALIZER_LIST(tab_contents_observer_registrar_(this)),
138 has_stopped_loading_(false), 142 has_stopped_loading_(false),
139 final_status_(FINAL_STATUS_MAX), 143 final_status_(FINAL_STATUS_MAX),
140 prerendering_has_started_(false), 144 prerendering_has_started_(false),
141 prerendering_has_been_cancelled_(false), 145 prerendering_has_been_cancelled_(false),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 PrerenderRenderWidgetHostView* view = 185 PrerenderRenderWidgetHostView* view =
182 new PrerenderRenderWidgetHostView(render_view_host_, this); 186 new PrerenderRenderWidgetHostView(render_view_host_, this);
183 view->Init(source_render_view_host->view()); 187 view->Init(source_render_view_host->view());
184 188
185 child_id_ = render_view_host_->process()->id(); 189 child_id_ = render_view_host_->process()->id();
186 route_id_ = render_view_host_->routing_id(); 190 route_id_ = render_view_host_->routing_id();
187 191
188 // Register this with the PrerenderTracker as a prerendering RenderViewHost. 192 // Register this with the PrerenderTracker as a prerendering RenderViewHost.
189 // This must be done before the Navigate message to catch all resource 193 // This must be done before the Navigate message to catch all resource
190 // requests. 194 // requests.
191 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, 195 prerender_tracker_->OnPrerenderingStarted(
192 prerender_manager_); 196 child_id_,
197 route_id_,
198 prerender_manager_);
193 199
194 // Close ourselves when the application is shutting down. 200 // Close ourselves when the application is shutting down.
195 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, 201 notification_registrar_.Add(this, NotificationType::APP_TERMINATING,
196 NotificationService::AllSources()); 202 NotificationService::AllSources());
197 203
198 // Register for our parent profile to shutdown, so we can shut ourselves down 204 // Register for our parent profile to shutdown, so we can shut ourselves down
199 // as well (should only be called for OTR profiles, as we should receive 205 // as well (should only be called for OTR profiles, as we should receive
200 // APP_TERMINATING before non-OTR profiles are destroyed). 206 // APP_TERMINATING before non-OTR profiles are destroyed).
201 // TODO(tburkard): figure out if this is needed. 207 // TODO(tburkard): figure out if this is needed.
202 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 208 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 render_view_host_observer_.reset( 291 render_view_host_observer_.reset(
286 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); 292 new PrerenderRenderViewHostObserver(this, render_view_host_mutable()));
287 293
288 child_id_ = render_view_host()->process()->id(); 294 child_id_ = render_view_host()->process()->id();
289 route_id_ = render_view_host()->routing_id(); 295 route_id_ = render_view_host()->routing_id();
290 296
291 // Register this with the ResourceDispatcherHost as a prerender 297 // Register this with the ResourceDispatcherHost as a prerender
292 // RenderViewHost. This must be done before the Navigate message to catch all 298 // RenderViewHost. This must be done before the Navigate message to catch all
293 // resource requests, but as it is on the same thread as the Navigate message 299 // resource requests, but as it is on the same thread as the Navigate message
294 // (IO) there is no race condition. 300 // (IO) there is no race condition.
295 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, 301 prerender_tracker_->OnPrerenderingStarted(
296 prerender_manager_); 302 child_id_,
303 route_id_,
304 prerender_manager_);
297 305
298 // Close ourselves when the application is shutting down. 306 // Close ourselves when the application is shutting down.
299 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, 307 notification_registrar_.Add(this, NotificationType::APP_TERMINATING,
300 NotificationService::AllSources()); 308 NotificationService::AllSources());
301 309
302 // Register for our parent profile to shutdown, so we can shut ourselves down 310 // Register for our parent profile to shutdown, so we can shut ourselves down
303 // as well (should only be called for OTR profiles, as we should receive 311 // as well (should only be called for OTR profiles, as we should receive
304 // APP_TERMINATING before non-OTR profiles are destroyed). 312 // APP_TERMINATING before non-OTR profiles are destroyed).
305 // TODO(tburkard): figure out if this is needed. 313 // TODO(tburkard): figure out if this is needed.
306 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 314 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 382
375 // If we haven't even started prerendering, we were just in the control 383 // If we haven't even started prerendering, we were just in the control
376 // group, which means we do not want to record the status. 384 // group, which means we do not want to record the status.
377 if (prerendering_has_started()) 385 if (prerendering_has_started())
378 RecordFinalStatus(final_status_); 386 RecordFinalStatus(final_status_);
379 387
380 // Only delete the RenderViewHost if we own it. 388 // Only delete the RenderViewHost if we own it.
381 if (render_view_host_) 389 if (render_view_host_)
382 render_view_host_->Shutdown(); 390 render_view_host_->Shutdown();
383 391
384 if (child_id_ != -1 && route_id_ != -1) { 392 if (child_id_ != -1 && route_id_ != -1)
385 PrerenderTracker::GetInstance()->OnPrerenderingFinished( 393 prerender_tracker_->OnPrerenderingFinished(child_id_, route_id_);
386 child_id_, route_id_);
387 }
388 394
389 // If we still have a TabContents, clean up anything we need to and then 395 // If we still have a TabContents, clean up anything we need to and then
390 // destroy it. 396 // destroy it.
391 if (prerender_contents_.get()) 397 if (prerender_contents_.get())
392 delete ReleasePrerenderContents(); 398 delete ReleasePrerenderContents();
393 } 399 }
394 400
395 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { 401 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() {
396 return this; 402 return this;
397 } 403 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 return; 727 return;
722 728
723 prerendering_has_been_cancelled_ = true; 729 prerendering_has_been_cancelled_ = true;
724 prerender_manager_->MoveEntryToPendingDelete(this); 730 prerender_manager_->MoveEntryToPendingDelete(this);
725 731
726 if (child_id_ != -1 && route_id_ != -1) { 732 if (child_id_ != -1 && route_id_ != -1) {
727 // Cancel the prerender in the PrerenderTracker. This is needed 733 // Cancel the prerender in the PrerenderTracker. This is needed
728 // because destroy may be called directly from the UI thread without calling 734 // because destroy may be called directly from the UI thread without calling
729 // TryCancel(). This is difficult to completely avoid, since prerendering 735 // TryCancel(). This is difficult to completely avoid, since prerendering
730 // can be cancelled before a RenderView is created. 736 // can be cancelled before a RenderView is created.
731 bool is_cancelled = 737 bool is_cancelled = prerender_tracker_->TryCancel(
732 PrerenderTracker::GetInstance()->TryCancel(child_id_, route_id_, 738 child_id_, route_id_, final_status);
733 final_status);
734 CHECK(is_cancelled); 739 CHECK(is_cancelled);
735 740
736 // A different final status may have been set already from another thread. 741 // A different final status may have been set already from another thread.
737 // If so, use it instead. 742 // If so, use it instead.
738 if (!PrerenderTracker::GetInstance()->GetFinalStatus(child_id_, route_id_, 743 if (!prerender_tracker_->GetFinalStatus(child_id_, route_id_,
739 &final_status)) { 744 &final_status)) {
740 NOTREACHED(); 745 NOTREACHED();
741 } 746 }
742 } 747 }
743 set_final_status(final_status); 748 set_final_status(final_status);
744 749
745 // We may destroy the PrerenderContents before we have initialized the 750 // We may destroy the PrerenderContents before we have initialized the
746 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to 751 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to
747 // avoid any more messages being sent. 752 // avoid any more messages being sent.
748 if (render_view_host_observer_.get()) 753 if (render_view_host_observer_.get())
749 render_view_host_observer_->set_prerender_contents(NULL); 754 render_view_host_observer_->set_prerender_contents(NULL);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 } 837 }
833 return render_view_host_; 838 return render_view_host_;
834 } 839 }
835 840
836 void PrerenderContents::CommitHistory(TabContentsWrapper* tab) { 841 void PrerenderContents::CommitHistory(TabContentsWrapper* tab) {
837 if (tab_contents_delegate_.get()) 842 if (tab_contents_delegate_.get())
838 tab_contents_delegate_->CommitHistory(tab); 843 tab_contents_delegate_->CommitHistory(tab);
839 } 844 }
840 845
841 } // namespace prerender 846 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_contents.h ('k') | chrome/browser/prerender/prerender_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698