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