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

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

Issue 23710022: Convert NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED to CallbackList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments and cleanup Created 7 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) 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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 return; 771 return;
772 772
773 if (!service_.get()) { 773 if (!service_.get()) {
774 service_ = WebDataService::FromBrowserContext(profile_); 774 service_ = WebDataService::FromBrowserContext(profile_);
775 } 775 }
776 776
777 if (service_.get()) { 777 if (service_.get()) {
778 load_handle_ = service_->GetKeywords(this); 778 load_handle_ = service_->GetKeywords(this);
779 } else { 779 } else {
780 ChangeToLoadedState(); 780 ChangeToLoadedState();
781 NotifyLoaded(); 781 on_loaded_callbacks_.Notify();
782 } 782 }
783 } 783 }
784 784
785 scoped_ptr<TemplateURLService::Subscription>
786 TemplateURLService::RegisterOnLoadedCallback(
787 const base::Closure& callback) {
788 return loaded_ ?
789 scoped_ptr<TemplateURLService::Subscription>() :
790 on_loaded_callbacks_.Add(callback);
791 }
792
785 void TemplateURLService::OnWebDataServiceRequestDone( 793 void TemplateURLService::OnWebDataServiceRequestDone(
786 WebDataService::Handle h, 794 WebDataService::Handle h,
787 const WDTypedResult* result) { 795 const WDTypedResult* result) {
788 // Reset the load_handle so that we don't try and cancel the load in 796 // Reset the load_handle so that we don't try and cancel the load in
789 // the destructor. 797 // the destructor.
790 load_handle_ = 0; 798 load_handle_ = 0;
791 799
792 if (!result) { 800 if (!result) {
793 // Results are null if the database went away or (most likely) wasn't 801 // Results are null if the database went away or (most likely) wasn't
794 // loaded. 802 // loaded.
795 load_failed_ = true; 803 load_failed_ = true;
796 ChangeToLoadedState(); 804 ChangeToLoadedState();
797 NotifyLoaded(); 805 on_loaded_callbacks_.Notify();
798 return; 806 return;
799 } 807 }
800 808
801 // initial_default_search_provider_ is only needed before we've finished 809 // initial_default_search_provider_ is only needed before we've finished
802 // loading. Now that we've loaded we can nuke it. 810 // loading. Now that we've loaded we can nuke it.
803 initial_default_search_provider_.reset(); 811 initial_default_search_provider_.reset();
804 812
805 TemplateURLVector template_urls; 813 TemplateURLVector template_urls;
806 TemplateURL* default_search_provider = NULL; 814 TemplateURL* default_search_provider = NULL;
807 int new_resource_keyword_version = 0; 815 int new_resource_keyword_version = 0;
(...skipping 11 matching lines...) Expand all
819 for (size_t i = 0; i < visits_to_add_.size(); ++i) 827 for (size_t i = 0; i < visits_to_add_.size(); ++i)
820 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); 828 UpdateKeywordSearchTermsForURL(visits_to_add_[i]);
821 visits_to_add_.clear(); 829 visits_to_add_.clear();
822 830
823 if (new_resource_keyword_version) 831 if (new_resource_keyword_version)
824 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); 832 service_->SetBuiltinKeywordVersion(new_resource_keyword_version);
825 833
826 EnsureDefaultSearchProviderExists(); 834 EnsureDefaultSearchProviderExists();
827 835
828 NotifyObservers(); 836 NotifyObservers();
829 NotifyLoaded(); 837 on_loaded_callbacks_.Notify();
830 } 838 }
831 839
832 string16 TemplateURLService::GetKeywordShortName(const string16& keyword, 840 string16 TemplateURLService::GetKeywordShortName(const string16& keyword,
833 bool* is_extension_keyword) { 841 bool* is_extension_keyword) {
834 const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); 842 const TemplateURL* template_url = GetTemplateURLForKeyword(keyword);
835 843
836 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService 844 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService
837 // to track changes to the model, this should become a DCHECK. 845 // to track changes to the model, this should become a DCHECK.
838 if (template_url) { 846 if (template_url) {
839 *is_extension_keyword = template_url->IsExtensionKeyword(); 847 *is_extension_keyword = template_url->IsExtensionKeyword();
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 } 1577 }
1570 1578
1571 void TemplateURLService::ChangeToLoadedState() { 1579 void TemplateURLService::ChangeToLoadedState() {
1572 DCHECK(!loaded_); 1580 DCHECK(!loaded_);
1573 1581
1574 UIThreadSearchTermsData search_terms_data(profile_); 1582 UIThreadSearchTermsData search_terms_data(profile_);
1575 provider_map_->Init(template_urls_, search_terms_data); 1583 provider_map_->Init(template_urls_, search_terms_data);
1576 loaded_ = true; 1584 loaded_ = true;
1577 } 1585 }
1578 1586
1579 void TemplateURLService::NotifyLoaded() {
1580 content::NotificationService::current()->Notify(
1581 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
1582 content::Source<TemplateURLService>(this),
1583 content::NotificationService::NoDetails());
1584 }
1585
1586 void TemplateURLService::SaveDefaultSearchProviderToPrefs( 1587 void TemplateURLService::SaveDefaultSearchProviderToPrefs(
1587 const TemplateURL* t_url) { 1588 const TemplateURL* t_url) {
1588 PrefService* prefs = GetPrefs(); 1589 PrefService* prefs = GetPrefs();
1589 if (!prefs) 1590 if (!prefs)
1590 return; 1591 return;
1591 1592
1592 bool enabled = false; 1593 bool enabled = false;
1593 std::string search_url; 1594 std::string search_url;
1594 std::string suggest_url; 1595 std::string suggest_url;
1595 std::string instant_url; 1596 std::string instant_url;
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 const ExtensionKeyword& extension_keyword) const { 2639 const ExtensionKeyword& extension_keyword) const {
2639 TemplateURLData data; 2640 TemplateURLData data;
2640 data.short_name = UTF8ToUTF16(extension_keyword.extension_name); 2641 data.short_name = UTF8ToUTF16(extension_keyword.extension_name);
2641 data.SetKeyword(UTF8ToUTF16(extension_keyword.extension_keyword)); 2642 data.SetKeyword(UTF8ToUTF16(extension_keyword.extension_keyword));
2642 // This URL is not actually used for navigation. It holds the extension's 2643 // This URL is not actually used for navigation. It holds the extension's
2643 // ID, as well as forcing the TemplateURL to be treated as a search keyword. 2644 // ID, as well as forcing the TemplateURL to be treated as a search keyword.
2644 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + 2645 data.SetURL(std::string(extensions::kExtensionScheme) + "://" +
2645 extension_keyword.extension_id + "/?q={searchTerms}"); 2646 extension_keyword.extension_id + "/?q={searchTerms}");
2646 return new TemplateURL(profile_, data); 2647 return new TemplateURL(profile_, data);
2647 } 2648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698