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

Side by Side Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc

Issue 10416002: Seculative resource prefetching for URLs CL. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Resolving conflicts. Created 8 years, 5 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/renderer_host/chrome_resource_dispatcher_host_delegate. h" 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/content_settings/host_content_settings_map.h" 12 #include "chrome/browser/content_settings/host_content_settings_map.h"
13 #include "chrome/browser/download/download_request_limiter.h" 13 #include "chrome/browser/download/download_request_limiter.h"
14 #include "chrome/browser/download/download_resource_throttle.h" 14 #include "chrome/browser/download/download_resource_throttle.h"
15 #include "chrome/browser/download/download_util.h" 15 #include "chrome/browser/download/download_util.h"
16 #include "chrome/browser/extensions/user_script_listener.h" 16 #include "chrome/browser/extensions/user_script_listener.h"
17 #include "chrome/browser/external_protocol/external_protocol_handler.h" 17 #include "chrome/browser/external_protocol/external_protocol_handler.h"
18 #include "chrome/browser/google/google_util.h" 18 #include "chrome/browser/google/google_util.h"
19 #include "chrome/browser/instant/instant_loader.h" 19 #include "chrome/browser/instant/instant_loader.h"
20 #include "chrome/browser/net/load_timing_observer.h" 20 #include "chrome/browser/net/load_timing_observer.h"
21 #include "chrome/browser/net/resource_prefetch_predictor_observer.h"
21 #include "chrome/browser/prerender/prerender_manager.h" 22 #include "chrome/browser/prerender/prerender_manager.h"
22 #include "chrome/browser/prerender/prerender_tracker.h" 23 #include "chrome/browser/prerender/prerender_tracker.h"
23 #include "chrome/browser/profiles/profile_io_data.h" 24 #include "chrome/browser/profiles/profile_io_data.h"
24 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" 25 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h"
25 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" 26 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h"
26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
27 #include "chrome/browser/ui/auto_login_prompter.h" 28 #include "chrome/browser/ui/auto_login_prompter.h"
28 #include "chrome/browser/ui/login/login_prompt.h" 29 #include "chrome/browser/ui/login/login_prompt.h"
29 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 30 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
30 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #endif 143 #endif
143 144
144 AppendChromeMetricsHeaders(request, resource_context, resource_type); 145 AppendChromeMetricsHeaders(request, resource_context, resource_type);
145 146
146 AppendStandardResourceThrottles(request, 147 AppendStandardResourceThrottles(request,
147 resource_context, 148 resource_context,
148 child_id, 149 child_id,
149 route_id, 150 route_id,
150 resource_type, 151 resource_type,
151 throttles); 152 throttles);
153
154 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
155 if (io_data->resource_prefetch_predictor_observer())
156 io_data->resource_prefetch_predictor_observer()->OnRequestStarted(
157 request, resource_type, child_id, route_id);
152 } 158 }
153 159
154 void ChromeResourceDispatcherHostDelegate::DownloadStarting( 160 void ChromeResourceDispatcherHostDelegate::DownloadStarting(
155 net::URLRequest* request, 161 net::URLRequest* request,
156 content::ResourceContext* resource_context, 162 content::ResourceContext* resource_context,
157 int child_id, 163 int child_id,
158 int route_id, 164 int route_id,
159 int request_id, 165 int request_id,
160 bool is_content_initiated, 166 bool is_content_initiated,
161 ScopedVector<content::ResourceThrottle>* throttles) { 167 ScopedVector<content::ResourceThrottle>* throttles) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 319 }
314 320
315 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( 321 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource(
316 const GURL& url, const std::string& mime_type) { 322 const GURL& url, const std::string& mime_type) {
317 // Special-case user scripts to get downloaded instead of viewed. 323 // Special-case user scripts to get downloaded instead of viewed.
318 return UserScript::IsURLUserScript(url, mime_type); 324 return UserScript::IsURLUserScript(url, mime_type);
319 } 325 }
320 326
321 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( 327 void ChromeResourceDispatcherHostDelegate::OnResponseStarted(
322 net::URLRequest* request, 328 net::URLRequest* request,
329 content::ResourceContext* resource_context,
323 content::ResourceResponse* response, 330 content::ResourceResponse* response,
324 IPC::Sender* sender) { 331 IPC::Sender* sender) {
325 LoadTimingObserver::PopulateTimingInfo(request, response); 332 LoadTimingObserver::PopulateTimingInfo(request, response);
326 333
327 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 334 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
328 335
329 if (request->url().SchemeIsSecure()) { 336 if (request->url().SchemeIsSecure()) {
330 const net::URLRequestContext* context = request->context(); 337 const net::URLRequestContext* context = request->context();
331 net::TransportSecurityState* state = context->transport_security_state(); 338 net::TransportSecurityState* state = context->transport_security_state();
332 if (state) { 339 if (state) {
333 net::TransportSecurityState::DomainState domain_state; 340 net::TransportSecurityState::DomainState domain_state;
334 bool has_sni = net::SSLConfigService::IsSNIAvailable( 341 bool has_sni = net::SSLConfigService::IsSNIAvailable(
335 context->ssl_config_service()); 342 context->ssl_config_service());
336 if (state->GetDomainState( 343 if (state->GetDomainState(
337 request->url().host(), has_sni, &domain_state)) { 344 request->url().host(), has_sni, &domain_state)) {
338 sender->Send(new ChromeViewMsg_AddStrictSecurityHost( 345 sender->Send(new ChromeViewMsg_AddStrictSecurityHost(
339 info->GetRouteID(), request->url().host())); 346 info->GetRouteID(), request->url().host()));
340 } 347 }
341 } 348 }
342 } 349 }
343 350
344 // See if the response contains the X-Auto-Login header. If so, this was 351 // See if the response contains the X-Auto-Login header. If so, this was
345 // a request for a login page, and the server is allowing the browser to 352 // a request for a login page, and the server is allowing the browser to
346 // suggest auto-login, if available. 353 // suggest auto-login, if available.
347 AutoLoginPrompter::ShowInfoBarIfPossible(request, info->GetChildID(), 354 AutoLoginPrompter::ShowInfoBarIfPossible(request, info->GetChildID(),
348 info->GetRouteID()); 355 info->GetRouteID());
356
357 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
358 if (io_data->resource_prefetch_predictor_observer())
359 io_data->resource_prefetch_predictor_observer()->OnResponseStarted(request);
349 } 360 }
350 361
351 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( 362 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
352 net::URLRequest* request, 363 net::URLRequest* request,
364 content::ResourceContext* resource_context,
353 content::ResourceResponse* response) { 365 content::ResourceResponse* response) {
354 LoadTimingObserver::PopulateTimingInfo(request, response); 366 LoadTimingObserver::PopulateTimingInfo(request, response);
355 367
356 #if defined(ENABLE_ONE_CLICK_SIGNIN) 368 #if defined(ENABLE_ONE_CLICK_SIGNIN)
357 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 369 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
358 370
359 // See if the response contains the Google-Accounts-SignIn header. If so, 371 // See if the response contains the Google-Accounts-SignIn header. If so,
360 // then the user has just finished signing in, and the server is allowing the 372 // then the user has just finished signing in, and the server is allowing the
361 // browser to suggest connecting the user's profile to the account. 373 // browser to suggest connecting the user's profile to the account.
362 OneClickSigninHelper::ShowInfoBarIfPossible(request, info->GetChildID(), 374 OneClickSigninHelper::ShowInfoBarIfPossible(request, info->GetChildID(),
363 info->GetRouteID()); 375 info->GetRouteID());
364 #endif 376 #endif
377
378 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
379 if (io_data->resource_prefetch_predictor_observer())
380 io_data->resource_prefetch_predictor_observer()->OnRequestRedirected(
381 request);
365 } 382 }
366 383
367 void ChromeResourceDispatcherHostDelegate::OnFieldTrialGroupFinalized( 384 void ChromeResourceDispatcherHostDelegate::OnFieldTrialGroupFinalized(
368 const std::string& trial_name, 385 const std::string& trial_name,
369 const std::string& group_name) { 386 const std::string& group_name) {
370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
371 chrome_variations::ID new_id = 388 chrome_variations::ID new_id =
372 experiments_helper::GetGoogleVariationID(trial_name, group_name); 389 experiments_helper::GetGoogleVariationID(trial_name, group_name);
373 if (new_id == chrome_variations::kEmptyID) 390 if (new_id == chrome_variations::kEmptyID)
374 return; 391 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 if (base::Base64Encode(serialized, &hashed)) { 433 if (base::Base64Encode(serialized, &hashed)) {
417 // If successful, swap the header value with the new one. 434 // If successful, swap the header value with the new one.
418 // Note that the list of IDs and the header could be temporarily out of sync 435 // Note that the list of IDs and the header could be temporarily out of sync
419 // if IDs are added as we are recreating the header, but we're OK with those 436 // if IDs are added as we are recreating the header, but we're OK with those
420 // descrepancies. 437 // descrepancies.
421 variation_ids_header_ = hashed; 438 variation_ids_header_ = hashed;
422 } else { 439 } else {
423 DVLOG(1) << "Failed to base64 encode Variation IDs value: " << serialized; 440 DVLOG(1) << "Failed to base64 encode Variation IDs value: " << serialized;
424 } 441 }
425 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698