Commit 9020aee1 authored by twifkak's avatar twifkak Committed by Commit bot

Create a synthetic field trial for precache.

For clients in a Precache trial group who've started a precache in the last 15
days, registers them in a matching group in the PrecacheSynthetic15D trial. For
those who've started a precache in the last 1 day, registers in them in the
PrecacheSynthetic1D trial also.

BUG=663987

Review-Url: https://codereview.chromium.org/2596093002
Cr-Commit-Position: refs/heads/master@{#443352}
parent 7903b42a
...@@ -49,6 +49,10 @@ namespace options { ...@@ -49,6 +49,10 @@ namespace options {
class BrowserOptionsHandler; class BrowserOptionsHandler;
} }
namespace precache {
void RegisterPrecacheSyntheticFieldTrial(base::Time);
}
namespace prerender { namespace prerender {
bool IsOmniboxEnabled(Profile* profile); bool IsOmniboxEnabled(Profile* profile);
} }
...@@ -107,6 +111,7 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor { ...@@ -107,6 +111,7 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
bool, bool,
const OnMetricsReportingCallbackType&); const OnMetricsReportingCallbackType&);
friend class options::BrowserOptionsHandler; friend class options::BrowserOptionsHandler;
friend void precache::RegisterPrecacheSyntheticFieldTrial(base::Time);
friend bool prerender::IsOmniboxEnabled(Profile* profile); friend bool prerender::IsOmniboxEnabled(Profile* profile);
friend class settings::MetricsReportingHandler; friend class settings::MetricsReportingHandler;
friend class speech::ChromeSpeechRecognitionManagerDelegate; friend class speech::ChromeSpeechRecognitionManagerDelegate;
......
...@@ -4,8 +4,13 @@ ...@@ -4,8 +4,13 @@
#include "chrome/browser/precache/precache_util.h" #include "chrome/browser/precache/precache_util.h"
#include <string>
#include <vector>
#include "base/metrics/field_trial.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/precache/precache_manager_factory.h" #include "chrome/browser/precache/precache_manager_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -21,6 +26,9 @@ class HttpResponseInfo; ...@@ -21,6 +26,9 @@ class HttpResponseInfo;
namespace { namespace {
const char kPrecacheSynthetic15D[] = "PrecacheSynthetic15D";
const char kPrecacheSynthetic1D[] = "PrecacheSynthetic1D";
void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url, void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url,
const GURL& referrer, const GURL& referrer,
base::TimeDelta latency, base::TimeDelta latency,
...@@ -42,7 +50,8 @@ void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url, ...@@ -42,7 +50,8 @@ void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url,
return; return;
precache_manager->UpdatePrecacheMetricsAndState( precache_manager->UpdatePrecacheMetricsAndState(
url, referrer, latency, fetch_time, info, size, is_user_traffic); url, referrer, latency, fetch_time, info, size, is_user_traffic,
base::Bind(&precache::RegisterPrecacheSyntheticFieldTrial));
} }
} // namespace } // namespace
...@@ -70,4 +79,25 @@ void UpdatePrecacheMetricsAndState(const net::URLRequest* request, ...@@ -70,4 +79,25 @@ void UpdatePrecacheMetricsAndState(const net::URLRequest* request,
data_use_measurement::IsUserRequest(*request), profile_id)); data_use_measurement::IsUserRequest(*request), profile_id));
} }
// |last_precache_time| is the last time precache task was run.
void RegisterPrecacheSyntheticFieldTrial(base::Time last_precache_time) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::vector<uint32_t> groups;
base::TimeDelta time_ago = base::Time::Now() - last_precache_time;
// Look up the current group name (e.g. Control or Enabled).
std::string group_name =
base::FieldTrialList::FindFullName(kPrecacheFieldTrialName);
// group_name should only be empty if the Precache trial does not exist.
if (!group_name.empty()) {
// Register matching synthetic trials for 15-day and 1-day candidates.
if (time_ago <= base::TimeDelta::FromDays(15))
ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
kPrecacheSynthetic15D, group_name);
if (time_ago <= base::TimeDelta::FromDays(1))
ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
kPrecacheSynthetic1D, group_name);
}
}
} // namespace precache } // namespace precache
...@@ -356,22 +356,35 @@ void PrecacheManager::UpdatePrecacheMetricsAndState( ...@@ -356,22 +356,35 @@ void PrecacheManager::UpdatePrecacheMetricsAndState(
const base::Time& fetch_time, const base::Time& fetch_time,
const net::HttpResponseInfo& info, const net::HttpResponseInfo& info,
int64_t size, int64_t size,
bool is_user_traffic) { bool is_user_traffic,
const base::Callback<void(base::Time)>& register_synthetic_trial) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordStatsForFetch(url, referrer, latency, fetch_time, info, size); BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::DB, FROM_HERE,
base::Bind(&PrecacheDatabase::GetLastPrecacheTimestamp,
base::Unretained(precache_database_.get())),
base::Bind(&PrecacheManager::RecordStatsForFetch, AsWeakPtr(), url,
referrer, latency, fetch_time, info, size,
register_synthetic_trial));
if (is_user_traffic && IsPrecaching()) if (is_user_traffic && IsPrecaching())
CancelPrecaching(); CancelPrecaching();
} }
void PrecacheManager::RecordStatsForFetch(const GURL& url, void PrecacheManager::RecordStatsForFetch(
const GURL& referrer, const GURL& url,
const base::TimeDelta& latency, const GURL& referrer,
const base::Time& fetch_time, const base::TimeDelta& latency,
const net::HttpResponseInfo& info, const base::Time& fetch_time,
int64_t size) { const net::HttpResponseInfo& info,
int64_t size,
const base::Callback<void(base::Time)>& register_synthetic_trial,
base::Time last_precache_time) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
register_synthetic_trial.Run(last_precache_time);
if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) { if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) {
// Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS. // Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS.
return; return;
......
...@@ -57,8 +57,9 @@ namespace precache { ...@@ -57,8 +57,9 @@ namespace precache {
class PrecacheDatabase; class PrecacheDatabase;
class PrecacheUnfinishedWork; class PrecacheUnfinishedWork;
// Visible for test.
extern const char kPrecacheFieldTrialName[]; extern const char kPrecacheFieldTrialName[];
// Visible for test.
extern const char kMinCacheSizeParam[]; extern const char kMinCacheSizeParam[];
size_t NumTopHosts(); size_t NumTopHosts();
...@@ -119,13 +120,15 @@ class PrecacheManager : public KeyedService, ...@@ -119,13 +120,15 @@ class PrecacheManager : public KeyedService,
// Update precache about an URL being fetched. Metrics related to precache are // Update precache about an URL being fetched. Metrics related to precache are
// updated and any ongoing precache will be cancelled if this is an user // updated and any ongoing precache will be cancelled if this is an user
// initiated request. Should be called on UI thread. // initiated request. Should be called on UI thread.
void UpdatePrecacheMetricsAndState(const GURL& url, void UpdatePrecacheMetricsAndState(
const GURL& referrer, const GURL& url,
const base::TimeDelta& latency, const GURL& referrer,
const base::Time& fetch_time, const base::TimeDelta& latency,
const net::HttpResponseInfo& info, const base::Time& fetch_time,
int64_t size, const net::HttpResponseInfo& info,
bool is_user_traffic); int64_t size,
bool is_user_traffic,
const base::Callback<void(base::Time)>& register_synthetic_trial);
private: private:
friend class PrecacheManagerTest; friend class PrecacheManagerTest;
...@@ -153,6 +156,11 @@ class PrecacheManager : public KeyedService, ...@@ -153,6 +156,11 @@ class PrecacheManager : public KeyedService,
// From PrecacheFetcher::PrecacheDelegate. // From PrecacheFetcher::PrecacheDelegate.
void OnDone() override; void OnDone() override;
// Registers the precache synthetic field trial for users whom the precache
// task was run recently. |last_precache_time| is the last time precache task
// was run.
void RegisterSyntheticFieldTrial(const base::Time last_precache_time);
// Callback when fetching unfinished work from storage is done. // Callback when fetching unfinished work from storage is done.
void OnGetUnfinishedWorkDone( void OnGetUnfinishedWorkDone(
std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); std::unique_ptr<PrecacheUnfinishedWork> unfinished_work);
...@@ -179,12 +187,15 @@ class PrecacheManager : public KeyedService, ...@@ -179,12 +187,15 @@ class PrecacheManager : public KeyedService,
AllowedType PrecachingAllowed() const; AllowedType PrecachingAllowed() const;
// Update precache-related metrics in response to a URL being fetched. // Update precache-related metrics in response to a URL being fetched.
void RecordStatsForFetch(const GURL& url, void RecordStatsForFetch(
const GURL& referrer, const GURL& url,
const base::TimeDelta& latency, const GURL& referrer,
const base::Time& fetch_time, const base::TimeDelta& latency,
const net::HttpResponseInfo& info, const base::Time& fetch_time,
int64_t size); const net::HttpResponseInfo& info,
int64_t size,
const base::Callback<void(base::Time)>& register_synthetic_trial,
base::Time last_precache_time);
// Update precache-related metrics in response to a URL being fetched. Called // Update precache-related metrics in response to a URL being fetched. Called
// by RecordStatsForFetch() by way of an asynchronous HistoryService callback. // by RecordStatsForFetch() by way of an asynchronous HistoryService callback.
......
...@@ -67,11 +67,13 @@ class PrecacheDatabase { ...@@ -67,11 +67,13 @@ class PrecacheDatabase {
base::Time GetLastPrecacheTimestamp(); base::Time GetLastPrecacheTimestamp();
// Report precache-related metrics in response to a URL being fetched, where // Report precache-related metrics in response to a URL being fetched, where
// the fetch was motivated by precaching. // the fetch was motivated by precaching. This is called from the network
// delegate, via precache_util.
void RecordURLPrefetchMetrics(const net::HttpResponseInfo& info, void RecordURLPrefetchMetrics(const net::HttpResponseInfo& info,
const base::TimeDelta& latency); const base::TimeDelta& latency);
// Records the precache of an url |url| for top host |referrer_host|. // Records the precache of an url |url| for top host |referrer_host|. This is
// called from PrecacheFetcher.
void RecordURLPrefetch(const GURL& url, void RecordURLPrefetch(const GURL& url,
const std::string& referrer_host, const std::string& referrer_host,
const base::Time& fetch_time, const base::Time& fetch_time,
...@@ -81,6 +83,7 @@ class PrecacheDatabase { ...@@ -81,6 +83,7 @@ class PrecacheDatabase {
// Report precache-related metrics in response to a URL being fetched, where // Report precache-related metrics in response to a URL being fetched, where
// the fetch was not motivated by precaching. |is_connection_cellular| // the fetch was not motivated by precaching. |is_connection_cellular|
// indicates whether the current network connection is a cellular network. // indicates whether the current network connection is a cellular network.
// This is called from the network delegate, via precache_util.
void RecordURLNonPrefetch(const GURL& url, void RecordURLNonPrefetch(const GURL& url,
const base::TimeDelta& latency, const base::TimeDelta& latency,
const base::Time& fetch_time, const base::Time& fetch_time,
...@@ -124,6 +127,7 @@ class PrecacheDatabase { ...@@ -124,6 +127,7 @@ class PrecacheDatabase {
private: private:
friend class PrecacheDatabaseTest; friend class PrecacheDatabaseTest;
friend class PrecacheFetcherTest; friend class PrecacheFetcherTest;
friend class PrecacheManagerTest;
bool IsDatabaseAccessible() const; bool IsDatabaseAccessible() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment