OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_CONTEXTUAL_SEARCH_RANKER_LOGGER_
IMPL_H_ |
| 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_RANKER_LOGGER_
IMPL_H_ |
| 7 |
| 8 #include "base/android/jni_android.h" |
| 9 #include "components/ukm/ukm_service.h" |
| 10 #include "url/gurl.h" |
| 11 |
| 12 class GURL; |
| 13 |
| 14 namespace ukm { |
| 15 class UkmService; |
| 16 } // namespace ukm |
| 17 |
| 18 class ContextualSearchRankerLoggerImpl { |
| 19 public: |
| 20 ContextualSearchRankerLoggerImpl(JNIEnv* env, jobject obj); |
| 21 ~ContextualSearchRankerLoggerImpl(); |
| 22 |
| 23 // Calls the destructor. Should be called when this native object is no |
| 24 // longer needed. |
| 25 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 26 |
| 27 // Sets up the UKM service to log contextual Search features for the given |
| 28 // base-page URL for the given model URL. |
| 29 void SetUkmServiceAndUrls( |
| 30 JNIEnv* env, |
| 31 jobject obj, |
| 32 const base::android::JavaParamRef<jstring>& j_base_page_url, |
| 33 const base::android::JavaParamRef<jstring>& j_model_url); |
| 34 |
| 35 // Logs a long value with the given feature name. |
| 36 void LogLong(JNIEnv* env, |
| 37 jobject obj, |
| 38 const base::android::JavaParamRef<jstring>& j_feature, |
| 39 jlong j_long); |
| 40 |
| 41 // Logs a string value with the given feature name. |
| 42 void LogString(JNIEnv* env, |
| 43 jobject obj, |
| 44 const base::android::JavaParamRef<jstring>& j_feature, |
| 45 const base::android::JavaParamRef<jstring>& j_string); |
| 46 |
| 47 // Writes the currently logged data and resets the current builder to be |
| 48 // ready to start logging the next set of data. |
| 49 void WriteLogAndReset(JNIEnv* env, jobject obj); |
| 50 |
| 51 private: |
| 52 // Set the UKM service and base-page URL. |
| 53 // TODO(donnd): write a test, using this to inject a test-ukm-service. |
| 54 void SetUkmService(ukm::UkmService* ukm_service, const GURL& page_url); |
| 55 |
| 56 // Used to log URL-keyed metrics. This pointer will outlive |this|. |
| 57 ukm::UkmService* ukm_service_; |
| 58 |
| 59 // The UKM source ID being used for this session. |
| 60 int32_t source_id_; |
| 61 |
| 62 // The entry builder for the current record. |
| 63 std::unique_ptr<ukm::UkmEntryBuilder> builder_; |
| 64 |
| 65 // The linked Java object. |
| 66 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(ContextualSearchRankerLoggerImpl); |
| 69 }; |
| 70 |
| 71 bool RegisterContextualSearchRankerLoggerImpl(JNIEnv* env); |
| 72 |
| 73 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_RANKER_LOGG
ER_IMPL_H_ |
OLD | NEW |