Chromium Code Reviews| 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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 DefaultSearchManager::Source source; | 718 DefaultSearchManager::Source source; |
| 719 const TemplateURLData* new_dse = | 719 const TemplateURLData* new_dse = |
| 720 default_search_manager_.GetDefaultSearchEngine(&source); | 720 default_search_manager_.GetDefaultSearchEngine(&source); |
| 721 // ApplyDefaultSearchChange will notify observers once it is done. | 721 // ApplyDefaultSearchChange will notify observers once it is done. |
| 722 ApplyDefaultSearchChange(new_dse, source); | 722 ApplyDefaultSearchChange(new_dse, source); |
| 723 } else { | 723 } else { |
| 724 NotifyObservers(); | 724 NotifyObservers(); |
| 725 } | 725 } |
| 726 } | 726 } |
| 727 | 727 |
| 728 bool TemplateURLService::UpdateTemplateURLVisitTime(TemplateURL* url) { | |
| 729 TemplateURLData data(url->data()); | |
| 730 data.last_visited = clock_->Now(); | |
| 731 const bool updated = UpdateNoNotify(url, TemplateURL(data)); | |
| 732 if (updated) | |
| 733 NotifyObservers(); | |
| 734 return updated; | |
| 735 } | |
| 736 | |
| 728 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) { | 737 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) { |
| 729 model_observers_.AddObserver(observer); | 738 model_observers_.AddObserver(observer); |
| 730 } | 739 } |
| 731 | 740 |
| 732 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { | 741 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { |
| 733 model_observers_.RemoveObserver(observer); | 742 model_observers_.RemoveObserver(observer); |
| 734 } | 743 } |
| 735 | 744 |
| 736 void TemplateURLService::Load() { | 745 void TemplateURLService::Load() { |
| 737 if (loaded_ || load_handle_ || disable_load_) | 746 if (loaded_ || load_handle_ || disable_load_) |
| (...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1770 void TemplateURLService::UpdateKeywordSearchTermsForURL( | 1779 void TemplateURLService::UpdateKeywordSearchTermsForURL( |
| 1771 const URLVisitedDetails& details) { | 1780 const URLVisitedDetails& details) { |
| 1772 if (!details.url.is_valid()) | 1781 if (!details.url.is_valid()) |
| 1773 return; | 1782 return; |
| 1774 | 1783 |
| 1775 const TemplateURLSet* urls_for_host = | 1784 const TemplateURLSet* urls_for_host = |
| 1776 provider_map_->GetURLsForHost(details.url.host()); | 1785 provider_map_->GetURLsForHost(details.url.host()); |
| 1777 if (!urls_for_host) | 1786 if (!urls_for_host) |
| 1778 return; | 1787 return; |
| 1779 | 1788 |
| 1789 TemplateURL* visited_url = nullptr; | |
| 1780 for (TemplateURLSet::const_iterator i = urls_for_host->begin(); | 1790 for (TemplateURLSet::const_iterator i = urls_for_host->begin(); |
| 1781 i != urls_for_host->end(); ++i) { | 1791 i != urls_for_host->end(); ++i) { |
| 1782 base::string16 search_terms; | 1792 base::string16 search_terms; |
| 1783 if ((*i)->ExtractSearchTermsFromURL(details.url, search_terms_data(), | 1793 if ((*i)->ExtractSearchTermsFromURL(details.url, search_terms_data(), |
| 1784 &search_terms) && | 1794 &search_terms) && |
| 1785 !search_terms.empty()) { | 1795 !search_terms.empty()) { |
| 1786 if (details.is_keyword_transition) { | 1796 if (details.is_keyword_transition) { |
| 1787 // The visit is the result of the user entering a keyword, generate a | 1797 // The visit is the result of the user entering a keyword, generate a |
| 1788 // KEYWORD_GENERATED visit for the KEYWORD so that the keyword typed | 1798 // KEYWORD_GENERATED visit for the KEYWORD so that the keyword typed |
| 1789 // count is boosted. | 1799 // count is boosted. |
| 1790 AddTabToSearchVisit(**i); | 1800 AddTabToSearchVisit(**i); |
| 1791 } | 1801 } |
| 1792 if (client_) { | 1802 if (client_) { |
| 1793 client_->SetKeywordSearchTermsForURL( | 1803 client_->SetKeywordSearchTermsForURL( |
| 1794 details.url, (*i)->id(), search_terms); | 1804 details.url, (*i)->id(), search_terms); |
| 1795 } | 1805 } |
| 1806 visited_url = *i; | |
|
Peter Kasting
2016/12/01 07:38:24
Why copy this into a temp and then make the call b
ltian
2016/12/01 10:02:58
Directly call it here will cause the error "attemp
Peter Kasting
2016/12/01 19:32:35
I understand this now. You're correct that ultima
| |
| 1796 } | 1807 } |
| 1797 } | 1808 } |
| 1809 if (visited_url != nullptr) { | |
|
Peter Kasting
2016/12/01 07:38:25
Nit: No {}
I would elide the "!= nullptr" as well
ltian
2016/12/01 10:02:58
Done.
| |
| 1810 UpdateTemplateURLVisitTime(visited_url); | |
| 1811 } | |
| 1798 } | 1812 } |
| 1799 | 1813 |
| 1800 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) { | 1814 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) { |
| 1801 // Only add visits for entries the user hasn't modified. If the user modified | 1815 // Only add visits for entries the user hasn't modified. If the user modified |
| 1802 // the entry the keyword may no longer correspond to the host name. It may be | 1816 // the entry the keyword may no longer correspond to the host name. It may be |
| 1803 // possible to do something more sophisticated here, but it's so rare as to | 1817 // possible to do something more sophisticated here, but it's so rare as to |
| 1804 // not be worth it. | 1818 // not be worth it. |
| 1805 if (!t_url.safe_for_autoreplace()) | 1819 if (!t_url.safe_for_autoreplace()) |
| 1806 return; | 1820 return; |
| 1807 | 1821 |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2475 | 2489 |
| 2476 if (most_recently_intalled_default) { | 2490 if (most_recently_intalled_default) { |
| 2477 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2491 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2478 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2492 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2479 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2493 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2480 most_recently_intalled_default->data()); | 2494 most_recently_intalled_default->data()); |
| 2481 } else { | 2495 } else { |
| 2482 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2496 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2483 } | 2497 } |
| 2484 } | 2498 } |
| OLD | NEW |