Commit 14b26d20 authored by stevet@chromium.org's avatar stevet@chromium.org

Rewrite TemplateURLService's SyncableService implmentation to avoid sending ACTION_DELETEs to Sync.

Update unit tests to reflect these changes.

BUG=140732
TEST=

Review URL: https://chromiumcodereview.appspot.com/10806065

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151391 0039d316-1c4b-4281-b951-d872f2087c98
parent 5b729260
...@@ -352,17 +352,11 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -352,17 +352,11 @@ class TemplateURLService : public WebDataServiceConsumer,
CreateTemplateURLFromSyncData); CreateTemplateURLFromSyncData);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
SyncKeywordConflictNeitherAutoreplace); ResolveSyncKeywordConflict);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
SyncKeywordConflictBothAutoreplace); IsLocalTemplateURLBetter);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL);
SyncKeywordConflictOneAutoreplace);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
FindDuplicateOfSyncTemplateURL);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
MergeSyncAndLocalURLDuplicates);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
PreSyncDeletes);
friend class TemplateURLServiceTestUtil; friend class TemplateURLServiceTestUtil;
...@@ -532,49 +526,46 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -532,49 +526,46 @@ class TemplateURLService : public WebDataServiceConsumer,
// execute the special character appending functionality. // execute the special character appending functionality.
string16 UniquifyKeyword(const TemplateURL& turl, bool force); string16 UniquifyKeyword(const TemplateURL& turl, bool force);
// Given a TemplateURL from Sync (cloud) and a local, non-extension // Returns true iff |local_turl| is considered "better" than |sync_turl| for
// TemplateURL with the same keyword, selects "better" and "worse" entries: // the purposes of resolving conflicts. |local_turl| must be a TemplateURL
// * If one of the TemplateURLs is replaceable and the other is not, the // known to the local model (though it may already be synced), and |sync_turl|
// non-replaceable entry is better. // is a new TemplateURL known to Sync but not yet known to the local model.
// * Otherwise, if |local_turl| was created by policy, is the default // The criteria for if |local_turl| is better than |sync_turl| is whether any
// provider, or was modified more recently, it is better. // of the following are true:
// * Otherwise |sync_turl| is better. // * |local_turl|'s last_modified timestamp is newer than sync_turl.
// Then resolves the conflict: // * |local_turl| is created by policy.
// * If the "worse" entry is |sync_turl|, and it is replaceable, add a // * |local_turl| is the local default search provider.
// syncer::SyncChange to delete it, and return false. bool IsLocalTemplateURLBetter(const TemplateURL* local_turl,
// * If the "worse" entry is |local_turl|, and it is replaceable, remove it const TemplateURL* sync_turl);
// from the service and return true.
// * Otherwise, uniquify the keyword of the "worse" entry. If it is // Given two synced TemplateURLs with a conflicting keyword, one of which
// |local_turl|, update it within the service. Add a SyncChange to update // needs to be added to or updated in the local model (|unapplied_sync_turl|)
// things (always for |sync_turl|, sometimes for |local_turl|; see // and one which is already known to the local model (|applied_sync_turl|),
// comments in implementation), and return true. // prepares the local model so that |unapplied_sync_turl| can be added to it,
// When the function returns true, callers can then go ahead and add or update // or applied as an update to an existing TemplateURL.
// |sync_turl| within the service. If it returns false, callers must not add // Since both entries are known to Sync and one of their keywords will change,
// the |sync_turl|, and must Remove() the |sync_turl| if it was being updated. // an ACTION_UPDATE will be appended to |change_list| to reflect this change.
// (Be careful; calling Remove() could add an ACTION_DELETE sync change, which // Note that |applied_sync_turl| must not be an extension keyword.
// this function has already done. Make sure to avoid duplicates.) void ResolveSyncKeywordConflict(TemplateURL* unapplied_sync_turl,
// TemplateURL* applied_sync_turl,
// Note that we never call this for conflicts with extension keywords because
// other code (e.g. AddToMaps()) is responsible for correctly prioritizing
// extension- vs. non-extension-based TemplateURLs with the same keyword.
bool ResolveSyncKeywordConflict(TemplateURL* sync_turl,
TemplateURL* local_turl,
syncer::SyncChangeList* change_list); syncer::SyncChangeList* change_list);
// Returns a TemplateURL from the service that has the same keyword and search // Adds |sync_turl| into the local model, possibly removing or updating a
// URL as |sync_turl|, if it exists. // local TemplateURL to make room for it. This expects |sync_turl| to be a new
TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); // entry from Sync, not currently known to the local model. |sync_data| should
// be a SyncDataMap where the contents are entries initially known to Sync
// Given a TemplateURL from the cloud and a local matching duplicate found by // during MergeDataAndStartSyncing.
// FindDuplicateOfSyncTemplateURL, merges the two. If |sync_turl| is newer, // Any necessary updates to Sync will be appended to |change_list|. This can
// this replaces |local_turl| with |sync_turl| using the service's Remove and // include updates on local TemplateURLs, if they are found in |sync_data|.
// Add. If |local_turl| is newer, this replaces |sync_turl| with |local_turl| // |initial_data| should be a SyncDataMap of the entries known to the local
// through through adding appropriate SyncChanges to |change_list|. This // model during MergeDataAndStartSyncing. If |sync_turl| replaces a local
// method takes ownership of |sync_turl|, and adds it to the model if it is // entry, that entry is removed from |initial_data| to prevent it from being
// newer, so the caller must release it if need be. // sent up to Sync.
void MergeSyncAndLocalURLDuplicates(TemplateURL* sync_turl, // This should only be called from MergeDataAndStartSyncing.
TemplateURL* local_turl, void MergeInSyncTemplateURL(TemplateURL* sync_turl,
syncer::SyncChangeList* change_list); const SyncDataMap& sync_data,
syncer::SyncChangeList* change_list,
SyncDataMap* local_data);
// Checks a newly added TemplateURL from Sync by its sync_guid and sets it as // Checks a newly added TemplateURL from Sync by its sync_guid and sets it as
// the default search provider if we were waiting for it. // the default search provider if we were waiting for it.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment