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

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: Moved MostVisitedURLsProvider into chrome/browser/precache 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..a7c82a798a83be975af7298ffd9a45976bcd889e 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -38,6 +38,9 @@
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "components/precache/content/precache_manager.h"
+#include "components/precache/content/precache_manager_factory.h"
+#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
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/resource_request_info.h"
@@ -299,6 +302,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())
+ 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));
+}
+
+#endif // defined(OS_ANDROID)
+
} // namespace
ChromeNetworkDelegate::ChromeNetworkDelegate(
@@ -515,6 +553,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