OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 if (!AddNoNotify(template_url, true)) | 372 if (!AddNoNotify(template_url, true)) |
373 return false; | 373 return false; |
374 NotifyObservers(); | 374 NotifyObservers(); |
375 return true; | 375 return true; |
376 } | 376 } |
377 | 377 |
378 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, | 378 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, |
379 const base::string16& short_name, | 379 const base::string16& short_name, |
380 const base::string16& keyword, | 380 const base::string16& keyword, |
381 const std::string& url) { | 381 const std::string& url) { |
| 382 DCHECK(!short_name.empty()); |
382 DCHECK(!keyword.empty()); | 383 DCHECK(!keyword.empty()); |
383 DCHECK(!url.empty()); | 384 DCHECK(!url.empty()); |
384 template_url->data_.short_name = short_name; | 385 template_url->data_.SetShortName(short_name); |
385 template_url->data_.SetKeyword(keyword); | 386 template_url->data_.SetKeyword(keyword); |
386 template_url->SetURL(url); | 387 template_url->SetURL(url); |
387 Add(template_url); | 388 Add(template_url); |
388 } | 389 } |
389 | 390 |
390 void TemplateURLService::AddExtensionControlledTURL( | 391 void TemplateURLService::AddExtensionControlledTURL( |
391 TemplateURL* template_url, | 392 TemplateURL* template_url, |
392 scoped_ptr<TemplateURL::AssociatedExtensionInfo> info) { | 393 scoped_ptr<TemplateURL::AssociatedExtensionInfo> info) { |
393 DCHECK(loaded_); | 394 DCHECK(loaded_); |
394 DCHECK(template_url); | 395 DCHECK(template_url); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 const std::string& extension_name, | 470 const std::string& extension_name, |
470 const std::string& keyword, | 471 const std::string& keyword, |
471 const std::string& template_url_string) { | 472 const std::string& template_url_string) { |
472 DCHECK(loaded_); | 473 DCHECK(loaded_); |
473 | 474 |
474 if (FindTemplateURLForExtension(extension_id, | 475 if (FindTemplateURLForExtension(extension_id, |
475 TemplateURL::OMNIBOX_API_EXTENSION)) | 476 TemplateURL::OMNIBOX_API_EXTENSION)) |
476 return; | 477 return; |
477 | 478 |
478 TemplateURLData data; | 479 TemplateURLData data; |
479 data.short_name = base::UTF8ToUTF16(extension_name); | 480 data.SetShortName(base::UTF8ToUTF16(extension_name)); |
480 data.SetKeyword(base::UTF8ToUTF16(keyword)); | 481 data.SetKeyword(base::UTF8ToUTF16(keyword)); |
481 data.SetURL(template_url_string); | 482 data.SetURL(template_url_string); |
482 TemplateURL* url = new TemplateURL(data); | 483 TemplateURL* url = new TemplateURL(data); |
483 scoped_ptr<TemplateURL::AssociatedExtensionInfo> info( | 484 scoped_ptr<TemplateURL::AssociatedExtensionInfo> info( |
484 new TemplateURL::AssociatedExtensionInfo( | 485 new TemplateURL::AssociatedExtensionInfo( |
485 TemplateURL::OMNIBOX_API_EXTENSION, extension_id)); | 486 TemplateURL::OMNIBOX_API_EXTENSION, extension_id)); |
486 AddExtensionControlledTURL(url, info.Pass()); | 487 AddExtensionControlledTURL(url, info.Pass()); |
487 } | 488 } |
488 | 489 |
489 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { | 490 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 syncer::SyncChange(FROM_HERE, | 1200 syncer::SyncChange(FROM_HERE, |
1200 syncer::SyncChange::ACTION_DELETE, | 1201 syncer::SyncChange::ACTION_DELETE, |
1201 sync_data)); | 1202 sync_data)); |
1202 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, | 1203 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, |
1203 DELETE_ENGINE_EMPTY_FIELD, DELETE_ENGINE_MAX); | 1204 DELETE_ENGINE_EMPTY_FIELD, DELETE_ENGINE_MAX); |
1204 return NULL; | 1205 return NULL; |
1205 } | 1206 } |
1206 | 1207 |
1207 TemplateURLData data(existing_turl ? | 1208 TemplateURLData data(existing_turl ? |
1208 existing_turl->data() : TemplateURLData()); | 1209 existing_turl->data() : TemplateURLData()); |
1209 data.short_name = base::UTF8ToUTF16(specifics.short_name()); | 1210 data.SetShortName(base::UTF8ToUTF16(specifics.short_name())); |
1210 data.originating_url = GURL(specifics.originating_url()); | 1211 data.originating_url = GURL(specifics.originating_url()); |
1211 base::string16 keyword(base::UTF8ToUTF16(specifics.keyword())); | 1212 base::string16 keyword(base::UTF8ToUTF16(specifics.keyword())); |
1212 // NOTE: Once this code has shipped in a couple of stable releases, we can | 1213 // NOTE: Once this code has shipped in a couple of stable releases, we can |
1213 // probably remove the migration portion, comment out the | 1214 // probably remove the migration portion, comment out the |
1214 // "autogenerate_keyword" field entirely in the .proto file, and fold the | 1215 // "autogenerate_keyword" field entirely in the .proto file, and fold the |
1215 // empty keyword case into the "delete data" block above. | 1216 // empty keyword case into the "delete data" block above. |
1216 bool reset_keyword = | 1217 bool reset_keyword = |
1217 specifics.autogenerate_keyword() || specifics.keyword().empty(); | 1218 specifics.autogenerate_keyword() || specifics.keyword().empty(); |
1218 if (reset_keyword) | 1219 if (reset_keyword) |
1219 keyword = base::ASCIIToUTF16("dummy"); // Will be replaced below. | 1220 keyword = base::ASCIIToUTF16("dummy"); // Will be replaced below. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 // Add specific initializers, if any. | 1336 // Add specific initializers, if any. |
1336 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); | 1337 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
1337 for (int i(0); i < num_initializers; ++i) { | 1338 for (int i(0); i < num_initializers; ++i) { |
1338 DCHECK(initializers[i].keyword); | 1339 DCHECK(initializers[i].keyword); |
1339 DCHECK(initializers[i].url); | 1340 DCHECK(initializers[i].url); |
1340 DCHECK(initializers[i].content); | 1341 DCHECK(initializers[i].content); |
1341 | 1342 |
1342 // TemplateURLService ends up owning the TemplateURL, don't try and free | 1343 // TemplateURLService ends up owning the TemplateURL, don't try and free |
1343 // it. | 1344 // it. |
1344 TemplateURLData data; | 1345 TemplateURLData data; |
1345 data.short_name = base::UTF8ToUTF16(initializers[i].content); | 1346 data.SetShortName(base::UTF8ToUTF16(initializers[i].content)); |
1346 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); | 1347 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); |
1347 data.SetURL(initializers[i].url); | 1348 data.SetURL(initializers[i].url); |
1348 TemplateURL* template_url = new TemplateURL(data); | 1349 TemplateURL* template_url = new TemplateURL(data); |
1349 AddNoNotify(template_url, true); | 1350 AddNoNotify(template_url, true); |
1350 | 1351 |
1351 // Set the first provided identifier to be the default. | 1352 // Set the first provided identifier to be the default. |
1352 if (i == 0) | 1353 if (i == 0) |
1353 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); | 1354 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); |
1354 } | 1355 } |
1355 } | 1356 } |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 *data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1806 *data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1806 } else if (source == DefaultSearchManager::FROM_FALLBACK) { | 1807 } else if (source == DefaultSearchManager::FROM_FALLBACK) { |
1807 default_search_provider_ = | 1808 default_search_provider_ = |
1808 FindPrepopulatedTemplateURL(data->prepopulate_id); | 1809 FindPrepopulatedTemplateURL(data->prepopulate_id); |
1809 if (default_search_provider_) { | 1810 if (default_search_provider_) { |
1810 TemplateURLData update_data(*data); | 1811 TemplateURLData update_data(*data); |
1811 update_data.sync_guid = default_search_provider_->sync_guid(); | 1812 update_data.sync_guid = default_search_provider_->sync_guid(); |
1812 if (!default_search_provider_->safe_for_autoreplace()) { | 1813 if (!default_search_provider_->safe_for_autoreplace()) { |
1813 update_data.safe_for_autoreplace = false; | 1814 update_data.safe_for_autoreplace = false; |
1814 update_data.SetKeyword(default_search_provider_->keyword()); | 1815 update_data.SetKeyword(default_search_provider_->keyword()); |
1815 update_data.short_name = default_search_provider_->short_name(); | 1816 update_data.SetShortName(default_search_provider_->short_name()); |
1816 } | 1817 } |
1817 UpdateNoNotify(default_search_provider_, TemplateURL(update_data)); | 1818 UpdateNoNotify(default_search_provider_, TemplateURL(update_data)); |
1818 } else { | 1819 } else { |
1819 // Normally the prepopulated fallback should be present in | 1820 // Normally the prepopulated fallback should be present in |
1820 // |template_urls_|, but in a few cases it might not be: | 1821 // |template_urls_|, but in a few cases it might not be: |
1821 // (1) Tests that initialize the TemplateURLService in peculiar ways. | 1822 // (1) Tests that initialize the TemplateURLService in peculiar ways. |
1822 // (2) If the user deleted the pre-populated default and we subsequently | 1823 // (2) If the user deleted the pre-populated default and we subsequently |
1823 // lost their user-selected value. | 1824 // lost their user-selected value. |
1824 TemplateURL* new_dse = new TemplateURL(*data); | 1825 TemplateURL* new_dse = new TemplateURL(*data); |
1825 if (AddNoNotify(new_dse, true)) | 1826 if (AddNoNotify(new_dse, true)) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1960 } | 1961 } |
1961 | 1962 |
1962 bool TemplateURLService::ResetTemplateURLNoNotify( | 1963 bool TemplateURLService::ResetTemplateURLNoNotify( |
1963 TemplateURL* url, | 1964 TemplateURL* url, |
1964 const base::string16& title, | 1965 const base::string16& title, |
1965 const base::string16& keyword, | 1966 const base::string16& keyword, |
1966 const std::string& search_url) { | 1967 const std::string& search_url) { |
1967 DCHECK(!keyword.empty()); | 1968 DCHECK(!keyword.empty()); |
1968 DCHECK(!search_url.empty()); | 1969 DCHECK(!search_url.empty()); |
1969 TemplateURLData data(url->data()); | 1970 TemplateURLData data(url->data()); |
1970 data.short_name = title; | 1971 data.SetShortName(title); |
1971 data.SetKeyword(keyword); | 1972 data.SetKeyword(keyword); |
1972 if (search_url != data.url()) { | 1973 if (search_url != data.url()) { |
1973 data.SetURL(search_url); | 1974 data.SetURL(search_url); |
1974 // The urls have changed, reset the favicon url. | 1975 // The urls have changed, reset the favicon url. |
1975 data.favicon_url = GURL(); | 1976 data.favicon_url = GURL(); |
1976 } | 1977 } |
1977 data.safe_for_autoreplace = false; | 1978 data.safe_for_autoreplace = false; |
1978 data.last_modified = clock_->Now(); | 1979 data.last_modified = clock_->Now(); |
1979 return UpdateNoNotify(url, TemplateURL(data)); | 1980 return UpdateNoNotify(url, TemplateURL(data)); |
1980 } | 1981 } |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2283 | 2284 |
2284 if (most_recently_intalled_default) { | 2285 if (most_recently_intalled_default) { |
2285 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2286 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
2286 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2287 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
2287 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2288 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
2288 most_recently_intalled_default->data()); | 2289 most_recently_intalled_default->data()); |
2289 } else { | 2290 } else { |
2290 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2291 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
2291 } | 2292 } |
2292 } | 2293 } |
OLD | NEW |