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

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: 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 13 matching lines...) Expand all
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
25 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
26 #include "chrome/common/extensions/extension_messages.h" 26 #include "chrome/common/extensions/extension_messages.h"
27 #include "chrome/common/icon_messages.h" 27 #include "chrome/common/icon_messages.h"
28 #include "chrome/common/render_messages.h" 28 #include "chrome/common/render_messages.h"
29 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "content/browser/browsing_instance.h" 30 #include "content/browser/browsing_instance.h"
31 #include "content/browser/renderer_host/render_view_host.h" 31 #include "content/browser/renderer_host/render_view_host.h"
32 #include "content/browser/renderer_host/resource_dispatcher_host.h" 32 #include "content/browser/renderer_host/resource_dispatcher_host.h"
33 #include "content/browser/renderer_host/resource_request_details.h" 33 #include "content/browser/renderer_host/resource_request_details.h"
34 #include "content/browser/resource_context.h"
34 #include "content/browser/site_instance.h" 35 #include "content/browser/site_instance.h"
35 #include "content/browser/tab_contents/tab_contents_delegate.h" 36 #include "content/browser/tab_contents/tab_contents_delegate.h"
36 #include "content/browser/tab_contents/tab_contents_view.h" 37 #include "content/browser/tab_contents/tab_contents_view.h"
37 #include "content/common/notification_service.h" 38 #include "content/common/notification_service.h"
38 #include "content/common/view_messages.h" 39 #include "content/common/view_messages.h"
39 #include "ui/gfx/rect.h" 40 #include "ui/gfx/rect.h"
40 41
41 #if defined(OS_MACOSX) 42 #if defined(OS_MACOSX)
42 #include "chrome/browser/mach_broker_mac.h" 43 #include "chrome/browser/mach_broker_mac.h"
43 #endif 44 #endif
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 PrerenderRenderWidgetHostView* view = 180 PrerenderRenderWidgetHostView* view =
180 new PrerenderRenderWidgetHostView(render_view_host_, this); 181 new PrerenderRenderWidgetHostView(render_view_host_, this);
181 view->Init(source_render_view_host->view()); 182 view->Init(source_render_view_host->view());
182 183
183 child_id_ = render_view_host_->process()->id(); 184 child_id_ = render_view_host_->process()->id();
184 route_id_ = render_view_host_->routing_id(); 185 route_id_ = render_view_host_->routing_id();
185 186
186 // Register this with the PrerenderTracker as a prerendering RenderViewHost. 187 // Register this with the PrerenderTracker as a prerendering RenderViewHost.
187 // This must be done before the Navigate message to catch all resource 188 // This must be done before the Navigate message to catch all resource
188 // requests. 189 // requests.
189 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, 190 g_browser_process->prerender_tracker()->OnPrerenderingStarted(
190 prerender_manager_); 191 child_id_, route_id_, prerender_manager_);
mmenke 2011/05/23 21:58:41 nit: Should use the same line breaking style in b
dominich 2011/05/23 22:22:55 Done.
jam 2011/05/24 16:06:24 nit: this is totally personal style, but for the r
191
192 // Close ourselves when the application is shutting down. 192 // Close ourselves when the application is shutting down.
193 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, 193 notification_registrar_.Add(this, NotificationType::APP_TERMINATING,
194 NotificationService::AllSources()); 194 NotificationService::AllSources());
195 195
196 // Register for our parent profile to shutdown, so we can shut ourselves down 196 // Register for our parent profile to shutdown, so we can shut ourselves down
197 // as well (should only be called for OTR profiles, as we should receive 197 // as well (should only be called for OTR profiles, as we should receive
198 // APP_TERMINATING before non-OTR profiles are destroyed). 198 // APP_TERMINATING before non-OTR profiles are destroyed).
199 // TODO(tburkard): figure out if this is needed. 199 // TODO(tburkard): figure out if this is needed.
200 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 200 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
201 Source<Profile>(profile_)); 201 Source<Profile>(profile_));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 render_view_host_observer_.reset( 283 render_view_host_observer_.reset(
284 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); 284 new PrerenderRenderViewHostObserver(this, render_view_host_mutable()));
285 285
286 child_id_ = render_view_host()->process()->id(); 286 child_id_ = render_view_host()->process()->id();
287 route_id_ = render_view_host()->routing_id(); 287 route_id_ = render_view_host()->routing_id();
288 288
289 // Register this with the ResourceDispatcherHost as a prerender 289 // Register this with the ResourceDispatcherHost as a prerender
290 // RenderViewHost. This must be done before the Navigate message to catch all 290 // RenderViewHost. This must be done before the Navigate message to catch all
291 // resource requests, but as it is on the same thread as the Navigate message 291 // resource requests, but as it is on the same thread as the Navigate message
292 // (IO) there is no race condition. 292 // (IO) there is no race condition.
293 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, 293 g_browser_process->prerender_tracker()->OnPrerenderingStarted(
294 prerender_manager_); 294 child_id_, route_id_,
295 295 prerender_manager_);
296 // Close ourselves when the application is shutting down. 296 // Close ourselves when the application is shutting down.
297 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, 297 notification_registrar_.Add(this, NotificationType::APP_TERMINATING,
298 NotificationService::AllSources()); 298 NotificationService::AllSources());
299 299
300 // Register for our parent profile to shutdown, so we can shut ourselves down 300 // Register for our parent profile to shutdown, so we can shut ourselves down
301 // as well (should only be called for OTR profiles, as we should receive 301 // as well (should only be called for OTR profiles, as we should receive
302 // APP_TERMINATING before non-OTR profiles are destroyed). 302 // APP_TERMINATING before non-OTR profiles are destroyed).
303 // TODO(tburkard): figure out if this is needed. 303 // TODO(tburkard): figure out if this is needed.
304 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 304 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
305 Source<Profile>(profile_)); 305 Source<Profile>(profile_));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // If we haven't even started prerendering, we were just in the control 370 // If we haven't even started prerendering, we were just in the control
371 // group, which means we do not want to record the status. 371 // group, which means we do not want to record the status.
372 if (prerendering_has_started()) 372 if (prerendering_has_started())
373 RecordFinalStatus(final_status_); 373 RecordFinalStatus(final_status_);
374 374
375 // Only delete the RenderViewHost if we own it. 375 // Only delete the RenderViewHost if we own it.
376 if (render_view_host_) 376 if (render_view_host_)
377 render_view_host_->Shutdown(); 377 render_view_host_->Shutdown();
378 378
379 if (child_id_ != -1 && route_id_ != -1) { 379 if (child_id_ != -1 && route_id_ != -1) {
380 PrerenderTracker::GetInstance()->OnPrerenderingFinished( 380 g_browser_process->prerender_tracker()->OnPrerenderingFinished(
381 child_id_, route_id_); 381 child_id_, route_id_);
382 } 382 }
383 383
384 // If we still have a TabContents, clean up anything we need to and then 384 // If we still have a TabContents, clean up anything we need to and then
385 // destroy it. 385 // destroy it.
386 if (prerender_contents_.get()) 386 if (prerender_contents_.get())
387 delete ReleasePrerenderContents(); 387 delete ReleasePrerenderContents();
388 } 388 }
389 389
390 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { 390 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 713
714 void PrerenderContents::Destroy(FinalStatus final_status) { 714 void PrerenderContents::Destroy(FinalStatus final_status) {
715 if (prerender_manager_->IsPendingDelete(this)) 715 if (prerender_manager_->IsPendingDelete(this))
716 return; 716 return;
717 717
718 if (child_id_ != -1 && route_id_ != -1) { 718 if (child_id_ != -1 && route_id_ != -1) {
719 // Cancel the prerender in the PrerenderTracker. This is needed 719 // Cancel the prerender in the PrerenderTracker. This is needed
720 // because destroy may be called directly from the UI thread without calling 720 // because destroy may be called directly from the UI thread without calling
721 // TryCancel(). This is difficult to completely avoid, since prerendering 721 // TryCancel(). This is difficult to completely avoid, since prerendering
722 // can be cancelled before a RenderView is created. 722 // can be cancelled before a RenderView is created.
723 bool is_cancelled = 723 bool is_cancelled = g_browser_process->prerender_tracker()->TryCancel(
724 PrerenderTracker::GetInstance()->TryCancel(child_id_, route_id_, 724 child_id_, route_id_, final_status);
725 final_status);
726 CHECK(is_cancelled); 725 CHECK(is_cancelled);
727 726
728 // A different final status may have been set already from another thread. 727 // A different final status may have been set already from another thread.
729 // If so, use it instead. 728 // If so, use it instead.
730 if (!PrerenderTracker::GetInstance()->GetFinalStatus(child_id_, route_id_, 729 if (!g_browser_process->prerender_tracker()->GetFinalStatus(
731 &final_status)) { 730 child_id_, route_id_, &final_status)) {
732 NOTREACHED(); 731 NOTREACHED();
733 } 732 }
734 } 733 }
735 734
736 prerender_manager_->MoveEntryToPendingDelete(this); 735 prerender_manager_->MoveEntryToPendingDelete(this);
737 set_final_status(final_status); 736 set_final_status(final_status);
738 // We may destroy the PrerenderContents before we have initialized the 737 // We may destroy the PrerenderContents before we have initialized the
739 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to 738 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to
740 // avoid any more messages being sent. 739 // avoid any more messages being sent.
741 if (render_view_host_observer_.get()) 740 if (render_view_host_observer_.get())
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } 824 }
826 return render_view_host_; 825 return render_view_host_;
827 } 826 }
828 827
829 void PrerenderContents::CommitHistory(TabContents* tc) { 828 void PrerenderContents::CommitHistory(TabContents* tc) {
830 if (tab_contents_delegate_.get()) 829 if (tab_contents_delegate_.get())
831 tab_contents_delegate_->CommitHistory(tc); 830 tab_contents_delegate_->CommitHistory(tc);
832 } 831 }
833 832
834 } // namespace prerender 833 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698