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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/chrome_network_delegate.cc
diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
index 230b40b3fcfd613ffa05ba5603efa781be3e0df1..1d418bafadbd5208286af728fe9b470392b913ab 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -52,6 +52,12 @@
#include "net/socket_stream/socket_stream.h"
#include "net/url_request/url_request.h"
+#if defined(OS_ANDROID)
+#include "components/precache/content/precache_manager.h"
+#include "components/precache/content/precache_manager_factory.h"
+#include "components/precache/core/precache_database.h"
+#endif
+
#if defined(OS_CHROMEOS)
#include "base/command_line.h"
#include "base/sys_info.h"
@@ -299,6 +305,41 @@ void RecordContentLengthHistograms(
#endif // defined(OS_ANDROID)
}
+#if defined(OS_ANDROID)
+
+void RecordPrecacheStatsOnUIThread(void* profile_id, const GURL& url,
+ const base::Time& fetch_time,
+ int64 received_content_length,
+ bool was_cached) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ // Ignore empty responses and empty URLs.
+ if (!received_content_length || url.is_empty())
mmenke 2013/10/31 16:45:00 Should only do this for HTTP and HTTPS requests, r
+ return;
+ Profile* profile = reinterpret_cast<Profile*>(profile_id);
+ if (!g_browser_process->profile_manager()->IsValidProfile(profile))
+ return;
+
+ precache::PrecacheManager* precache_manager =
+ precache::PrecacheManagerFactory::GetForBrowserContext(profile);
+
+ // This will be NULL in incognito mode.
+ if (!precache_manager)
+ return;
+
+ bool is_cellular = net::NetworkChangeNotifier::IsConnectionCellular(
+ net::NetworkChangeNotifier::GetConnectionType());
+
+ BrowserThread::PostTask(
+ BrowserThread::DB, FROM_HERE,
+ base::Bind(&precache::PrecacheDatabase::RecordURLFetched,
+ precache_manager->precache_database(), url, fetch_time,
+ received_content_length, was_cached,
+ 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
+}
+
+#endif // defined(OS_ANDROID)
+
} // namespace
ChromeNetworkDelegate::ChromeNetworkDelegate(
@@ -515,6 +556,17 @@ void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
// or missing, as is the case with chunked encoding.
int64 received_content_length = request->received_response_content_length();
+#if defined(OS_ANDROID)
+ if (precache::PrecacheManager::IsPrecachingEnabled()) {
+ // Record precache statistics for the fetch.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&RecordPrecacheStatsOnUIThread, profile_, request->url(),
+ request->response_info().response_time,
+ received_content_length, request->was_cached()));
+ }
+#endif // defined(OS_ANDROID)
+
// Only record for http or https urls.
bool is_http = request->url().SchemeIs("http");
bool is_https = request->url().SchemeIs("https");

Powered by Google App Engine
This is Rietveld 408576698