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

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

Issue 12094085: LoadTiming in net part 7: Hooking it all up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Sync, cleanup Created 7 years, 10 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 | Annotate | Revision Log
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/metrics/variations/variations_http_header_provider.h" 19 #include "chrome/browser/metrics/variations/variations_http_header_provider.h"
20 #include "chrome/browser/net/load_timing_observer.h"
21 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" 20 #include "chrome/browser/net/resource_prefetch_predictor_observer.h"
22 #include "chrome/browser/prerender/prerender_manager.h" 21 #include "chrome/browser/prerender/prerender_manager.h"
23 #include "chrome/browser/prerender/prerender_tracker.h" 22 #include "chrome/browser/prerender/prerender_tracker.h"
24 #include "chrome/browser/prerender/prerender_util.h" 23 #include "chrome/browser/prerender/prerender_util.h"
25 #include "chrome/browser/profiles/profile_io_data.h" 24 #include "chrome/browser/profiles/profile_io_data.h"
26 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" 25 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h"
27 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h " 26 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h "
28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
29 #include "chrome/browser/ui/auto_login_prompter.h" 28 #include "chrome/browser/ui/auto_login_prompter.h"
30 #include "chrome/browser/ui/login/login_prompt.h" 29 #include "chrome/browser/ui/login/login_prompt.h"
31 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 30 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
32 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
33 #include "chrome/common/extensions/extension_constants.h" 32 #include "chrome/common/extensions/extension_constants.h"
34 #include "chrome/common/extensions/user_script.h" 33 #include "chrome/common/extensions/user_script.h"
35 #include "chrome/common/render_messages.h" 34 #include "chrome/common/render_messages.h"
36 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/render_view_host.h" 37 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/resource_context.h" 38 #include "content/public/browser/resource_context.h"
40 #include "content/public/browser/resource_dispatcher_host.h" 39 #include "content/public/browser/resource_dispatcher_host.h"
41 #include "content/public/browser/resource_request_info.h" 40 #include "content/public/browser/resource_request_info.h"
41 #include "content/public/common/resource_response.h"
42 #include "net/base/load_flags.h" 42 #include "net/base/load_flags.h"
43 #include "net/base/load_timing_info.h"
43 #include "net/base/ssl_config_service.h" 44 #include "net/base/ssl_config_service.h"
44 #include "net/http/http_response_headers.h" 45 #include "net/http/http_response_headers.h"
45 #include "net/url_request/url_request.h" 46 #include "net/url_request/url_request.h"
46 47
47 #if defined(ENABLE_MANAGED_USERS) 48 #if defined(ENABLE_MANAGED_USERS)
48 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" 49 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h"
49 #endif 50 #endif
50 51
51 #if defined(USE_SYSTEM_PROTOBUF) 52 #if defined(USE_SYSTEM_PROTOBUF)
52 #include <google/protobuf/repeated_field.h> 53 #include <google/protobuf/repeated_field.h>
(...skipping 23 matching lines...) Expand all
76 render_view_id); 77 render_view_id);
77 if (!rvh) 78 if (!rvh)
78 return; 79 return;
79 80
80 content::NotificationService::current()->Notify( 81 content::NotificationService::current()->Notify(
81 chrome::NOTIFICATION_DOWNLOAD_INITIATED, 82 chrome::NOTIFICATION_DOWNLOAD_INITIATED,
82 content::Source<RenderViewHost>(rvh), 83 content::Source<RenderViewHost>(rvh),
83 content::NotificationService::NoDetails()); 84 content::NotificationService::NoDetails());
84 } 85 }
85 86
87 // The network stack returns actual connect times, while the renderer process
88 // expects times that the request was blocked in each phase of setting up
89 // a connection. Due to preconnect and late binding, it is possible for a
90 // connection attempt to start before a request has been started, so this
91 // function is needed to convert times from the network stack to times the
92 // renderer process expects.
93 void FixupLoadTimingInfo(net::LoadTimingInfo* load_timing_info) {
94 // If there are no times, do nothing.
95 if (load_timing_info->request_start.is_null())
96 return;
97
98 // Starting the request and resolving the proxy are the only phases of the
99 // request that occur before it blocks on starting a connection.
100 base::TimeTicks block_on_connect_start = load_timing_info->request_start;
101 if (!load_timing_info->proxy_resolve_end.is_null())
102 block_on_connect_start = load_timing_info->proxy_resolve_end;
103
104 net::LoadTimingInfo::ConnectTiming* connect_timing =
105 &load_timing_info->connect_timing;
106 if (!connect_timing->dns_start.is_null()) {
107 DCHECK(!connect_timing->dns_end.is_null());
108 if (connect_timing->dns_start < block_on_connect_start)
109 connect_timing->dns_start = block_on_connect_start;
110 if (connect_timing->dns_end < block_on_connect_start)
111 connect_timing->dns_end = block_on_connect_start;
112 }
113
114 if (!connect_timing->connect_start.is_null()) {
115 DCHECK(!connect_timing->connect_end.is_null());
116 if (connect_timing->connect_start < block_on_connect_start)
117 connect_timing->connect_start = block_on_connect_start;
118 if (connect_timing->connect_end < block_on_connect_start)
119 connect_timing->connect_end = block_on_connect_start;
120 }
121
122 if (!connect_timing->ssl_start.is_null()) {
123 DCHECK(!connect_timing->ssl_end.is_null());
124 if (connect_timing->ssl_start < block_on_connect_start)
125 connect_timing->ssl_start = block_on_connect_start;
126 if (connect_timing->ssl_end < block_on_connect_start)
127 connect_timing->ssl_end = block_on_connect_start;
128 }
129 }
130
86 } // end namespace 131 } // end namespace
87 132
88 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( 133 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate(
89 prerender::PrerenderTracker* prerender_tracker) 134 prerender::PrerenderTracker* prerender_tracker)
90 : download_request_limiter_(g_browser_process->download_request_limiter()), 135 : download_request_limiter_(g_browser_process->download_request_limiter()),
91 safe_browsing_(g_browser_process->safe_browsing_service()), 136 safe_browsing_(g_browser_process->safe_browsing_service()),
92 user_script_listener_(new extensions::UserScriptListener()), 137 user_script_listener_(new extensions::UserScriptListener()),
93 prerender_tracker_(prerender_tracker) { 138 prerender_tracker_(prerender_tracker) {
94 } 139 }
95 140
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 const GURL& url, const std::string& mime_type) { 411 const GURL& url, const std::string& mime_type) {
367 // Special-case user scripts to get downloaded instead of viewed. 412 // Special-case user scripts to get downloaded instead of viewed.
368 return extensions::UserScript::IsURLUserScript(url, mime_type); 413 return extensions::UserScript::IsURLUserScript(url, mime_type);
369 } 414 }
370 415
371 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( 416 void ChromeResourceDispatcherHostDelegate::OnResponseStarted(
372 net::URLRequest* request, 417 net::URLRequest* request,
373 content::ResourceContext* resource_context, 418 content::ResourceContext* resource_context,
374 content::ResourceResponse* response, 419 content::ResourceResponse* response,
375 IPC::Sender* sender) { 420 IPC::Sender* sender) {
376 LoadTimingObserver::PopulateTimingInfo(request, response); 421 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove.
422 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) {
423 request->GetLoadTimingInfo(&response->head.load_timing);
424 FixupLoadTimingInfo(&response->head.load_timing);
425 }
377 426
378 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 427 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
379 428
380 if (request->url().SchemeIsSecure()) { 429 if (request->url().SchemeIsSecure()) {
381 const net::URLRequestContext* context = request->context(); 430 const net::URLRequestContext* context = request->context();
382 net::TransportSecurityState* state = context->transport_security_state(); 431 net::TransportSecurityState* state = context->transport_security_state();
383 if (state) { 432 if (state) {
384 net::TransportSecurityState::DomainState domain_state; 433 net::TransportSecurityState::DomainState domain_state;
385 bool has_sni = net::SSLConfigService::IsSNIAvailable( 434 bool has_sni = net::SSLConfigService::IsSNIAvailable(
386 context->ssl_config_service()); 435 context->ssl_config_service());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 io_data->resource_prefetch_predictor_observer()->OnResponseStarted(request); 474 io_data->resource_prefetch_predictor_observer()->OnResponseStarted(request);
426 475
427 prerender::URLRequestResponseStarted(request); 476 prerender::URLRequestResponseStarted(request);
428 } 477 }
429 478
430 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( 479 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
431 const GURL& redirect_url, 480 const GURL& redirect_url,
432 net::URLRequest* request, 481 net::URLRequest* request,
433 content::ResourceContext* resource_context, 482 content::ResourceContext* resource_context,
434 content::ResourceResponse* response) { 483 content::ResourceResponse* response) {
435 LoadTimingObserver::PopulateTimingInfo(request, response); 484 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove.
485 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) {
486 request->GetLoadTimingInfo(&response->head.load_timing);
487 FixupLoadTimingInfo(&response->head.load_timing);
488 }
436 489
437 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 490 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
438 491
439 #if defined(ENABLE_ONE_CLICK_SIGNIN) 492 #if defined(ENABLE_ONE_CLICK_SIGNIN)
440 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 493 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
441 494
442 AppendChromeSyncGaiaHeader(request, resource_context); 495 AppendChromeSyncGaiaHeader(request, resource_context);
443 496
444 // See if the response contains the Google-Accounts-SignIn header. If so, 497 // See if the response contains the Google-Accounts-SignIn header. If so,
445 // then the user has just finished signing in, and the server is allowing the 498 // then the user has just finished signing in, and the server is allowing the
446 // browser to suggest connecting the user's profile to the account. 499 // browser to suggest connecting the user's profile to the account.
447 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data, 500 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data,
448 info->GetChildID(), 501 info->GetChildID(),
449 info->GetRouteID()); 502 info->GetRouteID());
450 #endif 503 #endif
451 504
452 if (io_data->resource_prefetch_predictor_observer()) { 505 if (io_data->resource_prefetch_predictor_observer()) {
453 io_data->resource_prefetch_predictor_observer()->OnRequestRedirected( 506 io_data->resource_prefetch_predictor_observer()->OnRequestRedirected(
454 redirect_url, request); 507 redirect_url, request);
455 } 508 }
456 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698