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

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: Added field trials 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "net/base/host_port_pair.h" 45 #include "net/base/host_port_pair.h"
46 #include "net/base/net_errors.h" 46 #include "net/base/net_errors.h"
47 #include "net/base/net_log.h" 47 #include "net/base/net_log.h"
48 #include "net/cookies/canonical_cookie.h" 48 #include "net/cookies/canonical_cookie.h"
49 #include "net/cookies/cookie_options.h" 49 #include "net/cookies/cookie_options.h"
50 #include "net/http/http_request_headers.h" 50 #include "net/http/http_request_headers.h"
51 #include "net/http/http_response_headers.h" 51 #include "net/http/http_response_headers.h"
52 #include "net/socket_stream/socket_stream.h" 52 #include "net/socket_stream/socket_stream.h"
53 #include "net/url_request/url_request.h" 53 #include "net/url_request/url_request.h"
54 54
55 #if defined(OS_ANDROID)
56 #include "components/precache/content/precache_manager.h"
57 #include "components/precache/content/precache_manager_factory.h"
58 #include "components/precache/core/precache_database.h"
59 #endif
60
55 #if defined(OS_CHROMEOS) 61 #if defined(OS_CHROMEOS)
56 #include "base/command_line.h" 62 #include "base/command_line.h"
57 #include "base/sys_info.h" 63 #include "base/sys_info.h"
58 #include "chrome/common/chrome_switches.h" 64 #include "chrome/common/chrome_switches.h"
59 #endif 65 #endif
60 66
61 #if defined(ENABLE_CONFIGURATION_POLICY) 67 #if defined(ENABLE_CONFIGURATION_POLICY)
62 #include "chrome/browser/policy/url_blacklist_manager.h" 68 #include "chrome/browser/policy/url_blacklist_manager.h"
63 #endif 69 #endif
64 70
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours", 298 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
293 received_content_length); 299 received_content_length);
294 300
295 if (freshness_lifetime.InHours() < 24) 301 if (freshness_lifetime.InHours() < 24)
296 return; 302 return;
297 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours", 303 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
298 received_content_length); 304 received_content_length);
299 #endif // defined(OS_ANDROID) 305 #endif // defined(OS_ANDROID)
300 } 306 }
301 307
308 #if defined(OS_ANDROID)
309
310 void RecordPrecacheStatsOnUIThread(void* profile_id, const GURL& url,
311 const base::Time& fetch_time,
312 int64 received_content_length,
313 bool was_cached) {
314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
315
316 // Ignore empty responses and empty URLs.
317 if (!received_content_length || url.is_empty())
mmenke 2013/10/31 16:45:00 Should only do this for HTTP and HTTPS requests, r
318 return;
319 Profile* profile = reinterpret_cast<Profile*>(profile_id);
320 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
321 return;
322
323 precache::PrecacheManager* precache_manager =
324 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
325
326 // This will be NULL in incognito mode.
327 if (!precache_manager)
328 return;
329
330 bool is_cellular = net::NetworkChangeNotifier::IsConnectionCellular(
331 net::NetworkChangeNotifier::GetConnectionType());
332
333 BrowserThread::PostTask(
334 BrowserThread::DB, FROM_HERE,
335 base::Bind(&precache::PrecacheDatabase::RecordURLFetched,
336 precache_manager->precache_database(), url, fetch_time,
337 received_content_length, was_cached,
338 precache_manager->IsPrecaching(), is_cellular));
mmenke 2013/10/31 16:45:00 Do we really need to get the time from the URL req
mmenke 2013/10/31 16:45:00 I don't think the ChromeNetworkDelegate should kno
339 }
340
341 #endif // defined(OS_ANDROID)
342
302 } // namespace 343 } // namespace
303 344
304 ChromeNetworkDelegate::ChromeNetworkDelegate( 345 ChromeNetworkDelegate::ChromeNetworkDelegate(
305 extensions::EventRouterForwarder* event_router, 346 extensions::EventRouterForwarder* event_router,
306 BooleanPrefMember* enable_referrers) 347 BooleanPrefMember* enable_referrers)
307 : event_router_(event_router), 348 : event_router_(event_router),
308 profile_(NULL), 349 profile_(NULL),
309 enable_referrers_(enable_referrers), 350 enable_referrers_(enable_referrers),
310 enable_do_not_track_(NULL), 351 enable_do_not_track_(NULL),
311 force_google_safe_search_(NULL), 352 force_google_safe_search_(NULL),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 549
509 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, 550 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
510 bool started) { 551 bool started) {
511 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request); 552 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
512 if (request->status().status() == net::URLRequestStatus::SUCCESS) { 553 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
513 // For better accuracy, we use the actual bytes read instead of the length 554 // For better accuracy, we use the actual bytes read instead of the length
514 // specified with the Content-Length header, which may be inaccurate, 555 // specified with the Content-Length header, which may be inaccurate,
515 // or missing, as is the case with chunked encoding. 556 // or missing, as is the case with chunked encoding.
516 int64 received_content_length = request->received_response_content_length(); 557 int64 received_content_length = request->received_response_content_length();
517 558
559 #if defined(OS_ANDROID)
560 if (precache::PrecacheManager::IsPrecachingEnabled()) {
561 // Record precache statistics for the fetch.
562 BrowserThread::PostTask(
563 BrowserThread::UI, FROM_HERE,
564 base::Bind(&RecordPrecacheStatsOnUIThread, profile_, request->url(),
565 request->response_info().response_time,
566 received_content_length, request->was_cached()));
567 }
568 #endif // defined(OS_ANDROID)
569
518 // Only record for http or https urls. 570 // Only record for http or https urls.
519 bool is_http = request->url().SchemeIs("http"); 571 bool is_http = request->url().SchemeIs("http");
520 bool is_https = request->url().SchemeIs("https"); 572 bool is_https = request->url().SchemeIs("https");
521 573
522 if (!request->was_cached() && // Don't record cached content 574 if (!request->was_cached() && // Don't record cached content
523 received_content_length && // Zero-byte responses aren't useful. 575 received_content_length && // Zero-byte responses aren't useful.
524 (is_http || is_https)) { // Only record for HTTP or HTTPS urls. 576 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
525 int64 original_content_length = 577 int64 original_content_length =
526 request->response_info().headers->GetInt64HeaderValue( 578 request->response_info().headers->GetInt64HeaderValue(
527 "x-original-content-length"); 579 "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, 802 int64 received_content_length, int64 original_content_length,
751 bool via_data_reduction_proxy) { 803 bool via_data_reduction_proxy) {
752 DCHECK_GE(received_content_length, 0); 804 DCHECK_GE(received_content_length, 0);
753 DCHECK_GE(original_content_length, 0); 805 DCHECK_GE(original_content_length, 0);
754 StoreAccumulatedContentLength(received_content_length, 806 StoreAccumulatedContentLength(received_content_length,
755 original_content_length, 807 original_content_length,
756 via_data_reduction_proxy); 808 via_data_reduction_proxy);
757 received_content_length_ += received_content_length; 809 received_content_length_ += received_content_length;
758 original_content_length_ += original_content_length; 810 original_content_length_ += original_content_length;
759 } 811 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698