OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 #include "chrome/browser/android/locale/special_locale_handler.h" | 5 #include "chrome/browser/android/locale/special_locale_handler.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/android/jni_weak_ref.h" | 9 #include "base/android/jni_weak_ref.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 template_url_service_->Remove(turl); | 93 template_url_service_->Remove(turl); |
94 } | 94 } |
95 prepopulate_ids_.pop_back(); | 95 prepopulate_ids_.pop_back(); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 void SpecialLocaleHandler::OverrideDefaultSearchProvider( | 99 void SpecialLocaleHandler::OverrideDefaultSearchProvider( |
100 JNIEnv* env, | 100 JNIEnv* env, |
101 const JavaParamRef<jobject>& obj) { | 101 const JavaParamRef<jobject>& obj) { |
102 // If the user has changed their default search provider, no-op. | 102 // If the user has changed their default search provider, no-op. |
103 TemplateURL* current_dsp = template_url_service_->GetDefaultSearchProvider(); | 103 const TemplateURL* current_dsp = |
| 104 template_url_service_->GetDefaultSearchProvider(); |
104 if (!current_dsp || | 105 if (!current_dsp || |
105 current_dsp->prepopulate_id() != TemplateURLPrepopulateData::google.id) { | 106 current_dsp->prepopulate_id() != TemplateURLPrepopulateData::google.id) { |
106 return; | 107 return; |
107 } | 108 } |
108 | 109 |
109 TemplateURL* turl = FindURLByPrepopulateID( | 110 TemplateURL* turl = FindURLByPrepopulateID( |
110 template_url_service_->GetTemplateURLs(), GetDesignatedSearchEngine()); | 111 template_url_service_->GetTemplateURLs(), GetDesignatedSearchEngine()); |
111 if (turl) { | 112 if (turl) { |
112 template_url_service_->SetUserSelectedDefaultSearchProvider(turl); | 113 template_url_service_->SetUserSelectedDefaultSearchProvider(turl); |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 void SpecialLocaleHandler::SetGoogleAsDefaultSearch( | 117 void SpecialLocaleHandler::SetGoogleAsDefaultSearch( |
117 JNIEnv* env, | 118 JNIEnv* env, |
118 const JavaParamRef<jobject>& obj) { | 119 const JavaParamRef<jobject>& obj) { |
119 // If the user has changed their default search provider, no-op. | 120 // If the user has changed their default search provider, no-op. |
120 TemplateURL* current_dsp = template_url_service_->GetDefaultSearchProvider(); | 121 const TemplateURL* current_dsp = |
| 122 template_url_service_->GetDefaultSearchProvider(); |
121 if (!current_dsp || | 123 if (!current_dsp || |
122 current_dsp->prepopulate_id() != GetDesignatedSearchEngine()) { | 124 current_dsp->prepopulate_id() != GetDesignatedSearchEngine()) { |
123 return; | 125 return; |
124 } | 126 } |
125 | 127 |
126 TemplateURL* turl = | 128 TemplateURL* turl = |
127 FindURLByPrepopulateID(template_url_service_->GetTemplateURLs(), | 129 FindURLByPrepopulateID(template_url_service_->GetTemplateURLs(), |
128 TemplateURLPrepopulateData::google.id); | 130 TemplateURLPrepopulateData::google.id); |
129 if (turl) { | 131 if (turl) { |
130 template_url_service_->SetUserSelectedDefaultSearchProvider(turl); | 132 template_url_service_->SetUserSelectedDefaultSearchProvider(turl); |
131 } | 133 } |
132 } | 134 } |
133 | 135 |
134 std::vector<std::unique_ptr<TemplateURLData>> | 136 std::vector<std::unique_ptr<TemplateURLData>> |
135 SpecialLocaleHandler::GetLocalPrepopulatedEngines(Profile* profile) { | 137 SpecialLocaleHandler::GetLocalPrepopulatedEngines(Profile* profile) { |
136 return TemplateURLPrepopulateData::GetLocalPrepopulatedEngines( | 138 return TemplateURLPrepopulateData::GetLocalPrepopulatedEngines( |
137 locale_, profile_->GetPrefs()); | 139 locale_, profile_->GetPrefs()); |
138 } | 140 } |
139 | 141 |
140 int SpecialLocaleHandler::GetDesignatedSearchEngine() { | 142 int SpecialLocaleHandler::GetDesignatedSearchEngine() { |
141 return TemplateURLPrepopulateData::sogou.id; | 143 return TemplateURLPrepopulateData::sogou.id; |
142 } | 144 } |
143 | 145 |
144 SpecialLocaleHandler::~SpecialLocaleHandler() {} | 146 SpecialLocaleHandler::~SpecialLocaleHandler() {} |
145 | 147 |
146 // static | 148 // static |
147 bool RegisterSpecialLocaleHandler(JNIEnv* env) { | 149 bool RegisterSpecialLocaleHandler(JNIEnv* env) { |
148 return RegisterNativesImpl(env); | 150 return RegisterNativesImpl(env); |
149 } | 151 } |
OLD | NEW |