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

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: Moved MostVisitedURLsProvider into chrome/browser/precache Created 7 years, 1 month 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"
mmenke 2013/10/29 18:23:34 Here and for the other new code, is there no if-de
sclittle 2013/10/29 23:40:45 There isn't any macro that is specifically defined
mmenke 2013/10/30 18:29:08 No, it's fine - I had just thought/hoped that ther
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 #if defined(OS_ANDROID)
306
307 void RecordPrecacheStatsOnUIThread(void* profile_id, const GURL& url,
308 const base::Time& fetch_time,
309 int64 received_content_length,
310 bool was_cached) {
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
312
313 // Ignore empty responses and empty URLs.
314 if (!received_content_length || url.is_empty())
315 return;
316 Profile* profile = reinterpret_cast<Profile*>(profile_id);
317 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
318 return;
319
320 precache::PrecacheManager* precache_manager =
321 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
322
323 // This will be NULL in incognito mode.
324 if (!precache_manager)
325 return;
326
327 bool is_cellular = net::NetworkChangeNotifier::IsConnectionCellular(
328 net::NetworkChangeNotifier::GetConnectionType());
329
330 BrowserThread::PostTask(
331 BrowserThread::DB, FROM_HERE,
332 base::Bind(&precache::PrecacheDatabase::RecordURLFetched,
333 precache_manager->precache_database(), url, fetch_time,
334 received_content_length, was_cached,
335 precache_manager->IsPrecaching(), is_cellular));
336 }
337
338 #endif // defined(OS_ANDROID)
339
302 } // namespace 340 } // namespace
303 341
304 ChromeNetworkDelegate::ChromeNetworkDelegate( 342 ChromeNetworkDelegate::ChromeNetworkDelegate(
305 extensions::EventRouterForwarder* event_router, 343 extensions::EventRouterForwarder* event_router,
306 BooleanPrefMember* enable_referrers) 344 BooleanPrefMember* enable_referrers)
307 : event_router_(event_router), 345 : event_router_(event_router),
308 profile_(NULL), 346 profile_(NULL),
309 enable_referrers_(enable_referrers), 347 enable_referrers_(enable_referrers),
310 enable_do_not_track_(NULL), 348 enable_do_not_track_(NULL),
311 force_google_safe_search_(NULL), 349 force_google_safe_search_(NULL),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 546
509 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, 547 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
510 bool started) { 548 bool started) {
511 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request); 549 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
512 if (request->status().status() == net::URLRequestStatus::SUCCESS) { 550 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
513 // For better accuracy, we use the actual bytes read instead of the length 551 // For better accuracy, we use the actual bytes read instead of the length
514 // specified with the Content-Length header, which may be inaccurate, 552 // specified with the Content-Length header, which may be inaccurate,
515 // or missing, as is the case with chunked encoding. 553 // or missing, as is the case with chunked encoding.
516 int64 received_content_length = request->received_response_content_length(); 554 int64 received_content_length = request->received_response_content_length();
517 555
556 #if defined(OS_ANDROID)
557 if (precache::PrecacheManager::IsPrecachingEnabled()) {
558 // Record precache statistics for the fetch.
559 BrowserThread::PostTask(
560 BrowserThread::UI, FROM_HERE,
561 base::Bind(&RecordPrecacheStatsOnUIThread, profile_, request->url(),
562 request->response_info().response_time,
563 received_content_length, request->was_cached()));
564 }
565 #endif // defined(OS_ANDROID)
566
518 // Only record for http or https urls. 567 // Only record for http or https urls.
519 bool is_http = request->url().SchemeIs("http"); 568 bool is_http = request->url().SchemeIs("http");
520 bool is_https = request->url().SchemeIs("https"); 569 bool is_https = request->url().SchemeIs("https");
521 570
522 if (!request->was_cached() && // Don't record cached content 571 if (!request->was_cached() && // Don't record cached content
523 received_content_length && // Zero-byte responses aren't useful. 572 received_content_length && // Zero-byte responses aren't useful.
524 (is_http || is_https)) { // Only record for HTTP or HTTPS urls. 573 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
525 int64 original_content_length = 574 int64 original_content_length =
526 request->response_info().headers->GetInt64HeaderValue( 575 request->response_info().headers->GetInt64HeaderValue(
527 "x-original-content-length"); 576 "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, 799 int64 received_content_length, int64 original_content_length,
751 bool via_data_reduction_proxy) { 800 bool via_data_reduction_proxy) {
752 DCHECK_GE(received_content_length, 0); 801 DCHECK_GE(received_content_length, 0);
753 DCHECK_GE(original_content_length, 0); 802 DCHECK_GE(original_content_length, 0);
754 StoreAccumulatedContentLength(received_content_length, 803 StoreAccumulatedContentLength(received_content_length,
755 original_content_length, 804 original_content_length,
756 via_data_reduction_proxy); 805 via_data_reduction_proxy);
757 received_content_length_ += received_content_length; 806 received_content_length_ += received_content_length;
758 original_content_length_ += original_content_length; 807 original_content_length_ += original_content_length;
759 } 808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698