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 // Update template_urls and return the index of default search provider in the | |
Peter Kasting
2016/11/02 00:34:03
Nit: Function comments should be descriptive ("Upd
ltian
2016/11/22 21:51:41
I will wrap the operations about populating and so
Peter Kasting
2016/11/22 21:57:10
Are you planning to call these methods from every
ltian
2016/11/22 23:25:10
Yes, it is a pull-based system and I think it is f
Peter Kasting
2016/11/22 23:36:20
Then why not force the caller to use that access p
| |
32 // list. Note that this function will also reorder the list so that if any | |
33 // custom search engine is set as default, it will be placed before the rest | |
34 // of | |
Peter Kasting
2016/11/02 00:34:03
Nit: Rewrap
ltian
2016/11/22 21:51:41
Done.
| |
35 // custom ones and after all the prepopulated ones. | |
31 jint GetDefaultSearchProvider( | 36 jint GetDefaultSearchProvider( |
Peter Kasting
2016/11/02 00:34:03
Nit: GetDefaultSearchProviderIndex()?
ltian
2016/11/22 21:51:41
Done.
| |
32 JNIEnv* env, | 37 JNIEnv* env, |
33 const base::android::JavaParamRef<jobject>& obj); | 38 const base::android::JavaParamRef<jobject>& obj); |
34 jint GetTemplateUrlCount(JNIEnv* env, | 39 jint GetTemplateUrlCount(JNIEnv* env, |
35 const base::android::JavaParamRef<jobject>& obj); | 40 const base::android::JavaParamRef<jobject>& obj); |
36 jboolean IsLoaded(JNIEnv* env, | 41 jboolean IsLoaded(JNIEnv* env, |
37 const base::android::JavaParamRef<jobject>& obj); | 42 const base::android::JavaParamRef<jobject>& obj); |
38 base::android::ScopedJavaLocalRef<jobject> GetTemplateUrlAt( | 43 base::android::ScopedJavaLocalRef<jobject> GetTemplateUrlAt( |
39 JNIEnv* env, | 44 JNIEnv* env, |
40 const base::android::JavaParamRef<jobject>& obj, | 45 const base::android::JavaParamRef<jobject>& obj, |
41 jint index); | 46 jint index); |
(...skipping 22 matching lines...) Expand all Loading... | |
64 base::android::ScopedJavaLocalRef<jstring> GetUrlForContextualSearchQuery( | 69 base::android::ScopedJavaLocalRef<jstring> GetUrlForContextualSearchQuery( |
65 JNIEnv* env, | 70 JNIEnv* env, |
66 const base::android::JavaParamRef<jobject>& obj, | 71 const base::android::JavaParamRef<jobject>& obj, |
67 const base::android::JavaParamRef<jstring>& jquery, | 72 const base::android::JavaParamRef<jstring>& jquery, |
68 const base::android::JavaParamRef<jstring>& jalternate_term, | 73 const base::android::JavaParamRef<jstring>& jalternate_term, |
69 jboolean jshould_prefetch, | 74 jboolean jshould_prefetch, |
70 const base::android::JavaParamRef<jstring>& jprotocol_version); | 75 const base::android::JavaParamRef<jstring>& jprotocol_version); |
71 base::android::ScopedJavaLocalRef<jstring> GetSearchEngineUrlFromTemplateUrl( | 76 base::android::ScopedJavaLocalRef<jstring> GetSearchEngineUrlFromTemplateUrl( |
72 JNIEnv* env, | 77 JNIEnv* env, |
73 const base::android::JavaParamRef<jobject>& obj, | 78 const base::android::JavaParamRef<jobject>& obj, |
74 jint index); | 79 const base::android::JavaParamRef<jstring>& jkeyword); |
75 | 80 |
76 static bool Register(JNIEnv* env); | 81 static bool Register(JNIEnv* env); |
77 | 82 |
78 private: | 83 private: |
79 ~TemplateUrlServiceAndroid() override; | 84 ~TemplateUrlServiceAndroid() override; |
80 | 85 |
81 bool IsPrepopulatedTemplate(TemplateURL* url); | |
82 | |
83 void OnTemplateURLServiceLoaded(); | 86 void OnTemplateURLServiceLoaded(); |
84 | 87 |
85 // TemplateUrlServiceObserver: | 88 // TemplateUrlServiceObserver: |
86 void OnTemplateURLServiceChanged() override; | 89 void OnTemplateURLServiceChanged() override; |
87 | 90 |
88 JavaObjectWeakGlobalRef weak_java_obj_; | 91 JavaObjectWeakGlobalRef weak_java_obj_; |
89 | 92 |
90 // Pointer to the TemplateUrlService for the main profile. | 93 // Pointer to the TemplateUrlService for the main profile. |
91 TemplateURLService* template_url_service_; | 94 TemplateURLService* template_url_service_; |
92 | 95 |
93 std::unique_ptr<TemplateURLService::Subscription> template_url_subscription_; | 96 std::unique_ptr<TemplateURLService::Subscription> template_url_subscription_; |
94 | 97 |
98 std::vector<TemplateURL*> template_urls_; | |
99 | |
95 DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid); | 100 DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid); |
96 }; | 101 }; |
97 | 102 |
98 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ | 103 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ |
OLD | NEW |