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 // Updates |template_urls_| and returns the index of the default search | |
| 33 // provider | |
| 34 // within |it. | |
|
Peter Kasting
2016/11/23 21:30:27
This comment lies, since it doesn't update this va
ltian
2016/11/29 02:44:03
Sorry I forgot to update the comment. I think for
| |
| 35 jint GetDefaultSearchProviderIndex( | |
| 32 JNIEnv* env, | 36 JNIEnv* env, |
| 33 const base::android::JavaParamRef<jobject>& obj); | 37 const base::android::JavaParamRef<jobject>& obj) const; |
| 34 jint GetTemplateUrlCount(JNIEnv* env, | 38 |
| 35 const base::android::JavaParamRef<jobject>& obj); | 39 jint GetTemplateUrlCount( |
| 40 JNIEnv* env, | |
| 41 const base::android::JavaParamRef<jobject>& obj) const; | |
| 36 jboolean IsLoaded(JNIEnv* env, | 42 jboolean IsLoaded(JNIEnv* env, |
| 37 const base::android::JavaParamRef<jobject>& obj); | 43 const base::android::JavaParamRef<jobject>& obj); |
| 38 base::android::ScopedJavaLocalRef<jobject> GetTemplateUrlAt( | 44 base::android::ScopedJavaLocalRef<jobject> GetTemplateUrlAt( |
| 39 JNIEnv* env, | 45 JNIEnv* env, |
| 40 const base::android::JavaParamRef<jobject>& obj, | 46 const base::android::JavaParamRef<jobject>& obj, |
| 41 jint index); | 47 jint index) const; |
| 42 jboolean IsSearchProviderManaged( | 48 jboolean IsSearchProviderManaged( |
| 43 JNIEnv* env, | 49 JNIEnv* env, |
| 44 const base::android::JavaParamRef<jobject>& obj); | 50 const base::android::JavaParamRef<jobject>& obj); |
| 45 jboolean IsSearchByImageAvailable( | 51 jboolean IsSearchByImageAvailable( |
| 46 JNIEnv* env, | 52 JNIEnv* env, |
| 47 const base::android::JavaParamRef<jobject>& obj); | 53 const base::android::JavaParamRef<jobject>& obj); |
| 48 jboolean IsDefaultSearchEngineGoogle( | 54 jboolean IsDefaultSearchEngineGoogle( |
| 49 JNIEnv* env, | 55 JNIEnv* env, |
| 50 const base::android::JavaParamRef<jobject>& obj); | 56 const base::android::JavaParamRef<jobject>& obj); |
| 51 base::android::ScopedJavaLocalRef<jstring> GetUrlForSearchQuery( | 57 base::android::ScopedJavaLocalRef<jstring> GetUrlForSearchQuery( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 64 base::android::ScopedJavaLocalRef<jstring> GetUrlForContextualSearchQuery( | 70 base::android::ScopedJavaLocalRef<jstring> GetUrlForContextualSearchQuery( |
| 65 JNIEnv* env, | 71 JNIEnv* env, |
| 66 const base::android::JavaParamRef<jobject>& obj, | 72 const base::android::JavaParamRef<jobject>& obj, |
| 67 const base::android::JavaParamRef<jstring>& jquery, | 73 const base::android::JavaParamRef<jstring>& jquery, |
| 68 const base::android::JavaParamRef<jstring>& jalternate_term, | 74 const base::android::JavaParamRef<jstring>& jalternate_term, |
| 69 jboolean jshould_prefetch, | 75 jboolean jshould_prefetch, |
| 70 const base::android::JavaParamRef<jstring>& jprotocol_version); | 76 const base::android::JavaParamRef<jstring>& jprotocol_version); |
| 71 base::android::ScopedJavaLocalRef<jstring> GetSearchEngineUrlFromTemplateUrl( | 77 base::android::ScopedJavaLocalRef<jstring> GetSearchEngineUrlFromTemplateUrl( |
| 72 JNIEnv* env, | 78 JNIEnv* env, |
| 73 const base::android::JavaParamRef<jobject>& obj, | 79 const base::android::JavaParamRef<jobject>& obj, |
| 74 jint index); | 80 const base::android::JavaParamRef<jstring>& jkeyword); |
| 75 | 81 |
| 76 static bool Register(JNIEnv* env); | 82 static bool Register(JNIEnv* env); |
| 77 | 83 |
| 78 private: | 84 private: |
| 79 ~TemplateUrlServiceAndroid() override; | 85 ~TemplateUrlServiceAndroid() override; |
| 80 | 86 |
| 81 bool IsPrepopulatedTemplate(TemplateURL* url); | |
| 82 | |
| 83 void OnTemplateURLServiceLoaded(); | 87 void OnTemplateURLServiceLoaded(); |
| 84 | 88 |
| 85 // TemplateUrlServiceObserver: | 89 // TemplateUrlServiceObserver: |
| 86 void OnTemplateURLServiceChanged() override; | 90 void OnTemplateURLServiceChanged() override; |
| 87 | 91 |
| 92 void LoadTemplateURLs(); | |
|
Peter Kasting
2016/11/23 21:30:27
Nit: Add comments about what this does.
ltian
2016/11/29 02:44:03
Done.
| |
| 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 std::vector<TemplateURL*> template_urls_; | |
|
Peter Kasting
2016/11/23 21:30:27
Nit: Add comments about why we need to cache this.
ltian
2016/11/29 02:44:03
Done.
| |
| 102 | |
| 103 size_t default_search_provider_index_; | |
| 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 |