Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/process_util.h" | 7 #include "base/process_util.h" |
| 8 #include "base/task.h" | 8 #include "base/task.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/background_contents_service.h" | 10 #include "chrome/browser/background_contents_service.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/prerender/prerender_final_status.h" | 12 #include "chrome/browser/prerender/prerender_final_status.h" |
| 13 #include "chrome/browser/prerender/prerender_manager.h" | 13 #include "chrome/browser/prerender/prerender_manager.h" |
| 14 #include "chrome/browser/prerender/prerender_render_widget_host_view.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/renderer_preferences_util.h" | 16 #include "chrome/browser/renderer_preferences_util.h" |
| 16 #include "chrome/browser/ui/login/login_prompt.h" | 17 #include "chrome/browser/ui/login/login_prompt.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "chrome/common/icon_messages.h" | 19 #include "chrome/common/icon_messages.h" |
| 19 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
| 20 #include "chrome/common/extensions/extension_messages.h" | 21 #include "chrome/common/extensions/extension_messages.h" |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/common/view_types.h" | 23 #include "chrome/common/view_types.h" |
| 23 #include "content/browser/browsing_instance.h" | 24 #include "content/browser/browsing_instance.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 const std::vector<GURL>& alias_urls, | 64 const std::vector<GURL>& alias_urls, |
| 64 const GURL& referrer) | 65 const GURL& referrer) |
| 65 : prerender_manager_(prerender_manager), | 66 : prerender_manager_(prerender_manager), |
| 66 render_view_host_(NULL), | 67 render_view_host_(NULL), |
| 67 prerender_url_(url), | 68 prerender_url_(url), |
| 68 referrer_(referrer), | 69 referrer_(referrer), |
| 69 profile_(profile), | 70 profile_(profile), |
| 70 page_id_(0), | 71 page_id_(0), |
| 71 has_stopped_loading_(false), | 72 has_stopped_loading_(false), |
| 72 final_status_(FINAL_STATUS_MAX), | 73 final_status_(FINAL_STATUS_MAX), |
| 74 pending_final_status_(FINAL_STATUS_MAX), | |
| 73 prerendering_has_started_(false) { | 75 prerendering_has_started_(false) { |
| 74 DCHECK(prerender_manager != NULL); | 76 DCHECK(prerender_manager != NULL); |
| 75 if (!AddAliasURL(prerender_url_)) | 77 if (!AddAliasURL(prerender_url_)) |
| 76 LOG(DFATAL) << "PrerenderContents given invalid URL " << prerender_url_; | 78 LOG(DFATAL) << "PrerenderContents given invalid URL " << prerender_url_; |
| 77 for (std::vector<GURL>::const_iterator it = alias_urls.begin(); | 79 for (std::vector<GURL>::const_iterator it = alias_urls.begin(); |
| 78 it != alias_urls.end(); | 80 it != alias_urls.end(); |
| 79 ++it) { | 81 ++it) { |
| 80 if (!AddAliasURL(*it)) | 82 if (!AddAliasURL(*it)) |
| 81 LOG(DFATAL) << "PrerenderContents given invalid URL " << prerender_url_; | 83 LOG(DFATAL) << "PrerenderContents given invalid URL " << prerender_url_; |
| 82 } | 84 } |
| 83 } | 85 } |
| 84 | 86 |
| 85 // static | 87 // static |
| 86 PrerenderContents::Factory* PrerenderContents::CreateFactory() { | 88 PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
| 87 return new PrerenderContentsFactoryImpl(); | 89 return new PrerenderContentsFactoryImpl(); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void PrerenderContents::StartPrerendering() { | 92 void PrerenderContents::StartPrerendering( |
| 93 const RenderViewHost* source_render_view_host) { | |
| 91 DCHECK(profile_ != NULL); | 94 DCHECK(profile_ != NULL); |
| 92 DCHECK(!prerendering_has_started_); | 95 DCHECK(!prerendering_has_started_); |
| 96 DCHECK(source_render_view_host != NULL); | |
| 97 DCHECK(source_render_view_host->view() != NULL); | |
| 93 prerendering_has_started_ = true; | 98 prerendering_has_started_ = true; |
| 94 SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile_); | 99 SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile_); |
| 95 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, | 100 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, |
| 96 NULL); | 101 NULL); |
| 97 | 102 |
| 98 int process_id = render_view_host_->process()->id(); | 103 int process_id = render_view_host_->process()->id(); |
| 99 int view_id = render_view_host_->routing_id(); | 104 int view_id = render_view_host_->routing_id(); |
| 100 std::pair<int, int> process_view_pair = std::make_pair(process_id, view_id); | 105 std::pair<int, int> process_view_pair = std::make_pair(process_id, view_id); |
| 101 NotificationService::current()->Notify( | 106 NotificationService::current()->Notify( |
| 102 NotificationType::PRERENDER_CONTENTS_STARTED, | 107 NotificationType::PRERENDER_CONTENTS_STARTED, |
| 103 Source<std::pair<int, int> >(&process_view_pair), | 108 Source<std::pair<int, int> >(&process_view_pair), |
| 104 NotificationService::NoDetails()); | 109 NotificationService::NoDetails()); |
| 105 | 110 |
| 106 // Create the RenderView, so it can receive messages. | 111 // Create the RenderView, so it can receive messages. |
| 107 render_view_host_->CreateRenderView(string16()); | 112 render_view_host_->CreateRenderView(string16()); |
| 108 | 113 |
| 109 // Hide the RVH, so that we will run at a lower CPU priority. | 114 // Give the RVH a PrerenderRenderWidgetHostView, both so its size can be set |
| 110 // Once the RVH is being swapped into a tab, we will Restore it again. | 115 // and so that the prerender can be cancelled under certain circumstances. |
| 111 render_view_host_->WasHidden(); | 116 PrerenderRenderWidgetHostView* view = |
| 117 new PrerenderRenderWidgetHostView(render_view_host_, this); | |
| 118 view->Init(source_render_view_host->view()); | |
| 119 | |
| 112 | 120 |
| 113 // Register this with the ResourceDispatcherHost as a prerender | 121 // Register this with the ResourceDispatcherHost as a prerender |
| 114 // RenderViewHost. This must be done before the Navigate message to catch all | 122 // RenderViewHost. This must be done before the Navigate message to catch all |
| 115 // resource requests, but as it is on the same thread as the Navigate message | 123 // resource requests, but as it is on the same thread as the Navigate message |
| 116 // (IO) there is no race condition. | 124 // (IO) there is no race condition. |
| 117 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); | 125 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); |
| 118 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 126 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 119 NewRunnableFunction(&AddChildRoutePair, rdh, | 127 NewRunnableFunction(&AddChildRoutePair, rdh, |
| 120 process_id, view_id)); | 128 process_id, view_id)); |
| 121 | 129 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 192 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); |
| 185 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 193 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 186 | 194 |
| 187 final_status_ = final_status; | 195 final_status_ = final_status; |
| 188 } | 196 } |
| 189 | 197 |
| 190 FinalStatus PrerenderContents::final_status() const { | 198 FinalStatus PrerenderContents::final_status() const { |
| 191 return final_status_; | 199 return final_status_; |
| 192 } | 200 } |
| 193 | 201 |
| 202 void PrerenderContents::set_pending_final_status( | |
| 203 FinalStatus pending_final_status) { | |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 205 DCHECK(pending_final_status >= FINAL_STATUS_USED && | |
| 206 pending_final_status < FINAL_STATUS_MAX); | |
|
cbentzel
2011/04/19 17:42:41
Do you want to DCHECK_EQ(FINAL_STATUS_MAX, pending
mmenke
2011/04/19 20:00:01
It can be done multiple times. I just wait for th
| |
| 207 | |
| 208 pending_final_status_ = pending_final_status; | |
| 209 } | |
| 210 | |
| 211 FinalStatus PrerenderContents::pending_final_status() const { | |
| 212 return pending_final_status_; | |
| 213 } | |
| 214 | |
| 194 PrerenderContents::~PrerenderContents() { | 215 PrerenderContents::~PrerenderContents() { |
| 195 DCHECK(final_status_ != FINAL_STATUS_MAX); | 216 DCHECK(final_status_ != FINAL_STATUS_MAX); |
| 196 | 217 |
| 197 // If we haven't even started prerendering, we were just in the control | 218 // If we haven't even started prerendering, we were just in the control |
| 198 // group, which means we do not want to record the status. | 219 // group, which means we do not want to record the status. |
| 199 if (prerendering_has_started()) | 220 if (prerendering_has_started()) |
| 200 RecordFinalStatus(final_status_); | 221 RecordFinalStatus(final_status_); |
| 201 | 222 |
| 202 if (!render_view_host_) // Will be null for unit tests. | 223 if (!render_view_host_) // Will be null for unit tests. |
| 203 return; | 224 return; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 return; | 562 return; |
| 542 | 563 |
| 543 size_t private_bytes, shared_bytes; | 564 size_t private_bytes, shared_bytes; |
| 544 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { | 565 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { |
| 545 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) | 566 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) |
| 546 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); | 567 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); |
| 547 } | 568 } |
| 548 } | 569 } |
| 549 | 570 |
| 550 } // namespace prerender | 571 } // namespace prerender |
| OLD | NEW |