| Index: chrome/browser/android/contextualsearch/ctr_recorder.cc
|
| diff --git a/chrome/browser/android/contextualsearch/ctr_recorder.cc b/chrome/browser/android/contextualsearch/ctr_recorder.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2da620943fdbac88adb9b4d61a2c13f9b88f9dac
|
| --- /dev/null
|
| +++ b/chrome/browser/android/contextualsearch/ctr_recorder.cc
|
| @@ -0,0 +1,88 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/android/contextualsearch/ctr_recorder.h"
|
| +
|
| +#include <set>
|
| +
|
| +#include "base/android/jni_string.h"
|
| +#include "base/android/scoped_java_ref.h"
|
| +#include "chrome/browser/android/contextualsearch/contextual_search_context.h"
|
| +#include "jni/CTRRecorder_jni.h"
|
| +
|
| +using base::android::AttachCurrentThread;
|
| +using base::android::ConvertUTF8ToJavaString;
|
| +using base::android::JavaParamRef;
|
| +using base::android::ScopedJavaLocalRef;
|
| +
|
| +CTRRecorder::CTRRecorder(JNIEnv* env, jobject obj) {
|
| + java_object_.Reset(env, obj);
|
| +
|
| + aggregator_.reset(new contextual_search::CTRAggregator(*this));
|
| + DCHECK(aggregator_);
|
| +}
|
| +
|
| +CTRRecorder::~CTRRecorder() {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + Java_CTRRecorder_clearNativePointer(env, java_object_.obj());
|
| +}
|
| +
|
| +// Java conduit
|
| +
|
| +void CTRRecorder::RecordImpression(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj,
|
| + jboolean did_click) {
|
| + aggregator_->RecordImpression(did_click);
|
| +}
|
| +
|
| +jboolean CTRRecorder::HasPreviousWeekData(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj) {
|
| + return aggregator_->HasPreviousWeekData();
|
| +}
|
| +
|
| +jfloat CTRRecorder::GetPreviousWeekCTR(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj) {
|
| + return aggregator_->GetPreviousWeekCTR();
|
| +}
|
| +
|
| +jboolean CTRRecorder::HasPrevious28DayData(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj) {
|
| + return aggregator_->HasPrevious28DayData();
|
| +}
|
| +
|
| +jfloat CTRRecorder::GetPrevious28DayCTR(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj) {
|
| + return aggregator_->GetPrevious28DayCTR();
|
| +}
|
| +
|
| +// DeviceIntStorage
|
| +
|
| +int CTRRecorder::ReadInt(std::string storage_key) {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jstring> j_storage_key =
|
| + ConvertUTF8ToJavaString(env, storage_key.c_str());
|
| + return Java_CTRRecorder_readInt(env, java_object_, j_storage_key);
|
| +}
|
| +
|
| +void CTRRecorder::WriteInt(std::string storage_key, int value) {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jstring> j_storage_key =
|
| + ConvertUTF8ToJavaString(env, storage_key.c_str());
|
| + Java_CTRRecorder_writeInt(env, java_object_, j_storage_key, value);
|
| +}
|
| +
|
| +// Java conduit boilerplate
|
| +
|
| +void CTRRecorder::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
| + delete this;
|
| +}
|
| +
|
| +bool RegisterCTRRecorder(JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
| + CTRRecorder* recorder = new CTRRecorder(env, obj);
|
| + return reinterpret_cast<intptr_t>(recorder);
|
| +}
|
|
|