| 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 #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 <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/process_util.h" | |
| 12 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/history/history_tab_helper.h" | 12 #include "chrome/browser/history/history_tab_helper.h" |
| 14 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
| 15 #include "chrome/browser/prerender/prerender_final_status.h" | 14 #include "chrome/browser/prerender/prerender_final_status.h" |
| 16 #include "chrome/browser/prerender/prerender_handle.h" | 15 #include "chrome/browser/prerender/prerender_handle.h" |
| 17 #include "chrome/browser/prerender/prerender_manager.h" | 16 #include "chrome/browser/prerender/prerender_manager.h" |
| 18 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" | 17 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" |
| 19 #include "chrome/browser/prerender/prerender_tracker.h" | 18 #include "chrome/browser/prerender/prerender_tracker.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 | 35 |
| 37 using content::DownloadItem; | 36 using content::DownloadItem; |
| 38 using content::OpenURLParams; | 37 using content::OpenURLParams; |
| 39 using content::RenderViewHost; | 38 using content::RenderViewHost; |
| 40 using content::ResourceRedirectDetails; | 39 using content::ResourceRedirectDetails; |
| 41 using content::SessionStorageNamespace; | 40 using content::SessionStorageNamespace; |
| 42 using content::WebContents; | 41 using content::WebContents; |
| 43 | 42 |
| 44 namespace prerender { | 43 namespace prerender { |
| 45 | 44 |
| 46 namespace { | |
| 47 | |
| 48 // Tells the render process at |child_id| whether |url| is a new prerendered | |
| 49 // page, or whether |url| is being removed as a prerendered page. Currently | |
| 50 // this will only inform the render process that created the prerendered page | |
| 51 // with <link rel="prerender"> tags about it. This means that if the user | |
| 52 // clicks on a link for a prerendered URL in a different page, the prerender | |
| 53 // will not be swapped in. | |
| 54 void InformRenderProcessAboutPrerender(const GURL& url, | |
| 55 bool is_add, | |
| 56 int child_id) { | |
| 57 if (child_id < 0) | |
| 58 return; | |
| 59 content::RenderProcessHost* render_process_host = | |
| 60 content::RenderProcessHost::FromID(child_id); | |
| 61 if (!render_process_host) | |
| 62 return; | |
| 63 IPC::Message* message = NULL; | |
| 64 if (is_add) | |
| 65 message = new PrerenderMsg_AddPrerenderURL(url); | |
| 66 else | |
| 67 message = new PrerenderMsg_RemovePrerenderURL(url); | |
| 68 render_process_host->Send(message); | |
| 69 } | |
| 70 | |
| 71 } // namespace | |
| 72 | |
| 73 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { | 45 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { |
| 74 public: | 46 public: |
| 75 virtual PrerenderContents* CreatePrerenderContents( | 47 virtual PrerenderContents* CreatePrerenderContents( |
| 76 PrerenderManager* prerender_manager, Profile* profile, | 48 PrerenderManager* prerender_manager, Profile* profile, |
| 77 const GURL& url, const content::Referrer& referrer, | 49 const GURL& url, const content::Referrer& referrer, |
| 78 Origin origin, uint8 experiment_id) OVERRIDE { | 50 Origin origin, uint8 experiment_id) OVERRIDE { |
| 79 return new PrerenderContents(prerender_manager, profile, | 51 return new PrerenderContents(prerender_manager, profile, |
| 80 url, referrer, origin, experiment_id); | 52 url, referrer, origin, experiment_id); |
| 81 } | 53 } |
| 82 }; | 54 }; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 bool user_gesture) OVERRIDE { | 132 bool user_gesture) OVERRIDE { |
| 161 // TODO(mmenke): Consider supporting this if it is a common case during | 133 // TODO(mmenke): Consider supporting this if it is a common case during |
| 162 // prerenders. | 134 // prerenders. |
| 163 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); | 135 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); |
| 164 } | 136 } |
| 165 | 137 |
| 166 private: | 138 private: |
| 167 PrerenderContents* prerender_contents_; | 139 PrerenderContents* prerender_contents_; |
| 168 }; | 140 }; |
| 169 | 141 |
| 142 void PrerenderContents::Observer::OnPrerenderAddAlias( |
| 143 PrerenderContents* contents, |
| 144 const GURL& alias_url) { |
| 145 } |
| 146 |
| 147 void PrerenderContents::Observer::OnPrerenderCreatedMatchCompleteReplacement( |
| 148 PrerenderContents* contents, PrerenderContents* replacement) { |
| 149 } |
| 150 |
| 170 PrerenderContents::Observer::Observer() { | 151 PrerenderContents::Observer::Observer() { |
| 171 } | 152 } |
| 172 | 153 |
| 173 PrerenderContents::Observer::~Observer() { | 154 PrerenderContents::Observer::~Observer() { |
| 174 } | 155 } |
| 175 | 156 |
| 176 PrerenderContents::PendingPrerenderInfo::PendingPrerenderInfo( | 157 PrerenderContents::PendingPrerenderInfo::PendingPrerenderInfo( |
| 177 base::WeakPtr<PrerenderHandle> weak_prerender_handle, | 158 base::WeakPtr<PrerenderHandle> weak_prerender_handle, |
| 178 Origin origin, | 159 Origin origin, |
| 179 const GURL& url, | 160 const GURL& url, |
| 180 const content::Referrer& referrer, | 161 const content::Referrer& referrer, |
| 181 const gfx::Size& size) : weak_prerender_handle(weak_prerender_handle), | 162 const gfx::Size& size) : weak_prerender_handle(weak_prerender_handle), |
| 182 origin(origin), | 163 origin(origin), |
| 183 url(url), | 164 url(url), |
| 184 referrer(referrer), | 165 referrer(referrer), |
| 185 size(size) { | 166 size(size) { |
| 186 } | 167 } |
| 187 | 168 |
| 188 PrerenderContents::PendingPrerenderInfo::~PendingPrerenderInfo() { | 169 PrerenderContents::PendingPrerenderInfo::~PendingPrerenderInfo() { |
| 189 } | 170 } |
| 190 | 171 |
| 191 void PrerenderContents::AddPendingPrerender( | 172 void PrerenderContents::AddPendingPrerender( |
| 192 scoped_ptr<PendingPrerenderInfo> pending_prerender_info) { | 173 scoped_ptr<PendingPrerenderInfo> pending_prerender_info) { |
| 193 pending_prerenders_.push_back(pending_prerender_info.release()); | 174 pending_prerenders_.push_back(pending_prerender_info.release()); |
| 194 } | 175 } |
| 195 | 176 |
| 196 void PrerenderContents::StartPendingPrerenders() { | 177 void PrerenderContents::PrepareForUse() { |
| 178 NotifyPrerenderStop(); |
| 179 |
| 197 SessionStorageNamespace* session_storage_namespace = NULL; | 180 SessionStorageNamespace* session_storage_namespace = NULL; |
| 198 if (prerender_contents_) { | 181 if (prerender_contents_) { |
| 199 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 182 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
| 200 session_storage_namespace = | 183 session_storage_namespace = |
| 201 prerender_contents_->web_contents()->GetController() | 184 prerender_contents_->web_contents()->GetController() |
| 202 .GetDefaultSessionStorageNamespace(); | 185 .GetDefaultSessionStorageNamespace(); |
| 203 } | 186 } |
| 204 prerender_manager_->StartPendingPrerenders( | 187 prerender_manager_->StartPendingPrerenders( |
| 205 child_id_, &pending_prerenders_, session_storage_namespace); | 188 child_id_, &pending_prerenders_, session_storage_namespace); |
| 206 pending_prerenders_.clear(); | 189 pending_prerenders_.clear(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 226 match_complete_status_(MATCH_COMPLETE_DEFAULT), | 209 match_complete_status_(MATCH_COMPLETE_DEFAULT), |
| 227 prerendering_has_been_cancelled_(false), | 210 prerendering_has_been_cancelled_(false), |
| 228 child_id_(-1), | 211 child_id_(-1), |
| 229 route_id_(-1), | 212 route_id_(-1), |
| 230 origin_(origin), | 213 origin_(origin), |
| 231 experiment_id_(experiment_id), | 214 experiment_id_(experiment_id), |
| 232 creator_child_id_(-1) { | 215 creator_child_id_(-1) { |
| 233 DCHECK(prerender_manager != NULL); | 216 DCHECK(prerender_manager != NULL); |
| 234 } | 217 } |
| 235 | 218 |
| 236 PrerenderContents* PrerenderContents::CreateMatchCompleteReplacement() const { | 219 PrerenderContents* PrerenderContents::CreateMatchCompleteReplacement() { |
| 237 PrerenderContents* new_contents = prerender_manager_->CreatePrerenderContents( | 220 PrerenderContents* new_contents = prerender_manager_->CreatePrerenderContents( |
| 238 prerender_url(), referrer(), origin(), experiment_id()); | 221 prerender_url(), referrer(), origin(), experiment_id()); |
| 239 | 222 |
| 240 new_contents->load_start_time_ = load_start_time_; | 223 new_contents->load_start_time_ = load_start_time_; |
| 241 new_contents->session_storage_namespace_id_ = session_storage_namespace_id_; | 224 new_contents->session_storage_namespace_id_ = session_storage_namespace_id_; |
| 242 new_contents->set_match_complete_status( | 225 new_contents->set_match_complete_status( |
| 243 PrerenderContents::MATCH_COMPLETE_REPLACEMENT_PENDING); | 226 PrerenderContents::MATCH_COMPLETE_REPLACEMENT_PENDING); |
| 244 | 227 |
| 245 const bool did_init = new_contents->Init(); | 228 const bool did_init = new_contents->Init(); |
| 246 DCHECK(did_init); | 229 DCHECK(did_init); |
| 247 DCHECK_EQ(alias_urls_.front(), new_contents->alias_urls_.front()); | 230 DCHECK_EQ(alias_urls_.front(), new_contents->alias_urls_.front()); |
| 248 DCHECK_EQ(1u, new_contents->alias_urls_.size()); | 231 DCHECK_EQ(1u, new_contents->alias_urls_.size()); |
| 249 new_contents->alias_urls_ = alias_urls_; | 232 new_contents->alias_urls_ = alias_urls_; |
| 250 new_contents->set_match_complete_status( | 233 new_contents->set_match_complete_status( |
| 251 PrerenderContents::MATCH_COMPLETE_REPLACEMENT); | 234 PrerenderContents::MATCH_COMPLETE_REPLACEMENT); |
| 235 NotifyPrerenderCreatedMatchCompleteReplacement(new_contents); |
| 252 return new_contents; | 236 return new_contents; |
| 253 } | 237 } |
| 254 | 238 |
| 255 bool PrerenderContents::Init() { | 239 bool PrerenderContents::Init() { |
| 256 return AddAliasURL(prerender_url_); | 240 return AddAliasURL(prerender_url_); |
| 257 } | 241 } |
| 258 | 242 |
| 259 // static | 243 // static |
| 260 PrerenderContents::Factory* PrerenderContents::CreateFactory() { | 244 PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
| 261 return new PrerenderContentsFactoryImpl(); | 245 return new PrerenderContentsFactoryImpl(); |
| 262 } | 246 } |
| 263 | 247 |
| 264 void PrerenderContents::StartPrerendering( | 248 void PrerenderContents::StartPrerendering( |
| 265 int creator_child_id, | 249 int creator_child_id, |
| 266 const gfx::Size& size, | 250 const gfx::Size& size, |
| 267 SessionStorageNamespace* session_storage_namespace) { | 251 SessionStorageNamespace* session_storage_namespace) { |
| 268 DCHECK(profile_ != NULL); | 252 DCHECK(profile_ != NULL); |
| 269 DCHECK(!size.IsEmpty()); | 253 DCHECK(!size.IsEmpty()); |
| 270 DCHECK(!prerendering_has_started_); | 254 DCHECK(!prerendering_has_started_); |
| 271 DCHECK(prerender_contents_.get() == NULL); | 255 DCHECK(prerender_contents_.get() == NULL); |
| 272 DCHECK_EQ(-1, creator_child_id_); | 256 DCHECK_EQ(-1, creator_child_id_); |
| 273 DCHECK(size_.IsEmpty()); | 257 DCHECK(size_.IsEmpty()); |
| 274 DCHECK_EQ(1U, alias_urls_.size()); | 258 DCHECK_EQ(1U, alias_urls_.size()); |
| 275 | 259 |
| 276 creator_child_id_ = creator_child_id; | 260 creator_child_id_ = creator_child_id; |
| 277 session_storage_namespace_id_ = session_storage_namespace->id(); | 261 session_storage_namespace_id_ = session_storage_namespace->id(); |
| 278 size_ = size; | 262 size_ = size; |
| 279 | 263 |
| 280 InformRenderProcessAboutPrerender(prerender_url_, true, | |
| 281 creator_child_id_); | |
| 282 | |
| 283 DCHECK(load_start_time_.is_null()); | 264 DCHECK(load_start_time_.is_null()); |
| 284 load_start_time_ = base::TimeTicks::Now(); | 265 load_start_time_ = base::TimeTicks::Now(); |
| 285 | 266 |
| 286 // Everything after this point sets up the WebContents object and associated | 267 // Everything after this point sets up the WebContents object and associated |
| 287 // RenderView for the prerender page. Don't do this for members of the | 268 // RenderView for the prerender page. Don't do this for members of the |
| 288 // control group. | 269 // control group. |
| 289 if (prerender_manager_->IsControlGroup(experiment_id())) | 270 if (prerender_manager_->IsControlGroup(experiment_id())) |
| 290 return; | 271 return; |
| 291 | 272 |
| 292 prerendering_has_started_ = true; | 273 prerendering_has_started_ = true; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 DCHECK_GE(route_id_, -1); | 345 DCHECK_GE(route_id_, -1); |
| 365 *route_id = route_id_; | 346 *route_id = route_id_; |
| 366 return route_id_ != -1; | 347 return route_id_ != -1; |
| 367 } | 348 } |
| 368 | 349 |
| 369 void PrerenderContents::SetFinalStatus(FinalStatus final_status) { | 350 void PrerenderContents::SetFinalStatus(FinalStatus final_status) { |
| 370 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 351 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); |
| 371 DCHECK(final_status_ == FINAL_STATUS_MAX); | 352 DCHECK(final_status_ == FINAL_STATUS_MAX); |
| 372 | 353 |
| 373 final_status_ = final_status; | 354 final_status_ = final_status; |
| 374 | |
| 375 if (!prerender_manager_->IsControlGroup(experiment_id()) && | |
| 376 prerendering_has_started()) { | |
| 377 NotifyPrerenderStop(); | |
| 378 } | |
| 379 } | 355 } |
| 380 | 356 |
| 381 PrerenderContents::~PrerenderContents() { | 357 PrerenderContents::~PrerenderContents() { |
| 382 DCHECK_NE(FINAL_STATUS_MAX, final_status()); | 358 DCHECK_NE(FINAL_STATUS_MAX, final_status()); |
| 383 DCHECK( | 359 DCHECK( |
| 384 prerendering_has_been_cancelled() || final_status() == FINAL_STATUS_USED); | 360 prerendering_has_been_cancelled() || final_status() == FINAL_STATUS_USED); |
| 385 DCHECK_NE(ORIGIN_MAX, origin()); | 361 DCHECK_NE(ORIGIN_MAX, origin()); |
| 386 | 362 |
| 387 prerender_manager_->RecordFinalStatusWithMatchCompleteStatus( | 363 prerender_manager_->RecordFinalStatusWithMatchCompleteStatus( |
| 388 origin(), experiment_id(), match_complete_status(), final_status()); | 364 origin(), experiment_id(), match_complete_status(), final_status()); |
| 389 | 365 |
| 390 if (child_id_ != -1 && route_id_ != -1) { | |
| 391 for (std::vector<GURL>::const_iterator it = alias_urls_.begin(); | |
| 392 it != alias_urls_.end(); | |
| 393 ++it) { | |
| 394 InformRenderProcessAboutPrerender(*it, false, creator_child_id_); | |
| 395 } | |
| 396 } | |
| 397 | |
| 398 // If we still have a WebContents, clean up anything we need to and then | 366 // If we still have a WebContents, clean up anything we need to and then |
| 399 // destroy it. | 367 // destroy it. |
| 400 if (prerender_contents_.get()) | 368 if (prerender_contents_.get()) |
| 401 delete ReleasePrerenderContents(); | 369 delete ReleasePrerenderContents(); |
| 402 } | 370 } |
| 403 | 371 |
| 404 void PrerenderContents::AddObserver(Observer* observer) { | 372 void PrerenderContents::AddObserver(Observer* observer) { |
| 405 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 373 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 406 observer_list_.AddObserver(observer); | 374 observer_list_.AddObserver(observer); |
| 407 } | 375 } |
| 408 | 376 |
| 377 void PrerenderContents::RemoveObserver(Observer* observer) { |
| 378 observer_list_.RemoveObserver(observer); |
| 379 } |
| 380 |
| 409 void PrerenderContents::Observe(int type, | 381 void PrerenderContents::Observe(int type, |
| 410 const content::NotificationSource& source, | 382 const content::NotificationSource& source, |
| 411 const content::NotificationDetails& details) { | 383 const content::NotificationDetails& details) { |
| 412 switch (type) { | 384 switch (type) { |
| 413 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 385 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
| 414 Destroy(FINAL_STATUS_PROFILE_DESTROYED); | 386 Destroy(FINAL_STATUS_PROFILE_DESTROYED); |
| 415 return; | 387 return; |
| 416 | 388 |
| 417 case chrome::NOTIFICATION_APP_TERMINATING: | 389 case chrome::NOTIFICATION_APP_TERMINATING: |
| 418 Destroy(FINAL_STATUS_APP_TERMINATING); | 390 Destroy(FINAL_STATUS_APP_TERMINATING); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 466 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 495 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStart(this)); | 467 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStart(this)); |
| 496 } | 468 } |
| 497 | 469 |
| 498 void PrerenderContents::NotifyPrerenderStop() { | 470 void PrerenderContents::NotifyPrerenderStop() { |
| 499 DCHECK_NE(FINAL_STATUS_MAX, final_status_); | 471 DCHECK_NE(FINAL_STATUS_MAX, final_status_); |
| 500 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStop(this)); | 472 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStop(this)); |
| 501 observer_list_.Clear(); | 473 observer_list_.Clear(); |
| 502 } | 474 } |
| 503 | 475 |
| 476 void PrerenderContents::NotifyPrerenderAddAlias(const GURL& alias_url) { |
| 477 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderAddAlias(this, |
| 478 alias_url)); |
| 479 } |
| 480 |
| 481 void PrerenderContents::NotifyPrerenderCreatedMatchCompleteReplacement( |
| 482 PrerenderContents* replacement) { |
| 483 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 484 OnPrerenderCreatedMatchCompleteReplacement(this, |
| 485 replacement)); |
| 486 } |
| 487 |
| 504 void PrerenderContents::DidUpdateFaviconURL( | 488 void PrerenderContents::DidUpdateFaviconURL( |
| 505 int32 page_id, | 489 int32 page_id, |
| 506 const std::vector<content::FaviconURL>& urls) { | 490 const std::vector<content::FaviconURL>& urls) { |
| 507 VLOG(1) << "PrerenderContents::OnUpdateFaviconURL" << icon_url_; | 491 VLOG(1) << "PrerenderContents::OnUpdateFaviconURL" << icon_url_; |
| 508 for (std::vector<content::FaviconURL>::const_iterator it = urls.begin(); | 492 for (std::vector<content::FaviconURL>::const_iterator it = urls.begin(); |
| 509 it != urls.end(); ++it) { | 493 it != urls.end(); ++it) { |
| 510 if (it->icon_type == content::FaviconURL::FAVICON) { | 494 if (it->icon_type == content::FaviconURL::FAVICON) { |
| 511 icon_url_ = it->icon_url; | 495 icon_url_ = it->icon_url; |
| 512 VLOG(1) << icon_url_; | 496 VLOG(1) << icon_url_; |
| 513 return; | 497 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 528 Destroy(FINAL_STATUS_HTTPS); | 512 Destroy(FINAL_STATUS_HTTPS); |
| 529 return false; | 513 return false; |
| 530 } | 514 } |
| 531 if (match_complete_status_ != MATCH_COMPLETE_REPLACEMENT_PENDING && | 515 if (match_complete_status_ != MATCH_COMPLETE_REPLACEMENT_PENDING && |
| 532 prerender_manager_->HasRecentlyBeenNavigatedTo(origin(), url)) { | 516 prerender_manager_->HasRecentlyBeenNavigatedTo(origin(), url)) { |
| 533 Destroy(FINAL_STATUS_RECENTLY_VISITED); | 517 Destroy(FINAL_STATUS_RECENTLY_VISITED); |
| 534 return false; | 518 return false; |
| 535 } | 519 } |
| 536 | 520 |
| 537 alias_urls_.push_back(url); | 521 alias_urls_.push_back(url); |
| 538 InformRenderProcessAboutPrerender(url, true, creator_child_id_); | 522 NotifyPrerenderAddAlias(url); |
| 539 return true; | 523 return true; |
| 540 } | 524 } |
| 541 | 525 |
| 542 bool PrerenderContents::Matches( | 526 bool PrerenderContents::Matches( |
| 543 const GURL& url, | 527 const GURL& url, |
| 544 const SessionStorageNamespace* session_storage_namespace) const { | 528 const SessionStorageNamespace* session_storage_namespace) const { |
| 545 DCHECK(child_id_ == -1 || session_storage_namespace); | 529 DCHECK(child_id_ == -1 || session_storage_namespace); |
| 546 if (session_storage_namespace && | 530 if (session_storage_namespace && |
| 547 session_storage_namespace_id_ != session_storage_namespace->id()) | 531 session_storage_namespace_id_ != session_storage_namespace->id()) |
| 548 return false; | 532 return false; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 | 566 |
| 583 void PrerenderContents::DidFinishLoad(int64 frame_id, | 567 void PrerenderContents::DidFinishLoad(int64 frame_id, |
| 584 const GURL& validated_url, | 568 const GURL& validated_url, |
| 585 bool is_main_frame, | 569 bool is_main_frame, |
| 586 RenderViewHost* render_view_host) { | 570 RenderViewHost* render_view_host) { |
| 587 if (is_main_frame) | 571 if (is_main_frame) |
| 588 has_finished_loading_ = true; | 572 has_finished_loading_ = true; |
| 589 } | 573 } |
| 590 | 574 |
| 591 void PrerenderContents::Destroy(FinalStatus final_status) { | 575 void PrerenderContents::Destroy(FinalStatus final_status) { |
| 576 DCHECK_NE(final_status, FINAL_STATUS_USED); |
| 577 |
| 592 if (prerendering_has_been_cancelled_) | 578 if (prerendering_has_been_cancelled_) |
| 593 return; | 579 return; |
| 594 | 580 |
| 595 if (child_id_ != -1 && route_id_ != -1) { | 581 if (child_id_ != -1 && route_id_ != -1) { |
| 596 // Cancel the prerender in the PrerenderTracker. This is needed | 582 // Cancel the prerender in the PrerenderTracker. This is needed |
| 597 // because destroy may be called directly from the UI thread without calling | 583 // because destroy may be called directly from the UI thread without calling |
| 598 // TryCancel(). This is difficult to completely avoid, since prerendering | 584 // TryCancel(). This is difficult to completely avoid, since prerendering |
| 599 // can be cancelled before a RenderView is created. | 585 // can be cancelled before a RenderView is created. |
| 600 bool is_cancelled = prerender_manager()->prerender_tracker()->TryCancel( | 586 bool is_cancelled = prerender_manager()->prerender_tracker()->TryCancel( |
| 601 child_id_, route_id_, final_status); | 587 child_id_, route_id_, final_status); |
| 602 CHECK(is_cancelled); | 588 CHECK(is_cancelled); |
| 603 | 589 |
| 604 // A different final status may have been set already from another thread. | 590 // A different final status may have been set already from another thread. |
| 605 // If so, use it instead. | 591 // If so, use it instead. |
| 606 if (!prerender_manager()->prerender_tracker()-> | 592 if (!prerender_manager()->prerender_tracker()-> |
| 607 GetFinalStatus(child_id_, route_id_, &final_status)) { | 593 GetFinalStatus(child_id_, route_id_, &final_status)) { |
| 608 NOTREACHED(); | 594 NOTREACHED(); |
| 609 } | 595 } |
| 610 } | 596 } |
| 611 SetFinalStatus(final_status); | 597 SetFinalStatus(final_status); |
| 612 | 598 |
| 613 prerendering_has_been_cancelled_ = true; | 599 prerendering_has_been_cancelled_ = true; |
| 614 prerender_manager_->AddToHistory(this); | 600 prerender_manager_->AddToHistory(this); |
| 615 prerender_manager_->MoveEntryToPendingDelete(this, final_status); | 601 prerender_manager_->MoveEntryToPendingDelete(this, final_status); |
| 616 | 602 |
| 603 if (!prerender_manager_->IsControlGroup(experiment_id()) && |
| 604 prerendering_has_started()) { |
| 605 NotifyPrerenderStop(); |
| 606 } |
| 607 |
| 617 // We may destroy the PrerenderContents before we have initialized the | 608 // We may destroy the PrerenderContents before we have initialized the |
| 618 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 609 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
| 619 // avoid any more messages being sent. | 610 // avoid any more messages being sent. |
| 620 if (render_view_host_observer_) | 611 if (render_view_host_observer_) |
| 621 render_view_host_observer_->set_prerender_contents(NULL); | 612 render_view_host_observer_->set_prerender_contents(NULL); |
| 622 } | 613 } |
| 623 | 614 |
| 624 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { | 615 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { |
| 625 if (process_metrics_.get() == NULL) { | 616 if (process_metrics_.get() == NULL) { |
| 626 // If a PrenderContents hasn't started prerending, don't be fully formed. | 617 // If a PrenderContents hasn't started prerending, don't be fully formed. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 693 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
| 703 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) | 694 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) |
| 704 return false; | 695 return false; |
| 705 const WebContents* web_contents = prerender_contents_->web_contents(); | 696 const WebContents* web_contents = prerender_contents_->web_contents(); |
| 706 return (web_contents->GetSiteInstance() != | 697 return (web_contents->GetSiteInstance() != |
| 707 web_contents->GetPendingSiteInstance()); | 698 web_contents->GetPendingSiteInstance()); |
| 708 } | 699 } |
| 709 | 700 |
| 710 | 701 |
| 711 } // namespace prerender | 702 } // namespace prerender |
| OLD | NEW |