summaryrefslogtreecommitdiffstats
path: root/components/suggestions
diff options
context:
space:
mode:
authorfserb <fserb@chromium.org>2015-09-08 09:38:35 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-08 16:39:27 +0000
commitdfc94c7413f8d6c45effcfc89e86b513c83440fe (patch)
tree18197d3ad8e76fe2144e277b420f4239568425a2 /components/suggestions
parentfe051b75d3ef6bf3104b305ea2150f3d2d919a61 (diff)
downloadchromium_src-dfc94c7413f8d6c45effcfc89e86b513c83440fe.zip
chromium_src-dfc94c7413f8d6c45effcfc89e86b513c83440fe.tar.gz
chromium_src-dfc94c7413f8d6c45effcfc89e86b513c83440fe.tar.bz2
Add impression/click pings to MostLikely suggestions on SuggestionsService/LocalNTP
BUG=514752 Review URL: https://codereview.chromium.org/1312103005 Cr-Commit-Position: refs/heads/master@{#347718}
Diffstat (limited to 'components/suggestions')
-rw-r--r--components/suggestions/proto/suggestions.proto11
-rw-r--r--components/suggestions/suggestions_service.cc16
-rw-r--r--components/suggestions/suggestions_service.h4
-rw-r--r--components/suggestions/suggestions_service_unittest.cc9
4 files changed, 35 insertions, 5 deletions
diff --git a/components/suggestions/proto/suggestions.proto b/components/suggestions/proto/suggestions.proto
index 8771de6..12621e4 100644
--- a/components/suggestions/proto/suggestions.proto
+++ b/components/suggestions/proto/suggestions.proto
@@ -21,14 +21,19 @@ enum ProviderId {
// The SuggestionsProfile is a protobuf response from the server that contains
// the list of suggestions to be presented to the user.
//
+// Notice that the tags on this proto must match the ones on the server side.
+//
// Next tag: 2
message SuggestionsProfile {
repeated ChromeSuggestion suggestions = 1;
+
+ // Timestamp when the profile was generated (usec).
+ optional int64 timestamp = 16;
}
// The suggestions for this user, ordered from best to worst.
//
-// Next tag: 6
+// Next tag: 15
message ChromeSuggestion {
// The URL of the suggestion.
optional string url = 1;
@@ -47,6 +52,10 @@ message ChromeSuggestion {
// The timestamp (usec) at which this suggestion ceases to be valid.
optional int64 expiry_ts = 7;
+
+ // URL that should be pinged back when the suggestion is shown/clicked.
+ optional string impression_url = 13;
+ optional string click_url = 14;
}
// A list of URLs that should be filtered from the SuggestionsProfile.
diff --git a/components/suggestions/suggestions_service.cc b/components/suggestions/suggestions_service.cc
index 666ee51..1cfa265 100644
--- a/components/suggestions/suggestions_service.cc
+++ b/components/suggestions/suggestions_service.cc
@@ -85,6 +85,8 @@ const int kSchedulingMaxDelaySec = 5 * 60;
const char kFaviconURL[] =
"https://s2.googleusercontent.com/s2/favicons?domain_url=%s&alt=s&sz=32";
+const char kPingURL[] =
+ "https://www.google.com/chromesuggestions/click?q=%lld&cd=%d";
} // namespace
// TODO(mathp): Put this in TemplateURL.
@@ -319,7 +321,7 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) {
int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch())
.ToInternalValue();
SetDefaultExpiryTimestamp(&suggestions, now_usec + kDefaultExpiryUsec);
- PopulateFaviconUrls(&suggestions);
+ PopulateExtraData(&suggestions);
suggestions_store_->StoreSuggestions(suggestions);
} else {
LogResponseState(RESPONSE_INVALID);
@@ -329,12 +331,22 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) {
ScheduleBlacklistUpload();
}
-void SuggestionsService::PopulateFaviconUrls(SuggestionsProfile* suggestions) {
+void SuggestionsService::PopulateExtraData(SuggestionsProfile* suggestions) {
for (int i = 0; i < suggestions->suggestions_size(); ++i) {
suggestions::ChromeSuggestion* s = suggestions->mutable_suggestions(i);
if (!s->has_favicon_url() || s->favicon_url().empty()) {
s->set_favicon_url(base::StringPrintf(kFaviconURL, s->url().c_str()));
}
+ if (!s->has_impression_url() || s->impression_url().empty()) {
+ s->set_impression_url(
+ base::StringPrintf(
+ kPingURL, static_cast<long long>(suggestions->timestamp()), -1));
+ }
+
+ if (!s->has_click_url() || s->click_url().empty()) {
+ s->set_click_url(base::StringPrintf(
+ kPingURL, static_cast<long long>(suggestions->timestamp()), i));
+ }
}
}
diff --git a/components/suggestions/suggestions_service.h b/components/suggestions/suggestions_service.h
index 7f0aab3..8bfe0c2 100644
--- a/components/suggestions/suggestions_service.h
+++ b/components/suggestions/suggestions_service.h
@@ -143,8 +143,8 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate {
// Updates |scheduling_delay_| based on the success of the last request.
void UpdateBlacklistDelay(bool last_request_successful);
- // Adds favicon URLs to suggestions profile.
- void PopulateFaviconUrls(SuggestionsProfile* suggestions);
+ // Adds extra data to suggestions profile.
+ void PopulateExtraData(SuggestionsProfile* suggestions);
// Test seams.
base::TimeDelta blacklist_delay() const { return scheduling_delay_; }
diff --git a/components/suggestions/suggestions_service_unittest.cc b/components/suggestions/suggestions_service_unittest.cc
index 355450c..b4677cf 100644
--- a/components/suggestions/suggestions_service_unittest.cc
+++ b/components/suggestions/suggestions_service_unittest.cc
@@ -39,6 +39,10 @@ const char kTestUrl[] = "http://go.com";
const char kTestFaviconUrl[] =
"https://s2.googleusercontent.com/s2/favicons?domain_url="
"http://go.com&alt=s&sz=32";
+const char kTestImpressionUrl[] =
+ "https://www.google.com/chromesuggestions/click?q=123&cd=-1";
+const char kTestClickUrl[] =
+ "https://www.google.com/chromesuggestions/click?q=123&cd=0";
const char kBlacklistUrl[] = "http://blacklist.com";
const char kBlacklistUrlAlt[] = "http://blacklist-atl.com";
const int64 kTestDefaultExpiry = 1402200000000000;
@@ -84,6 +88,7 @@ namespace suggestions {
SuggestionsProfile CreateSuggestionsProfile() {
SuggestionsProfile profile;
+ profile.set_timestamp(123);
ChromeSuggestion* suggestion = profile.add_suggestions();
suggestion->set_title(kTestTitle);
suggestion->set_url(kTestUrl);
@@ -94,6 +99,7 @@ SuggestionsProfile CreateSuggestionsProfile() {
// Creates one suggestion with expiry timestamp and one without.
SuggestionsProfile CreateSuggestionsProfileWithExpiryTimestamps() {
SuggestionsProfile profile;
+ profile.set_timestamp(123);
ChromeSuggestion* suggestion = profile.add_suggestions();
suggestion->set_title(kTestTitle);
suggestion->set_url(kTestUrl);
@@ -164,6 +170,9 @@ class SuggestionsServiceTest : public testing::Test {
EXPECT_EQ(kTestUrl, suggestions_profile.suggestions(0).url());
EXPECT_EQ(kTestFaviconUrl,
suggestions_profile.suggestions(0).favicon_url());
+ EXPECT_EQ(kTestImpressionUrl,
+ suggestions_profile.suggestions(0).impression_url());
+ EXPECT_EQ(kTestClickUrl, suggestions_profile.suggestions(0).click_url());
}
void SetBlacklistFailure() {