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

Side by Side Diff: chrome/browser/net/chrome_network_delegate.cc

Issue 2202023002: Precache should cancel when there is user traffic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/precache/precache_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/net/chrome_network_delegate.h" 5 #include "chrome/browser/net/chrome_network_delegate.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "net/cookies/canonical_cookie.h" 56 #include "net/cookies/canonical_cookie.h"
57 #include "net/cookies/cookie_options.h" 57 #include "net/cookies/cookie_options.h"
58 #include "net/http/http_request_headers.h" 58 #include "net/http/http_request_headers.h"
59 #include "net/http/http_response_headers.h" 59 #include "net/http/http_response_headers.h"
60 #include "net/http/http_status_code.h" 60 #include "net/http/http_status_code.h"
61 #include "net/log/net_log.h" 61 #include "net/log/net_log.h"
62 #include "net/url_request/url_request.h" 62 #include "net/url_request/url_request.h"
63 63
64 #if BUILDFLAG(ANDROID_JAVA_UI) 64 #if BUILDFLAG(ANDROID_JAVA_UI)
65 #include "chrome/browser/io_thread.h" 65 #include "chrome/browser/io_thread.h"
66 #include "chrome/browser/precache/precache_manager_factory.h" 66 #include "chrome/browser/precache/precache_util.h"
67 #include "components/precache/content/precache_manager.h"
68 #endif 67 #endif
69 68
70 #if defined(OS_CHROMEOS) 69 #if defined(OS_CHROMEOS)
71 #include "base/sys_info.h" 70 #include "base/sys_info.h"
72 #include "chrome/common/chrome_switches.h" 71 #include "chrome/common/chrome_switches.h"
73 #endif 72 #endif
74 73
75 #if defined(ENABLE_EXTENSIONS) 74 #if defined(ENABLE_EXTENSIONS)
76 #include "extensions/common/constants.h" 75 #include "extensions/common/constants.h"
77 #endif 76 #endif
(...skipping 22 matching lines...) Expand all
100 void ForceGoogleSafeSearchCallbackWrapper( 99 void ForceGoogleSafeSearchCallbackWrapper(
101 const net::CompletionCallback& callback, 100 const net::CompletionCallback& callback,
102 net::URLRequest* request, 101 net::URLRequest* request,
103 GURL* new_url, 102 GURL* new_url,
104 int rv) { 103 int rv) {
105 if (rv == net::OK && new_url->is_empty()) 104 if (rv == net::OK && new_url->is_empty())
106 safe_search_util::ForceGoogleSafeSearch(request, new_url); 105 safe_search_util::ForceGoogleSafeSearch(request, new_url);
107 callback.Run(rv); 106 callback.Run(rv);
108 } 107 }
109 108
110 #if BUILDFLAG(ANDROID_JAVA_UI)
111 void RecordPrecacheStatsOnUIThread(const GURL& url,
112 const GURL& referrer,
113 base::TimeDelta latency,
114 const base::Time& fetch_time,
115 int64_t size,
116 bool was_cached,
117 void* profile_id) {
118 DCHECK_CURRENTLY_ON(BrowserThread::UI);
119
120 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id))
121 return;
122 Profile* profile = reinterpret_cast<Profile*>(profile_id);
123
124 precache::PrecacheManager* precache_manager =
125 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
126 // |precache_manager| could be NULL if the profile is off the record.
127 if (!precache_manager || !precache_manager->IsPrecachingAllowed())
128 return;
129
130 precache_manager->RecordStatsForFetch(url, referrer, latency, fetch_time,
131 size, was_cached);
132 }
133 #endif // BUILDFLAG(ANDROID_JAVA_UI)
134
135 void ReportInvalidReferrerSendOnUI() { 109 void ReportInvalidReferrerSendOnUI() {
136 base::RecordAction( 110 base::RecordAction(
137 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); 111 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer"));
138 } 112 }
139 113
140 void ReportInvalidReferrerSend(const GURL& target_url, 114 void ReportInvalidReferrerSend(const GURL& target_url,
141 const GURL& referrer_url) { 115 const GURL& referrer_url) {
142 LOG(ERROR) << "Cancelling request to " << target_url 116 LOG(ERROR) << "Cancelling request to " << target_url
143 << " with invalid referrer " << referrer_url; 117 << " with invalid referrer " << referrer_url;
144 // Record information to help debug http://crbug.com/422871 118 // Record information to help debug http://crbug.com/422871
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 RecordNetworkErrorHistograms(request); 496 RecordNetworkErrorHistograms(request);
523 if (started) { 497 if (started) {
524 // Only call in for requests that were started, to obey the precondition 498 // Only call in for requests that were started, to obey the precondition
525 // that RecordCacheStateStats can only be called on requests for which 499 // that RecordCacheStateStats can only be called on requests for which
526 // OnResponseStarted was called. 500 // OnResponseStarted was called.
527 RecordCacheStateStats(request); 501 RecordCacheStateStats(request);
528 } 502 }
529 503
530 if (request->status().status() == net::URLRequestStatus::SUCCESS) { 504 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
531 #if BUILDFLAG(ANDROID_JAVA_UI) 505 #if BUILDFLAG(ANDROID_JAVA_UI)
532 // For better accuracy, we use the actual bytes read instead of the length 506 precache::UpdatePrecacheMetricsAndState(request, profile_);
533 // specified with the Content-Length header, which may be inaccurate,
534 // or missing, as is the case with chunked encoding.
535 int64_t received_content_length =
536 request->received_response_content_length();
537 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time();
538
539 // Record precache metrics when a fetch is completed successfully, if
540 // precaching is allowed.
541 BrowserThread::PostTask(
542 BrowserThread::UI, FROM_HERE,
543 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
544 GURL(request->referrer()), latency, base::Time::Now(),
545 received_content_length, request->was_cached(), profile_));
546 #endif // BUILDFLAG(ANDROID_JAVA_UI) 507 #endif // BUILDFLAG(ANDROID_JAVA_UI)
547 extensions_delegate_->OnCompleted(request, started); 508 extensions_delegate_->OnCompleted(request, started);
548 } else if (request->status().status() == net::URLRequestStatus::FAILED || 509 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
549 request->status().status() == net::URLRequestStatus::CANCELED) { 510 request->status().status() == net::URLRequestStatus::CANCELED) {
550 extensions_delegate_->OnCompleted(request, started); 511 extensions_delegate_->OnCompleted(request, started);
551 } else { 512 } else {
552 NOTREACHED(); 513 NOTREACHED();
553 } 514 }
554 if (domain_reliability_monitor_) 515 if (domain_reliability_monitor_)
555 domain_reliability_monitor_->OnCompleted(request, started); 516 domain_reliability_monitor_->OnCompleted(request, started);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 if (!data_use_aggregator_) 710 if (!data_use_aggregator_)
750 return; 711 return;
751 712
752 if (is_data_usage_off_the_record_) { 713 if (is_data_usage_off_the_record_) {
753 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); 714 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes);
754 return; 715 return;
755 } 716 }
756 717
757 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); 718 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes);
758 } 719 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/precache/precache_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698