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

Side by Side Diff: chrome/browser/android/ntp/ntp_snippets_bridge.cc

Issue 2609413005: [NTP::SectionOrder] Add category position metric for opened suggestions. (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h" 5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <algorithm>
8 #include <utility> 9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/android/callback_android.h" 12 #include "base/android/callback_android.h"
12 #include "base/android/jni_android.h" 13 #include "base/android/jni_android.h"
13 #include "base/android/jni_array.h" 14 #include "base/android/jni_array.h"
14 #include "base/android/jni_string.h" 15 #include "base/android/jni_string.h"
15 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/stl_util.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "chrome/browser/history/history_service_factory.h" 19 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" 20 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_android.h" 22 #include "chrome/browser/profiles/profile_android.h"
21 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
22 #include "components/history/core/browser/history_service.h" 24 #include "components/history/core/browser/history_service.h"
23 #include "components/ntp_snippets/content_suggestion.h" 25 #include "components/ntp_snippets/content_suggestion.h"
24 #include "components/ntp_snippets/content_suggestions_metrics.h" 26 #include "components/ntp_snippets/content_suggestions_metrics.h"
25 #include "components/ntp_snippets/pref_names.h" 27 #include "components/ntp_snippets/pref_names.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 ntp_snippets::ContentSuggestionsService* content_suggestions_service = 102 ntp_snippets::ContentSuggestionsService* content_suggestions_service =
101 ContentSuggestionsServiceFactory::GetForProfile( 103 ContentSuggestionsServiceFactory::GetForProfile(
102 ProfileManager::GetLastUsedProfile()); 104 ProfileManager::GetLastUsedProfile());
103 // Can maybe be null in some cases? (Incognito profile?) crbug.com/647920 105 // Can maybe be null in some cases? (Incognito profile?) crbug.com/647920
104 if (!content_suggestions_service) { 106 if (!content_suggestions_service) {
105 return nullptr; 107 return nullptr;
106 } 108 }
107 return content_suggestions_service->remote_suggestions_scheduler(); 109 return content_suggestions_service->remote_suggestions_scheduler();
108 } 110 }
109 111
112 int GetCategoryPosition(
113 Category category,
114 const ntp_snippets::ContentSuggestionsService* service) {
115 std::vector<Category> ordered_categories = service->GetCategories();
116 DCHECK(base::ContainsValue(ordered_categories, category));
117 auto it =
118 std::find(ordered_categories.begin(), ordered_categories.end(), category);
119 return it - ordered_categories.begin();
120 }
noyau (Ping after 24h) 2017/01/05 14:38:04 Can this lookup can be done by the metrics code in
vitaliii 2017/01/05 15:16:59 Done.
jkrcal 2017/01/05 15:18:08 I am not sure this is the right way, since metrics
vitaliii 2017/01/05 15:47:37 Acknowledged.
121
110 } // namespace 122 } // namespace
111 123
112 static jlong Init(JNIEnv* env, 124 static jlong Init(JNIEnv* env,
113 const JavaParamRef<jobject>& obj, 125 const JavaParamRef<jobject>& obj,
114 const JavaParamRef<jobject>& j_profile) { 126 const JavaParamRef<jobject>& j_profile) {
115 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); 127 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile);
116 return reinterpret_cast<intptr_t>(snippets_bridge); 128 return reinterpret_cast<intptr_t>(snippets_bridge);
117 } 129 }
118 130
119 // Initiates a background fetch for remote suggestions. 131 // Initiates a background fetch for remote suggestions.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 const base::android::JavaParamRef<jobject>& obj) { 269 const base::android::JavaParamRef<jobject>& obj) {
258 content_suggestions_service_->ReloadSuggestions(); 270 content_suggestions_service_->ReloadSuggestions();
259 } 271 }
260 272
261 void NTPSnippetsBridge::DismissSuggestion( 273 void NTPSnippetsBridge::DismissSuggestion(
262 JNIEnv* env, 274 JNIEnv* env,
263 const JavaParamRef<jobject>& obj, 275 const JavaParamRef<jobject>& obj,
264 const JavaParamRef<jstring>& jurl, 276 const JavaParamRef<jstring>& jurl,
265 jint global_position, 277 jint global_position,
266 jint j_category_id, 278 jint j_category_id,
267 jint category_position, 279 jint position_in_category,
268 const JavaParamRef<jstring>& id_within_category) { 280 const JavaParamRef<jstring>& id_within_category) {
269 Category category = Category::FromIDValue(j_category_id); 281 Category category = Category::FromIDValue(j_category_id);
270 282
271 content_suggestions_service_->DismissSuggestion(ContentSuggestion::ID( 283 content_suggestions_service_->DismissSuggestion(ContentSuggestion::ID(
272 category, ConvertJavaStringToUTF8(env, id_within_category))); 284 category, ConvertJavaStringToUTF8(env, id_within_category)));
273 285
274 history_service_->QueryURL( 286 history_service_->QueryURL(
275 GURL(ConvertJavaStringToUTF8(env, jurl)), /*want_visits=*/false, 287 GURL(ConvertJavaStringToUTF8(env, jurl)), /*want_visits=*/false,
276 base::Bind( 288 base::Bind(
277 [](int global_position, Category category, int category_position, 289 [](int global_position, Category category, int position_in_category,
278 bool success, const history::URLRow& row, 290 bool success, const history::URLRow& row,
279 const history::VisitVector& visit_vector) { 291 const history::VisitVector& visit_vector) {
280 bool visited = success && row.visit_count() != 0; 292 bool visited = success && row.visit_count() != 0;
281 ntp_snippets::metrics::OnSuggestionDismissed( 293 ntp_snippets::metrics::OnSuggestionDismissed(
282 global_position, category, category_position, visited); 294 global_position, category, position_in_category, visited);
283 }, 295 },
284 global_position, category, category_position), 296 global_position, category, position_in_category),
285 &tracker_); 297 &tracker_);
286 } 298 }
287 299
288 void NTPSnippetsBridge::DismissCategory(JNIEnv* env, 300 void NTPSnippetsBridge::DismissCategory(JNIEnv* env,
289 const JavaParamRef<jobject>& obj, 301 const JavaParamRef<jobject>& obj,
290 jint j_category_id) { 302 jint j_category_id) {
291 Category category = Category::FromIDValue(j_category_id); 303 Category category = Category::FromIDValue(j_category_id);
292 304
293 content_suggestions_service_->DismissCategory(category); 305 content_suggestions_service_->DismissCategory(category);
294 306
(...skipping 25 matching lines...) Expand all
320 } 332 }
321 ntp_snippets::metrics::OnPageShown(suggestions_per_category); 333 ntp_snippets::metrics::OnPageShown(suggestions_per_category);
322 content_suggestions_service_->user_classifier()->OnEvent( 334 content_suggestions_service_->user_classifier()->OnEvent(
323 ntp_snippets::UserClassifier::Metric::NTP_OPENED); 335 ntp_snippets::UserClassifier::Metric::NTP_OPENED);
324 } 336 }
325 337
326 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, 338 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env,
327 const JavaParamRef<jobject>& obj, 339 const JavaParamRef<jobject>& obj,
328 jint global_position, 340 jint global_position,
329 jint j_category_id, 341 jint j_category_id,
330 jint category_position, 342 jint position_in_category,
331 jlong publish_timestamp_ms, 343 jlong publish_timestamp_ms,
332 jfloat score) { 344 jfloat score) {
333 PrefService* pref_service = ProfileManager::GetLastUsedProfile()->GetPrefs(); 345 PrefService* pref_service = ProfileManager::GetLastUsedProfile()->GetPrefs();
334 base::Time last_background_fetch_time = 346 base::Time last_background_fetch_time =
335 base::Time::FromInternalValue(pref_service->GetInt64( 347 base::Time::FromInternalValue(pref_service->GetInt64(
336 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); 348 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime));
337 349
338 ntp_snippets::metrics::OnSuggestionShown( 350 ntp_snippets::metrics::OnSuggestionShown(
339 global_position, Category::FromIDValue(j_category_id), category_position, 351 global_position, Category::FromIDValue(j_category_id),
340 base::Time::FromJavaTime(publish_timestamp_ms), 352 position_in_category, base::Time::FromJavaTime(publish_timestamp_ms),
341 last_background_fetch_time, score); 353 last_background_fetch_time, score);
342 if (global_position == 0) { 354 if (global_position == 0) {
343 content_suggestions_service_->user_classifier()->OnEvent( 355 content_suggestions_service_->user_classifier()->OnEvent(
344 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); 356 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN);
345 } 357 }
346 } 358 }
347 359
348 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, 360 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env,
349 const JavaParamRef<jobject>& obj, 361 const JavaParamRef<jobject>& obj,
350 jint global_position, 362 jint global_position,
351 jint j_category_id, 363 jint j_category_id,
352 jint category_position, 364 jint position_in_category,
353 jlong publish_timestamp_ms, 365 jlong publish_timestamp_ms,
354 jfloat score, 366 jfloat score,
355 int windowOpenDisposition) { 367 int windowOpenDisposition) {
368 const Category category = Category::FromIDValue(j_category_id);
356 ntp_snippets::metrics::OnSuggestionOpened( 369 ntp_snippets::metrics::OnSuggestionOpened(
357 global_position, Category::FromIDValue(j_category_id), category_position, 370 global_position, category,
358 base::Time::FromJavaTime(publish_timestamp_ms), score, 371 GetCategoryPosition(category, content_suggestions_service_),
359 static_cast<WindowOpenDisposition>(windowOpenDisposition)); 372 position_in_category, base::Time::FromJavaTime(publish_timestamp_ms),
373 score, static_cast<WindowOpenDisposition>(windowOpenDisposition));
360 // TODO(vitaliii): Add ContentSuggestionsService::OnSuggestionOpened and 374 // TODO(vitaliii): Add ContentSuggestionsService::OnSuggestionOpened and
361 // notify the ranker and the classifier there instead. Do not expose both of 375 // notify the ranker and the classifier there instead. Do not expose both of
362 // them at all. See crbug.com/674080. 376 // them at all. See crbug.com/674080.
363 content_suggestions_service_->category_ranker()->OnSuggestionOpened( 377 content_suggestions_service_->category_ranker()->OnSuggestionOpened(category);
364 Category::FromIDValue(j_category_id));
365 content_suggestions_service_->user_classifier()->OnEvent( 378 content_suggestions_service_->user_classifier()->OnEvent(
366 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED); 379 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED);
367 } 380 }
368 381
369 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, 382 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env,
370 const JavaParamRef<jobject>& obj, 383 const JavaParamRef<jobject>& obj,
371 jint global_position, 384 jint global_position,
372 jint j_category_id, 385 jint j_category_id,
373 jint category_position, 386 jint position_in_category,
374 jlong publish_timestamp_ms, 387 jlong publish_timestamp_ms,
375 jfloat score) { 388 jfloat score) {
376 ntp_snippets::metrics::OnSuggestionMenuOpened( 389 ntp_snippets::metrics::OnSuggestionMenuOpened(
377 global_position, Category::FromIDValue(j_category_id), category_position, 390 global_position, Category::FromIDValue(j_category_id),
378 base::Time::FromJavaTime(publish_timestamp_ms), score); 391 position_in_category, base::Time::FromJavaTime(publish_timestamp_ms),
392 score);
379 } 393 }
380 394
381 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, 395 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env,
382 const JavaParamRef<jobject>& obj, 396 const JavaParamRef<jobject>& obj,
383 jint j_category_id, 397 jint j_category_id,
384 jint position) { 398 jint position) {
385 ntp_snippets::metrics::OnMoreButtonShown(Category::FromIDValue(j_category_id), 399 ntp_snippets::metrics::OnMoreButtonShown(Category::FromIDValue(j_category_id),
386 position); 400 position);
387 } 401 }
388 402
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 JNIEnv* env = AttachCurrentThread(); 483 JNIEnv* env = AttachCurrentThread();
470 Java_SnippetsBridge_onMoreSuggestions( 484 Java_SnippetsBridge_onMoreSuggestions(
471 env, observer_, category.id(), 485 env, observer_, category.id(),
472 ToJavaSuggestionList(env, category, suggestions)); 486 ToJavaSuggestionList(env, category, suggestions));
473 } 487 }
474 488
475 // static 489 // static
476 bool NTPSnippetsBridge::Register(JNIEnv* env) { 490 bool NTPSnippetsBridge::Register(JNIEnv* env) {
477 return RegisterNativesImpl(env); 491 return RegisterNativesImpl(env);
478 } 492 }
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/ntp_snippets_bridge.h ('k') | components/ntp_snippets/content_suggestions_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698