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

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

Issue 263823007: Handle TemplateURLService load failure better (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove initial default copying Created 6 years, 7 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) 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/template_url_service.h" 5 #include "chrome/browser/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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 411 }
412 if (!prepopulate_id.empty() && !*is_managed) { 412 if (!prepopulate_id.empty() && !*is_managed) {
413 int value; 413 int value;
414 base::StringToInt(prepopulate_id, &value); 414 base::StringToInt(prepopulate_id, &value);
415 (*default_provider_data)->prepopulate_id = value; 415 (*default_provider_data)->prepopulate_id = value;
416 } 416 }
417 return true; 417 return true;
418 } 418 }
419 419
420 // static 420 // static
421 void TemplateURLService::SaveDefaultSearchProviderToPrefs(
422 const TemplateURL* t_url, PrefService* prefs) {
423 if (!prefs)
424 return;
425
426 bool enabled = false;
427 std::string search_url;
428 std::string suggest_url;
429 std::string instant_url;
430 std::string image_url;
431 std::string new_tab_url;
432 std::string search_url_post_params;
433 std::string suggest_url_post_params;
434 std::string instant_url_post_params;
435 std::string image_url_post_params;
436 std::string icon_url;
437 std::string encodings;
438 std::string short_name;
439 std::string keyword;
440 std::string id_string;
441 std::string prepopulate_id;
442 base::ListValue alternate_urls;
443 std::string search_terms_replacement_key;
444 if (t_url) {
445 DCHECK_EQ(TemplateURL::NORMAL, t_url->GetType());
446 enabled = true;
447 search_url = t_url->url();
448 suggest_url = t_url->suggestions_url();
449 instant_url = t_url->instant_url();
450 image_url = t_url->image_url();
451 new_tab_url = t_url->new_tab_url();
452 search_url_post_params = t_url->search_url_post_params();
453 suggest_url_post_params = t_url->suggestions_url_post_params();
454 instant_url_post_params = t_url->instant_url_post_params();
455 image_url_post_params = t_url->image_url_post_params();
456 GURL icon_gurl = t_url->favicon_url();
457 if (!icon_gurl.is_empty())
458 icon_url = icon_gurl.spec();
459 encodings = JoinString(t_url->input_encodings(), ';');
460 short_name = base::UTF16ToUTF8(t_url->short_name());
461 keyword = base::UTF16ToUTF8(t_url->keyword());
462 id_string = base::Int64ToString(t_url->id());
463 prepopulate_id = base::Int64ToString(t_url->prepopulate_id());
464 for (size_t i = 0; i < t_url->alternate_urls().size(); ++i)
465 alternate_urls.AppendString(t_url->alternate_urls()[i]);
466 search_terms_replacement_key = t_url->search_terms_replacement_key();
467 }
468 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled);
469 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url);
470 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url);
471 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url);
472 prefs->SetString(prefs::kDefaultSearchProviderImageURL, image_url);
473 prefs->SetString(prefs::kDefaultSearchProviderNewTabURL, new_tab_url);
474 prefs->SetString(prefs::kDefaultSearchProviderSearchURLPostParams,
475 search_url_post_params);
476 prefs->SetString(prefs::kDefaultSearchProviderSuggestURLPostParams,
477 suggest_url_post_params);
478 prefs->SetString(prefs::kDefaultSearchProviderInstantURLPostParams,
479 instant_url_post_params);
480 prefs->SetString(prefs::kDefaultSearchProviderImageURLPostParams,
481 image_url_post_params);
482 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url);
483 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings);
484 prefs->SetString(prefs::kDefaultSearchProviderName, short_name);
485 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword);
486 prefs->SetString(prefs::kDefaultSearchProviderID, id_string);
487 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id);
488 prefs->Set(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls);
489 prefs->SetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey,
490 search_terms_replacement_key);
491 }
492
493 // static
494 base::string16 TemplateURLService::GenerateKeyword(const GURL& url) { 421 base::string16 TemplateURLService::GenerateKeyword(const GURL& url) {
495 DCHECK(url.is_valid()); 422 DCHECK(url.is_valid());
496 // Strip "www." off the front of the keyword; otherwise the keyword won't work 423 // Strip "www." off the front of the keyword; otherwise the keyword won't work
497 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . 424 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
498 // Special case: if the host was exactly "www." (not sure this can happen but 425 // Special case: if the host was exactly "www." (not sure this can happen but
499 // perhaps with some weird intranet and custom DNS server?), ensure we at 426 // perhaps with some weird intranet and custom DNS server?), ensure we at
500 // least don't return the empty string. 427 // least don't return the empty string.
501 base::string16 keyword(net::StripWWWFromHost(url)); 428 base::string16 keyword(net::StripWWWFromHost(url));
502 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; 429 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword;
503 } 430 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 // case the term replaces the URL it's unlikely another keyword would have the 488 // case the term replaces the URL it's unlikely another keyword would have the
562 // same url. 489 // same url.
563 // TODO(jnd): Add additional parameters to get post data when the search URL 490 // TODO(jnd): Add additional parameters to get post data when the search URL
564 // has post parameters. 491 // has post parameters.
565 return GURL(search_ref.ReplaceSearchTermsUsingTermsData( 492 return GURL(search_ref.ReplaceSearchTermsUsingTermsData(
566 TemplateURLRef::SearchTermsArgs( 493 TemplateURLRef::SearchTermsArgs(
567 base::ASCIIToUTF16("blah.blah.blah.blah.blah")), 494 base::ASCIIToUTF16("blah.blah.blah.blah.blah")),
568 search_terms_data, NULL)); 495 search_terms_data, NULL));
569 } 496 }
570 497
498 void TemplateURLService::SaveDefaultSearchProviderToPrefs(
499 const TemplateURL* t_url,
500 PrefService* prefs) const {
501 if (!prefs || load_failed_)
erikwright (departed) 2014/05/06 19:48:02 This seems strange to me. Wouldn't it be better to
Peter Kasting 2014/05/06 19:58:03 For a world where prefs are just a cache until the
502 return;
503
504 bool enabled = false;
505 std::string search_url;
506 std::string suggest_url;
507 std::string instant_url;
508 std::string image_url;
509 std::string new_tab_url;
510 std::string search_url_post_params;
511 std::string suggest_url_post_params;
512 std::string instant_url_post_params;
513 std::string image_url_post_params;
514 std::string icon_url;
515 std::string encodings;
516 std::string short_name;
517 std::string keyword;
518 std::string id_string;
519 std::string prepopulate_id;
520 base::ListValue alternate_urls;
521 std::string search_terms_replacement_key;
522 if (t_url) {
523 DCHECK_EQ(TemplateURL::NORMAL, t_url->GetType());
524 enabled = true;
525 search_url = t_url->url();
526 suggest_url = t_url->suggestions_url();
527 instant_url = t_url->instant_url();
528 image_url = t_url->image_url();
529 new_tab_url = t_url->new_tab_url();
530 search_url_post_params = t_url->search_url_post_params();
531 suggest_url_post_params = t_url->suggestions_url_post_params();
532 instant_url_post_params = t_url->instant_url_post_params();
533 image_url_post_params = t_url->image_url_post_params();
534 GURL icon_gurl = t_url->favicon_url();
535 if (!icon_gurl.is_empty())
536 icon_url = icon_gurl.spec();
537 encodings = JoinString(t_url->input_encodings(), ';');
538 short_name = base::UTF16ToUTF8(t_url->short_name());
539 keyword = base::UTF16ToUTF8(t_url->keyword());
540 id_string = base::Int64ToString(t_url->id());
541 prepopulate_id = base::Int64ToString(t_url->prepopulate_id());
542 for (size_t i = 0; i < t_url->alternate_urls().size(); ++i)
543 alternate_urls.AppendString(t_url->alternate_urls()[i]);
544 search_terms_replacement_key = t_url->search_terms_replacement_key();
545 }
546 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled);
547 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url);
548 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url);
549 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url);
550 prefs->SetString(prefs::kDefaultSearchProviderImageURL, image_url);
551 prefs->SetString(prefs::kDefaultSearchProviderNewTabURL, new_tab_url);
552 prefs->SetString(prefs::kDefaultSearchProviderSearchURLPostParams,
553 search_url_post_params);
554 prefs->SetString(prefs::kDefaultSearchProviderSuggestURLPostParams,
555 suggest_url_post_params);
556 prefs->SetString(prefs::kDefaultSearchProviderInstantURLPostParams,
557 instant_url_post_params);
558 prefs->SetString(prefs::kDefaultSearchProviderImageURLPostParams,
559 image_url_post_params);
560 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url);
561 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings);
562 prefs->SetString(prefs::kDefaultSearchProviderName, short_name);
563 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword);
564 prefs->SetString(prefs::kDefaultSearchProviderID, id_string);
565 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id);
566 prefs->Set(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls);
567 prefs->SetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey,
568 search_terms_replacement_key);
569 }
570
571 bool TemplateURLService::CanReplaceKeyword( 571 bool TemplateURLService::CanReplaceKeyword(
572 const base::string16& keyword, 572 const base::string16& keyword,
573 const GURL& url, 573 const GURL& url,
574 TemplateURL** template_url_to_replace) { 574 TemplateURL** template_url_to_replace) {
575 DCHECK(!keyword.empty()); // This should only be called for non-empty 575 DCHECK(!keyword.empty()); // This should only be called for non-empty
576 // keywords. If we need to support empty kewords 576 // keywords. If we need to support empty kewords
577 // the code needs to change slightly. 577 // the code needs to change slightly.
578 TemplateURL* existing_url = GetTemplateURLForKeyword(keyword); 578 TemplateURL* existing_url = GetTemplateURLForKeyword(keyword);
579 if (template_url_to_replace) 579 if (template_url_to_replace)
580 *template_url_to_replace = existing_url; 580 *template_url_to_replace = existing_url;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { 803 void TemplateURLService::IncrementUsageCount(TemplateURL* url) {
804 DCHECK(url); 804 DCHECK(url);
805 // Extension-controlled search engines are not persisted. 805 // Extension-controlled search engines are not persisted.
806 if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) 806 if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)
807 return; 807 return;
808 if (std::find(template_urls_.begin(), template_urls_.end(), url) == 808 if (std::find(template_urls_.begin(), template_urls_.end(), url) ==
809 template_urls_.end()) 809 template_urls_.end())
810 return; 810 return;
811 ++url->data_.usage_count; 811 ++url->data_.usage_count;
812 812
813 if (service_.get()) 813 if (service_)
814 service_.get()->UpdateKeyword(url->data()); 814 service_->UpdateKeyword(url->data());
815 } 815 }
816 816
817 void TemplateURLService::ResetTemplateURL(TemplateURL* url, 817 void TemplateURLService::ResetTemplateURL(TemplateURL* url,
818 const base::string16& title, 818 const base::string16& title,
819 const base::string16& keyword, 819 const base::string16& keyword,
820 const std::string& search_url) { 820 const std::string& search_url) {
821 if (!loaded_) 821 if (!loaded_)
822 return; 822 return;
823 DCHECK(!keyword.empty()); 823 DCHECK(!keyword.empty());
824 DCHECK(!search_url.empty()); 824 DCHECK(!search_url.empty());
(...skipping 26 matching lines...) Expand all
851 SetDefaultSearchProvider(url); 851 SetDefaultSearchProvider(url);
852 if (default_search_manager_) { 852 if (default_search_manager_) {
853 if (url) 853 if (url)
854 default_search_manager_->SetUserSelectedDefaultSearchEngine(url->data()); 854 default_search_manager_->SetUserSelectedDefaultSearchEngine(url->data());
855 else 855 else
856 default_search_manager_->ClearUserSelectedDefaultSearchEngine(); 856 default_search_manager_->ClearUserSelectedDefaultSearchEngine();
857 } 857 }
858 } 858 }
859 859
860 TemplateURL* TemplateURLService::GetDefaultSearchProvider() { 860 TemplateURL* TemplateURLService::GetDefaultSearchProvider() {
861 if (loaded_ && !load_failed_) 861 return (loaded_ && !load_failed_) ?
862 return default_search_provider_; 862 default_search_provider_ : initial_default_search_provider_.get();
863 // We're not loaded, rely on the default search provider stored in prefs.
864 return initial_default_search_provider_.get();
865 } 863 }
866 864
867 bool TemplateURLService::IsSearchResultsPageFromDefaultSearchProvider( 865 bool TemplateURLService::IsSearchResultsPageFromDefaultSearchProvider(
868 const GURL& url) { 866 const GURL& url) {
869 TemplateURL* default_provider = GetDefaultSearchProvider(); 867 TemplateURL* default_provider = GetDefaultSearchProvider();
870 return default_provider && default_provider->IsSearchURL(url); 868 return default_provider && default_provider->IsSearchURL(url);
871 } 869 }
872 870
873 bool TemplateURLService::IsExtensionControlledDefaultSearch() { 871 bool TemplateURLService::IsExtensionControlledDefaultSearch() {
874 const TemplateURL* default_provider = GetDefaultSearchProvider(); 872 const TemplateURL* default_provider = GetDefaultSearchProvider();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 } 963 }
966 964
967 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { 965 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) {
968 model_observers_.RemoveObserver(observer); 966 model_observers_.RemoveObserver(observer);
969 } 967 }
970 968
971 void TemplateURLService::Load() { 969 void TemplateURLService::Load() {
972 if (loaded_ || load_handle_) 970 if (loaded_ || load_handle_)
973 return; 971 return;
974 972
975 if (!service_.get()) { 973 if (!service_)
976 service_ = WebDataService::FromBrowserContext(profile_); 974 service_ = WebDataService::FromBrowserContext(profile_);
977 }
978 975
979 if (service_.get()) { 976 if (service_) {
980 load_handle_ = service_->GetKeywords(this); 977 load_handle_ = service_->GetKeywords(this);
981 } else { 978 } else {
982 ChangeToLoadedState(); 979 ChangeToLoadedState();
983 on_loaded_callbacks_.Notify(); 980 on_loaded_callbacks_.Notify();
984 } 981 }
985 } 982 }
986 983
987 scoped_ptr<TemplateURLService::Subscription> 984 scoped_ptr<TemplateURLService::Subscription>
988 TemplateURLService::RegisterOnLoadedCallback( 985 TemplateURLService::RegisterOnLoadedCallback(
989 const base::Closure& callback) { 986 const base::Closure& callback) {
990 return loaded_ ? 987 return loaded_ ?
991 scoped_ptr<TemplateURLService::Subscription>() : 988 scoped_ptr<TemplateURLService::Subscription>() :
992 on_loaded_callbacks_.Add(callback); 989 on_loaded_callbacks_.Add(callback);
993 } 990 }
994 991
995 void TemplateURLService::OnWebDataServiceRequestDone( 992 void TemplateURLService::OnWebDataServiceRequestDone(
996 WebDataService::Handle h, 993 WebDataService::Handle h,
997 const WDTypedResult* result) { 994 const WDTypedResult* result) {
998 // Reset the load_handle so that we don't try and cancel the load in 995 // Reset the load_handle so that we don't try and cancel the load in
999 // the destructor. 996 // the destructor.
1000 load_handle_ = 0; 997 load_handle_ = 0;
1001 998
1002 if (!result) { 999 if (!result) {
1003 // Results are null if the database went away or (most likely) wasn't 1000 // Results are null if the database went away or (most likely) wasn't
1004 // loaded. 1001 // loaded.
1005 load_failed_ = true; 1002 load_failed_ = true;
1003 service_ = NULL;
1006 ChangeToLoadedState(); 1004 ChangeToLoadedState();
1007 on_loaded_callbacks_.Notify(); 1005 on_loaded_callbacks_.Notify();
1008 return; 1006 return;
1009 } 1007 }
1010 1008
1011 // initial_default_search_provider_ is only needed before we've finished 1009 // initial_default_search_provider_ is only needed before we've finished
1012 // loading. Now that we've loaded we can nuke it. 1010 // loading. Now that we've loaded we can nuke it.
1013 initial_default_search_provider_.reset(); 1011 initial_default_search_provider_.reset();
1014 1012
1015 TemplateURLVector template_urls; 1013 TemplateURLVector template_urls;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 syncer::ModelType type, 1271 syncer::ModelType type,
1274 const syncer::SyncDataList& initial_sync_data, 1272 const syncer::SyncDataList& initial_sync_data,
1275 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 1273 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
1276 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { 1274 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
1277 DCHECK(loaded_); 1275 DCHECK(loaded_);
1278 DCHECK_EQ(type, syncer::SEARCH_ENGINES); 1276 DCHECK_EQ(type, syncer::SEARCH_ENGINES);
1279 DCHECK(!sync_processor_.get()); 1277 DCHECK(!sync_processor_.get());
1280 DCHECK(sync_processor.get()); 1278 DCHECK(sync_processor.get());
1281 DCHECK(sync_error_factory.get()); 1279 DCHECK(sync_error_factory.get());
1282 syncer::SyncMergeResult merge_result(type); 1280 syncer::SyncMergeResult merge_result(type);
1281
1282 // Disable sync if we failed to load.
1283 if (load_failed_) {
1284 merge_result.set_error(syncer::SyncError(
1285 FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
1286 "Local database load failed.", syncer::SEARCH_ENGINES));
1287 return merge_result;
1288 }
1289
1283 sync_processor_ = sync_processor.Pass(); 1290 sync_processor_ = sync_processor.Pass();
1284 sync_error_factory_ = sync_error_factory.Pass(); 1291 sync_error_factory_ = sync_error_factory.Pass();
1285 1292
1286 // We just started syncing, so set our wait-for-default flag if we are 1293 // We just started syncing, so set our wait-for-default flag if we are
1287 // expecting a default from Sync. 1294 // expecting a default from Sync.
1288 if (GetPrefs()) { 1295 if (GetPrefs()) {
1289 std::string default_guid = GetPrefs()->GetString( 1296 std::string default_guid = GetPrefs()->GetString(
1290 prefs::kSyncedDefaultSearchProviderGUID); 1297 prefs::kSyncedDefaultSearchProviderGUID);
1291 const TemplateURL* current_default = GetDefaultSearchProvider(); 1298 const TemplateURL* current_default = GetDefaultSearchProvider();
1292 1299
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 RemoveNoNotify(existing_keyword_turl); 1885 RemoveNoNotify(existing_keyword_turl);
1879 } else { 1886 } else {
1880 existing_turl->data_.SetKeyword(old_keyword); 1887 existing_turl->data_.SetKeyword(old_keyword);
1881 keyword_to_template_map_[old_keyword] = existing_turl; 1888 keyword_to_template_map_[old_keyword] = existing_turl;
1882 } 1889 }
1883 } 1890 }
1884 } 1891 }
1885 if (!existing_turl->sync_guid().empty()) 1892 if (!existing_turl->sync_guid().empty())
1886 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl; 1893 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl;
1887 1894
1888 if (service_.get()) 1895 if (service_)
1889 service_->UpdateKeyword(existing_turl->data()); 1896 service_->UpdateKeyword(existing_turl->data());
1890 1897
1891 // Inform sync of the update. 1898 // Inform sync of the update.
1892 ProcessTemplateURLChange(FROM_HERE, 1899 ProcessTemplateURLChange(FROM_HERE,
1893 existing_turl, 1900 existing_turl,
1894 syncer::SyncChange::ACTION_UPDATE); 1901 syncer::SyncChange::ACTION_UPDATE);
1895 1902
1896 if (default_search_provider_ == existing_turl) { 1903 if (default_search_provider_ == existing_turl) {
1897 bool success = SetDefaultSearchProviderNoNotify(existing_turl); 1904 bool success = SetDefaultSearchProviderNoNotify(existing_turl);
1898 DCHECK(success); 1905 DCHECK(success);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 UMA_HISTOGRAM_ENUMERATION("Search.DefaultSearchChangeOrigin", 2174 UMA_HISTOGRAM_ENUMERATION("Search.DefaultSearchChangeOrigin",
2168 dsp_change_origin_, DSP_CHANGE_MAX); 2175 dsp_change_origin_, DSP_CHANGE_MAX);
2169 default_search_provider_ = url; 2176 default_search_provider_ = url;
2170 } 2177 }
2171 } 2178 }
2172 2179
2173 if (url) { 2180 if (url) {
2174 // Don't mark the url as edited, otherwise we won't be able to rev the 2181 // Don't mark the url as edited, otherwise we won't be able to rev the
2175 // template urls we ship with. 2182 // template urls we ship with.
2176 url->data_.show_in_default_list = true; 2183 url->data_.show_in_default_list = true;
2177 if (service_.get() && (url->GetType() == TemplateURL::NORMAL)) 2184 if (service_ && (url->GetType() == TemplateURL::NORMAL))
2178 service_->UpdateKeyword(url->data()); 2185 service_->UpdateKeyword(url->data());
2179 2186
2180 if (url->url_ref().HasGoogleBaseURLs()) { 2187 if (url->url_ref().HasGoogleBaseURLs()) {
2181 GoogleURLTracker::RequestServerCheck(profile_, false); 2188 GoogleURLTracker::RequestServerCheck(profile_, false);
2182 #if defined(ENABLE_RLZ) 2189 #if defined(ENABLE_RLZ)
2183 RLZTracker::RecordProductEvent(rlz_lib::CHROME, 2190 RLZTracker::RecordProductEvent(rlz_lib::CHROME,
2184 RLZTracker::CHROME_OMNIBOX, 2191 RLZTracker::CHROME_OMNIBOX,
2185 rlz_lib::SET_TO_GOOGLE); 2192 rlz_lib::SET_TO_GOOGLE);
2186 #endif 2193 #endif
2187 } 2194 }
(...skipping 14 matching lines...) Expand all
2202 // needs to set a new default as well. If we update the default here, we're 2209 // needs to set a new default as well. If we update the default here, we're
2203 // likely to race with the update from the other client, resulting in 2210 // likely to race with the update from the other client, resulting in
2204 // a possibly random default search provider. 2211 // a possibly random default search provider.
2205 if (sync_processor_.get() && url && !url->sync_guid().empty() && 2212 if (sync_processor_.get() && url && !url->sync_guid().empty() &&
2206 GetPrefs() && !processing_syncer_changes_) { 2213 GetPrefs() && !processing_syncer_changes_) {
2207 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, 2214 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID,
2208 url->sync_guid()); 2215 url->sync_guid());
2209 } 2216 }
2210 } 2217 }
2211 2218
2212 if (service_.get()) 2219 if (service_)
2213 service_->SetDefaultSearchProviderID(url ? url->id() : 0); 2220 service_->SetDefaultSearchProviderID(url ? url->id() : 0);
2214 2221
2215 // Inform sync the change to the show_in_default_list flag. 2222 // Inform sync the change to the show_in_default_list flag.
2216 if (url) 2223 if (url)
2217 ProcessTemplateURLChange(FROM_HERE, 2224 ProcessTemplateURLChange(FROM_HERE,
2218 url, 2225 url,
2219 syncer::SyncChange::ACTION_UPDATE); 2226 syncer::SyncChange::ACTION_UPDATE);
2220 return true; 2227 return true;
2221 } 2228 }
2222 2229
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 existing_keyword_turl->short_name(), new_keyword, 2261 existing_keyword_turl->short_name(), new_keyword,
2255 existing_keyword_turl->url()); 2262 existing_keyword_turl->url());
2256 } 2263 }
2257 } 2264 }
2258 template_urls_.push_back(template_url); 2265 template_urls_.push_back(template_url);
2259 AddToMaps(template_url); 2266 AddToMaps(template_url);
2260 2267
2261 if (newly_adding && 2268 if (newly_adding &&
2262 (template_url->GetType() != 2269 (template_url->GetType() !=
2263 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { 2270 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
2264 if (service_.get()) 2271 if (service_)
2265 service_->AddKeyword(template_url->data()); 2272 service_->AddKeyword(template_url->data());
2266 2273
2267 // Inform sync of the addition. Note that this will assign a GUID to 2274 // Inform sync of the addition. Note that this will assign a GUID to
2268 // template_url and add it to the guid_to_template_map_. 2275 // template_url and add it to the guid_to_template_map_.
2269 ProcessTemplateURLChange(FROM_HERE, 2276 ProcessTemplateURLChange(FROM_HERE,
2270 template_url, 2277 template_url,
2271 syncer::SyncChange::ACTION_ADD); 2278 syncer::SyncChange::ACTION_ADD);
2272 } 2279 }
2273 2280
2274 return true; 2281 return true;
2275 } 2282 }
2276 2283
2277 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { 2284 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) {
2278 DCHECK(template_url != default_search_provider_); 2285 DCHECK(template_url != default_search_provider_);
2279 2286
2280 TemplateURLVector::iterator i = 2287 TemplateURLVector::iterator i =
2281 std::find(template_urls_.begin(), template_urls_.end(), template_url); 2288 std::find(template_urls_.begin(), template_urls_.end(), template_url);
2282 if (i == template_urls_.end()) 2289 if (i == template_urls_.end())
2283 return; 2290 return;
2284 2291
2285 RemoveFromMaps(template_url); 2292 RemoveFromMaps(template_url);
2286 2293
2287 // Remove it from the vector containing all TemplateURLs. 2294 // Remove it from the vector containing all TemplateURLs.
2288 template_urls_.erase(i); 2295 template_urls_.erase(i);
2289 2296
2290 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { 2297 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) {
2291 if (service_.get()) 2298 if (service_)
2292 service_->RemoveKeyword(template_url->id()); 2299 service_->RemoveKeyword(template_url->id());
2293 2300
2294 // Inform sync of the deletion. 2301 // Inform sync of the deletion.
2295 ProcessTemplateURLChange(FROM_HERE, 2302 ProcessTemplateURLChange(FROM_HERE,
2296 template_url, 2303 template_url,
2297 syncer::SyncChange::ACTION_DELETE); 2304 syncer::SyncChange::ACTION_DELETE);
2298 2305
2299 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, 2306 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName,
2300 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); 2307 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX);
2301 } 2308 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2351 } 2358 }
2352 2359
2353 // The database loaded a managed |default_search_provider|, but it has 2360 // The database loaded a managed |default_search_provider|, but it has
2354 // been updated in the prefs. Remove it from the database, and update the 2361 // been updated in the prefs. Remove it from the database, and update the
2355 // |default_search_provider| pointer here. 2362 // |default_search_provider| pointer here.
2356 if (*default_search_provider && 2363 if (*default_search_provider &&
2357 (*default_search_provider)->id() == template_url->id()) 2364 (*default_search_provider)->id() == template_url->id())
2358 *default_search_provider = NULL; 2365 *default_search_provider = NULL;
2359 2366
2360 i = template_urls->erase(i); 2367 i = template_urls->erase(i);
2361 if (service_.get()) 2368 if (service_)
2362 service_->RemoveKeyword(template_url->id()); 2369 service_->RemoveKeyword(template_url->id());
2363 delete template_url; 2370 delete template_url;
2364 } else { 2371 } else {
2365 ++i; 2372 ++i;
2366 } 2373 }
2367 } 2374 }
2368 } 2375 }
2369 2376
2370 void TemplateURLService::ResetTemplateURLGUID(TemplateURL* url, 2377 void TemplateURLService::ResetTemplateURLGUID(TemplateURL* url,
2371 const std::string& guid) { 2378 const std::string& guid) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 TemplateURLVector* template_urls) { 2582 TemplateURLVector* template_urls) {
2576 DCHECK(template_urls); 2583 DCHECK(template_urls);
2577 for (TemplateURLVector::iterator i = template_urls->begin(); 2584 for (TemplateURLVector::iterator i = template_urls->begin();
2578 i != template_urls->end(); ++i) { 2585 i != template_urls->end(); ++i) {
2579 TemplateURL* template_url = *i; 2586 TemplateURL* template_url = *i;
2580 DCHECK(template_url); 2587 DCHECK(template_url);
2581 if (template_url->sync_guid().empty() && 2588 if (template_url->sync_guid().empty() &&
2582 (template_url->GetType() != 2589 (template_url->GetType() !=
2583 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { 2590 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
2584 template_url->data_.sync_guid = base::GenerateGUID(); 2591 template_url->data_.sync_guid = base::GenerateGUID();
2585 if (service_.get()) 2592 if (service_)
2586 service_->UpdateKeyword(template_url->data()); 2593 service_->UpdateKeyword(template_url->data());
2587 } 2594 }
2588 } 2595 }
2589 } 2596 }
2590 2597
2591 void TemplateURLService::AddTemplateURLsAndSetupDefaultEngine( 2598 void TemplateURLService::AddTemplateURLsAndSetupDefaultEngine(
2592 TemplateURLVector* template_urls, 2599 TemplateURLVector* template_urls,
2593 TemplateURL* default_search_provider) { 2600 TemplateURL* default_search_provider) {
2594 DCHECK(template_urls); 2601 DCHECK(template_urls);
2595 is_default_search_managed_ = false; 2602 is_default_search_managed_ = false;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 new_dse = *i; 2761 new_dse = *i;
2755 break; 2762 break;
2756 } 2763 }
2757 } 2764 }
2758 } 2765 }
2759 } 2766 }
2760 if (!new_dse) 2767 if (!new_dse)
2761 new_dse = FindNewDefaultSearchProvider(); 2768 new_dse = FindNewDefaultSearchProvider();
2762 SetDefaultSearchProviderNoNotify(new_dse); 2769 SetDefaultSearchProviderNoNotify(new_dse);
2763 } 2770 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698