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/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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 NotifyLoaded(); |
| 782 } | 782 } |
| 783 } | 783 } |
| 784 | 784 |
| 785 scoped_ptr<TemplateURLService::Subscription> | |
| 786 TemplateURLService::RegisterOnLoadedCallback( | |
|
Peter Kasting
2013/10/02 22:22:04
Nit: Indent 4
Cait (Slow)
2013/10/03 15:36:45
Done.
| |
| 787 const base::Closure& callback) { | |
| 788 if (loaded_) | |
|
Peter Kasting
2013/10/02 22:22:04
Nit: I very slightly prefer:
return loaded_ ?
Cait (Slow)
2013/10/03 15:36:45
Done.
| |
| 789 return scoped_ptr<TemplateURLService::Subscription>(); | |
| 790 return 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. |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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() { | 1587 void TemplateURLService::NotifyLoaded() { |
| 1580 content::NotificationService::current()->Notify( | 1588 on_loaded_callbacks_.Notify(); |
|
Peter Kasting
2013/10/02 22:22:04
Nit: At this point, we can just nuke NotifyLoaded(
Cait (Slow)
2013/10/03 15:36:45
Done.
| |
| 1581 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | |
| 1582 content::Source<TemplateURLService>(this), | |
| 1583 content::NotificationService::NoDetails()); | |
| 1584 } | 1589 } |
| 1585 | 1590 |
| 1586 void TemplateURLService::SaveDefaultSearchProviderToPrefs( | 1591 void TemplateURLService::SaveDefaultSearchProviderToPrefs( |
| 1587 const TemplateURL* t_url) { | 1592 const TemplateURL* t_url) { |
| 1588 PrefService* prefs = GetPrefs(); | 1593 PrefService* prefs = GetPrefs(); |
| 1589 if (!prefs) | 1594 if (!prefs) |
| 1590 return; | 1595 return; |
| 1591 | 1596 |
| 1592 bool enabled = false; | 1597 bool enabled = false; |
| 1593 std::string search_url; | 1598 std::string search_url; |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2638 const ExtensionKeyword& extension_keyword) const { | 2643 const ExtensionKeyword& extension_keyword) const { |
| 2639 TemplateURLData data; | 2644 TemplateURLData data; |
| 2640 data.short_name = UTF8ToUTF16(extension_keyword.extension_name); | 2645 data.short_name = UTF8ToUTF16(extension_keyword.extension_name); |
| 2641 data.SetKeyword(UTF8ToUTF16(extension_keyword.extension_keyword)); | 2646 data.SetKeyword(UTF8ToUTF16(extension_keyword.extension_keyword)); |
| 2642 // This URL is not actually used for navigation. It holds the extension's | 2647 // 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. | 2648 // ID, as well as forcing the TemplateURL to be treated as a search keyword. |
| 2644 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + | 2649 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + |
| 2645 extension_keyword.extension_id + "/?q={searchTerms}"); | 2650 extension_keyword.extension_id + "/?q={searchTerms}"); |
| 2646 return new TemplateURL(profile_, data); | 2651 return new TemplateURL(profile_, data); |
| 2647 } | 2652 } |
| OLD | NEW |