| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
| 22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/sys_info.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 25 #include "base/timer/elapsed_timer.h" | 26 #include "base/timer/elapsed_timer.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
| 28 #include "chrome/browser/net/prediction_options.h" | 29 #include "chrome/browser/net/prediction_options.h" |
| 29 #include "chrome/browser/prerender/prerender_contents.h" | 30 #include "chrome/browser/prerender/prerender_contents.h" |
| 30 #include "chrome/browser/prerender/prerender_field_trial.h" | 31 #include "chrome/browser/prerender/prerender_field_trial.h" |
| 31 #include "chrome/browser/prerender/prerender_final_status.h" | 32 #include "chrome/browser/prerender/prerender_final_status.h" |
| 32 #include "chrome/browser/prerender/prerender_handle.h" | 33 #include "chrome/browser/prerender/prerender_handle.h" |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 PrerenderData* data = it->get(); | 840 PrerenderData* data = it->get(); |
| 840 if (data == prerender_data) { | 841 if (data == prerender_data) { |
| 841 data->set_expiry_time(std::min(data->expiry_time(), | 842 data->set_expiry_time(std::min(data->expiry_time(), |
| 842 GetExpiryTimeForNavigatedAwayPrerender())); | 843 GetExpiryTimeForNavigatedAwayPrerender())); |
| 843 SortActivePrerenders(); | 844 SortActivePrerenders(); |
| 844 return; | 845 return; |
| 845 } | 846 } |
| 846 } | 847 } |
| 847 } | 848 } |
| 848 | 849 |
| 850 bool PrerenderManager::IsLowEndDevice() const { |
| 851 return base::SysInfo::IsLowEndDevice(); |
| 852 } |
| 853 |
| 849 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender( | 854 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender( |
| 850 Origin origin, | 855 Origin origin, |
| 851 const GURL& url_arg, | 856 const GURL& url_arg, |
| 852 const content::Referrer& referrer, | 857 const content::Referrer& referrer, |
| 853 const gfx::Size& size, | 858 const gfx::Size& size, |
| 854 SessionStorageNamespace* session_storage_namespace) { | 859 SessionStorageNamespace* session_storage_namespace) { |
| 855 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 860 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 856 | 861 |
| 862 // Allow only Requests for offlining on low end devices, the lifetime of |
| 863 // those prerenders is managed by the offliner. |
| 864 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) |
| 865 return nullptr; |
| 866 |
| 857 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || | 867 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
| 858 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && | 868 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && |
| 859 IsGoogleSearchResultURL(referrer.url)) { | 869 IsGoogleSearchResultURL(referrer.url)) { |
| 860 origin = ORIGIN_GWS_PRERENDER; | 870 origin = ORIGIN_GWS_PRERENDER; |
| 861 } | 871 } |
| 862 | 872 |
| 863 GURL url = url_arg; | 873 GURL url = url_arg; |
| 864 GURL alias_url; | 874 GURL alias_url; |
| 865 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) | 875 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) |
| 866 url = alias_url; | 876 url = alias_url; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 DCHECK_EQ(1u, erased); | 1293 DCHECK_EQ(1u, erased); |
| 1284 } | 1294 } |
| 1285 | 1295 |
| 1286 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1296 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
| 1287 PrerenderContents::Factory* prerender_contents_factory) { | 1297 PrerenderContents::Factory* prerender_contents_factory) { |
| 1288 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1298 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1289 prerender_contents_factory_.reset(prerender_contents_factory); | 1299 prerender_contents_factory_.reset(prerender_contents_factory); |
| 1290 } | 1300 } |
| 1291 | 1301 |
| 1292 } // namespace prerender | 1302 } // namespace prerender |
| OLD | NEW |