| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 : profile_(profile), | 108 : profile_(profile), |
| 109 loaded_(false), | 109 loaded_(false), |
| 110 load_failed_(false), | 110 load_failed_(false), |
| 111 load_handle_(0), | 111 load_handle_(0), |
| 112 default_search_provider_(NULL), | 112 default_search_provider_(NULL), |
| 113 is_default_search_managed_(false), | 113 is_default_search_managed_(false), |
| 114 next_id_(kInvalidTemplateURLID + 1), | 114 next_id_(kInvalidTemplateURLID + 1), |
| 115 time_provider_(&base::Time::Now), | 115 time_provider_(&base::Time::Now), |
| 116 models_associated_(false), | 116 models_associated_(false), |
| 117 processing_syncer_changes_(false), | 117 processing_syncer_changes_(false), |
| 118 sync_processor_(NULL), | |
| 119 pending_synced_default_search_(false) { | 118 pending_synced_default_search_(false) { |
| 120 DCHECK(profile_); | 119 DCHECK(profile_); |
| 121 Init(NULL, 0); | 120 Init(NULL, 0); |
| 122 } | 121 } |
| 123 | 122 |
| 124 TemplateURLService::TemplateURLService(const Initializer* initializers, | 123 TemplateURLService::TemplateURLService(const Initializer* initializers, |
| 125 const int count) | 124 const int count) |
| 126 : profile_(NULL), | 125 : profile_(NULL), |
| 127 loaded_(false), | 126 loaded_(false), |
| 128 load_failed_(false), | 127 load_failed_(false), |
| 129 load_handle_(0), | 128 load_handle_(0), |
| 130 service_(NULL), | 129 service_(NULL), |
| 131 default_search_provider_(NULL), | 130 default_search_provider_(NULL), |
| 132 is_default_search_managed_(false), | 131 is_default_search_managed_(false), |
| 133 next_id_(kInvalidTemplateURLID + 1), | 132 next_id_(kInvalidTemplateURLID + 1), |
| 134 time_provider_(&base::Time::Now), | 133 time_provider_(&base::Time::Now), |
| 135 models_associated_(false), | 134 models_associated_(false), |
| 136 processing_syncer_changes_(false), | 135 processing_syncer_changes_(false), |
| 137 sync_processor_(NULL), | |
| 138 pending_synced_default_search_(false) { | 136 pending_synced_default_search_(false) { |
| 139 Init(initializers, count); | 137 Init(initializers, count); |
| 140 } | 138 } |
| 141 | 139 |
| 142 TemplateURLService::~TemplateURLService() { | 140 TemplateURLService::~TemplateURLService() { |
| 143 if (load_handle_) { | 141 if (load_handle_) { |
| 144 DCHECK(service_.get()); | 142 DCHECK(service_.get()); |
| 145 service_->CancelRequest(load_handle_); | 143 service_->CancelRequest(load_handle_); |
| 146 } | 144 } |
| 147 | 145 |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 return error; | 811 return error; |
| 814 | 812 |
| 815 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); | 813 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); |
| 816 | 814 |
| 817 return error; | 815 return error; |
| 818 } | 816 } |
| 819 | 817 |
| 820 SyncError TemplateURLService::MergeDataAndStartSyncing( | 818 SyncError TemplateURLService::MergeDataAndStartSyncing( |
| 821 syncable::ModelType type, | 819 syncable::ModelType type, |
| 822 const SyncDataList& initial_sync_data, | 820 const SyncDataList& initial_sync_data, |
| 823 SyncChangeProcessor* sync_processor) { | 821 scoped_ptr<SyncChangeProcessor> sync_processor) { |
| 824 DCHECK(loaded()); | 822 DCHECK(loaded()); |
| 825 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 823 DCHECK_EQ(type, syncable::SEARCH_ENGINES); |
| 826 DCHECK(!sync_processor_); | 824 DCHECK(!sync_processor_.get()); |
| 827 sync_processor_ = sync_processor; | 825 DCHECK(sync_processor.get()); |
| 826 sync_processor_ = sync_processor.Pass(); |
| 828 | 827 |
| 829 // We just started syncing, so set our wait-for-default flag if we are | 828 // We just started syncing, so set our wait-for-default flag if we are |
| 830 // expecting a default from Sync. | 829 // expecting a default from Sync. |
| 831 if (GetPrefs()) { | 830 if (GetPrefs()) { |
| 832 std::string default_guid = GetPrefs()->GetString( | 831 std::string default_guid = GetPrefs()->GetString( |
| 833 prefs::kSyncedDefaultSearchProviderGUID); | 832 prefs::kSyncedDefaultSearchProviderGUID); |
| 834 const TemplateURL* current_default = GetDefaultSearchProvider(); | 833 const TemplateURL* current_default = GetDefaultSearchProvider(); |
| 835 | 834 |
| 836 if (!default_guid.empty() && | 835 if (!default_guid.empty() && |
| 837 (!current_default || current_default->sync_guid() != default_guid)) | 836 (!current_default || current_default->sync_guid() != default_guid)) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 if (error.IsSet()) | 924 if (error.IsSet()) |
| 926 return error; | 925 return error; |
| 927 | 926 |
| 928 models_associated_ = true; | 927 models_associated_ = true; |
| 929 return SyncError(); | 928 return SyncError(); |
| 930 } | 929 } |
| 931 | 930 |
| 932 void TemplateURLService::StopSyncing(syncable::ModelType type) { | 931 void TemplateURLService::StopSyncing(syncable::ModelType type) { |
| 933 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 932 DCHECK_EQ(type, syncable::SEARCH_ENGINES); |
| 934 models_associated_ = false; | 933 models_associated_ = false; |
| 935 sync_processor_ = NULL; | 934 sync_processor_.reset(); |
| 936 } | 935 } |
| 937 | 936 |
| 938 void TemplateURLService::ProcessTemplateURLChange( | 937 void TemplateURLService::ProcessTemplateURLChange( |
| 939 const TemplateURL* turl, | 938 const TemplateURL* turl, |
| 940 SyncChange::SyncChangeType type) { | 939 SyncChange::SyncChangeType type) { |
| 941 DCHECK_NE(type, SyncChange::ACTION_INVALID); | 940 DCHECK_NE(type, SyncChange::ACTION_INVALID); |
| 942 DCHECK(turl); | 941 DCHECK(turl); |
| 943 | 942 |
| 944 if (!models_associated_) | 943 if (!models_associated_) |
| 945 return; // Not syncing. | 944 return; // Not syncing. |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 rlz_lib::SET_TO_GOOGLE); | 1591 rlz_lib::SET_TO_GOOGLE); |
| 1593 #endif | 1592 #endif |
| 1594 } | 1593 } |
| 1595 } | 1594 } |
| 1596 | 1595 |
| 1597 if (!is_default_search_managed_) { | 1596 if (!is_default_search_managed_) { |
| 1598 SaveDefaultSearchProviderToPrefs(url); | 1597 SaveDefaultSearchProviderToPrefs(url); |
| 1599 | 1598 |
| 1600 // If we are syncing, we want to set the synced pref that will notify other | 1599 // If we are syncing, we want to set the synced pref that will notify other |
| 1601 // instances to change their default to this new search provider. | 1600 // instances to change their default to this new search provider. |
| 1602 if (sync_processor_ && url && !url->sync_guid().empty() && GetPrefs()) { | 1601 if (sync_processor_.get() && url && !url->sync_guid().empty() && |
| 1602 GetPrefs()) { |
| 1603 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, | 1603 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, |
| 1604 url->sync_guid()); | 1604 url->sync_guid()); |
| 1605 } | 1605 } |
| 1606 } | 1606 } |
| 1607 | 1607 |
| 1608 if (service_.get()) | 1608 if (service_.get()) |
| 1609 service_->SetDefaultSearchProvider(url); | 1609 service_->SetDefaultSearchProvider(url); |
| 1610 | 1610 |
| 1611 // Inform sync the change to the show_in_default_list flag. | 1611 // Inform sync the change to the show_in_default_list flag. |
| 1612 if (url) | 1612 if (url) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1838 // having the same GUID. | 1838 // having the same GUID. |
| 1839 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); | 1839 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); |
| 1840 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); | 1840 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); |
| 1841 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 1841 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
| 1842 } | 1842 } |
| 1843 } | 1843 } |
| 1844 | 1844 |
| 1845 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( | 1845 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( |
| 1846 const std::string& guid) { | 1846 const std::string& guid) { |
| 1847 // If we're not syncing or if default search is managed by policy, ignore. | 1847 // If we're not syncing or if default search is managed by policy, ignore. |
| 1848 if (!sync_processor_ || is_default_search_managed_) | 1848 if (!sync_processor_.get() || is_default_search_managed_) |
| 1849 return; | 1849 return; |
| 1850 | 1850 |
| 1851 PrefService* prefs = GetPrefs(); | 1851 PrefService* prefs = GetPrefs(); |
| 1852 if (prefs && pending_synced_default_search_ && | 1852 if (prefs && pending_synced_default_search_ && |
| 1853 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID) == guid) { | 1853 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID) == guid) { |
| 1854 // Make sure this actually exists. We should not be calling this unless we | 1854 // Make sure this actually exists. We should not be calling this unless we |
| 1855 // really just added this TemplateURL. | 1855 // really just added this TemplateURL. |
| 1856 const TemplateURL* turl_from_sync = GetTemplateURLForGUID(guid); | 1856 const TemplateURL* turl_from_sync = GetTemplateURLForGUID(guid); |
| 1857 DCHECK(turl_from_sync); | 1857 DCHECK(turl_from_sync); |
| 1858 SetDefaultSearchProvider(turl_from_sync); | 1858 SetDefaultSearchProvider(turl_from_sync); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1904 dst->set_input_encodings(input_encodings); | 1904 dst->set_input_encodings(input_encodings); |
| 1905 dst->set_show_in_default_list(specifics.show_in_default_list()); | 1905 dst->set_show_in_default_list(specifics.show_in_default_list()); |
| 1906 dst->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); | 1906 dst->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); |
| 1907 dst->SetPrepopulateId(specifics.prepopulate_id()); | 1907 dst->SetPrepopulateId(specifics.prepopulate_id()); |
| 1908 dst->set_autogenerate_keyword(specifics.autogenerate_keyword()); | 1908 dst->set_autogenerate_keyword(specifics.autogenerate_keyword()); |
| 1909 dst->SetInstantURL(specifics.instant_url(), 0, 0); | 1909 dst->SetInstantURL(specifics.instant_url(), 0, 0); |
| 1910 dst->set_last_modified( | 1910 dst->set_last_modified( |
| 1911 base::Time::FromInternalValue(specifics.last_modified())); | 1911 base::Time::FromInternalValue(specifics.last_modified())); |
| 1912 dst->set_sync_guid(specifics.sync_guid()); | 1912 dst->set_sync_guid(specifics.sync_guid()); |
| 1913 } | 1913 } |
| OLD | NEW |