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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 | 584 |
585 // initial_default_search_provider_ is only needed before we've finished | 585 // initial_default_search_provider_ is only needed before we've finished |
586 // loading. Now that we've loaded we can nuke it. | 586 // loading. Now that we've loaded we can nuke it. |
587 initial_default_search_provider_.reset(); | 587 initial_default_search_provider_.reset(); |
588 is_default_search_managed_ = false; | 588 is_default_search_managed_ = false; |
589 | 589 |
590 TemplateURLVector template_urls; | 590 TemplateURLVector template_urls; |
591 TemplateURL* default_search_provider = NULL; | 591 TemplateURL* default_search_provider = NULL; |
592 int new_resource_keyword_version = 0; | 592 int new_resource_keyword_version = 0; |
593 GetSearchProvidersUsingKeywordResult(*result, service_.get(), profile_, | 593 GetSearchProvidersUsingKeywordResult(*result, service_.get(), profile_, |
594 &template_urls, &default_search_provider, &new_resource_keyword_version); | 594 &template_urls, &default_search_provider, &new_resource_keyword_version, |
595 &pre_sync_deletes_); | |
595 | 596 |
596 bool database_specified_a_default = (default_search_provider != NULL); | 597 bool database_specified_a_default = (default_search_provider != NULL); |
597 | 598 |
598 // Check if default search provider is now managed. | 599 // Check if default search provider is now managed. |
599 scoped_ptr<TemplateURL> default_from_prefs; | 600 scoped_ptr<TemplateURL> default_from_prefs; |
600 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, | 601 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, |
601 &is_default_search_managed_); | 602 &is_default_search_managed_); |
602 | 603 |
603 // Check if the default search provider has been changed in Web Data by | 604 // Check if the default search provider has been changed in Web Data by |
604 // another program. No immediate action is performed because the default | 605 // another program. No immediate action is performed because the default |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 | 952 |
952 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); | 953 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); |
953 iter != sync_data_map.end(); ++iter) { | 954 iter != sync_data_map.end(); ++iter) { |
954 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); | 955 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); |
955 scoped_ptr<TemplateURL> sync_turl( | 956 scoped_ptr<TemplateURL> sync_turl( |
956 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, | 957 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, |
957 iter->second, &new_changes)); | 958 iter->second, &new_changes)); |
958 if (!sync_turl.get()) | 959 if (!sync_turl.get()) |
959 continue; | 960 continue; |
960 | 961 |
962 if (pre_sync_deletes_.find(sync_turl->sync_guid()) != | |
963 pre_sync_deletes_.end()) { | |
964 // This entry was deleted before the initial sync began (possibly through | |
965 // preprocessing in TemplateURLService's loading code). Ignore it and send | |
966 // an ACTION_DELETE up to the server. | |
967 new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE, | |
968 iter->second)); | |
969 continue; | |
970 } | |
971 | |
961 if (local_turl) { | 972 if (local_turl) { |
962 // This local search engine is already synced. If the timestamp differs | 973 // This local search engine is already synced. If the timestamp differs |
963 // from Sync, we need to update locally or to the cloud. Note that if the | 974 // from Sync, we need to update locally or to the cloud. Note that if the |
964 // timestamps are equal, we touch neither. | 975 // timestamps are equal, we touch neither. |
965 if (sync_turl->last_modified() > local_turl->last_modified()) { | 976 if (sync_turl->last_modified() > local_turl->last_modified()) { |
966 // We've received an update from Sync. We should replace all synced | 977 // We've received an update from Sync. We should replace all synced |
967 // fields in the local TemplateURL. Note that this includes the | 978 // fields in the local TemplateURL. Note that this includes the |
968 // TemplateURLID and the TemplateURL may have to be reparsed. This | 979 // TemplateURLID and the TemplateURL may have to be reparsed. This |
969 // also makes the local data's last_modified timestamp equal to Sync's, | 980 // also makes the local data's last_modified timestamp equal to Sync's, |
970 // avoiding an Update on the next MergeData call. | 981 // avoiding an Update on the next MergeData call. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1018 iter != local_data_map.end(); ++iter) { | 1029 iter != local_data_map.end(); ++iter) { |
1019 new_changes.push_back(SyncChange(SyncChange::ACTION_ADD, iter->second)); | 1030 new_changes.push_back(SyncChange(SyncChange::ACTION_ADD, iter->second)); |
1020 } | 1031 } |
1021 | 1032 |
1022 PreventDuplicateGUIDUpdates(&new_changes); | 1033 PreventDuplicateGUIDUpdates(&new_changes); |
1023 | 1034 |
1024 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); | 1035 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); |
1025 if (error.IsSet()) | 1036 if (error.IsSet()) |
1026 return error; | 1037 return error; |
1027 | 1038 |
1039 // The ACTION_DELETEs from this set are processed. Empty it so we don't try to | |
1040 // reuse them on the next call to MergeDataAndStartSyncing. | |
1041 pre_sync_deletes_.clear(); | |
1042 | |
1028 models_associated_ = true; | 1043 models_associated_ = true; |
1029 return SyncError(); | 1044 return SyncError(); |
1030 } | 1045 } |
1031 | 1046 |
1032 void TemplateURLService::StopSyncing(syncable::ModelType type) { | 1047 void TemplateURLService::StopSyncing(syncable::ModelType type) { |
1033 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 1048 DCHECK_EQ(type, syncable::SEARCH_ENGINES); |
1034 models_associated_ = false; | 1049 models_associated_ = false; |
1035 sync_processor_.reset(); | 1050 sync_processor_.reset(); |
1036 sync_error_factory_.reset(); | 1051 sync_error_factory_.reset(); |
1037 } | 1052 } |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2203 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2218 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2204 // should be persisted to disk and synced. | 2219 // should be persisted to disk and synced. |
2205 if (template_url->sync_guid().empty() && | 2220 if (template_url->sync_guid().empty() && |
2206 !template_url->IsExtensionKeyword()) { | 2221 !template_url->IsExtensionKeyword()) { |
2207 template_url->data_.sync_guid = guid::GenerateGUID(); | 2222 template_url->data_.sync_guid = guid::GenerateGUID(); |
2208 if (service_.get()) | 2223 if (service_.get()) |
2209 service_->UpdateKeyword(template_url->data()); | 2224 service_->UpdateKeyword(template_url->data()); |
2210 } | 2225 } |
2211 } | 2226 } |
2212 } | 2227 } |
2228 | |
2229 void TemplateURLService::AddPreSyncDeletedGUIDForTesting( | |
2230 const std::string& guid) { | |
2231 pre_sync_deletes_.insert(guid); | |
Peter Kasting
2012/05/15 21:28:10
Why not just do this directly in the test? It has
SteveT
2012/05/16 13:26:43
True. Removed this method.
| |
2232 } | |
OLD | NEW |