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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 return error; | 815 return error; |
818 | 816 |
819 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); | 817 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); |
820 | 818 |
821 return error; | 819 return error; |
822 } | 820 } |
823 | 821 |
824 SyncError TemplateURLService::MergeDataAndStartSyncing( | 822 SyncError TemplateURLService::MergeDataAndStartSyncing( |
825 syncable::ModelType type, | 823 syncable::ModelType type, |
826 const SyncDataList& initial_sync_data, | 824 const SyncDataList& initial_sync_data, |
827 SyncChangeProcessor* sync_processor) { | 825 scoped_ptr<SyncChangeProcessor> sync_processor) { |
828 DCHECK(loaded()); | 826 DCHECK(loaded()); |
829 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 827 DCHECK_EQ(type, syncable::SEARCH_ENGINES); |
830 DCHECK(!sync_processor_); | 828 DCHECK(!sync_processor_.get()); |
831 sync_processor_ = sync_processor; | 829 DCHECK(sync_processor.get()); |
| 830 sync_processor_ = sync_processor.Pass(); |
832 | 831 |
833 // We just started syncing, so set our wait-for-default flag if we are | 832 // We just started syncing, so set our wait-for-default flag if we are |
834 // expecting a default from Sync. | 833 // expecting a default from Sync. |
835 if (GetPrefs()) { | 834 if (GetPrefs()) { |
836 std::string default_guid = GetPrefs()->GetString( | 835 std::string default_guid = GetPrefs()->GetString( |
837 prefs::kSyncedDefaultSearchProviderGUID); | 836 prefs::kSyncedDefaultSearchProviderGUID); |
838 const TemplateURL* current_default = GetDefaultSearchProvider(); | 837 const TemplateURL* current_default = GetDefaultSearchProvider(); |
839 | 838 |
840 if (!default_guid.empty() && | 839 if (!default_guid.empty() && |
841 (!current_default || current_default->sync_guid() != default_guid)) | 840 (!current_default || current_default->sync_guid() != default_guid)) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 if (error.IsSet()) | 928 if (error.IsSet()) |
930 return error; | 929 return error; |
931 | 930 |
932 models_associated_ = true; | 931 models_associated_ = true; |
933 return SyncError(); | 932 return SyncError(); |
934 } | 933 } |
935 | 934 |
936 void TemplateURLService::StopSyncing(syncable::ModelType type) { | 935 void TemplateURLService::StopSyncing(syncable::ModelType type) { |
937 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 936 DCHECK_EQ(type, syncable::SEARCH_ENGINES); |
938 models_associated_ = false; | 937 models_associated_ = false; |
939 sync_processor_ = NULL; | 938 sync_processor_.reset(); |
940 } | 939 } |
941 | 940 |
942 void TemplateURLService::ProcessTemplateURLChange( | 941 void TemplateURLService::ProcessTemplateURLChange( |
943 const TemplateURL* turl, | 942 const TemplateURL* turl, |
944 SyncChange::SyncChangeType type) { | 943 SyncChange::SyncChangeType type) { |
945 DCHECK_NE(type, SyncChange::ACTION_INVALID); | 944 DCHECK_NE(type, SyncChange::ACTION_INVALID); |
946 DCHECK(turl); | 945 DCHECK(turl); |
947 | 946 |
948 if (!models_associated_) | 947 if (!models_associated_) |
949 return; // Not syncing. | 948 return; // Not syncing. |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 rlz_lib::SET_TO_GOOGLE); | 1595 rlz_lib::SET_TO_GOOGLE); |
1597 #endif | 1596 #endif |
1598 } | 1597 } |
1599 } | 1598 } |
1600 | 1599 |
1601 if (!is_default_search_managed_) { | 1600 if (!is_default_search_managed_) { |
1602 SaveDefaultSearchProviderToPrefs(url); | 1601 SaveDefaultSearchProviderToPrefs(url); |
1603 | 1602 |
1604 // If we are syncing, we want to set the synced pref that will notify other | 1603 // If we are syncing, we want to set the synced pref that will notify other |
1605 // instances to change their default to this new search provider. | 1604 // instances to change their default to this new search provider. |
1606 if (sync_processor_ && url && !url->sync_guid().empty() && GetPrefs()) { | 1605 if (sync_processor_.get() && url && !url->sync_guid().empty() && |
| 1606 GetPrefs()) { |
1607 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, | 1607 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, |
1608 url->sync_guid()); | 1608 url->sync_guid()); |
1609 } | 1609 } |
1610 } | 1610 } |
1611 | 1611 |
1612 if (service_.get()) | 1612 if (service_.get()) |
1613 service_->SetDefaultSearchProvider(url); | 1613 service_->SetDefaultSearchProvider(url); |
1614 | 1614 |
1615 // Inform sync the change to the show_in_default_list flag. | 1615 // Inform sync the change to the show_in_default_list flag. |
1616 if (url) | 1616 if (url) |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1842 // having the same GUID. | 1842 // having the same GUID. |
1843 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); | 1843 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); |
1844 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); | 1844 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); |
1845 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 1845 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
1846 } | 1846 } |
1847 } | 1847 } |
1848 | 1848 |
1849 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( | 1849 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( |
1850 const std::string& guid) { | 1850 const std::string& guid) { |
1851 // If we're not syncing or if default search is managed by policy, ignore. | 1851 // If we're not syncing or if default search is managed by policy, ignore. |
1852 if (!sync_processor_ || is_default_search_managed_) | 1852 if (!sync_processor_.get() || is_default_search_managed_) |
1853 return; | 1853 return; |
1854 | 1854 |
1855 PrefService* prefs = GetPrefs(); | 1855 PrefService* prefs = GetPrefs(); |
1856 if (prefs && pending_synced_default_search_ && | 1856 if (prefs && pending_synced_default_search_ && |
1857 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID) == guid) { | 1857 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID) == guid) { |
1858 // Make sure this actually exists. We should not be calling this unless we | 1858 // Make sure this actually exists. We should not be calling this unless we |
1859 // really just added this TemplateURL. | 1859 // really just added this TemplateURL. |
1860 const TemplateURL* turl_from_sync = GetTemplateURLForGUID(guid); | 1860 const TemplateURL* turl_from_sync = GetTemplateURLForGUID(guid); |
1861 DCHECK(turl_from_sync); | 1861 DCHECK(turl_from_sync); |
1862 SetDefaultSearchProvider(turl_from_sync); | 1862 SetDefaultSearchProvider(turl_from_sync); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 dst->set_input_encodings(input_encodings); | 1908 dst->set_input_encodings(input_encodings); |
1909 dst->set_show_in_default_list(specifics.show_in_default_list()); | 1909 dst->set_show_in_default_list(specifics.show_in_default_list()); |
1910 dst->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); | 1910 dst->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); |
1911 dst->SetPrepopulateId(specifics.prepopulate_id()); | 1911 dst->SetPrepopulateId(specifics.prepopulate_id()); |
1912 dst->set_autogenerate_keyword(specifics.autogenerate_keyword()); | 1912 dst->set_autogenerate_keyword(specifics.autogenerate_keyword()); |
1913 dst->SetInstantURL(specifics.instant_url(), 0, 0); | 1913 dst->SetInstantURL(specifics.instant_url(), 0, 0); |
1914 dst->set_last_modified( | 1914 dst->set_last_modified( |
1915 base::Time::FromInternalValue(specifics.last_modified())); | 1915 base::Time::FromInternalValue(specifics.last_modified())); |
1916 dst->set_sync_guid(specifics.sync_guid()); | 1916 dst->set_sync_guid(specifics.sync_guid()); |
1917 } | 1917 } |
OLD | NEW |