OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CTR_RECORDER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CTR_RECORDER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include "base/android/jni_android.h" |
| 11 #include "components/contextual_search/browser/ctr_aggregator.h" |
| 12 |
| 13 // Provides a Java conduit to the CTRAggregator in the Contextual Search |
| 14 // component. This allows Java to access the aggregated CTR values. |
| 15 // This class also provides device-specific integer storage through its |
| 16 // associated Java class as required to implement the CTRAggregator. |
| 17 class CTRRecorder : public contextual_search::DeviceIntStorage { |
| 18 public: |
| 19 // Constructs a new CTRRecorder linked to the given Java object. |
| 20 CTRRecorder(JNIEnv* env, jobject obj); |
| 21 ~CTRRecorder() override; |
| 22 |
| 23 // Should be called when this native object is no longer needed (calls the |
| 24 // destructor). |
| 25 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 26 |
| 27 // Record an impression. Records a click if |did_click| is true. |
| 28 void RecordImpression(JNIEnv* env, |
| 29 const base::android::JavaParamRef<jobject>& obj, |
| 30 jboolean did_click); |
| 31 // Returns whether there is data recorded for the previous week. |
| 32 jboolean HasPreviousWeekData(JNIEnv* env, |
| 33 const base::android::JavaParamRef<jobject>& obj); |
| 34 // Returns the CTR for this user for the previous week. |
| 35 // If the data for this user is not complete for the previous week then NAN is |
| 36 // returned. |
| 37 jfloat GetPreviousWeekCTR(JNIEnv* env, |
| 38 const base::android::JavaParamRef<jobject>& obj); |
| 39 // Returns whether there is data recorded for the previous 28-day period that |
| 40 // ended in the previous week. |
| 41 jboolean HasPrevious28DayData( |
| 42 JNIEnv* env, |
| 43 const base::android::JavaParamRef<jobject>& obj); |
| 44 // Returns the CTR for this user for the 28-day period that ended in the |
| 45 // previous week. If the data for this user is not complete for the 28-day |
| 46 // period that ended in the previous week then NAN is returned. |
| 47 jfloat GetPrevious28DayCTR(JNIEnv* env, |
| 48 const base::android::JavaParamRef<jobject>& obj); |
| 49 |
| 50 // NativeIntStorage Overrides. |
| 51 int ReadInt(std::string storage_key) override; |
| 52 void WriteInt(std::string storage_key, int value) override; |
| 53 |
| 54 private: |
| 55 // The CTRAggregator that we forward requests to. |
| 56 std::unique_ptr<contextual_search::CTRAggregator> aggregator_; |
| 57 |
| 58 // The linked Java object. |
| 59 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(CTRRecorder); |
| 62 }; |
| 63 |
| 64 bool RegisterCTRRecorder(JNIEnv* env); |
| 65 |
| 66 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CTR_RECORDER_H_ |
OLD | NEW |