Commit 535b3d91 authored by Filip Gorski's avatar Filip Gorski Committed by Commit Bot

[EoC] Adding basic methods for event reporting

* Wires evend reporting for Explore on Content from the bridge to the
  contextual content suggestions service

Bug: 824185, 824186
Change-Id: Ie03931a90c6ad7bb2db204fe26ce2a769c81d141
Reviewed-on: https://chromium-review.googlesource.com/989410
Commit-Queue: Filip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547612}
parent bc323f8c
......@@ -12,6 +12,7 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.ntp.snippets.KnownCategories;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList;
import java.util.List;
......@@ -73,11 +74,14 @@ public class ContextualSuggestionsBridge {
/**
* Reports an event happening in the context of the current URL.
*
* @param webContents Web contents with the document for which event is reported.
* @param eventId Id of the reported event.
*/
public void reportEvent(int eventId) {
public void reportEvent(WebContents webContents, int eventId) {
assert mNativeContextualSuggestionsBridge != 0;
nativeReportEvent(mNativeContextualSuggestionsBridge, eventId);
assert webContents != null && !webContents.isDestroyed();
nativeReportEvent(mNativeContextualSuggestionsBridge, webContents, eventId);
}
@CalledByNative
......@@ -112,5 +116,6 @@ public class ContextualSuggestionsBridge {
private native void nativeFetchSuggestionFavicon(
long nativeContextualSuggestionsBridge, String suggestionId, Callback<Bitmap> callback);
private native void nativeClearState(long nativeContextualSuggestionsBridge);
private native void nativeReportEvent(long nativeContextualSuggestionsBridge, int eventId);
private native void nativeReportEvent(
long nativeContextualSuggestionsBridge, WebContents webContents, int eventId);
}
......@@ -13,6 +13,8 @@
#include "chrome/browser/profiles/profile_android.h"
#include "components/ntp_snippets/category.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ukm/content/source_url_recorder.h"
#include "content/public/browser/web_contents.h"
#include "jni/ContextualSuggestionsBridge_jni.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/image/image.h"
......@@ -122,9 +124,23 @@ void ContextualSuggestionsBridge::ClearState(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
}
void ContextualSuggestionsBridge::ReportEvent(JNIEnv* env,
const JavaParamRef<jobject>& obj,
jint j_event_id) {}
void ContextualSuggestionsBridge::ReportEvent(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jobject>& j_web_contents,
jint j_event_id) {
if (!contextual_content_suggestions_service_)
return;
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(j_web_contents);
ukm::SourceId ukm_source_id =
ukm::GetSourceIdForWebContentsDocument(web_contents);
contextual_content_suggestions_service_->ReportEvent(ukm_source_id,
j_event_id);
}
void ContextualSuggestionsBridge::OnSuggestionsAvailable(
ScopedJavaGlobalRef<jobject> j_callback,
......
......@@ -58,6 +58,7 @@ class ContextualSuggestionsBridge {
// Reports an event happening in UI (for the purpose of metrics collection).
void ReportEvent(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jobject>& j_web_contents,
jint j_event_id);
private:
......
......@@ -163,6 +163,7 @@ static_library("ntp_snippets") {
"//components/variations/service",
"//components/web_resource",
"//services/identity/public/cpp",
"//services/metrics/public/cpp:metrics_cpp",
"//third_party/icu/",
"//ui/gfx",
]
......
......@@ -26,6 +26,7 @@ include_rules = [
"+net/url_request",
"+google_apis",
"+services/identity/public/cpp",
"+services/metrics/public/cpp",
"+ui/base",
"+ui/gfx",
]
......@@ -69,6 +69,10 @@ void ContextualContentSuggestionsService::FetchContextualSuggestionImage(
}
}
void ContextualContentSuggestionsService::ReportEvent(
ukm::SourceId ukm_source_id,
int event_id) {}
// TODO(gaschler): Cache contextual suggestions at run-time.
void ContextualContentSuggestionsService::DidFetchContextualSuggestions(
const GURL& url,
......
......@@ -17,6 +17,7 @@
#include "components/ntp_snippets/callbacks.h"
#include "components/ntp_snippets/content_suggestion.h"
#include "components/ntp_snippets/contextual/contextual_suggestions_fetcher.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
namespace ntp_snippets {
......@@ -69,6 +70,10 @@ class ContextualContentSuggestionsService : public KeyedService {
const ContentSuggestion::ID& suggestion_id,
ImageFetchedCallback callback);
// Used to report events using various metrics (e.g. UMA, UKM).
// TODO(donnd): Change type of event ID, implement.
void ReportEvent(ukm::SourceId sourceId, int event_id);
private:
void DidFetchContextualSuggestions(
const GURL& url,
......
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