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" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "content/browser/renderer_host/resource_request_details.h" | 26 #include "content/browser/renderer_host/resource_request_details.h" |
| 27 #include "content/browser/site_instance.h" | 27 #include "content/browser/site_instance.h" |
| 28 #include "content/common/notification_service.h" | 28 #include "content/common/notification_service.h" |
| 29 #include "content/common/view_messages.h" | 29 #include "content/common/view_messages.h" |
| 30 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
| 31 | 31 |
| 32 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
| 33 #include "chrome/browser/mach_broker_mac.h" | 33 #include "chrome/browser/mach_broker_mac.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #include <algorithm> | |
|
mmenke
2011/04/22 18:24:45
This should go up top, above #include "base/proces
dominich
2011/04/22 18:35:15
Done.
| |
| 37 | |
| 36 namespace prerender { | 38 namespace prerender { |
| 37 | 39 |
| 40 // Compares URLs ignoring any ref for the purposes of matching URLs when | |
| 41 // prerendering. | |
| 42 struct PrerenderUrlPredicate { | |
| 43 explicit PrerenderUrlPredicate(const GURL& url) | |
| 44 : url_(url) { | |
| 45 } | |
| 46 | |
| 47 bool operator()(const GURL& url) const { | |
| 48 return url.host() == url_.host() && | |
|
mmenke
2011/04/22 18:24:45
Should probably have scheme in here to reduce the
dominich
2011/04/22 18:35:15
Done.
| |
| 49 url.port() == url_.port() && | |
| 50 url.path() == url_.path() && | |
| 51 url.query() == url_.query(); | |
| 52 } | |
| 53 GURL url_; | |
| 54 }; | |
| 55 | |
| 38 void AddChildRoutePair(ResourceDispatcherHost* rdh, | 56 void AddChildRoutePair(ResourceDispatcherHost* rdh, |
| 39 int child_id, int route_id) { | 57 int child_id, int route_id) { |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 41 rdh->AddPrerenderChildRoutePair(child_id, route_id); | 59 rdh->AddPrerenderChildRoutePair(child_id, route_id); |
| 42 } | 60 } |
| 43 | 61 |
| 44 void RemoveChildRoutePair(ResourceDispatcherHost* rdh, | 62 void RemoveChildRoutePair(ResourceDispatcherHost* rdh, |
| 45 int child_id, int route_id) { | 63 int child_id, int route_id) { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 47 rdh->RemovePrerenderChildRoutePair(child_id, route_id); | 65 rdh->RemovePrerenderChildRoutePair(child_id, route_id); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 } | 502 } |
| 485 | 503 |
| 486 bool PrerenderContents::AddAliasURL(const GURL& url) { | 504 bool PrerenderContents::AddAliasURL(const GURL& url) { |
| 487 if (!url.SchemeIs("http")) | 505 if (!url.SchemeIs("http")) |
| 488 return false; | 506 return false; |
| 489 alias_urls_.push_back(url); | 507 alias_urls_.push_back(url); |
| 490 return true; | 508 return true; |
| 491 } | 509 } |
| 492 | 510 |
| 493 bool PrerenderContents::MatchesURL(const GURL& url) const { | 511 bool PrerenderContents::MatchesURL(const GURL& url) const { |
| 494 return std::find(alias_urls_.begin(), alias_urls_.end(), url) | 512 return std::find_if(alias_urls_.begin(), |
| 495 != alias_urls_.end(); | 513 alias_urls_.end(), |
| 514 PrerenderUrlPredicate(url)) != alias_urls_.end(); | |
| 496 } | 515 } |
| 497 | 516 |
| 498 void PrerenderContents::DidStopLoading() { | 517 void PrerenderContents::DidStopLoading() { |
| 499 has_stopped_loading_ = true; | 518 has_stopped_loading_ = true; |
| 500 } | 519 } |
| 501 | 520 |
| 502 void PrerenderContents::Destroy(FinalStatus final_status) { | 521 void PrerenderContents::Destroy(FinalStatus final_status) { |
| 503 prerender_manager_->RemoveEntry(this); | 522 prerender_manager_->RemoveEntry(this); |
| 504 set_final_status(final_status); | 523 set_final_status(final_status); |
| 505 delete this; | 524 delete this; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 return; | 560 return; |
| 542 | 561 |
| 543 size_t private_bytes, shared_bytes; | 562 size_t private_bytes, shared_bytes; |
| 544 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { | 563 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { |
| 545 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) | 564 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) |
| 546 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); | 565 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); |
| 547 } | 566 } |
| 548 } | 567 } |
| 549 | 568 |
| 550 } // namespace prerender | 569 } // namespace prerender |
| OLD | NEW |