Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ |
| 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ | 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/android/jni_weak_ref.h" | 10 #include "base/android/jni_weak_ref.h" |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "components/search_engines/template_url_service.h" | 13 #include "components/search_engines/template_url_service.h" |
| 14 #include "components/search_engines/template_url_service_observer.h" | 14 #include "components/search_engines/template_url_service_observer.h" |
| 15 | 15 |
| 16 class TemplateURL; | 16 class TemplateURL; |
| 17 | 17 |
| 18 | 18 |
| 19 // Android wrapper of the TemplateUrlService which provides access from the Java | 19 // Android wrapper of the TemplateUrlService which provides access from the Java |
| 20 // layer. Note that on Android, there's only a single profile, and therefore | 20 // layer. Note that on Android, there's only a single profile, and therefore |
| 21 // a single instance of this wrapper. | 21 // a single instance of this wrapper. |
| 22 class TemplateUrlServiceAndroid : public TemplateURLServiceObserver { | 22 class TemplateUrlServiceAndroid : public TemplateURLServiceObserver { |
| 23 public: | 23 public: |
| 24 TemplateUrlServiceAndroid(JNIEnv* env, jobject obj); | 24 TemplateUrlServiceAndroid(JNIEnv* env, jobject obj); |
| 25 | 25 |
| 26 void Load(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 26 void Load(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 27 void SetUserSelectedDefaultSearchProvider( | 27 void SetUserSelectedDefaultSearchProvider( |
| 28 JNIEnv* env, | 28 JNIEnv* env, |
| 29 const base::android::JavaParamRef<jobject>& obj, | 29 const base::android::JavaParamRef<jobject>& obj, |
| 30 jint selected_index); | 30 const base::android::JavaParamRef<jstring>& jkeyword); |
| 31 jint GetDefaultSearchProvider( | 31 |
| 32 jint GetDefaultSearchProviderIndex( | |
| 32 JNIEnv* env, | 33 JNIEnv* env, |
| 33 const base::android::JavaParamRef<jobject>& obj); | 34 const base::android::JavaParamRef<jobject>& obj) const; |
| 34 jint GetTemplateUrlCount(JNIEnv* env, | 35 |
| 35 const base::android::JavaParamRef<jobject>& obj); | 36 jint GetTemplateUrlCount( |
| 36 jboolean IsLoaded(JNIEnv* env, | 37 JNIEnv* env, |
| 37 const base::android::JavaParamRef<jobject>& obj); | 38 const base::android::JavaParamRef<jobject>& obj) const; |
| 39 jboolean IsLoaded( | |
| 40 JNIEnv* env, | |
| 41 const base::android::JavaParamRef<jobject>& obj) const; | |
| 38 base::android::ScopedJavaLocalRef<jobject> GetTemplateUrlAt( | 42 base::android::ScopedJavaLocalRef<jobject> GetTemplateUrlAt( |
| 39 JNIEnv* env, | 43 JNIEnv* env, |
| 40 const base::android::JavaParamRef<jobject>& obj, | 44 const base::android::JavaParamRef<jobject>& obj, |
| 41 jint index); | 45 jint index) const; |
| 42 jboolean IsSearchProviderManaged( | 46 jboolean IsSearchProviderManaged( |
| 43 JNIEnv* env, | 47 JNIEnv* env, |
| 44 const base::android::JavaParamRef<jobject>& obj); | 48 const base::android::JavaParamRef<jobject>& obj); |
| 45 jboolean IsSearchByImageAvailable( | 49 jboolean IsSearchByImageAvailable( |
| 46 JNIEnv* env, | 50 JNIEnv* env, |
| 47 const base::android::JavaParamRef<jobject>& obj); | 51 const base::android::JavaParamRef<jobject>& obj); |
| 48 jboolean IsDefaultSearchEngineGoogle( | 52 jboolean IsDefaultSearchEngineGoogle( |
| 49 JNIEnv* env, | 53 JNIEnv* env, |
| 50 const base::android::JavaParamRef<jobject>& obj); | 54 const base::android::JavaParamRef<jobject>& obj); |
| 51 base::android::ScopedJavaLocalRef<jstring> GetUrlForSearchQuery( | 55 base::android::ScopedJavaLocalRef<jstring> GetUrlForSearchQuery( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 64 base::android::ScopedJavaLocalRef<jstring> GetUrlForContextualSearchQuery( | 68 base::android::ScopedJavaLocalRef<jstring> GetUrlForContextualSearchQuery( |
| 65 JNIEnv* env, | 69 JNIEnv* env, |
| 66 const base::android::JavaParamRef<jobject>& obj, | 70 const base::android::JavaParamRef<jobject>& obj, |
| 67 const base::android::JavaParamRef<jstring>& jquery, | 71 const base::android::JavaParamRef<jstring>& jquery, |
| 68 const base::android::JavaParamRef<jstring>& jalternate_term, | 72 const base::android::JavaParamRef<jstring>& jalternate_term, |
| 69 jboolean jshould_prefetch, | 73 jboolean jshould_prefetch, |
| 70 const base::android::JavaParamRef<jstring>& jprotocol_version); | 74 const base::android::JavaParamRef<jstring>& jprotocol_version); |
| 71 base::android::ScopedJavaLocalRef<jstring> GetSearchEngineUrlFromTemplateUrl( | 75 base::android::ScopedJavaLocalRef<jstring> GetSearchEngineUrlFromTemplateUrl( |
| 72 JNIEnv* env, | 76 JNIEnv* env, |
| 73 const base::android::JavaParamRef<jobject>& obj, | 77 const base::android::JavaParamRef<jobject>& obj, |
| 74 jint index); | 78 const base::android::JavaParamRef<jstring>& jkeyword); |
| 75 | 79 |
| 76 static bool Register(JNIEnv* env); | 80 static bool Register(JNIEnv* env); |
| 77 | 81 |
| 78 private: | 82 private: |
| 79 ~TemplateUrlServiceAndroid() override; | 83 ~TemplateUrlServiceAndroid() override; |
| 80 | 84 |
| 81 bool IsPrepopulatedTemplate(TemplateURL* url); | |
| 82 | |
| 83 void OnTemplateURLServiceLoaded(); | 85 void OnTemplateURLServiceLoaded(); |
| 84 | 86 |
| 85 // TemplateUrlServiceObserver: | 87 // TemplateUrlServiceObserver: |
| 86 void OnTemplateURLServiceChanged() override; | 88 void OnTemplateURLServiceChanged() override; |
| 87 | 89 |
| 90 // Retrieves and sorts TemplateURL list and calculates the index of the | |
| 91 // default search provider with it. | |
|
Peter Kasting
2016/11/29 03:32:18
This comment is incorrect, since the function does
ltian
2016/11/30 06:36:17
Sorry for forgetting update the comment up to date
| |
| 92 void LoadTemplateURLs(); | |
| 93 | |
| 88 JavaObjectWeakGlobalRef weak_java_obj_; | 94 JavaObjectWeakGlobalRef weak_java_obj_; |
| 89 | 95 |
| 90 // Pointer to the TemplateUrlService for the main profile. | 96 // Pointer to the TemplateUrlService for the main profile. |
| 91 TemplateURLService* template_url_service_; | 97 TemplateURLService* template_url_service_; |
| 92 | 98 |
| 93 std::unique_ptr<TemplateURLService::Subscription> template_url_subscription_; | 99 std::unique_ptr<TemplateURLService::Subscription> template_url_subscription_; |
| 94 | 100 |
| 101 // Caches the up-to-date TemplateURL list so that calls from Android could | |
| 102 // directly get data from it. | |
| 103 std::vector<TemplateURL*> template_urls_; | |
| 104 | |
| 95 DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid); | 105 DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid); |
| 96 }; | 106 }; |
| 97 | 107 |
| 98 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ | 108 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ |
| OLD | NEW |