Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: chrome/browser/search_engines/template_url_service.cc

Issue 8689007: Defend against deleting the default search provider when merging duplicate TURLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_service_sync_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 DCHECK(local_turl); 1800 DCHECK(local_turl);
1801 DCHECK(change_list); 1801 DCHECK(change_list);
1802 1802
1803 scoped_ptr<TemplateURL> scoped_sync_turl(sync_turl); 1803 scoped_ptr<TemplateURL> scoped_sync_turl(sync_turl);
1804 1804
1805 if (scoped_sync_turl->last_modified() > local_turl->last_modified()) { 1805 if (scoped_sync_turl->last_modified() > local_turl->last_modified()) {
1806 // Fully replace local_url with Sync's copy. Note that because use Add 1806 // Fully replace local_url with Sync's copy. Note that because use Add
1807 // rather than ResetTemplateURL, |sync_url| is added with a fresh 1807 // rather than ResetTemplateURL, |sync_url| is added with a fresh
1808 // TemplateURLID. We don't need to sync the new ID back to the server since 1808 // TemplateURLID. We don't need to sync the new ID back to the server since
1809 // it's only relevant locally. 1809 // it's only relevant locally.
1810 Remove(local_turl); 1810 bool delete_default = (local_turl == GetDefaultSearchProvider());
1811 // Force the local ID to 0 so we can add it. 1811 if (delete_default && is_default_search_managed_) {
1812 scoped_sync_turl->set_id(0); 1812 NOTREACHED() << "Tried to delete managed default search provider";
1813 Add(scoped_sync_turl.release()); 1813 } else {
1814 if (delete_default)
1815 default_search_provider_ = NULL;
1816
1817 Remove(local_turl);
1818
1819 // Force the local ID to 0 so we can add it.
1820 scoped_sync_turl->set_id(0);
1821 TemplateURL* temp = scoped_sync_turl.release();
1822 Add(temp);
1823 if (delete_default)
1824 SetDefaultSearchProvider(temp);
1825 }
1814 } else { 1826 } else {
1815 // Change the local TURL's GUID to the server's GUID and push an update to 1827 // Change the local TURL's GUID to the server's GUID and push an update to
1816 // Sync. This ensures that the rest of local_url's fields are sync'd up to 1828 // Sync. This ensures that the rest of local_url's fields are sync'd up to
1817 // the server, and the next time local_url is synced, it is recognized by 1829 // the server, and the next time local_url is synced, it is recognized by
1818 // having the same GUID. 1830 // having the same GUID.
1819 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); 1831 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid());
1820 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); 1832 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl);
1821 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); 1833 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data));
1822 } 1834 }
1823 } 1835 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 i != template_urls->end(); ++i) { 1869 i != template_urls->end(); ++i) {
1858 TemplateURL* template_url = *i; 1870 TemplateURL* template_url = *i;
1859 DCHECK(template_url); 1871 DCHECK(template_url);
1860 if (template_url->sync_guid().empty()) { 1872 if (template_url->sync_guid().empty()) {
1861 template_url->set_sync_guid(guid::GenerateGUID()); 1873 template_url->set_sync_guid(guid::GenerateGUID());
1862 if (service_.get()) 1874 if (service_.get())
1863 service_->UpdateKeyword(*template_url); 1875 service_->UpdateKeyword(*template_url);
1864 } 1876 }
1865 } 1877 }
1866 } 1878 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_service_sync_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698