Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: chrome/browser/search_engines/util.cc

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved check to Protector, work with search engines via TemplateURLService Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/search_engines/util.h" 5 #include "chrome/browser/search_engines/util.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } else { 57 } else {
58 ids.insert(prepopulate_id); 58 ids.insert(prepopulate_id);
59 ++i; 59 ++i;
60 } 60 }
61 } else { 61 } else {
62 ++i; 62 ++i;
63 } 63 }
64 } 64 }
65 } 65 }
66 66
67 // Returns the TemplateURL with id specified from the list of TemplateURLs.
68 // If not found, returns NULL.
69 TemplateURL* GetTemplateURLByID(
70 const std::vector<TemplateURL*>& template_urls,
71 int64 id) {
72 for (std::vector<TemplateURL*>::const_iterator i = template_urls.begin();
73 i != template_urls.end(); ++i) {
74 if ((*i)->id() == id) {
75 return *i;
76 }
77 }
78 return NULL;
79 }
80
67 // Loads engines from prepopulate data and merges them in with the existing 81 // Loads engines from prepopulate data and merges them in with the existing
68 // engines. This is invoked when the version of the prepopulate data changes. 82 // engines. This is invoked when the version of the prepopulate data changes.
69 void MergeEnginesFromPrepopulateData( 83 void MergeEnginesFromPrepopulateData(
70 PrefService* prefs, 84 PrefService* prefs,
71 WebDataService* service, 85 WebDataService* service,
72 std::vector<TemplateURL*>* template_urls, 86 std::vector<TemplateURL*>* template_urls,
73 const TemplateURL** default_search_provider) { 87 const TemplateURL** default_search_provider) {
74 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); 88 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI));
75 DCHECK(template_urls); 89 DCHECK(template_urls);
76 DCHECK(default_search_provider); 90 DCHECK(default_search_provider);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 187
174 const int resource_keyword_version = 188 const int resource_keyword_version =
175 TemplateURLPrepopulateData::GetDataVersion(prefs); 189 TemplateURLPrepopulateData::GetDataVersion(prefs);
176 if (keyword_result.builtin_keyword_version != resource_keyword_version) { 190 if (keyword_result.builtin_keyword_version != resource_keyword_version) {
177 // There should never be duplicate TemplateURLs. We had a bug such that 191 // There should never be duplicate TemplateURLs. We had a bug such that
178 // duplicate TemplateURLs existed for one locale. As such we invoke 192 // duplicate TemplateURLs existed for one locale. As such we invoke
179 // RemoveDuplicatePrepopulateIDs to nuke the duplicates. 193 // RemoveDuplicatePrepopulateIDs to nuke the duplicates.
180 RemoveDuplicatePrepopulateIDs(template_urls, service); 194 RemoveDuplicatePrepopulateIDs(template_urls, service);
181 } 195 }
182 196
183 if (keyword_result.default_search_provider_id) { 197 int64 default_search_provider_id = keyword_result.default_search_provider_id;
184 // See if we can find the default search provider. 198 if (default_search_provider_id) {
185 for (std::vector<TemplateURL*>::iterator i = template_urls->begin(); 199 *default_search_provider =
186 i != template_urls->end(); ++i) { 200 GetTemplateURLByID(*template_urls, default_search_provider_id);
187 if ((*i)->id() == keyword_result.default_search_provider_id) {
188 *default_search_provider = *i;
189 break;
190 }
191 }
192 } 201 }
193 202
194 if (keyword_result.builtin_keyword_version != resource_keyword_version) { 203 if (keyword_result.builtin_keyword_version != resource_keyword_version) {
195 MergeEnginesFromPrepopulateData(prefs, service, template_urls, 204 MergeEnginesFromPrepopulateData(prefs, service, template_urls,
196 default_search_provider); 205 default_search_provider);
197 *new_resource_keyword_version = resource_keyword_version; 206 *new_resource_keyword_version = resource_keyword_version;
198 } 207 }
199 } 208 }
200 209
210 bool VerifyDefaultSearchProviderUsingKeywordResult(
211 const WDTypedResult& result,
212 const std::vector<TemplateURL*>& template_urls,
213 const TemplateURL** backup_default_search_provider) {
214 DCHECK(backup_default_search_provider);
215 DCHECK(*backup_default_search_provider == NULL);
216 DCHECK(result.GetType() == KEYWORDS_RESULT);
sky 2011/10/21 17:20:30 DCHECK_EQ
whywhat 2011/10/21 20:31:53 Done.
217
218 WDKeywordsResult keyword_result = reinterpret_cast<
sky 2011/10/21 17:20:30 This should take a WDKeywordsResult.
whywhat 2011/10/21 20:31:53 Do you mean the fiunction? But I'd have to reinter
sky 2011/10/21 21:34:11 I thought the caller already was doing it. But as
219 const WDResult<WDKeywordsResult>*>(&result)->GetValue();
220
221 *backup_default_search_provider = GetTemplateURLByID(
222 template_urls,
223 keyword_result.default_search_provider_id_backup);
224 return keyword_result.is_default_search_provider_verified;
225 }
226
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698