Chromium Code Reviews| Index: chrome/browser/android/contextualsearch/ctr_recorder.h |
| diff --git a/chrome/browser/android/contextualsearch/ctr_recorder.h b/chrome/browser/android/contextualsearch/ctr_recorder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0adeb1e22ac2c915eae98486c3d77cc3d9581c66 |
| --- /dev/null |
| +++ b/chrome/browser/android/contextualsearch/ctr_recorder.h |
| @@ -0,0 +1,84 @@ |
| +// 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. |
| + |
| +#ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CTR_RECORDER_H_ |
| +#define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CTR_RECORDER_H_ |
| + |
| +#include <stddef.h> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "components/contextual_search/browser/ctr_aggregator.h" |
| +#include "components/contextual_search/browser/weekly_activity_storage.h" |
| + |
| +// Provides a Java conduit to the CTRAggregator in the Contextual Search |
| +// component. This allows Java to access the aggregated CTR values. |
| +// This class also provides device-specific integer storage through its |
| +// associated Java class as required to implement the WeeklyActivityStorage. |
| +class CTRRecorder : public contextual_search::WeeklyActivityStorage { |
| + public: |
| + // Constructs a new CTRRecorder linked to the given Java object. |
| + CTRRecorder(JNIEnv* env, jobject obj); |
| + ~CTRRecorder() override; |
| + |
| + // Calls the destructor. Should be called when this native object is no |
| + // longer needed. |
| + void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| + |
| + // Records an impression. Also records a click if |did_click| is true. |
| + void RecordImpression(JNIEnv* env, |
|
Theresa
2016/09/27 20:53:56
For the methods that just call through to componen
Donn Denman
2016/09/28 00:38:43
Done.
|
| + const base::android::JavaParamRef<jobject>& obj, |
| + jboolean did_click); |
| + // Returns the current week number. |
| + jint GetCurrentWeekNumber(JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj); |
| + // Returns whether there is data recorded for the previous week. |
| + jboolean HasPreviousWeekData(JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj); |
| + // Returns the number of impressions for this user for the previous week. |
| + // If the data for this user is not complete for the previous week, as |
| + // indicated by |HasPreviousWeekData| then NAN is returned. |
| + jint GetPreviousWeekImpressions( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj); |
| + // Returns the CTR for this user for the previous week. |
| + // If the data for this user is not complete for the previous week, as |
| + // indicated by |HasPreviousWeekData| then the result is undefined. |
| + jfloat GetPreviousWeekCTR(JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj); |
| + // Returns whether there is data recorded for the previous 28-day period that |
| + // ended in the previous week. |
| + jboolean HasPrevious28DayData( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj); |
| + // Returns the number of impressions for this user for the 28-day period that |
| + // ended in the previous week. If the data for this user is not complete for |
| + // the 28-day period that ended in the previous week, as indicated by |
| + // |HasPrevious28DayData| then the result is undefined. |
| + jint GetPrevious28DayImpressions( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj); |
| + // Returns the CTR for this user for the 28-day period that ended in the |
| + // previous week. If the data for this user is not complete for the 28-day |
| + // period that ended in the previous week, as indicated by |
| + // |HasPrevious28DayData| then NAN is returned. |
| + jfloat GetPrevious28DayCTR(JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj); |
| + |
| + // WeeklyActivityStorage Overrides. |
| + int ReadStorage(std::string storage_bucket) override; |
| + void WriteStorage(std::string storage_bucket, int value) override; |
| + |
| + private: |
| + // The CTRAggregator that we forward requests to. |
| + std::unique_ptr<contextual_search::CTRAggregator> aggregator_; |
| + |
| + // The linked Java object. |
| + base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CTRRecorder); |
| +}; |
| + |
| +bool RegisterCTRRecorder(JNIEnv* env); |
| + |
| +#endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CTR_RECORDER_H_ |