Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 8 #include <string> |
| 9 #include <map> | |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
| 14 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 15 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
| 16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 | 20 |
| 19 using content::BrowserThread; | 21 using content::BrowserThread; |
| 20 | 22 |
| 21 string16 GetDefaultSearchEngineName(Profile* profile) { | 23 string16 GetDefaultSearchEngineName(Profile* profile) { |
| 22 if (!profile) { | 24 if (!profile) { |
| 23 NOTREACHED(); | 25 NOTREACHED(); |
| 24 return string16(); | 26 return string16(); |
| 25 } | 27 } |
| 26 const TemplateURL* const default_provider = | 28 const TemplateURL* const default_provider = |
| 27 TemplateURLServiceFactory::GetForProfile(profile)-> | 29 TemplateURLServiceFactory::GetForProfile(profile)-> |
| 28 GetDefaultSearchProvider(); | 30 GetDefaultSearchProvider(); |
| 29 if (!default_provider) { | 31 if (!default_provider) { |
| 30 // TODO(cpu): bug 1187517. It is possible to have no default provider. | 32 // TODO(cpu): bug 1187517. It is possible to have no default provider. |
| 31 // returning an empty string is a stopgap measure for the crash | 33 // returning an empty string is a stopgap measure for the crash |
| 32 // http://code.google.com/p/chromium/issues/detail?id=2573 | 34 // http://code.google.com/p/chromium/issues/detail?id=2573 |
| 33 return string16(); | 35 return string16(); |
| 34 } | 36 } |
| 35 return default_provider->short_name(); | 37 return default_provider->short_name(); |
| 36 } | 38 } |
| 37 | 39 |
| 38 // Removes (and deletes) TemplateURLs from |urls| that have duplicate | 40 void RemoveDuplicatePrepopulateIDs( |
| 39 // prepopulate ids. Duplicate prepopulate ids are not allowed, but due to a | |
| 40 // bug it was possible get dups. This step is only called when the version | |
| 41 // number changes. Only pass in a non-NULL value for |service| if the removed | |
| 42 // items should be removed from the DB. If |removed_keyword_guids| is not NULL, | |
| 43 // the Sync GUID of each item removed from the DB will be added to it. | |
| 44 static void RemoveDuplicatePrepopulateIDs( | |
| 45 std::vector<TemplateURL*>* template_urls, | |
| 46 WebDataService* service, | 41 WebDataService* service, |
| 42 const ScopedVector<TemplateURL>& prepopulated_urls, | |
| 43 TemplateURL* default_search_provider, | |
| 44 TemplateURLService::TemplateURLVector* template_urls, | |
| 47 std::set<std::string>* removed_keyword_guids) { | 45 std::set<std::string>* removed_keyword_guids) { |
| 46 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 48 DCHECK(template_urls); | 47 DCHECK(template_urls); |
| 49 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 50 | 48 |
| 51 std::set<int> ids; | 49 // For convenience construct an ID->TemplateURL* map from |prepopulated_urls|. |
| 52 for (std::vector<TemplateURL*>::iterator i = template_urls->begin(); | 50 typedef std::map<int, TemplateURL*> PrepopulatedURLMap; |
| 53 i != template_urls->end(); ) { | 51 PrepopulatedURLMap prepopulated_url_map; |
| 54 int prepopulate_id = (*i)->prepopulate_id(); | 52 for (std::vector<TemplateURL*>::const_iterator i(prepopulated_urls.begin()); |
| 55 if (prepopulate_id) { | 53 i != prepopulated_urls.end(); ++i) |
| 56 if (ids.find(prepopulate_id) != ids.end()) { | 54 prepopulated_url_map[(*i)->prepopulate_id()] = *i; |
| 57 if (service) { | 55 |
| 58 service->RemoveKeyword((*i)->id()); | 56 // Separate |template_urls| into prepopulated and non-prepopulated groups. |
| 59 if (removed_keyword_guids) | 57 typedef std::multimap<int, TemplateURL*> UncheckedURLMap; |
| 60 removed_keyword_guids->insert((*i)->sync_guid()); | 58 UncheckedURLMap unchecked_urls; |
| 61 } | 59 TemplateURLService::TemplateURLVector checked_urls; |
| 62 delete *i; | 60 for (TemplateURLService::TemplateURLVector::iterator i( |
| 63 i = template_urls->erase(i); | 61 template_urls->begin()); i != template_urls->end(); ++i) { |
| 64 } else { | 62 TemplateURL* turl = *i; |
| 65 ids.insert(prepopulate_id); | 63 int prepopulate_id = turl->prepopulate_id(); |
| 66 ++i; | 64 if (prepopulate_id) |
| 65 unchecked_urls.insert(std::make_pair(prepopulate_id, turl)); | |
| 66 else | |
| 67 checked_urls.push_back(turl); | |
| 68 } | |
| 69 | |
| 70 // For each group of prepopulated URLs with one ID, find the best URL to use | |
| 71 // and add it to the (initially all non-prepopulated) URLs we've already OKed. | |
| 72 // Delete the others from the service and from memory. | |
| 73 while (!unchecked_urls.empty()) { | |
| 74 // Find the best URL. | |
| 75 int prepopulate_id = unchecked_urls.begin()->first; | |
| 76 PrepopulatedURLMap::const_iterator prepopulated_url = | |
| 77 prepopulated_url_map.find(prepopulate_id); | |
| 78 UncheckedURLMap::iterator end = unchecked_urls.upper_bound(prepopulate_id); | |
| 79 UncheckedURLMap::iterator best = unchecked_urls.begin(); | |
| 80 bool matched_keyword = false; | |
| 81 for (UncheckedURLMap::iterator i = unchecked_urls.begin(); i != end; ++i) { | |
| 82 // A URL is automatically the best if it's the default search engine. | |
| 83 if (i->second == default_search_provider) { | |
| 84 best = i; | |
| 85 break; | |
| 67 } | 86 } |
| 68 } else { | 87 |
| 69 ++i; | 88 // Otherwise, a URL is best if it matches the prepopulated data's keyword; |
| 89 // if none match, just fall back to using the one with the lowest ID. | |
| 90 if (matched_keyword) | |
| 91 continue; | |
| 92 if ((prepopulated_url != prepopulated_url_map.end()) && | |
| 93 i->second->HasSameKeywordAs(*prepopulated_url->second)) { | |
| 94 best = i; | |
| 95 matched_keyword = true; | |
| 96 } else if (i->second->id() < best->second->id()) { | |
| 97 best = i; | |
| 98 } | |
| 70 } | 99 } |
| 100 | |
| 101 // Add the best URL to the checked group and delete the rest. | |
| 102 checked_urls.push_back(best->second); | |
| 103 for (UncheckedURLMap::iterator i = unchecked_urls.begin(); i != end; ++i) { | |
| 104 if (i == best) | |
| 105 continue; | |
| 106 if (service) { | |
| 107 service->RemoveKeyword(i->second->id()); | |
| 108 if (removed_keyword_guids) | |
| 109 removed_keyword_guids->insert(i->second->sync_guid()); | |
| 110 } | |
| 111 delete i->second; | |
| 112 } | |
| 113 | |
| 114 // Done with this group. | |
| 115 unchecked_urls.erase(unchecked_urls.begin(), end); | |
| 71 } | 116 } |
| 117 | |
| 118 // Return the checked URLs. | |
| 119 template_urls->swap(checked_urls); | |
| 72 } | 120 } |
| 73 | 121 |
| 74 // Returns the TemplateURL with id specified from the list of TemplateURLs. | 122 // Returns the TemplateURL with id specified from the list of TemplateURLs. |
| 75 // If not found, returns NULL. | 123 // If not found, returns NULL. |
| 76 TemplateURL* GetTemplateURLByID( | 124 TemplateURL* GetTemplateURLByID( |
| 77 const std::vector<TemplateURL*>& template_urls, | 125 const TemplateURLService::TemplateURLVector& template_urls, |
| 78 int64 id) { | 126 int64 id) { |
| 79 for (std::vector<TemplateURL*>::const_iterator i = template_urls.begin(); | 127 for (TemplateURLService::TemplateURLVector::const_iterator i( |
| 80 i != template_urls.end(); ++i) { | 128 template_urls.begin()); i != template_urls.end(); ++i) { |
| 81 if ((*i)->id() == id) { | 129 if ((*i)->id() == id) { |
| 82 return *i; | 130 return *i; |
| 83 } | 131 } |
| 84 } | 132 } |
| 85 return NULL; | 133 return NULL; |
| 86 } | 134 } |
| 87 | 135 |
| 88 // Loads engines from prepopulate data and merges them in with the existing | 136 // Loads engines from prepopulate data and merges them in with the existing |
| 89 // engines. This is invoked when the version of the prepopulate data changes. | 137 // engines. This is invoked when the version of the prepopulate data changes. |
| 90 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed | 138 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed |
| 91 // from the DB will be added to it. | 139 // from the DB will be added to it. Note that this function will take |
| 140 // ownership of |prepopulated_urls| and will clear the vector. | |
| 92 void MergeEnginesFromPrepopulateData( | 141 void MergeEnginesFromPrepopulateData( |
| 93 Profile* profile, | 142 Profile* profile, |
| 94 WebDataService* service, | 143 WebDataService* service, |
| 95 std::vector<TemplateURL*>* template_urls, | 144 ScopedVector<TemplateURL>& prepopulated_urls, |
|
Peter Kasting
2012/05/24 17:43:53
Nit: Google style prohibits non-const refs; pass b
| |
| 145 size_t default_search_index, | |
| 146 TemplateURLService::TemplateURLVector* template_urls, | |
| 96 TemplateURL** default_search_provider, | 147 TemplateURL** default_search_provider, |
| 97 std::set<std::string>* removed_keyword_guids) { | 148 std::set<std::string>* removed_keyword_guids) { |
| 98 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); | 149 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 99 DCHECK(template_urls); | 150 DCHECK(template_urls); |
| 100 DCHECK(default_search_provider); | 151 DCHECK(default_search_provider); |
| 101 | 152 |
| 102 // Create a map to hold all provided |template_urls| that originally came from | 153 // Create a map to hold all provided |template_urls| that originally came from |
| 103 // prepopulate data (i.e. have a non-zero prepopulate_id()). | 154 // prepopulate data (i.e. have a non-zero prepopulate_id()). |
| 104 typedef std::map<int, TemplateURL*> IDMap; | 155 typedef std::map<int, TemplateURL*> IDMap; |
| 105 IDMap id_to_turl; | 156 IDMap id_to_turl; |
| 106 for (std::vector<TemplateURL*>::iterator i(template_urls->begin()); | 157 for (TemplateURLService::TemplateURLVector::iterator i( |
| 107 i != template_urls->end(); ++i) { | 158 template_urls->begin()); i != template_urls->end(); ++i) { |
| 108 int prepopulate_id = (*i)->prepopulate_id(); | 159 int prepopulate_id = (*i)->prepopulate_id(); |
| 109 if (prepopulate_id > 0) | 160 if (prepopulate_id > 0) |
| 110 id_to_turl[prepopulate_id] = *i; | 161 id_to_turl[prepopulate_id] = *i; |
| 111 } | 162 } |
| 112 | 163 |
| 113 // Get the current set of prepopulatd URLs. | |
| 114 std::vector<TemplateURL*> prepopulated_urls; | |
| 115 size_t default_search_index; | |
| 116 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile, | |
| 117 &prepopulated_urls, &default_search_index); | |
| 118 | |
| 119 // For each current prepopulated URL, check whether |template_urls| contained | 164 // For each current prepopulated URL, check whether |template_urls| contained |
| 120 // a matching prepopulated URL. If so, update the passed-in URL to match the | 165 // a matching prepopulated URL. If so, update the passed-in URL to match the |
| 121 // current data. (If the passed-in URL was user-edited, we persist the user's | 166 // current data. (If the passed-in URL was user-edited, we persist the user's |
| 122 // name and keyword.) If not, add the prepopulated URL to |template_urls|. | 167 // name and keyword.) If not, add the prepopulated URL to |template_urls|. |
| 123 // Along the way, point |default_search_provider| at the default prepopulated | 168 // Along the way, point |default_search_provider| at the default prepopulated |
| 124 // URL, if the user hasn't already set another URL as default. | 169 // URL, if the user hasn't already set another URL as default. |
| 125 for (size_t i = 0; i < prepopulated_urls.size(); ++i) { | 170 for (size_t i = 0; i < prepopulated_urls.size(); ++i) { |
| 126 // We take ownership of |prepopulated_urls[i]|. | 171 // We take ownership of |prepopulated_urls[i]|. |
| 127 scoped_ptr<TemplateURL> prepopulated_url(prepopulated_urls[i]); | 172 scoped_ptr<TemplateURL> prepopulated_url(prepopulated_urls[i]); |
| 128 const int prepopulated_id = prepopulated_url->prepopulate_id(); | 173 const int prepopulated_id = prepopulated_url->prepopulate_id(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 139 if (!existing_url->safe_for_autoreplace()) { | 184 if (!existing_url->safe_for_autoreplace()) { |
| 140 data.safe_for_autoreplace = false; | 185 data.safe_for_autoreplace = false; |
| 141 data.SetKeyword(existing_url->keyword()); | 186 data.SetKeyword(existing_url->keyword()); |
| 142 data.short_name = existing_url->short_name(); | 187 data.short_name = existing_url->short_name(); |
| 143 } | 188 } |
| 144 data.id = existing_url->id(); | 189 data.id = existing_url->id(); |
| 145 if (service) | 190 if (service) |
| 146 service->UpdateKeyword(data); | 191 service->UpdateKeyword(data); |
| 147 | 192 |
| 148 // Replace the entry in |template_urls| with the updated one. | 193 // Replace the entry in |template_urls| with the updated one. |
| 149 std::vector<TemplateURL*>::iterator j = std::find(template_urls->begin(), | 194 TemplateURLService::TemplateURLVector::iterator j = std::find( |
| 150 template_urls->end(), existing_url.get()); | 195 template_urls->begin(), template_urls->end(), existing_url.get()); |
| 151 *j = new TemplateURL(profile, data); | 196 *j = new TemplateURL(profile, data); |
| 152 url_in_vector = *j; | 197 url_in_vector = *j; |
| 153 if (*default_search_provider == existing_url.get()) | 198 if (*default_search_provider == existing_url.get()) |
| 154 *default_search_provider = url_in_vector; | 199 *default_search_provider = url_in_vector; |
| 155 } else { | 200 } else { |
| 156 template_urls->push_back(prepopulated_url.release()); | 201 template_urls->push_back(prepopulated_url.release()); |
| 157 url_in_vector = template_urls->back(); | 202 url_in_vector = template_urls->back(); |
| 158 } | 203 } |
| 159 DCHECK(url_in_vector); | 204 DCHECK(url_in_vector); |
| 160 if (i == default_search_index && !*default_search_provider) | 205 if (i == default_search_index && !*default_search_provider) |
| 161 *default_search_provider = url_in_vector; | 206 *default_search_provider = url_in_vector; |
| 162 } | 207 } |
| 208 // The above loop takes ownership of all the contents of prepopulated_urls. | |
| 209 // Clear the pointers. | |
| 210 prepopulated_urls.weak_erase(prepopulated_urls.begin(), | |
| 211 prepopulated_urls.end()); | |
| 163 | 212 |
| 164 // The block above removed all the URLs from the |id_to_turl| map that were | 213 // The block above removed all the URLs from the |id_to_turl| map that were |
| 165 // found in the prepopulate data. Any remaining URLs that haven't been | 214 // found in the prepopulate data. Any remaining URLs that haven't been |
| 166 // user-edited or made default can be removed from the data store. | 215 // user-edited or made default can be removed from the data store. |
| 167 for (IDMap::iterator i(id_to_turl.begin()); i != id_to_turl.end(); ++i) { | 216 for (IDMap::iterator i(id_to_turl.begin()); i != id_to_turl.end(); ++i) { |
| 168 const TemplateURL* template_url = i->second; | 217 const TemplateURL* template_url = i->second; |
| 169 if ((template_url->safe_for_autoreplace()) && | 218 if ((template_url->safe_for_autoreplace()) && |
| 170 (template_url != *default_search_provider)) { | 219 (template_url != *default_search_provider)) { |
| 171 std::vector<TemplateURL*>::iterator j = | 220 TemplateURLService::TemplateURLVector::iterator j = |
| 172 std::find(template_urls->begin(), template_urls->end(), template_url); | 221 std::find(template_urls->begin(), template_urls->end(), template_url); |
| 173 DCHECK(j != template_urls->end()); | 222 DCHECK(j != template_urls->end()); |
| 174 template_urls->erase(j); | 223 template_urls->erase(j); |
| 175 if (service) { | 224 if (service) { |
| 176 service->RemoveKeyword(template_url->id()); | 225 service->RemoveKeyword(template_url->id()); |
| 177 if (removed_keyword_guids) | 226 if (removed_keyword_guids) |
| 178 removed_keyword_guids->insert(template_url->sync_guid()); | 227 removed_keyword_guids->insert(template_url->sync_guid()); |
| 179 } | 228 } |
| 180 delete template_url; | 229 delete template_url; |
| 181 } | 230 } |
| 182 } | 231 } |
| 183 } | 232 } |
| 184 | 233 |
| 185 void GetSearchProvidersUsingKeywordResult( | 234 void GetSearchProvidersUsingKeywordResult( |
| 186 const WDTypedResult& result, | 235 const WDTypedResult& result, |
| 187 WebDataService* service, | 236 WebDataService* service, |
| 188 Profile* profile, | 237 Profile* profile, |
| 189 std::vector<TemplateURL*>* template_urls, | 238 TemplateURLService::TemplateURLVector* template_urls, |
| 190 TemplateURL** default_search_provider, | 239 TemplateURL** default_search_provider, |
| 191 int* new_resource_keyword_version, | 240 int* new_resource_keyword_version, |
| 192 std::set<std::string>* removed_keyword_guids) { | 241 std::set<std::string>* removed_keyword_guids) { |
| 193 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 194 DCHECK(template_urls); | 243 DCHECK(template_urls); |
| 195 DCHECK(template_urls->empty()); | 244 DCHECK(template_urls->empty()); |
| 196 DCHECK(default_search_provider); | 245 DCHECK(default_search_provider); |
| 197 DCHECK(*default_search_provider == NULL); | 246 DCHECK(*default_search_provider == NULL); |
| 198 DCHECK_EQ(result.GetType(), KEYWORDS_RESULT); | 247 DCHECK_EQ(result.GetType(), KEYWORDS_RESULT); |
| 199 DCHECK(new_resource_keyword_version); | 248 DCHECK(new_resource_keyword_version); |
| 200 | 249 |
| 201 *new_resource_keyword_version = 0; | 250 *new_resource_keyword_version = 0; |
| 202 WDKeywordsResult keyword_result = reinterpret_cast< | 251 WDKeywordsResult keyword_result = reinterpret_cast< |
| 203 const WDResult<WDKeywordsResult>*>(&result)->GetValue(); | 252 const WDResult<WDKeywordsResult>*>(&result)->GetValue(); |
| 204 | 253 |
| 205 for (KeywordTable::Keywords::const_iterator i( | 254 for (KeywordTable::Keywords::const_iterator i( |
| 206 keyword_result.keywords.begin()); i != keyword_result.keywords.end(); | 255 keyword_result.keywords.begin()); i != keyword_result.keywords.end(); |
| 207 ++i) | 256 ++i) |
| 208 template_urls->push_back(new TemplateURL(profile, *i)); | 257 template_urls->push_back(new TemplateURL(profile, *i)); |
| 209 | 258 |
| 210 const int resource_keyword_version = | |
| 211 TemplateURLPrepopulateData::GetDataVersion( | |
| 212 profile ? profile->GetPrefs() : NULL); | |
| 213 if (keyword_result.builtin_keyword_version != resource_keyword_version) { | |
| 214 // There should never be duplicate TemplateURLs. We had a bug such that | |
| 215 // duplicate TemplateURLs existed for one locale. As such we invoke | |
| 216 // RemoveDuplicatePrepopulateIDs to nuke the duplicates. | |
| 217 RemoveDuplicatePrepopulateIDs(template_urls, service, | |
| 218 removed_keyword_guids); | |
| 219 } | |
| 220 | |
| 221 int64 default_search_provider_id = keyword_result.default_search_provider_id; | 259 int64 default_search_provider_id = keyword_result.default_search_provider_id; |
| 222 if (default_search_provider_id) { | 260 if (default_search_provider_id) { |
| 223 *default_search_provider = | 261 *default_search_provider = |
| 224 GetTemplateURLByID(*template_urls, default_search_provider_id); | 262 GetTemplateURLByID(*template_urls, default_search_provider_id); |
| 225 } | 263 } |
| 226 | 264 |
| 265 ScopedVector<TemplateURL> prepopulated_urls; | |
| 266 size_t default_search_index; | |
| 267 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile, | |
| 268 &prepopulated_urls.get(), &default_search_index); | |
| 269 RemoveDuplicatePrepopulateIDs(service, prepopulated_urls, | |
| 270 *default_search_provider, template_urls, | |
| 271 removed_keyword_guids); | |
| 272 | |
| 273 const int resource_keyword_version = | |
| 274 TemplateURLPrepopulateData::GetDataVersion( | |
| 275 profile ? profile->GetPrefs() : NULL); | |
| 227 if (keyword_result.builtin_keyword_version != resource_keyword_version) { | 276 if (keyword_result.builtin_keyword_version != resource_keyword_version) { |
| 228 MergeEnginesFromPrepopulateData(profile, service, template_urls, | 277 MergeEnginesFromPrepopulateData(profile, service, prepopulated_urls, |
| 229 default_search_provider, | 278 default_search_index, template_urls, default_search_provider, |
| 230 removed_keyword_guids); | 279 removed_keyword_guids); |
| 231 *new_resource_keyword_version = resource_keyword_version; | 280 *new_resource_keyword_version = resource_keyword_version; |
| 232 } | 281 } |
| 233 } | 282 } |
| 234 | 283 |
| 235 bool DidDefaultSearchProviderChange( | 284 bool DidDefaultSearchProviderChange( |
| 236 const WDTypedResult& result, | 285 const WDTypedResult& result, |
| 237 Profile* profile, | 286 Profile* profile, |
| 238 scoped_ptr<TemplateURL>* backup_default_search_provider) { | 287 scoped_ptr<TemplateURL>* backup_default_search_provider) { |
| 239 DCHECK(backup_default_search_provider); | 288 DCHECK(backup_default_search_provider); |
| 240 DCHECK(!backup_default_search_provider->get()); | 289 DCHECK(!backup_default_search_provider->get()); |
| 241 DCHECK_EQ(result.GetType(), KEYWORDS_RESULT); | 290 DCHECK_EQ(result.GetType(), KEYWORDS_RESULT); |
| 242 | 291 |
| 243 WDKeywordsResult keyword_result = reinterpret_cast< | 292 WDKeywordsResult keyword_result = reinterpret_cast< |
| 244 const WDResult<WDKeywordsResult>*>(&result)->GetValue(); | 293 const WDResult<WDKeywordsResult>*>(&result)->GetValue(); |
| 245 | 294 |
| 246 if (!keyword_result.did_default_search_provider_change) | 295 if (!keyword_result.did_default_search_provider_change) |
| 247 return false; | 296 return false; |
| 248 | 297 |
| 249 if (keyword_result.backup_valid) { | 298 if (keyword_result.backup_valid) { |
| 250 backup_default_search_provider->reset(new TemplateURL(profile, | 299 backup_default_search_provider->reset(new TemplateURL(profile, |
| 251 keyword_result.default_search_provider_backup)); | 300 keyword_result.default_search_provider_backup)); |
| 252 } | 301 } |
| 253 return true; | 302 return true; |
| 254 } | 303 } |
| OLD | NEW |