Chromium Code Reviews| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 return nullptr; | 228 return nullptr; |
| 229 if (origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN && | 229 if (origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN && |
| 230 source_web_contents->GetURL().host_piece() == url.host_piece()) { | 230 source_web_contents->GetURL().host_piece() == url.host_piece()) { |
| 231 origin = ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN; | 231 origin = ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN; |
| 232 } | 232 } |
| 233 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 233 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
| 234 session_storage_namespace = | 234 session_storage_namespace = |
| 235 source_web_contents->GetController() | 235 source_web_contents->GetController() |
| 236 .GetDefaultSessionStorageNamespace(); | 236 .GetDefaultSessionStorageNamespace(); |
| 237 } | 237 } |
| 238 | 238 return AddPrerender( |
| 239 return AddPrerender(origin, url, referrer, size, session_storage_namespace); | 239 origin, url, referrer, gfx::Rect(size), session_storage_namespace); |
|
mmenke
2016/08/19 15:22:29
Need to include the header for gfx::Rect (Hrm...no
Yusuf
2016/08/19 17:20:33
Done.
| |
| 240 } | 240 } |
| 241 | 241 |
| 242 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox( | 242 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox( |
| 243 const GURL& url, | 243 const GURL& url, |
| 244 SessionStorageNamespace* session_storage_namespace, | 244 SessionStorageNamespace* session_storage_namespace, |
| 245 const gfx::Size& size) { | 245 const gfx::Size& size) { |
| 246 if (!IsOmniboxEnabled(profile_)) | 246 if (!IsOmniboxEnabled(profile_)) |
| 247 return nullptr; | 247 return nullptr; |
| 248 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, | 248 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), gfx::Rect(size), |
| 249 session_storage_namespace); | 249 session_storage_namespace); |
| 250 } | 250 } |
| 251 | 251 |
| 252 std::unique_ptr<PrerenderHandle> | 252 std::unique_ptr<PrerenderHandle> |
| 253 PrerenderManager::AddPrerenderFromExternalRequest( | 253 PrerenderManager::AddPrerenderFromExternalRequest( |
| 254 const GURL& url, | 254 const GURL& url, |
| 255 const content::Referrer& referrer, | 255 const content::Referrer& referrer, |
| 256 SessionStorageNamespace* session_storage_namespace, | 256 SessionStorageNamespace* session_storage_namespace, |
| 257 const gfx::Size& size) { | 257 const gfx::Rect& bounds) { |
| 258 return AddPrerender( | 258 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, |
| 259 ORIGIN_EXTERNAL_REQUEST, url, referrer, size, session_storage_namespace); | 259 bounds, session_storage_namespace); |
| 260 } | 260 } |
| 261 | 261 |
| 262 std::unique_ptr<PrerenderHandle> | 262 std::unique_ptr<PrerenderHandle> |
| 263 PrerenderManager::AddPrerenderOnCellularFromExternalRequest( | 263 PrerenderManager::AddPrerenderOnCellularFromExternalRequest( |
| 264 const GURL& url, | 264 const GURL& url, |
| 265 const content::Referrer& referrer, | 265 const content::Referrer& referrer, |
| 266 SessionStorageNamespace* session_storage_namespace, | 266 SessionStorageNamespace* session_storage_namespace, |
| 267 const gfx::Size& size) { | 267 const gfx::Rect& bounds) { |
| 268 return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR, | 268 return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR, |
| 269 url, | 269 url, |
| 270 referrer, | 270 referrer, |
| 271 size, | 271 bounds, |
| 272 session_storage_namespace); | 272 session_storage_namespace); |
| 273 } | 273 } |
| 274 | 274 |
| 275 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant( | 275 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant( |
| 276 const GURL& url, | 276 const GURL& url, |
| 277 content::SessionStorageNamespace* session_storage_namespace, | 277 content::SessionStorageNamespace* session_storage_namespace, |
| 278 const gfx::Size& size) { | 278 const gfx::Size& size) { |
| 279 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, | 279 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), gfx::Rect(size), |
| 280 session_storage_namespace); | 280 session_storage_namespace); |
| 281 } | 281 } |
| 282 | 282 |
| 283 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForOffline( | 283 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForOffline( |
| 284 const GURL& url, | 284 const GURL& url, |
| 285 content::SessionStorageNamespace* session_storage_namespace, | 285 content::SessionStorageNamespace* session_storage_namespace, |
| 286 const gfx::Size& size) { | 286 const gfx::Size& size) { |
| 287 return AddPrerender(ORIGIN_OFFLINE, url, content::Referrer(), size, | 287 return AddPrerender(ORIGIN_OFFLINE, url, content::Referrer(), gfx::Rect(size), |
| 288 session_storage_namespace); | 288 session_storage_namespace); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void PrerenderManager::CancelAllPrerenders() { | 291 void PrerenderManager::CancelAllPrerenders() { |
| 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 293 while (!active_prerenders_.empty()) { | 293 while (!active_prerenders_.empty()) { |
| 294 PrerenderContents* prerender_contents = | 294 PrerenderContents* prerender_contents = |
| 295 active_prerenders_.front()->contents(); | 295 active_prerenders_.front()->contents(); |
| 296 prerender_contents->Destroy(FINAL_STATUS_CANCELLED); | 296 prerender_contents->Destroy(FINAL_STATUS_CANCELLED); |
| 297 } | 297 } |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 } | 846 } |
| 847 | 847 |
| 848 bool PrerenderManager::IsLowEndDevice() const { | 848 bool PrerenderManager::IsLowEndDevice() const { |
| 849 return base::SysInfo::IsLowEndDevice(); | 849 return base::SysInfo::IsLowEndDevice(); |
| 850 } | 850 } |
| 851 | 851 |
| 852 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender( | 852 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender( |
| 853 Origin origin, | 853 Origin origin, |
| 854 const GURL& url_arg, | 854 const GURL& url_arg, |
| 855 const content::Referrer& referrer, | 855 const content::Referrer& referrer, |
| 856 const gfx::Size& size, | 856 const gfx::Rect& bounds, |
| 857 SessionStorageNamespace* session_storage_namespace) { | 857 SessionStorageNamespace* session_storage_namespace) { |
| 858 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 858 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 859 | 859 |
| 860 // Allow only Requests for offlining on low end devices, the lifetime of | 860 // Allow only Requests for offlining on low end devices, the lifetime of |
| 861 // those prerenders is managed by the offliner. | 861 // those prerenders is managed by the offliner. |
| 862 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) | 862 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) |
| 863 return nullptr; | 863 return nullptr; |
| 864 | 864 |
| 865 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || | 865 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
| 866 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && | 866 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 | 947 |
| 948 histograms_->RecordPrerenderStarted(origin); | 948 histograms_->RecordPrerenderStarted(origin); |
| 949 DCHECK(!prerender_contents_ptr->prerendering_has_started()); | 949 DCHECK(!prerender_contents_ptr->prerendering_has_started()); |
| 950 | 950 |
| 951 std::unique_ptr<PrerenderHandle> prerender_handle = | 951 std::unique_ptr<PrerenderHandle> prerender_handle = |
| 952 base::WrapUnique(new PrerenderHandle(active_prerenders_.back().get())); | 952 base::WrapUnique(new PrerenderHandle(active_prerenders_.back().get())); |
| 953 SortActivePrerenders(); | 953 SortActivePrerenders(); |
| 954 | 954 |
| 955 last_prerender_start_time_ = GetCurrentTimeTicks(); | 955 last_prerender_start_time_ = GetCurrentTimeTicks(); |
| 956 | 956 |
| 957 gfx::Size contents_size = | 957 gfx::Rect contents_bounds = |
| 958 size.IsEmpty() ? config_.default_tab_bounds.size() : size; | 958 bounds.IsEmpty() ? config_.default_tab_bounds : bounds; |
| 959 | 959 |
| 960 prerender_contents_ptr->StartPrerendering(contents_size, | 960 prerender_contents_ptr->StartPrerendering(contents_bounds, |
| 961 session_storage_namespace); | 961 session_storage_namespace); |
| 962 | 962 |
| 963 DCHECK(IsControlGroup() || | 963 DCHECK(IsControlGroup() || |
| 964 prerender_contents_ptr->prerendering_has_started()); | 964 prerender_contents_ptr->prerendering_has_started()); |
| 965 | 965 |
| 966 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) | 966 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) |
| 967 histograms_->RecordConcurrency(active_prerenders_.size()); | 967 histograms_->RecordConcurrency(active_prerenders_.size()); |
| 968 | 968 |
| 969 StartSchedulingPeriodicCleanups(); | 969 StartSchedulingPeriodicCleanups(); |
| 970 return prerender_handle; | 970 return prerender_handle; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 DCHECK_EQ(1u, erased); | 1291 DCHECK_EQ(1u, erased); |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1294 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
| 1295 PrerenderContents::Factory* prerender_contents_factory) { | 1295 PrerenderContents::Factory* prerender_contents_factory) { |
| 1296 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1296 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1297 prerender_contents_factory_.reset(prerender_contents_factory); | 1297 prerender_contents_factory_.reset(prerender_contents_factory); |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 } // namespace prerender | 1300 } // namespace prerender |
| OLD | NEW |