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

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

Issue 1266243003: Tweaks to the precache triggering code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 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
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 <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 callback.Run(rv); 104 callback.Run(rv);
105 } 105 }
106 106
107 #if defined(OS_ANDROID) 107 #if defined(OS_ANDROID)
108 void RecordPrecacheStatsOnUIThread(const GURL& url, 108 void RecordPrecacheStatsOnUIThread(const GURL& url,
109 const base::Time& fetch_time, int64 size, 109 const base::Time& fetch_time, int64 size,
110 bool was_cached, void* profile_id) { 110 bool was_cached, void* profile_id) {
111 DCHECK_CURRENTLY_ON(BrowserThread::UI); 111 DCHECK_CURRENTLY_ON(BrowserThread::UI);
112 112
113 Profile* profile = reinterpret_cast<Profile*>(profile_id); 113 Profile* profile = reinterpret_cast<Profile*>(profile_id);
114 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) { 114 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
115 return; 115 return;
116 }
117 116
118 precache::PrecacheManager* precache_manager = 117 precache::PrecacheManager* precache_manager =
119 precache::PrecacheManagerFactory::GetForBrowserContext(profile); 118 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
120 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) { 119 // |precache_manager| could be NULL if the profile is off the record.
121 // |precache_manager| could be NULL if the profile is off the record. 120 if (!precache_manager || !precache_manager->WouldRun())
122 return; 121 return;
123 }
124 122
125 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached); 123 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
126 } 124 }
127 #endif // defined(OS_ANDROID) 125 #endif // defined(OS_ANDROID)
128 126
129 void ReportInvalidReferrerSendOnUI() { 127 void ReportInvalidReferrerSendOnUI() {
130 base::RecordAction( 128 base::RecordAction(
131 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); 129 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer"));
132 } 130 }
133 131
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 RecordCacheStateStats(request); 493 RecordCacheStateStats(request);
496 } 494 }
497 495
498 if (request->status().status() == net::URLRequestStatus::SUCCESS) { 496 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
499 #if defined(OS_ANDROID) 497 #if defined(OS_ANDROID)
500 // For better accuracy, we use the actual bytes read instead of the length 498 // For better accuracy, we use the actual bytes read instead of the length
501 // specified with the Content-Length header, which may be inaccurate, 499 // specified with the Content-Length header, which may be inaccurate,
502 // or missing, as is the case with chunked encoding. 500 // or missing, as is the case with chunked encoding.
503 int64 received_content_length = request->received_response_content_length(); 501 int64 received_content_length = request->received_response_content_length();
504 502
505 // Record precache metrics when a fetch is completed successfully. 503 // Record precache metrics when a fetch is completed successfully, if
504 // precaching is allowed.
506 BrowserThread::PostTask( 505 BrowserThread::PostTask(
507 BrowserThread::UI, FROM_HERE, 506 BrowserThread::UI, FROM_HERE,
508 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(), 507 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
509 base::Time::Now(), received_content_length, 508 base::Time::Now(), received_content_length,
510 request->was_cached(), profile_)); 509 request->was_cached(), profile_));
511 #endif // defined(OS_ANDROID) 510 #endif // defined(OS_ANDROID)
512 extensions_delegate_->OnCompleted(request, started); 511 extensions_delegate_->OnCompleted(request, started);
513 } else if (request->status().status() == net::URLRequestStatus::FAILED || 512 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
514 request->status().status() == net::URLRequestStatus::CANCELED) { 513 request->status().status() == net::URLRequestStatus::CANCELED) {
515 extensions_delegate_->OnCompleted(request, started); 514 extensions_delegate_->OnCompleted(request, started);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 return experimental_web_platform_features_enabled_; 682 return experimental_web_platform_features_enabled_;
684 } 683 }
685 684
686 bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( 685 bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
687 const net::URLRequest& request, 686 const net::URLRequest& request,
688 const GURL& target_url, 687 const GURL& target_url,
689 const GURL& referrer_url) const { 688 const GURL& referrer_url) const {
690 ReportInvalidReferrerSend(target_url, referrer_url); 689 ReportInvalidReferrerSend(target_url, referrer_url);
691 return true; 690 return true;
692 } 691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698