| 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/browser.h" | 20 #include "chrome/browser/ui/browser.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 = prerender_contents_-> | 183 session_storage_namespace = prerender_contents_-> |
| 201 GetController().GetDefaultSessionStorageNamespace(); | 184 GetController().GetDefaultSessionStorageNamespace(); |
| 202 } | 185 } |
| 203 prerender_manager_->StartPendingPrerenders( | 186 prerender_manager_->StartPendingPrerenders( |
| 204 child_id_, &pending_prerenders_, session_storage_namespace); | 187 child_id_, &pending_prerenders_, session_storage_namespace); |
| 205 pending_prerenders_.clear(); | 188 pending_prerenders_.clear(); |
| 206 } | 189 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 225 match_complete_status_(MATCH_COMPLETE_DEFAULT), | 208 match_complete_status_(MATCH_COMPLETE_DEFAULT), |
| 226 prerendering_has_been_cancelled_(false), | 209 prerendering_has_been_cancelled_(false), |
| 227 child_id_(-1), | 210 child_id_(-1), |
| 228 route_id_(-1), | 211 route_id_(-1), |
| 229 origin_(origin), | 212 origin_(origin), |
| 230 experiment_id_(experiment_id), | 213 experiment_id_(experiment_id), |
| 231 creator_child_id_(-1) { | 214 creator_child_id_(-1) { |
| 232 DCHECK(prerender_manager != NULL); | 215 DCHECK(prerender_manager != NULL); |
| 233 } | 216 } |
| 234 | 217 |
| 235 PrerenderContents* PrerenderContents::CreateMatchCompleteReplacement() const { | 218 PrerenderContents* PrerenderContents::CreateMatchCompleteReplacement() { |
| 236 PrerenderContents* new_contents = prerender_manager_->CreatePrerenderContents( | 219 PrerenderContents* new_contents = prerender_manager_->CreatePrerenderContents( |
| 237 prerender_url(), referrer(), origin(), experiment_id()); | 220 prerender_url(), referrer(), origin(), experiment_id()); |
| 238 | 221 |
| 239 new_contents->load_start_time_ = load_start_time_; | 222 new_contents->load_start_time_ = load_start_time_; |
| 240 new_contents->session_storage_namespace_id_ = session_storage_namespace_id_; | 223 new_contents->session_storage_namespace_id_ = session_storage_namespace_id_; |
| 241 new_contents->set_match_complete_status( | 224 new_contents->set_match_complete_status( |
| 242 PrerenderContents::MATCH_COMPLETE_REPLACEMENT_PENDING); | 225 PrerenderContents::MATCH_COMPLETE_REPLACEMENT_PENDING); |
| 243 | 226 |
| 244 const bool did_init = new_contents->Init(); | 227 const bool did_init = new_contents->Init(); |
| 245 DCHECK(did_init); | 228 DCHECK(did_init); |
| 246 DCHECK_EQ(alias_urls_.front(), new_contents->alias_urls_.front()); | 229 DCHECK_EQ(alias_urls_.front(), new_contents->alias_urls_.front()); |
| 247 DCHECK_EQ(1u, new_contents->alias_urls_.size()); | 230 DCHECK_EQ(1u, new_contents->alias_urls_.size()); |
| 248 new_contents->alias_urls_ = alias_urls_; | 231 new_contents->alias_urls_ = alias_urls_; |
| 249 new_contents->set_match_complete_status( | 232 new_contents->set_match_complete_status( |
| 250 PrerenderContents::MATCH_COMPLETE_REPLACEMENT); | 233 PrerenderContents::MATCH_COMPLETE_REPLACEMENT); |
| 234 NotifyPrerenderCreatedMatchCompleteReplacement(new_contents); |
| 251 return new_contents; | 235 return new_contents; |
| 252 } | 236 } |
| 253 | 237 |
| 254 bool PrerenderContents::Init() { | 238 bool PrerenderContents::Init() { |
| 255 return AddAliasURL(prerender_url_); | 239 return AddAliasURL(prerender_url_); |
| 256 } | 240 } |
| 257 | 241 |
| 258 // static | 242 // static |
| 259 PrerenderContents::Factory* PrerenderContents::CreateFactory() { | 243 PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
| 260 return new PrerenderContentsFactoryImpl(); | 244 return new PrerenderContentsFactoryImpl(); |
| 261 } | 245 } |
| 262 | 246 |
| 263 void PrerenderContents::StartPrerendering( | 247 void PrerenderContents::StartPrerendering( |
| 264 int creator_child_id, | 248 int creator_child_id, |
| 265 const gfx::Size& size, | 249 const gfx::Size& size, |
| 266 SessionStorageNamespace* session_storage_namespace) { | 250 SessionStorageNamespace* session_storage_namespace) { |
| 267 DCHECK(profile_ != NULL); | 251 DCHECK(profile_ != NULL); |
| 268 DCHECK(!size.IsEmpty()); | 252 DCHECK(!size.IsEmpty()); |
| 269 DCHECK(!prerendering_has_started_); | 253 DCHECK(!prerendering_has_started_); |
| 270 DCHECK(prerender_contents_.get() == NULL); | 254 DCHECK(prerender_contents_.get() == NULL); |
| 271 DCHECK_EQ(-1, creator_child_id_); | 255 DCHECK_EQ(-1, creator_child_id_); |
| 272 DCHECK(size_.IsEmpty()); | 256 DCHECK(size_.IsEmpty()); |
| 273 DCHECK_EQ(1U, alias_urls_.size()); | 257 DCHECK_EQ(1U, alias_urls_.size()); |
| 274 | 258 |
| 275 creator_child_id_ = creator_child_id; | 259 creator_child_id_ = creator_child_id; |
| 276 session_storage_namespace_id_ = session_storage_namespace->id(); | 260 session_storage_namespace_id_ = session_storage_namespace->id(); |
| 277 size_ = size; | 261 size_ = size; |
| 278 | 262 |
| 279 InformRenderProcessAboutPrerender(prerender_url_, true, | |
| 280 creator_child_id_); | |
| 281 | |
| 282 DCHECK(load_start_time_.is_null()); | 263 DCHECK(load_start_time_.is_null()); |
| 283 load_start_time_ = base::TimeTicks::Now(); | 264 load_start_time_ = base::TimeTicks::Now(); |
| 284 | 265 |
| 285 // Everything after this point sets up the WebContents object and associated | 266 // Everything after this point sets up the WebContents object and associated |
| 286 // RenderView for the prerender page. Don't do this for members of the | 267 // RenderView for the prerender page. Don't do this for members of the |
| 287 // control group. | 268 // control group. |
| 288 if (prerender_manager_->IsControlGroup(experiment_id())) | 269 if (prerender_manager_->IsControlGroup(experiment_id())) |
| 289 return; | 270 return; |
| 290 | 271 |
| 291 prerendering_has_started_ = true; | 272 prerendering_has_started_ = true; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 DCHECK_GE(route_id_, -1); | 343 DCHECK_GE(route_id_, -1); |
| 363 *route_id = route_id_; | 344 *route_id = route_id_; |
| 364 return route_id_ != -1; | 345 return route_id_ != -1; |
| 365 } | 346 } |
| 366 | 347 |
| 367 void PrerenderContents::SetFinalStatus(FinalStatus final_status) { | 348 void PrerenderContents::SetFinalStatus(FinalStatus final_status) { |
| 368 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 349 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); |
| 369 DCHECK(final_status_ == FINAL_STATUS_MAX); | 350 DCHECK(final_status_ == FINAL_STATUS_MAX); |
| 370 | 351 |
| 371 final_status_ = final_status; | 352 final_status_ = final_status; |
| 372 | |
| 373 if (!prerender_manager_->IsControlGroup(experiment_id()) && | |
| 374 prerendering_has_started()) { | |
| 375 NotifyPrerenderStop(); | |
| 376 } | |
| 377 } | 353 } |
| 378 | 354 |
| 379 PrerenderContents::~PrerenderContents() { | 355 PrerenderContents::~PrerenderContents() { |
| 380 DCHECK_NE(FINAL_STATUS_MAX, final_status()); | 356 DCHECK_NE(FINAL_STATUS_MAX, final_status()); |
| 381 DCHECK( | 357 DCHECK( |
| 382 prerendering_has_been_cancelled() || final_status() == FINAL_STATUS_USED); | 358 prerendering_has_been_cancelled() || final_status() == FINAL_STATUS_USED); |
| 383 DCHECK_NE(ORIGIN_MAX, origin()); | 359 DCHECK_NE(ORIGIN_MAX, origin()); |
| 384 | 360 |
| 385 prerender_manager_->RecordFinalStatusWithMatchCompleteStatus( | 361 prerender_manager_->RecordFinalStatusWithMatchCompleteStatus( |
| 386 origin(), experiment_id(), match_complete_status(), final_status()); | 362 origin(), experiment_id(), match_complete_status(), final_status()); |
| 387 | 363 |
| 388 if (child_id_ != -1 && route_id_ != -1) { | |
| 389 for (std::vector<GURL>::const_iterator it = alias_urls_.begin(); | |
| 390 it != alias_urls_.end(); | |
| 391 ++it) { | |
| 392 InformRenderProcessAboutPrerender(*it, false, creator_child_id_); | |
| 393 } | |
| 394 } | |
| 395 | |
| 396 // If we still have a WebContents, clean up anything we need to and then | 364 // If we still have a WebContents, clean up anything we need to and then |
| 397 // destroy it. | 365 // destroy it. |
| 398 if (prerender_contents_.get()) | 366 if (prerender_contents_.get()) |
| 399 delete ReleasePrerenderContents(); | 367 delete ReleasePrerenderContents(); |
| 400 } | 368 } |
| 401 | 369 |
| 402 void PrerenderContents::AddObserver(Observer* observer) { | 370 void PrerenderContents::AddObserver(Observer* observer) { |
| 403 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 371 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 404 observer_list_.AddObserver(observer); | 372 observer_list_.AddObserver(observer); |
| 405 } | 373 } |
| 406 | 374 |
| 375 void PrerenderContents::RemoveObserver(Observer* observer) { |
| 376 observer_list_.RemoveObserver(observer); |
| 377 } |
| 378 |
| 407 void PrerenderContents::Observe(int type, | 379 void PrerenderContents::Observe(int type, |
| 408 const content::NotificationSource& source, | 380 const content::NotificationSource& source, |
| 409 const content::NotificationDetails& details) { | 381 const content::NotificationDetails& details) { |
| 410 switch (type) { | 382 switch (type) { |
| 411 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 383 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
| 412 Destroy(FINAL_STATUS_PROFILE_DESTROYED); | 384 Destroy(FINAL_STATUS_PROFILE_DESTROYED); |
| 413 return; | 385 return; |
| 414 | 386 |
| 415 case chrome::NOTIFICATION_APP_TERMINATING: | 387 case chrome::NOTIFICATION_APP_TERMINATING: |
| 416 Destroy(FINAL_STATUS_APP_TERMINATING); | 388 Destroy(FINAL_STATUS_APP_TERMINATING); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 465 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 494 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStart(this)); | 466 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStart(this)); |
| 495 } | 467 } |
| 496 | 468 |
| 497 void PrerenderContents::NotifyPrerenderStop() { | 469 void PrerenderContents::NotifyPrerenderStop() { |
| 498 DCHECK_NE(FINAL_STATUS_MAX, final_status_); | 470 DCHECK_NE(FINAL_STATUS_MAX, final_status_); |
| 499 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStop(this)); | 471 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderStop(this)); |
| 500 observer_list_.Clear(); | 472 observer_list_.Clear(); |
| 501 } | 473 } |
| 502 | 474 |
| 475 void PrerenderContents::NotifyPrerenderAddAlias(const GURL& alias_url) { |
| 476 FOR_EACH_OBSERVER(Observer, observer_list_, OnPrerenderAddAlias(this, |
| 477 alias_url)); |
| 478 } |
| 479 |
| 480 void PrerenderContents::NotifyPrerenderCreatedMatchCompleteReplacement( |
| 481 PrerenderContents* replacement) { |
| 482 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 483 OnPrerenderCreatedMatchCompleteReplacement(this, |
| 484 replacement)); |
| 485 } |
| 486 |
| 503 void PrerenderContents::DidUpdateFaviconURL( | 487 void PrerenderContents::DidUpdateFaviconURL( |
| 504 int32 page_id, | 488 int32 page_id, |
| 505 const std::vector<content::FaviconURL>& urls) { | 489 const std::vector<content::FaviconURL>& urls) { |
| 506 VLOG(1) << "PrerenderContents::OnUpdateFaviconURL" << icon_url_; | 490 VLOG(1) << "PrerenderContents::OnUpdateFaviconURL" << icon_url_; |
| 507 for (std::vector<content::FaviconURL>::const_iterator it = urls.begin(); | 491 for (std::vector<content::FaviconURL>::const_iterator it = urls.begin(); |
| 508 it != urls.end(); ++it) { | 492 it != urls.end(); ++it) { |
| 509 if (it->icon_type == content::FaviconURL::FAVICON) { | 493 if (it->icon_type == content::FaviconURL::FAVICON) { |
| 510 icon_url_ = it->icon_url; | 494 icon_url_ = it->icon_url; |
| 511 VLOG(1) << icon_url_; | 495 VLOG(1) << icon_url_; |
| 512 return; | 496 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 527 Destroy(FINAL_STATUS_HTTPS); | 511 Destroy(FINAL_STATUS_HTTPS); |
| 528 return false; | 512 return false; |
| 529 } | 513 } |
| 530 if (match_complete_status_ != MATCH_COMPLETE_REPLACEMENT_PENDING && | 514 if (match_complete_status_ != MATCH_COMPLETE_REPLACEMENT_PENDING && |
| 531 prerender_manager_->HasRecentlyBeenNavigatedTo(origin(), url)) { | 515 prerender_manager_->HasRecentlyBeenNavigatedTo(origin(), url)) { |
| 532 Destroy(FINAL_STATUS_RECENTLY_VISITED); | 516 Destroy(FINAL_STATUS_RECENTLY_VISITED); |
| 533 return false; | 517 return false; |
| 534 } | 518 } |
| 535 | 519 |
| 536 alias_urls_.push_back(url); | 520 alias_urls_.push_back(url); |
| 537 InformRenderProcessAboutPrerender(url, true, creator_child_id_); | 521 NotifyPrerenderAddAlias(url); |
| 538 return true; | 522 return true; |
| 539 } | 523 } |
| 540 | 524 |
| 541 bool PrerenderContents::Matches( | 525 bool PrerenderContents::Matches( |
| 542 const GURL& url, | 526 const GURL& url, |
| 543 const SessionStorageNamespace* session_storage_namespace) const { | 527 const SessionStorageNamespace* session_storage_namespace) const { |
| 544 DCHECK(child_id_ == -1 || session_storage_namespace); | 528 DCHECK(child_id_ == -1 || session_storage_namespace); |
| 545 if (session_storage_namespace && | 529 if (session_storage_namespace && |
| 546 session_storage_namespace_id_ != session_storage_namespace->id()) | 530 session_storage_namespace_id_ != session_storage_namespace->id()) |
| 547 return false; | 531 return false; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 565 |
| 582 void PrerenderContents::DidFinishLoad(int64 frame_id, | 566 void PrerenderContents::DidFinishLoad(int64 frame_id, |
| 583 const GURL& validated_url, | 567 const GURL& validated_url, |
| 584 bool is_main_frame, | 568 bool is_main_frame, |
| 585 RenderViewHost* render_view_host) { | 569 RenderViewHost* render_view_host) { |
| 586 if (is_main_frame) | 570 if (is_main_frame) |
| 587 has_finished_loading_ = true; | 571 has_finished_loading_ = true; |
| 588 } | 572 } |
| 589 | 573 |
| 590 void PrerenderContents::Destroy(FinalStatus final_status) { | 574 void PrerenderContents::Destroy(FinalStatus final_status) { |
| 575 DCHECK_NE(final_status, FINAL_STATUS_USED); |
| 576 |
| 591 if (prerendering_has_been_cancelled_) | 577 if (prerendering_has_been_cancelled_) |
| 592 return; | 578 return; |
| 593 | 579 |
| 594 if (child_id_ != -1 && route_id_ != -1) { | 580 if (child_id_ != -1 && route_id_ != -1) { |
| 595 // Cancel the prerender in the PrerenderTracker. This is needed | 581 // Cancel the prerender in the PrerenderTracker. This is needed |
| 596 // because destroy may be called directly from the UI thread without calling | 582 // because destroy may be called directly from the UI thread without calling |
| 597 // TryCancel(). This is difficult to completely avoid, since prerendering | 583 // TryCancel(). This is difficult to completely avoid, since prerendering |
| 598 // can be cancelled before a RenderView is created. | 584 // can be cancelled before a RenderView is created. |
| 599 bool is_cancelled = prerender_manager()->prerender_tracker()->TryCancel( | 585 bool is_cancelled = prerender_manager()->prerender_tracker()->TryCancel( |
| 600 child_id_, route_id_, final_status); | 586 child_id_, route_id_, final_status); |
| 601 CHECK(is_cancelled); | 587 CHECK(is_cancelled); |
| 602 | 588 |
| 603 // A different final status may have been set already from another thread. | 589 // A different final status may have been set already from another thread. |
| 604 // If so, use it instead. | 590 // If so, use it instead. |
| 605 if (!prerender_manager()->prerender_tracker()-> | 591 if (!prerender_manager()->prerender_tracker()-> |
| 606 GetFinalStatus(child_id_, route_id_, &final_status)) { | 592 GetFinalStatus(child_id_, route_id_, &final_status)) { |
| 607 NOTREACHED(); | 593 NOTREACHED(); |
| 608 } | 594 } |
| 609 } | 595 } |
| 610 SetFinalStatus(final_status); | 596 SetFinalStatus(final_status); |
| 611 | 597 |
| 612 prerendering_has_been_cancelled_ = true; | 598 prerendering_has_been_cancelled_ = true; |
| 613 prerender_manager_->AddToHistory(this); | 599 prerender_manager_->AddToHistory(this); |
| 614 prerender_manager_->MoveEntryToPendingDelete(this, final_status); | 600 prerender_manager_->MoveEntryToPendingDelete(this, final_status); |
| 615 | 601 |
| 602 if (!prerender_manager_->IsControlGroup(experiment_id()) && |
| 603 (prerendering_has_started() || |
| 604 match_complete_status() == MATCH_COMPLETE_REPLACEMENT)) { |
| 605 NotifyPrerenderStop(); |
| 606 } |
| 607 |
| 616 // We may destroy the PrerenderContents before we have initialized the | 608 // We may destroy the PrerenderContents before we have initialized the |
| 617 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 609 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
| 618 // avoid any more messages being sent. | 610 // avoid any more messages being sent. |
| 619 if (render_view_host_observer_) | 611 if (render_view_host_observer_) |
| 620 render_view_host_observer_->set_prerender_contents(NULL); | 612 render_view_host_observer_->set_prerender_contents(NULL); |
| 621 } | 613 } |
| 622 | 614 |
| 623 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { | 615 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { |
| 624 if (process_metrics_.get() == NULL) { | 616 if (process_metrics_.get() == NULL) { |
| 625 // 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 685 |
| 694 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 686 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
| 695 if (!prerender_contents_) | 687 if (!prerender_contents_) |
| 696 return false; | 688 return false; |
| 697 return (prerender_contents_->GetSiteInstance() != | 689 return (prerender_contents_->GetSiteInstance() != |
| 698 prerender_contents_->GetPendingSiteInstance()); | 690 prerender_contents_->GetPendingSiteInstance()); |
| 699 } | 691 } |
| 700 | 692 |
| 701 | 693 |
| 702 } // namespace prerender | 694 } // namespace prerender |
| OLD | NEW |