| 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 } else { | 1158 } else { |
| 1159 // The search engine from the cloud has not been synced locally. Merge it | 1159 // The search engine from the cloud has not been synced locally. Merge it |
| 1160 // into our local model. This will handle any conflicts with local (and | 1160 // into our local model. This will handle any conflicts with local (and |
| 1161 // already-synced) TemplateURLs. It will prefer to keep entries from Sync | 1161 // already-synced) TemplateURLs. It will prefer to keep entries from Sync |
| 1162 // over not-yet-synced TemplateURLs. | 1162 // over not-yet-synced TemplateURLs. |
| 1163 MergeInSyncTemplateURL(sync_turl.get(), sync_data_map, &new_changes, | 1163 MergeInSyncTemplateURL(sync_turl.get(), sync_data_map, &new_changes, |
| 1164 &local_data_map); | 1164 &local_data_map); |
| 1165 } | 1165 } |
| 1166 } | 1166 } |
| 1167 | 1167 |
| 1168 // If there is a pending synced default search provider that was processed |
| 1169 // above, set it now. |
| 1170 TemplateURL* pending_default = GetPendingSyncedDefaultSearchProvider(); |
| 1171 if (pending_default) { |
| 1172 AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 1173 &dsp_change_origin_, DSP_CHANGE_SYNC_ADD); |
| 1174 SetDefaultSearchProvider(pending_default); |
| 1175 } |
| 1176 |
| 1168 // The remaining SyncData in local_data_map should be everything that needs to | 1177 // The remaining SyncData in local_data_map should be everything that needs to |
| 1169 // be pushed as ADDs to sync. | 1178 // be pushed as ADDs to sync. |
| 1170 for (SyncDataMap::const_iterator iter = local_data_map.begin(); | 1179 for (SyncDataMap::const_iterator iter = local_data_map.begin(); |
| 1171 iter != local_data_map.end(); ++iter) { | 1180 iter != local_data_map.end(); ++iter) { |
| 1172 new_changes.push_back( | 1181 new_changes.push_back( |
| 1173 syncer::SyncChange(FROM_HERE, | 1182 syncer::SyncChange(FROM_HERE, |
| 1174 syncer::SyncChange::ACTION_ADD, | 1183 syncer::SyncChange::ACTION_ADD, |
| 1175 iter->second)); | 1184 iter->second)); |
| 1176 } | 1185 } |
| 1177 | 1186 |
| (...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 local_data->erase(guid); | 2427 local_data->erase(guid); |
| 2419 } | 2428 } |
| 2420 } | 2429 } |
| 2421 | 2430 |
| 2422 if (should_add_sync_turl) { | 2431 if (should_add_sync_turl) { |
| 2423 const std::string guid = sync_turl->sync_guid(); | 2432 const std::string guid = sync_turl->sync_guid(); |
| 2424 // Force the local ID to kInvalidTemplateURLID so we can add it. | 2433 // Force the local ID to kInvalidTemplateURLID so we can add it. |
| 2425 TemplateURLData data(sync_turl->data()); | 2434 TemplateURLData data(sync_turl->data()); |
| 2426 data.id = kInvalidTemplateURLID; | 2435 data.id = kInvalidTemplateURLID; |
| 2427 Add(new TemplateURL(profile_, data)); | 2436 Add(new TemplateURL(profile_, data)); |
| 2428 | |
| 2429 // Possibly set the newly added |turl| as the default search provider. | |
| 2430 SetDefaultSearchProviderIfNewlySynced(guid); | |
| 2431 } | 2437 } |
| 2432 } | 2438 } |
| 2433 | 2439 |
| 2434 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( | 2440 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( |
| 2435 const std::string& guid) { | 2441 const std::string& guid) { |
| 2436 // If we're not syncing or if default search is managed by policy, ignore. | 2442 // If we're not syncing or if default search is managed by policy, ignore. |
| 2437 if (!sync_processor_.get() || is_default_search_managed_) | 2443 if (!sync_processor_.get() || is_default_search_managed_) |
| 2438 return; | 2444 return; |
| 2439 | 2445 |
| 2440 PrefService* prefs = GetPrefs(); | 2446 PrefService* prefs = GetPrefs(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2473 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2479 // TODO(mpcomplete): If we allow editing extension keywords, then those |
| 2474 // should be persisted to disk and synced. | 2480 // should be persisted to disk and synced. |
| 2475 if (template_url->sync_guid().empty() && | 2481 if (template_url->sync_guid().empty() && |
| 2476 !template_url->IsExtensionKeyword()) { | 2482 !template_url->IsExtensionKeyword()) { |
| 2477 template_url->data_.sync_guid = base::GenerateGUID(); | 2483 template_url->data_.sync_guid = base::GenerateGUID(); |
| 2478 if (service_.get()) | 2484 if (service_.get()) |
| 2479 service_->UpdateKeyword(template_url->data()); | 2485 service_->UpdateKeyword(template_url->data()); |
| 2480 } | 2486 } |
| 2481 } | 2487 } |
| 2482 } | 2488 } |
| OLD | NEW |