Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/browser/prerender/prerender_manager.cc

Issue 2259533003: Use bounds instead of size for prerender requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments nit Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "content/public/browser/render_frame_host.h" 52 #include "content/public/browser/render_frame_host.h"
53 #include "content/public/browser/render_process_host.h" 53 #include "content/public/browser/render_process_host.h"
54 #include "content/public/browser/render_view_host.h" 54 #include "content/public/browser/render_view_host.h"
55 #include "content/public/browser/resource_request_details.h" 55 #include "content/public/browser/resource_request_details.h"
56 #include "content/public/browser/session_storage_namespace.h" 56 #include "content/public/browser/session_storage_namespace.h"
57 #include "content/public/browser/site_instance.h" 57 #include "content/public/browser/site_instance.h"
58 #include "content/public/browser/web_contents.h" 58 #include "content/public/browser/web_contents.h"
59 #include "content/public/browser/web_contents_delegate.h" 59 #include "content/public/browser/web_contents_delegate.h"
60 #include "content/public/common/url_constants.h" 60 #include "content/public/common/url_constants.h"
61 #include "extensions/common/constants.h" 61 #include "extensions/common/constants.h"
62 #include "ui/gfx/geometry/rect.h"
62 63
63 using content::BrowserThread; 64 using content::BrowserThread;
64 using content::RenderViewHost; 65 using content::RenderViewHost;
65 using content::SessionStorageNamespace; 66 using content::SessionStorageNamespace;
66 using content::WebContents; 67 using content::WebContents;
67 using namespace chrome_browser_net; 68 using namespace chrome_browser_net;
68 69
69 namespace prerender { 70 namespace prerender {
70 71
71 namespace { 72 namespace {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 return nullptr; 229 return nullptr;
229 if (origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN && 230 if (origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN &&
230 source_web_contents->GetURL().host_piece() == url.host_piece()) { 231 source_web_contents->GetURL().host_piece() == url.host_piece()) {
231 origin = ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN; 232 origin = ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN;
232 } 233 }
233 // TODO(ajwong): This does not correctly handle storage for isolated apps. 234 // TODO(ajwong): This does not correctly handle storage for isolated apps.
234 session_storage_namespace = 235 session_storage_namespace =
235 source_web_contents->GetController() 236 source_web_contents->GetController()
236 .GetDefaultSessionStorageNamespace(); 237 .GetDefaultSessionStorageNamespace();
237 } 238 }
238 239 return AddPrerender(
239 return AddPrerender(origin, url, referrer, size, session_storage_namespace); 240 origin, url, referrer, gfx::Rect(size), session_storage_namespace);
240 } 241 }
241 242
242 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox( 243 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox(
243 const GURL& url, 244 const GURL& url,
244 SessionStorageNamespace* session_storage_namespace, 245 SessionStorageNamespace* session_storage_namespace,
245 const gfx::Size& size) { 246 const gfx::Size& size) {
246 if (!IsOmniboxEnabled(profile_)) 247 if (!IsOmniboxEnabled(profile_))
247 return nullptr; 248 return nullptr;
248 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, 249 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), gfx::Rect(size),
249 session_storage_namespace); 250 session_storage_namespace);
250 } 251 }
251 252
252 std::unique_ptr<PrerenderHandle> 253 std::unique_ptr<PrerenderHandle>
253 PrerenderManager::AddPrerenderFromExternalRequest( 254 PrerenderManager::AddPrerenderFromExternalRequest(
254 const GURL& url, 255 const GURL& url,
255 const content::Referrer& referrer, 256 const content::Referrer& referrer,
256 SessionStorageNamespace* session_storage_namespace, 257 SessionStorageNamespace* session_storage_namespace,
257 const gfx::Size& size) { 258 const gfx::Rect& bounds) {
258 return AddPrerender( 259 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer,
259 ORIGIN_EXTERNAL_REQUEST, url, referrer, size, session_storage_namespace); 260 bounds, session_storage_namespace);
260 } 261 }
261 262
262 std::unique_ptr<PrerenderHandle> 263 std::unique_ptr<PrerenderHandle>
263 PrerenderManager::AddPrerenderOnCellularFromExternalRequest( 264 PrerenderManager::AddPrerenderOnCellularFromExternalRequest(
264 const GURL& url, 265 const GURL& url,
265 const content::Referrer& referrer, 266 const content::Referrer& referrer,
266 SessionStorageNamespace* session_storage_namespace, 267 SessionStorageNamespace* session_storage_namespace,
267 const gfx::Size& size) { 268 const gfx::Rect& bounds) {
268 return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR, 269 return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR,
269 url, 270 url,
270 referrer, 271 referrer,
271 size, 272 bounds,
272 session_storage_namespace); 273 session_storage_namespace);
273 } 274 }
274 275
275 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant( 276 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant(
276 const GURL& url, 277 const GURL& url,
277 content::SessionStorageNamespace* session_storage_namespace, 278 content::SessionStorageNamespace* session_storage_namespace,
278 const gfx::Size& size) { 279 const gfx::Size& size) {
279 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, 280 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), gfx::Rect(size),
280 session_storage_namespace); 281 session_storage_namespace);
281 } 282 }
282 283
283 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForOffline( 284 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForOffline(
284 const GURL& url, 285 const GURL& url,
285 content::SessionStorageNamespace* session_storage_namespace, 286 content::SessionStorageNamespace* session_storage_namespace,
286 const gfx::Size& size) { 287 const gfx::Size& size) {
287 return AddPrerender(ORIGIN_OFFLINE, url, content::Referrer(), size, 288 return AddPrerender(ORIGIN_OFFLINE, url, content::Referrer(), gfx::Rect(size),
288 session_storage_namespace); 289 session_storage_namespace);
289 } 290 }
290 291
291 void PrerenderManager::CancelAllPrerenders() { 292 void PrerenderManager::CancelAllPrerenders() {
292 DCHECK_CURRENTLY_ON(BrowserThread::UI); 293 DCHECK_CURRENTLY_ON(BrowserThread::UI);
293 while (!active_prerenders_.empty()) { 294 while (!active_prerenders_.empty()) {
294 PrerenderContents* prerender_contents = 295 PrerenderContents* prerender_contents =
295 active_prerenders_.front()->contents(); 296 active_prerenders_.front()->contents();
296 prerender_contents->Destroy(FINAL_STATUS_CANCELLED); 297 prerender_contents->Destroy(FINAL_STATUS_CANCELLED);
297 } 298 }
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 847 }
847 848
848 bool PrerenderManager::IsLowEndDevice() const { 849 bool PrerenderManager::IsLowEndDevice() const {
849 return base::SysInfo::IsLowEndDevice(); 850 return base::SysInfo::IsLowEndDevice();
850 } 851 }
851 852
852 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender( 853 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender(
853 Origin origin, 854 Origin origin,
854 const GURL& url_arg, 855 const GURL& url_arg,
855 const content::Referrer& referrer, 856 const content::Referrer& referrer,
856 const gfx::Size& size, 857 const gfx::Rect& bounds,
857 SessionStorageNamespace* session_storage_namespace) { 858 SessionStorageNamespace* session_storage_namespace) {
858 DCHECK_CURRENTLY_ON(BrowserThread::UI); 859 DCHECK_CURRENTLY_ON(BrowserThread::UI);
859 860
860 // Allow only Requests for offlining on low end devices, the lifetime of 861 // Allow only Requests for offlining on low end devices, the lifetime of
861 // those prerenders is managed by the offliner. 862 // those prerenders is managed by the offliner.
862 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) 863 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE)
863 return nullptr; 864 return nullptr;
864 865
865 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || 866 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN ||
866 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && 867 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) &&
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 948
948 histograms_->RecordPrerenderStarted(origin); 949 histograms_->RecordPrerenderStarted(origin);
949 DCHECK(!prerender_contents_ptr->prerendering_has_started()); 950 DCHECK(!prerender_contents_ptr->prerendering_has_started());
950 951
951 std::unique_ptr<PrerenderHandle> prerender_handle = 952 std::unique_ptr<PrerenderHandle> prerender_handle =
952 base::WrapUnique(new PrerenderHandle(active_prerenders_.back().get())); 953 base::WrapUnique(new PrerenderHandle(active_prerenders_.back().get()));
953 SortActivePrerenders(); 954 SortActivePrerenders();
954 955
955 last_prerender_start_time_ = GetCurrentTimeTicks(); 956 last_prerender_start_time_ = GetCurrentTimeTicks();
956 957
957 gfx::Size contents_size = 958 gfx::Rect contents_bounds =
958 size.IsEmpty() ? config_.default_tab_bounds.size() : size; 959 bounds.IsEmpty() ? config_.default_tab_bounds : bounds;
959 960
960 prerender_contents_ptr->StartPrerendering(contents_size, 961 prerender_contents_ptr->StartPrerendering(contents_bounds,
961 session_storage_namespace); 962 session_storage_namespace);
962 963
963 DCHECK(IsControlGroup() || 964 DCHECK(IsControlGroup() ||
964 prerender_contents_ptr->prerendering_has_started()); 965 prerender_contents_ptr->prerendering_has_started());
965 966
966 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP) 967 if (GetMode() == PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP)
967 histograms_->RecordConcurrency(active_prerenders_.size()); 968 histograms_->RecordConcurrency(active_prerenders_.size());
968 969
969 StartSchedulingPeriodicCleanups(); 970 StartSchedulingPeriodicCleanups();
970 return prerender_handle; 971 return prerender_handle;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 DCHECK_EQ(1u, erased); 1292 DCHECK_EQ(1u, erased);
1292 } 1293 }
1293 1294
1294 void PrerenderManager::SetPrerenderContentsFactoryForTest( 1295 void PrerenderManager::SetPrerenderContentsFactoryForTest(
1295 PrerenderContents::Factory* prerender_contents_factory) { 1296 PrerenderContents::Factory* prerender_contents_factory) {
1296 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1297 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1297 prerender_contents_factory_.reset(prerender_contents_factory); 1298 prerender_contents_factory_.reset(prerender_contents_factory);
1298 } 1299 }
1299 1300
1300 } // namespace prerender 1301 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | chrome/browser/prerender/prerender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698