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

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

Issue 27047003: Precache tracking database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@precache
Patch Set: General fixes, added tests, and moved PrecacheManager into component Created 7 years, 2 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 20 matching lines...) Expand all
31 #include "chrome/browser/google/google_util.h" 31 #include "chrome/browser/google/google_util.h"
32 #include "chrome/browser/net/chrome_network_data_saving_metrics.h" 32 #include "chrome/browser/net/chrome_network_data_saving_metrics.h"
33 #include "chrome/browser/net/client_hints.h" 33 #include "chrome/browser/net/client_hints.h"
34 #include "chrome/browser/net/connect_interceptor.h" 34 #include "chrome/browser/net/connect_interceptor.h"
35 #include "chrome/browser/net/load_time_stats.h" 35 #include "chrome/browser/net/load_time_stats.h"
36 #include "chrome/browser/performance_monitor/performance_monitor.h" 36 #include "chrome/browser/performance_monitor/performance_monitor.h"
37 #include "chrome/browser/profiles/profile_manager.h" 37 #include "chrome/browser/profiles/profile_manager.h"
38 #include "chrome/browser/task_manager/task_manager.h" 38 #include "chrome/browser/task_manager/task_manager.h"
39 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
40 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
41 #include "components/precache/content/precache_manager.h"
42 #include "components/precache/content/precache_manager_factory.h"
43 #include "components/precache/core/precache_database.h"
41 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/render_view_host.h" 45 #include "content/public/browser/render_view_host.h"
43 #include "content/public/browser/resource_request_info.h" 46 #include "content/public/browser/resource_request_info.h"
44 #include "extensions/common/constants.h" 47 #include "extensions/common/constants.h"
45 #include "net/base/host_port_pair.h" 48 #include "net/base/host_port_pair.h"
46 #include "net/base/net_errors.h" 49 #include "net/base/net_errors.h"
47 #include "net/base/net_log.h" 50 #include "net/base/net_log.h"
48 #include "net/cookies/canonical_cookie.h" 51 #include "net/cookies/canonical_cookie.h"
49 #include "net/cookies/cookie_options.h" 52 #include "net/cookies/cookie_options.h"
50 #include "net/http/http_request_headers.h" 53 #include "net/http/http_request_headers.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours", 295 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
293 received_content_length); 296 received_content_length);
294 297
295 if (freshness_lifetime.InHours() < 24) 298 if (freshness_lifetime.InHours() < 24)
296 return; 299 return;
297 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours", 300 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
298 received_content_length); 301 received_content_length);
299 #endif // defined(OS_ANDROID) 302 #endif // defined(OS_ANDROID)
300 } 303 }
301 304
305 void RecordPrecacheStatsOnUIThread(void* profile_id, const GURL& url,
bengr 2013/10/23 19:03:36 Why is this a void*? Can it be a const Profile*?
bengr 2013/10/23 19:03:36 To be explicit, I'd wrap this function in #if defi
sclittle 2013/10/24 22:11:38 It's a void* because that's what the ChromeNetwork
sclittle 2013/10/24 22:11:38 Done.
306 const base::Time& fetch_time,
307 int64 received_content_length,
308 bool was_cached) {
309 if (!received_content_length || url.is_empty())
310 return;
311 Profile* profile = reinterpret_cast<Profile*>(profile_id);
312 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
313 return;
314 precache::PrecacheManager* precache_manager =
315 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
316 if (!precache_manager)
bengr 2013/10/23 19:03:36 Can this ever happen? How?
sclittle 2013/10/24 22:11:38 This will happen if the profile is incognito.
317 return;
318 scoped_refptr<precache::PrecacheDatabase> precache_database =
319 precache_manager->precache_database();
320 if (!precache_database)
bengr 2013/10/23 19:03:36 Likewise.
sclittle 2013/10/24 22:11:38 This can never happen. Removed if statement.
321 return;
322
323 bool is_cellular = net::NetworkChangeNotifier::IsConnectionCellular(
bengr 2013/10/23 19:03:36 I wonder what fraction is labeled as CONNECTION_UN
sclittle 2013/10/24 22:11:38 Check out the NCN histograms, including NCN.CM.Tim
324 net::NetworkChangeNotifier::GetConnectionType());
325
326 BrowserThread::PostTask(
327 BrowserThread::DB, FROM_HERE,
328 base::Bind(&precache::PrecacheDatabase::RecordURLFetched,
329 precache_database, url, fetch_time, received_content_length,
330 was_cached, precache_manager->is_precaching(), is_cellular));
331 }
332
302 } // namespace 333 } // namespace
303 334
304 ChromeNetworkDelegate::ChromeNetworkDelegate( 335 ChromeNetworkDelegate::ChromeNetworkDelegate(
305 extensions::EventRouterForwarder* event_router, 336 extensions::EventRouterForwarder* event_router,
306 BooleanPrefMember* enable_referrers) 337 BooleanPrefMember* enable_referrers)
307 : event_router_(event_router), 338 : event_router_(event_router),
308 profile_(NULL), 339 profile_(NULL),
309 enable_referrers_(enable_referrers), 340 enable_referrers_(enable_referrers),
310 enable_do_not_track_(NULL), 341 enable_do_not_track_(NULL),
311 force_google_safe_search_(NULL), 342 force_google_safe_search_(NULL),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 539
509 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, 540 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
510 bool started) { 541 bool started) {
511 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request); 542 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
512 if (request->status().status() == net::URLRequestStatus::SUCCESS) { 543 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
513 // For better accuracy, we use the actual bytes read instead of the length 544 // For better accuracy, we use the actual bytes read instead of the length
514 // specified with the Content-Length header, which may be inaccurate, 545 // specified with the Content-Length header, which may be inaccurate,
515 // or missing, as is the case with chunked encoding. 546 // or missing, as is the case with chunked encoding.
516 int64 received_content_length = request->received_response_content_length(); 547 int64 received_content_length = request->received_response_content_length();
517 548
549 #if defined(OS_ANDROID)
550 if (precache::PrecacheManager::IsPrecachingEnabled()) {
551 // Record precache statistics for the fetch.
552 BrowserThread::PostTask(
553 BrowserThread::UI, FROM_HERE,
554 base::Bind(&RecordPrecacheStatsOnUIThread, profile_, request->url(),
555 request->response_info().response_time,
556 received_content_length, request->was_cached()));
bengr 2013/10/23 19:03:36 In what cases does was_cached() return true? Is it
sclittle 2013/10/24 22:11:38 was_cached() returns true if the response was serv
557 }
558 #endif // defined(OS_ANDROID)
559
518 // Only record for http or https urls. 560 // Only record for http or https urls.
519 bool is_http = request->url().SchemeIs("http"); 561 bool is_http = request->url().SchemeIs("http");
520 bool is_https = request->url().SchemeIs("https"); 562 bool is_https = request->url().SchemeIs("https");
521 563
522 if (!request->was_cached() && // Don't record cached content 564 if (!request->was_cached() && // Don't record cached content
523 received_content_length && // Zero-byte responses aren't useful. 565 received_content_length && // Zero-byte responses aren't useful.
524 (is_http || is_https)) { // Only record for HTTP or HTTPS urls. 566 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
525 int64 original_content_length = 567 int64 original_content_length =
526 request->response_info().headers->GetInt64HeaderValue( 568 request->response_info().headers->GetInt64HeaderValue(
527 "x-original-content-length"); 569 "x-original-content-length");
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 int64 received_content_length, int64 original_content_length, 792 int64 received_content_length, int64 original_content_length,
751 bool via_data_reduction_proxy) { 793 bool via_data_reduction_proxy) {
752 DCHECK_GE(received_content_length, 0); 794 DCHECK_GE(received_content_length, 0);
753 DCHECK_GE(original_content_length, 0); 795 DCHECK_GE(original_content_length, 0);
754 StoreAccumulatedContentLength(received_content_length, 796 StoreAccumulatedContentLength(received_content_length,
755 original_content_length, 797 original_content_length,
756 via_data_reduction_proxy); 798 via_data_reduction_proxy);
757 received_content_length_ += received_content_length; 799 received_content_length_ += received_content_length;
758 original_content_length_ += original_content_length; 800 original_content_length_ += original_content_length;
759 } 801 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698