summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authortburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 17:32:30 +0000
committertburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 17:32:30 +0000
commitb9370fcd6785eda5cb6572b90bdfdc058d0e5911 (patch)
treef338247b7251e4589882a72f38c2e060e98e32f8 /chrome
parent8755298521e5dc36c5a7f015b4e2161e679a6e59 (diff)
downloadchromium_src-b9370fcd6785eda5cb6572b90bdfdc058d0e5911.zip
chromium_src-b9370fcd6785eda5cb6572b90bdfdc058d0e5911.tar.gz
chromium_src-b9370fcd6785eda5cb6572b90bdfdc058d0e5911.tar.bz2
Adding a local predictor field trial, and a facility
to report local predictor stats based on a whitelist of URL hashes (only placeholder dummy file for now). R=shishir@chromium.org Review URL: https://codereview.chromium.org/11364034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_resources.grd2
-rw-r--r--chrome/browser/prerender/prerender_field_trial.cc27
-rw-r--r--chrome/browser/prerender/prerender_field_trial.h3
-rw-r--r--chrome/browser/prerender/prerender_local_predictor.cc55
-rw-r--r--chrome/browser/prerender/prerender_local_predictor.h7
-rw-r--r--chrome/browser/prerender/prerender_manager.cc3
-rw-r--r--chrome/browser/resources/prerender_url_whitelist.dat1
7 files changed, 98 insertions, 0 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index bffa941..6b46316 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -157,6 +157,8 @@
<include name="IDR_POLICY_CSS" file="resources\policy.css" type="BINDATA"/>
<include name="IDR_POLICY_HTML" file="resources\policy.html" flattenhtml="true" allowexternalscript="true" type="BINDATA"/>
<include name="IDR_POLICY_JS" file="resources\policy.js" type="BINDATA"/>
+ <include name="IDR_PRERENDER_URL_WHITELIST"
+ file="resources\prerender_url_whitelist.dat" type="BINDATA"/>
<if expr="pp_ifdef('enable_printing')">
<include name="IDR_PRINT_PREVIEW_HTML" file="resources\print_preview\print_preview.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_PRINT_PREVIEW_JS" file="resources\print_preview\print_preview.js" flattenhtml="true" type="BINDATA" />
diff --git a/chrome/browser/prerender/prerender_field_trial.cc b/chrome/browser/prerender/prerender_field_trial.cc
index 7938dca..15bd501 100644
--- a/chrome/browser/prerender/prerender_field_trial.cc
+++ b/chrome/browser/prerender/prerender_field_trial.cc
@@ -30,6 +30,9 @@ const char kSpeculativePrefetchingTrialName[] = "SpeculativePrefetching";
int g_speculative_prefetching_learning_group = kint32min;
int g_speculative_prefetching_prefetching_group = kint32min;
+const char kLocalPredictorTrialName[] = "PrerenderLocalPredictor";
+int g_local_predictor_default_group_number = kint32min;
+
void SetupPrefetchFieldTrial() {
chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
@@ -143,6 +146,7 @@ void SetupPrerenderFieldTrial() {
void ConfigureOmniboxPrerender();
void ConfigureSpeculativePrefetching();
+void ConfigureLocalPredictor();
void ConfigurePrefetchAndPrerender(const CommandLine& command_line) {
enum PrerenderOption {
@@ -204,6 +208,7 @@ void ConfigurePrefetchAndPrerender(const CommandLine& command_line) {
ConfigureOmniboxPrerender();
ConfigureSpeculativePrefetching();
+ ConfigureLocalPredictor();
}
void ConfigureOmniboxPrerender() {
@@ -333,4 +338,26 @@ bool IsSpeculativeResourcePrefetchingEnabled(Profile* profile) {
return group == g_speculative_prefetching_prefetching_group;
}
+void ConfigureLocalPredictor() {
+ const FieldTrial::Probability kDivisor = 100;
+
+ FieldTrial::Probability kEnableProbability = 90;
+ chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
+ if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
+ channel == chrome::VersionInfo::CHANNEL_BETA) {
+ kEnableProbability = 1;
+ }
+ scoped_refptr<FieldTrial> local_predictor_trial(
+ FieldTrialList::FactoryGetFieldTrial(
+ kLocalPredictorTrialName, kDivisor, "Disabled",
+ 2013, 12, 31, &g_local_predictor_default_group_number));
+ local_predictor_trial->AppendGroup("Enabled", kEnableProbability);
+}
+
+bool IsLocalPredictorEnabled() {
+ const int group = FieldTrialList::FindValue(kLocalPredictorTrialName);
+ return (group != FieldTrial::kNotFinalized &&
+ group != g_omnibox_trial_default_group_number);
+}
+
} // namespace prerender
diff --git a/chrome/browser/prerender/prerender_field_trial.h b/chrome/browser/prerender/prerender_field_trial.h
index 3cd4fc3..3efcbad 100644
--- a/chrome/browser/prerender/prerender_field_trial.h
+++ b/chrome/browser/prerender/prerender_field_trial.h
@@ -29,6 +29,9 @@ bool IsSpeculativeResourcePrefetchingLearningEnabled(Profile* profile);
// resource prefetching experiment.
bool IsSpeculativeResourcePrefetchingEnabled(Profile* profile);
+// Returns true iff the Prerender Local Predictor is enabled.
+bool IsLocalPredictorEnabled();
+
} // namespace prerender
#endif // CHROME_BROWSER_PRERENDER_PRERENDER_FIELD_TRIAL_H_
diff --git a/chrome/browser/prerender/prerender_local_predictor.cc b/chrome/browser/prerender/prerender_local_predictor.cc
index d7fdfc9..cf371ee 100644
--- a/chrome/browser/prerender/prerender_local_predictor.cc
+++ b/chrome/browser/prerender/prerender_local_predictor.cc
@@ -23,6 +23,9 @@
#include "chrome/browser/history/history_service_factory.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/page_transition_types.h"
+#include "crypto/secure_hash.h"
+#include "grit/browser_resources.h"
+#include "ui/base/resource/resource_bundle.h"
using content::BrowserThread;
using content::PageTransition;
@@ -32,6 +35,8 @@ namespace prerender {
namespace {
+static const size_t kURLHashSize = 5;
+
// Task to lookup the URL for a given URLID.
class GetURLForURLIDTask : public HistoryDBTask {
public:
@@ -144,6 +149,24 @@ bool IsRootPageURL(const GURL& url) {
(!url.has_ref());
}
+int64 URLHashToInt64(const unsigned char* data) {
+ COMPILE_ASSERT(kURLHashSize < sizeof(int64), url_hash_must_fit_in_int64);
+ int64 value = 0;
+ memcpy(&value, data, kURLHashSize);
+ return value;
+}
+
+int64 GetInt64URLHashForURL(const GURL& url) {
+ COMPILE_ASSERT(kURLHashSize < sizeof(int64), url_hash_must_fit_in_int64);
+ scoped_ptr<crypto::SecureHash> hash(
+ crypto::SecureHash::Create(crypto::SecureHash::SHA256));
+ int64 hash_value = 0;
+ const char* url_string = url.spec().c_str();
+ hash->Update(url_string, strlen(url_string));
+ hash->Finish(&hash_value, kURLHashSize);
+ return hash_value;
+}
+
} // namespace
struct PrerenderLocalPredictor::PrerenderData {
@@ -183,6 +206,33 @@ PrerenderLocalPredictor::PrerenderLocalPredictor(
&PrerenderLocalPredictor::Init);
RecordEvent(EVENT_INIT_SCHEDULED);
}
+
+ static const size_t kChecksumHashSize = 32;
+ base::RefCountedStaticMemory* url_whitelist_data =
+ ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
+ IDR_PRERENDER_URL_WHITELIST, ui::SCALE_FACTOR_NONE);
+ size_t size = url_whitelist_data->size();
+ const unsigned char* front = url_whitelist_data->front();
+ if (size < kChecksumHashSize ||
+ (size - kChecksumHashSize) % kURLHashSize != 0) {
+ RecordEvent(EVENT_URL_WHITELIST_ERROR);
+ return;
+ }
+ scoped_ptr<crypto::SecureHash> hash(
+ crypto::SecureHash::Create(crypto::SecureHash::SHA256));
+ hash->Update(front + kChecksumHashSize, size - kChecksumHashSize);
+ char hash_value[kChecksumHashSize];
+ hash->Finish(hash_value, kChecksumHashSize);
+ if (memcmp(hash_value, front, kChecksumHashSize)) {
+ RecordEvent(EVENT_URL_WHITELIST_ERROR);
+ return;
+ }
+ for (const unsigned char* p = front + kChecksumHashSize;
+ p < front + size;
+ p += kURLHashSize) {
+ url_whitelist_.insert(URLHashToInt64(p));
+ }
+ RecordEvent(EVENT_URL_WHITELIST_OK);
}
PrerenderLocalPredictor::~PrerenderLocalPredictor() {
@@ -318,6 +368,11 @@ void PrerenderLocalPredictor::OnLookupURL(history::URLID url_id,
}
}
+ if (url_whitelist_.count(GetInt64URLHashForURL(url)) > 0) {
+ RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST);
+ if (IsRootPageURL(url))
+ RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST_ROOT_PAGE);
+ }
if (IsRootPageURL(url))
RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ROOT_PAGE);
if (url.SchemeIs("http"))
diff --git a/chrome/browser/prerender/prerender_local_predictor.h b/chrome/browser/prerender/prerender_local_predictor.h
index 4543aed..375fdf6 100644
--- a/chrome/browser/prerender/prerender_local_predictor.h
+++ b/chrome/browser/prerender/prerender_local_predictor.h
@@ -7,6 +7,7 @@
#include <vector>
+#include "base/hash_tables.h"
#include "base/timer.h"
#include "chrome/browser/common/cancelable_request.h"
#include "chrome/browser/history/visit_database.h"
@@ -47,6 +48,10 @@ class PrerenderLocalPredictor : public history::VisitDatabaseObserver {
EVENT_PRERENDER_URL_LOOKUP_RESULT_CONTAINS_LOGIN = 19,
EVENT_START_URL_LOOKUP = 20,
EVENT_ADD_VISIT_NOT_ROOTPAGE = 21,
+ EVENT_URL_WHITELIST_ERROR = 22,
+ EVENT_URL_WHITELIST_OK = 23,
+ EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST = 24,
+ EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST_ROOT_PAGE = 25,
EVENT_MAX_VALUE
};
@@ -95,6 +100,8 @@ class PrerenderLocalPredictor : public history::VisitDatabaseObserver {
scoped_ptr<PrerenderData> current_prerender_;
scoped_ptr<PrerenderData> last_swapped_in_prerender_;
+ base::hash_set<int64> url_whitelist_;
+
DISALLOW_COPY_AND_ASSIGN(PrerenderLocalPredictor);
};
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index 4c25663..342bf34 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -200,6 +200,9 @@ PrerenderManager::PrerenderManager(Profile* profile,
// the same thread that it was created on.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (IsLocalPredictorEnabled())
+ local_predictor_.reset(new PrerenderLocalPredictor(this));
+
// Certain experiments override our default config_ values.
switch (PrerenderManager::GetMode()) {
case PrerenderManager::PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP:
diff --git a/chrome/browser/resources/prerender_url_whitelist.dat b/chrome/browser/resources/prerender_url_whitelist.dat
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/chrome/browser/resources/prerender_url_whitelist.dat
@@ -0,0 +1 @@
+0