| 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_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 if (prerendering_status != NetworkPredictionStatus::ENABLED) { | 934 if (prerendering_status != NetworkPredictionStatus::ENABLED) { |
| 935 FinalStatus final_status = | 935 FinalStatus final_status = |
| 936 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK | 936 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK |
| 937 ? FINAL_STATUS_CELLULAR_NETWORK | 937 ? FINAL_STATUS_CELLULAR_NETWORK |
| 938 : FINAL_STATUS_PRERENDERING_DISABLED; | 938 : FINAL_STATUS_PRERENDERING_DISABLED; |
| 939 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, | 939 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, |
| 940 final_status); | 940 final_status); |
| 941 return nullptr; | 941 return nullptr; |
| 942 } | 942 } |
| 943 | 943 |
| 944 if (PrerenderData* preexisting_prerender_data = |
| 945 FindPrerenderData(url, session_storage_namespace)) { |
| 946 RecordFinalStatusWithoutCreatingPrerenderContents( |
| 947 url, origin, FINAL_STATUS_DUPLICATE); |
| 948 return base::WrapUnique(new PrerenderHandle(preexisting_prerender_data)); |
| 949 } |
| 950 |
| 944 if (IsNoStatePrefetch(origin)) { | 951 if (IsNoStatePrefetch(origin)) { |
| 945 base::TimeDelta prefetch_age; | 952 base::TimeDelta prefetch_age; |
| 946 GetPrefetchInformation(url, &prefetch_age, nullptr); | 953 GetPrefetchInformation(url, &prefetch_age, nullptr); |
| 947 if (!prefetch_age.is_zero() && | 954 if (!prefetch_age.is_zero() && |
| 948 prefetch_age < | 955 prefetch_age < |
| 949 base::TimeDelta::FromMinutes(net::HttpCache::kPrefetchReuseMins)) { | 956 base::TimeDelta::FromMinutes(net::HttpCache::kPrefetchReuseMins)) { |
| 950 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, | 957 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, |
| 951 FINAL_STATUS_DUPLICATE); | 958 FINAL_STATUS_DUPLICATE); |
| 952 return nullptr; | 959 return nullptr; |
| 953 } | 960 } |
| 954 } else if (PrerenderData* preexisting_prerender_data = | |
| 955 FindPrerenderData(url, session_storage_namespace)) { | |
| 956 RecordFinalStatusWithoutCreatingPrerenderContents( | |
| 957 url, origin, FINAL_STATUS_DUPLICATE); | |
| 958 return base::WrapUnique(new PrerenderHandle(preexisting_prerender_data)); | |
| 959 } | 961 } |
| 960 | 962 |
| 961 // Do not prerender if there are too many render processes, and we would | 963 // Do not prerender if there are too many render processes, and we would |
| 962 // have to use an existing one. We do not want prerendering to happen in | 964 // have to use an existing one. We do not want prerendering to happen in |
| 963 // a shared process, so that we can always reliably lower the CPU | 965 // a shared process, so that we can always reliably lower the CPU |
| 964 // priority for prerendering. | 966 // priority for prerendering. |
| 965 // In single-process mode, ShouldTryToUseExistingProcessHost() always returns | 967 // In single-process mode, ShouldTryToUseExistingProcessHost() always returns |
| 966 // true, so that case needs to be explicitly checked for. | 968 // true, so that case needs to be explicitly checked for. |
| 967 // TODO(tburkard): Figure out how to cancel prerendering in the opposite | 969 // TODO(tburkard): Figure out how to cancel prerendering in the opposite |
| 968 // case, when a new tab is added to a process used for prerendering. | 970 // case, when a new tab is added to a process used for prerendering. |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 return weak_factory_.GetWeakPtr(); | 1439 return weak_factory_.GetWeakPtr(); |
| 1438 } | 1440 } |
| 1439 | 1441 |
| 1440 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1442 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
| 1441 PrerenderContents::Factory* prerender_contents_factory) { | 1443 PrerenderContents::Factory* prerender_contents_factory) { |
| 1442 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1444 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1443 prerender_contents_factory_.reset(prerender_contents_factory); | 1445 prerender_contents_factory_.reset(prerender_contents_factory); |
| 1444 } | 1446 } |
| 1445 | 1447 |
| 1446 } // namespace prerender | 1448 } // namespace prerender |
| OLD | NEW |