| 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/guid.h" | 10 #include "base/guid.h" |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 // in through Sync. | 857 // in through Sync. |
| 858 pending_synced_default_search_ = true; | 858 pending_synced_default_search_ = true; |
| 859 } | 859 } |
| 860 UpdateDefaultSearch(); | 860 UpdateDefaultSearch(); |
| 861 } else { | 861 } else { |
| 862 NOTREACHED(); | 862 NOTREACHED(); |
| 863 } | 863 } |
| 864 } | 864 } |
| 865 | 865 |
| 866 syncer::SyncDataList TemplateURLService::GetAllSyncData( | 866 syncer::SyncDataList TemplateURLService::GetAllSyncData( |
| 867 syncable::ModelType type) const { | 867 syncer::ModelType type) const { |
| 868 DCHECK_EQ(syncable::SEARCH_ENGINES, type); | 868 DCHECK_EQ(syncer::SEARCH_ENGINES, type); |
| 869 | 869 |
| 870 syncer::SyncDataList current_data; | 870 syncer::SyncDataList current_data; |
| 871 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); | 871 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); |
| 872 iter != template_urls_.end(); ++iter) { | 872 iter != template_urls_.end(); ++iter) { |
| 873 // We don't sync extension keywords. | 873 // We don't sync extension keywords. |
| 874 // TODO(mpcomplete): If we allow editing extension keywords, then those | 874 // TODO(mpcomplete): If we allow editing extension keywords, then those |
| 875 // should be persisted to disk and synced. | 875 // should be persisted to disk and synced. |
| 876 if ((*iter)->IsExtensionKeyword()) | 876 if ((*iter)->IsExtensionKeyword()) |
| 877 continue; | 877 continue; |
| 878 // We don't sync keywords managed by policy. | 878 // We don't sync keywords managed by policy. |
| 879 if ((*iter)->created_by_policy()) | 879 if ((*iter)->created_by_policy()) |
| 880 continue; | 880 continue; |
| 881 current_data.push_back(CreateSyncDataFromTemplateURL(**iter)); | 881 current_data.push_back(CreateSyncDataFromTemplateURL(**iter)); |
| 882 } | 882 } |
| 883 | 883 |
| 884 return current_data; | 884 return current_data; |
| 885 } | 885 } |
| 886 | 886 |
| 887 syncer::SyncError TemplateURLService::ProcessSyncChanges( | 887 syncer::SyncError TemplateURLService::ProcessSyncChanges( |
| 888 const tracked_objects::Location& from_here, | 888 const tracked_objects::Location& from_here, |
| 889 const syncer::SyncChangeList& change_list) { | 889 const syncer::SyncChangeList& change_list) { |
| 890 if (!models_associated_) { | 890 if (!models_associated_) { |
| 891 syncer::SyncError error(FROM_HERE, "Models not yet associated.", | 891 syncer::SyncError error(FROM_HERE, "Models not yet associated.", |
| 892 syncable::SEARCH_ENGINES); | 892 syncer::SEARCH_ENGINES); |
| 893 return error; | 893 return error; |
| 894 } | 894 } |
| 895 DCHECK(loaded_); | 895 DCHECK(loaded_); |
| 896 | 896 |
| 897 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); | 897 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); |
| 898 | 898 |
| 899 // We've started syncing, so set our origin member to the base Sync value. | 899 // We've started syncing, so set our origin member to the base Sync value. |
| 900 // As we move through Sync Code, we may set this to increasingly specific | 900 // As we move through Sync Code, we may set this to increasingly specific |
| 901 // origins so we can tell what exactly caused a DSP change. | 901 // origins so we can tell what exactly caused a DSP change. |
| 902 AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, | 902 AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
| 903 DSP_CHANGE_SYNC_UNINTENTIONAL); | 903 DSP_CHANGE_SYNC_UNINTENTIONAL); |
| 904 | 904 |
| 905 syncer::SyncChangeList new_changes; | 905 syncer::SyncChangeList new_changes; |
| 906 syncer::SyncError error; | 906 syncer::SyncError error; |
| 907 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); | 907 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); |
| 908 iter != change_list.end(); ++iter) { | 908 iter != change_list.end(); ++iter) { |
| 909 DCHECK_EQ(syncable::SEARCH_ENGINES, iter->sync_data().GetDataType()); | 909 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType()); |
| 910 | 910 |
| 911 std::string guid = | 911 std::string guid = |
| 912 iter->sync_data().GetSpecifics().search_engine().sync_guid(); | 912 iter->sync_data().GetSpecifics().search_engine().sync_guid(); |
| 913 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); | 913 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); |
| 914 scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData( | 914 scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData( |
| 915 profile_, existing_turl, iter->sync_data(), &new_changes)); | 915 profile_, existing_turl, iter->sync_data(), &new_changes)); |
| 916 if (!turl.get()) | 916 if (!turl.get()) |
| 917 continue; | 917 continue; |
| 918 | 918 |
| 919 // Explicitly don't check for conflicts against extension keywords; in this | 919 // Explicitly don't check for conflicts against extension keywords; in this |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 // inconsistent data to Sync. We return the last error we received. | 1004 // inconsistent data to Sync. We return the last error we received. |
| 1005 if (error.IsSet()) | 1005 if (error.IsSet()) |
| 1006 return error; | 1006 return error; |
| 1007 | 1007 |
| 1008 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); | 1008 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); |
| 1009 | 1009 |
| 1010 return error; | 1010 return error; |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 syncer::SyncError TemplateURLService::MergeDataAndStartSyncing( | 1013 syncer::SyncError TemplateURLService::MergeDataAndStartSyncing( |
| 1014 syncable::ModelType type, | 1014 syncer::ModelType type, |
| 1015 const syncer::SyncDataList& initial_sync_data, | 1015 const syncer::SyncDataList& initial_sync_data, |
| 1016 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 1016 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 1017 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { | 1017 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { |
| 1018 DCHECK(loaded_); | 1018 DCHECK(loaded_); |
| 1019 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 1019 DCHECK_EQ(type, syncer::SEARCH_ENGINES); |
| 1020 DCHECK(!sync_processor_.get()); | 1020 DCHECK(!sync_processor_.get()); |
| 1021 DCHECK(sync_processor.get()); | 1021 DCHECK(sync_processor.get()); |
| 1022 DCHECK(sync_error_factory.get()); | 1022 DCHECK(sync_error_factory.get()); |
| 1023 sync_processor_ = sync_processor.Pass(); | 1023 sync_processor_ = sync_processor.Pass(); |
| 1024 sync_error_factory_ = sync_error_factory.Pass(); | 1024 sync_error_factory_ = sync_error_factory.Pass(); |
| 1025 | 1025 |
| 1026 // We just started syncing, so set our wait-for-default flag if we are | 1026 // We just started syncing, so set our wait-for-default flag if we are |
| 1027 // expecting a default from Sync. | 1027 // expecting a default from Sync. |
| 1028 if (GetPrefs()) { | 1028 if (GetPrefs()) { |
| 1029 std::string default_guid = GetPrefs()->GetString( | 1029 std::string default_guid = GetPrefs()->GetString( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1042 // We've started syncing, so set our origin member to the base Sync value. | 1042 // We've started syncing, so set our origin member to the base Sync value. |
| 1043 // As we move through Sync Code, we may set this to increasingly specific | 1043 // As we move through Sync Code, we may set this to increasingly specific |
| 1044 // origins so we can tell what exactly caused a DSP change. | 1044 // origins so we can tell what exactly caused a DSP change. |
| 1045 AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, | 1045 AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
| 1046 DSP_CHANGE_SYNC_UNINTENTIONAL); | 1046 DSP_CHANGE_SYNC_UNINTENTIONAL); |
| 1047 | 1047 |
| 1048 syncer::SyncChangeList new_changes; | 1048 syncer::SyncChangeList new_changes; |
| 1049 | 1049 |
| 1050 // Build maps of our sync GUIDs to syncer::SyncData. | 1050 // Build maps of our sync GUIDs to syncer::SyncData. |
| 1051 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( | 1051 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( |
| 1052 GetAllSyncData(syncable::SEARCH_ENGINES)); | 1052 GetAllSyncData(syncer::SEARCH_ENGINES)); |
| 1053 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); | 1053 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); |
| 1054 | 1054 |
| 1055 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); | 1055 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); |
| 1056 iter != sync_data_map.end(); ++iter) { | 1056 iter != sync_data_map.end(); ++iter) { |
| 1057 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); | 1057 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); |
| 1058 scoped_ptr<TemplateURL> sync_turl( | 1058 scoped_ptr<TemplateURL> sync_turl( |
| 1059 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, | 1059 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, |
| 1060 iter->second, &new_changes)); | 1060 iter->second, &new_changes)); |
| 1061 if (!sync_turl.get()) | 1061 if (!sync_turl.get()) |
| 1062 continue; | 1062 continue; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 return error; | 1145 return error; |
| 1146 | 1146 |
| 1147 // The ACTION_DELETEs from this set are processed. Empty it so we don't try to | 1147 // The ACTION_DELETEs from this set are processed. Empty it so we don't try to |
| 1148 // reuse them on the next call to MergeDataAndStartSyncing. | 1148 // reuse them on the next call to MergeDataAndStartSyncing. |
| 1149 pre_sync_deletes_.clear(); | 1149 pre_sync_deletes_.clear(); |
| 1150 | 1150 |
| 1151 models_associated_ = true; | 1151 models_associated_ = true; |
| 1152 return syncer::SyncError(); | 1152 return syncer::SyncError(); |
| 1153 } | 1153 } |
| 1154 | 1154 |
| 1155 void TemplateURLService::StopSyncing(syncable::ModelType type) { | 1155 void TemplateURLService::StopSyncing(syncer::ModelType type) { |
| 1156 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 1156 DCHECK_EQ(type, syncer::SEARCH_ENGINES); |
| 1157 models_associated_ = false; | 1157 models_associated_ = false; |
| 1158 sync_processor_.reset(); | 1158 sync_processor_.reset(); |
| 1159 sync_error_factory_.reset(); | 1159 sync_error_factory_.reset(); |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 void TemplateURLService::ProcessTemplateURLChange( | 1162 void TemplateURLService::ProcessTemplateURLChange( |
| 1163 const TemplateURL* turl, | 1163 const TemplateURL* turl, |
| 1164 syncer::SyncChange::SyncChangeType type) { | 1164 syncer::SyncChange::SyncChangeType type) { |
| 1165 DCHECK_NE(type, syncer::SyncChange::ACTION_INVALID); | 1165 DCHECK_NE(type, syncer::SyncChange::ACTION_INVALID); |
| 1166 DCHECK(turl); | 1166 DCHECK(turl); |
| (...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2405 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2405 // TODO(mpcomplete): If we allow editing extension keywords, then those |
| 2406 // should be persisted to disk and synced. | 2406 // should be persisted to disk and synced. |
| 2407 if (template_url->sync_guid().empty() && | 2407 if (template_url->sync_guid().empty() && |
| 2408 !template_url->IsExtensionKeyword()) { | 2408 !template_url->IsExtensionKeyword()) { |
| 2409 template_url->data_.sync_guid = base::GenerateGUID(); | 2409 template_url->data_.sync_guid = base::GenerateGUID(); |
| 2410 if (service_.get()) | 2410 if (service_.get()) |
| 2411 service_->UpdateKeyword(template_url->data()); | 2411 service_->UpdateKeyword(template_url->data()); |
| 2412 } | 2412 } |
| 2413 } | 2413 } |
| 2414 } | 2414 } |
| OLD | NEW |