| 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 "base/android/jni_helper.h" | 8 #include "base/android/jni_helper.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "content/public/browser/notification_observer.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/public/browser/notification_registrar.h" | 11 #include "chrome/browser/search_engines/template_url_service.h" |
| 12 | 12 |
| 13 class TemplateURL; | 13 class TemplateURL; |
| 14 class TemplateURLService; | |
| 15 | 14 |
| 16 | 15 |
| 17 // Android wrapper of the TemplateUrlService which provides access from the Java | 16 // Android wrapper of the TemplateUrlService which provides access from the Java |
| 18 // layer. Note that on Android, there's only a single profile, and therefore | 17 // layer. Note that on Android, there's only a single profile, and therefore |
| 19 // a single instance of this wrapper. | 18 // a single instance of this wrapper. |
| 20 class TemplateUrlServiceAndroid : public content::NotificationObserver { | 19 class TemplateUrlServiceAndroid { |
| 21 public: | 20 public: |
| 22 TemplateUrlServiceAndroid(JNIEnv* env, jobject obj); | 21 TemplateUrlServiceAndroid(JNIEnv* env, jobject obj); |
| 23 | 22 |
| 24 void Load(JNIEnv* env, jobject obj); | 23 void Load(JNIEnv* env, jobject obj); |
| 25 void SetDefaultSearchProvider(JNIEnv* env, jobject obj, jint selected_index); | 24 void SetDefaultSearchProvider(JNIEnv* env, jobject obj, jint selected_index); |
| 26 jint GetDefaultSearchProvider(JNIEnv* env, jobject obj); | 25 jint GetDefaultSearchProvider(JNIEnv* env, jobject obj); |
| 27 jint GetTemplateUrlCount(JNIEnv* env, jobject obj); | 26 jint GetTemplateUrlCount(JNIEnv* env, jobject obj); |
| 28 jboolean IsLoaded(JNIEnv* env, jobject obj); | 27 jboolean IsLoaded(JNIEnv* env, jobject obj); |
| 29 base::android::ScopedJavaLocalRef<jobject> | 28 base::android::ScopedJavaLocalRef<jobject> |
| 30 GetPrepopulatedTemplateUrlAt(JNIEnv* env, jobject obj, jint index); | 29 GetPrepopulatedTemplateUrlAt(JNIEnv* env, jobject obj, jint index); |
| 31 jboolean IsSearchProviderManaged(JNIEnv* env, jobject obj); | 30 jboolean IsSearchProviderManaged(JNIEnv* env, jobject obj); |
| 32 jboolean IsSearchByImageAvailable(JNIEnv* env, jobject obj); | 31 jboolean IsSearchByImageAvailable(JNIEnv* env, jobject obj); |
| 33 jboolean IsDefaultSearchEngineGoogle(JNIEnv* env, jobject obj); | 32 jboolean IsDefaultSearchEngineGoogle(JNIEnv* env, jobject obj); |
| 34 base::android::ScopedJavaLocalRef<jstring> GetUrlForSearchQuery( | 33 base::android::ScopedJavaLocalRef<jstring> GetUrlForSearchQuery( |
| 35 JNIEnv* env, | 34 JNIEnv* env, |
| 36 jobject obj, | 35 jobject obj, |
| 37 jstring jquery); | 36 jstring jquery); |
| 38 base::android::ScopedJavaLocalRef<jstring> ReplaceSearchTermsInUrl( | 37 base::android::ScopedJavaLocalRef<jstring> ReplaceSearchTermsInUrl( |
| 39 JNIEnv* env, | 38 JNIEnv* env, |
| 40 jobject obj, | 39 jobject obj, |
| 41 jstring jquery, | 40 jstring jquery, |
| 42 jstring jcurrent_url); | 41 jstring jcurrent_url); |
| 43 | 42 |
| 44 // NotificationObserver: | |
| 45 virtual void Observe(int type, | |
| 46 const content::NotificationSource& source, | |
| 47 const content::NotificationDetails& details) OVERRIDE; | |
| 48 | |
| 49 static bool Register(JNIEnv* env); | 43 static bool Register(JNIEnv* env); |
| 50 | 44 |
| 51 private: | 45 private: |
| 52 virtual ~TemplateUrlServiceAndroid(); | 46 ~TemplateUrlServiceAndroid(); |
| 53 | 47 |
| 54 bool IsPrepopulatedTemplate(TemplateURL* url); | 48 bool IsPrepopulatedTemplate(TemplateURL* url); |
| 55 | 49 |
| 50 void OnTemplateURLServiceLoaded(); |
| 51 |
| 56 JavaObjectWeakGlobalRef weak_java_obj_; | 52 JavaObjectWeakGlobalRef weak_java_obj_; |
| 57 content::NotificationRegistrar registrar_; | |
| 58 | 53 |
| 59 // Pointer to the TemplateUrlService for the main profile. | 54 // Pointer to the TemplateUrlService for the main profile. |
| 60 TemplateURLService* template_url_service_; | 55 TemplateURLService* template_url_service_; |
| 61 | 56 |
| 57 scoped_ptr<TemplateURLService::Subscription> template_url_subscription_; |
| 58 |
| 62 DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid); | 59 DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid); |
| 63 }; | 60 }; |
| 64 | 61 |
| 65 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ | 62 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_ |
| OLD | NEW |