Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, | 345 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, |
| 346 DontUpdateKeywordSearchForNonReplaceable); | 346 DontUpdateKeywordSearchForNonReplaceable); |
| 347 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue); | 347 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue); |
| 348 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders); | 348 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders); |
| 349 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 349 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
| 350 CreateSyncDataFromTemplateURL); | 350 CreateSyncDataFromTemplateURL); |
| 351 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 351 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
| 352 CreateTemplateURLFromSyncData); | 352 CreateTemplateURLFromSyncData); |
| 353 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); | 353 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); |
| 354 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 354 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
| 355 SyncKeywordConflictNeitherAutoreplace); | 355 ResolveSyncKeywordConflict); |
| 356 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); | |
| 356 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 357 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
| 357 SyncKeywordConflictBothAutoreplace); | 358 IsLocalTemplateURLBetter); |
| 358 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | |
| 359 SyncKeywordConflictOneAutoreplace); | |
| 360 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | |
| 361 FindDuplicateOfSyncTemplateURL); | |
| 362 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | |
| 363 MergeSyncAndLocalURLDuplicates); | |
| 364 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | |
| 365 PreSyncDeletes); | |
| 366 | 359 |
| 367 friend class TemplateURLServiceTestUtil; | 360 friend class TemplateURLServiceTestUtil; |
| 368 | 361 |
| 369 typedef std::map<string16, TemplateURL*> KeywordToTemplateMap; | 362 typedef std::map<string16, TemplateURL*> KeywordToTemplateMap; |
| 370 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; | 363 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; |
| 371 typedef std::list<std::string> PendingExtensionIDs; | 364 typedef std::list<std::string> PendingExtensionIDs; |
| 372 | 365 |
| 373 // Declaration of values to be used in an enumerated histogram to tally | 366 // Declaration of values to be used in an enumerated histogram to tally |
| 374 // changes to the default search provider from various entry points. In | 367 // changes to the default search provider from various entry points. In |
| 375 // particular, we use this to see what proportion of changes are from Sync | 368 // particular, we use this to see what proportion of changes are from Sync |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); | 518 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); |
| 526 | 519 |
| 527 // Attempts to generate a unique keyword for |turl| based on its original | 520 // Attempts to generate a unique keyword for |turl| based on its original |
| 528 // keyword. If its keyword is already unique, that is returned. Otherwise, it | 521 // keyword. If its keyword is already unique, that is returned. Otherwise, it |
| 529 // tries to return the autogenerated keyword if that is unique to the Service, | 522 // tries to return the autogenerated keyword if that is unique to the Service, |
| 530 // and finally it repeatedly appends special characters to the keyword until | 523 // and finally it repeatedly appends special characters to the keyword until |
| 531 // it is unique to the Service. If |force| is true, then this will only | 524 // it is unique to the Service. If |force| is true, then this will only |
| 532 // execute the special character appending functionality. | 525 // execute the special character appending functionality. |
| 533 string16 UniquifyKeyword(const TemplateURL& turl, bool force); | 526 string16 UniquifyKeyword(const TemplateURL& turl, bool force); |
| 534 | 527 |
| 535 // Given a TemplateURL from Sync (cloud) and a local, non-extension | 528 // Returns true iff |local_turl| is considered "better" than |sync_turl| for |
| 536 // TemplateURL with the same keyword, selects "better" and "worse" entries: | 529 // the purposes of resolving conflicts. |local_turl| must be a TemplateURL |
| 537 // * If one of the TemplateURLs is replaceable and the other is not, the | 530 // known to the local model (though it may already be synced), and |sync_turl| |
| 538 // non-replaceable entry is better. | 531 // is a new TemplateURL known to Sync but not yet known to the local model. |
| 539 // * Otherwise, if |local_turl| was created by policy, is the default | 532 // The criteria for if |local_turl| if better than |sync_turl| is whether any |
|
Nicolas Zea
2012/08/06 19:35:23
"if better" -> is better
SteveT
2012/08/07 00:17:09
Done.
| |
| 540 // provider, or was modified more recently, it is better. | 533 // of the following are true: |
| 541 // * Otherwise |sync_turl| is better. | 534 // * |local_turl|'s last_modified timestamp is newer than sync_turl. |
| 542 // Then resolves the conflict: | 535 // * |local_turl| is created by policy. |
| 543 // * If the "worse" entry is |sync_turl|, and it is replaceable, add a | 536 // * |local_turl| is the local default search provider. |
| 544 // syncer::SyncChange to delete it, and return false. | 537 bool IsLocalTemplateURLBetter(const TemplateURL* local_turl, |
| 545 // * If the "worse" entry is |local_turl|, and it is replaceable, remove it | 538 const TemplateURL* sync_turl); |
| 546 // from the service and return true. | 539 |
| 547 // * Otherwise, uniquify the keyword of the "worse" entry. If it is | 540 // Given two synced TemplateURLs with a conflicting keyword, one of which |
| 548 // |local_turl|, update it within the service. Add a SyncChange to update | 541 // needs to be added to or updated in the local model (|unapplied_sync_turl|) |
| 549 // things (always for |sync_turl|, sometimes for |local_turl|; see | 542 // and one which is already known to the local model (|applied_sync_turl|), |
| 550 // comments in implementation), and return true. | 543 // prepares the local model so that |unapplied_sync_turl| can be added to it, |
| 551 // When the function returns true, callers can then go ahead and add or update | 544 // or applied as an update to an existing TemplateURL. |
| 552 // |sync_turl| within the service. If it returns false, callers must not add | 545 // Since both entries are known to Sync and one of their keywords will change, |
| 553 // the |sync_turl|, and must Remove() the |sync_turl| if it was being updated. | 546 // an ACTION_UPDATE will be appended to |change_list| to reflect this change. |
| 554 // (Be careful; calling Remove() could add an ACTION_DELETE sync change, which | 547 // Note that |applied_sync_turl| must not be an extension keyword. |
| 555 // this function has already done. Make sure to avoid duplicates.) | 548 void ResolveSyncKeywordConflict(TemplateURL* unapplied_sync_turl, |
| 556 // | 549 TemplateURL* applied_sync_turl, |
| 557 // Note that we never call this for conflicts with extension keywords because | |
| 558 // other code (e.g. AddToMaps()) is responsible for correctly prioritizing | |
| 559 // extension- vs. non-extension-based TemplateURLs with the same keyword. | |
| 560 bool ResolveSyncKeywordConflict(TemplateURL* sync_turl, | |
| 561 TemplateURL* local_turl, | |
| 562 syncer::SyncChangeList* change_list); | 550 syncer::SyncChangeList* change_list); |
| 563 | 551 |
| 564 // Returns a TemplateURL from the service that has the same keyword and search | 552 // Adds |sync_turl| into the local model, possibly removing or updating a |
| 565 // URL as |sync_turl|, if it exists. | 553 // local TemplateURL to make room for it. This expects |sync_turl| to be a new |
| 566 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); | 554 // entry from Sync, not currently known to the local model. |sync_data| should |
| 567 | 555 // be a SyncDataMap where the contents are entries initially known to Sync |
| 568 // Given a TemplateURL from the cloud and a local matching duplicate found by | 556 // during MergeDataAndStartSyncing. |
| 569 // FindDuplicateOfSyncTemplateURL, merges the two. If |sync_turl| is newer, | 557 // Any necessary updates to Sync will be appended to |change_list|. This can |
| 570 // this replaces |local_turl| with |sync_turl| using the service's Remove and | 558 // include updates on local TemplateURLs, if they are found in |sync_data|. |
| 571 // Add. If |local_turl| is newer, this replaces |sync_turl| with |local_turl| | 559 // |initial_data| should be a SyncDataMap of the entries known to the local |
| 572 // through through adding appropriate SyncChanges to |change_list|. This | 560 // model during MergeDataAndStartSyncing. If |sync_turl| replaces a local |
| 573 // method takes ownership of |sync_turl|, and adds it to the model if it is | 561 // entry, that entry is removed from |initial_data| to prevent it from being |
| 574 // newer, so the caller must release it if need be. | 562 // sent up to Sync. |
| 575 void MergeSyncAndLocalURLDuplicates(TemplateURL* sync_turl, | 563 // This should only be called from MergeDataAndStartSyncing. |
| 576 TemplateURL* local_turl, | 564 void MergeInSyncTemplateURL(TemplateURL* sync_turl, |
| 577 syncer::SyncChangeList* change_list); | 565 const SyncDataMap& sync_data, |
| 566 syncer::SyncChangeList* change_list, | |
| 567 SyncDataMap* local_data); | |
| 578 | 568 |
| 579 // Checks a newly added TemplateURL from Sync by its sync_guid and sets it as | 569 // Checks a newly added TemplateURL from Sync by its sync_guid and sets it as |
| 580 // the default search provider if we were waiting for it. | 570 // the default search provider if we were waiting for it. |
| 581 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); | 571 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); |
| 582 | 572 |
| 583 // Retrieve the pending default search provider according to Sync. Returns | 573 // Retrieve the pending default search provider according to Sync. Returns |
| 584 // NULL if there was no pending search provider from Sync. | 574 // NULL if there was no pending search provider from Sync. |
| 585 TemplateURL* GetPendingSyncedDefaultSearchProvider(); | 575 TemplateURL* GetPendingSyncedDefaultSearchProvider(); |
| 586 | 576 |
| 587 // Goes through a vector of TemplateURLs and ensure that both the in-memory | 577 // Goes through a vector of TemplateURLs and ensure that both the in-memory |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 | 670 |
| 681 // This is used to log the origin of changes to the default search provider. | 671 // This is used to log the origin of changes to the default search provider. |
| 682 // We set this value to increasingly specific values when we know what is the | 672 // We set this value to increasingly specific values when we know what is the |
| 683 // cause/origin of a default search change. | 673 // cause/origin of a default search change. |
| 684 DefaultSearchChangeOrigin dsp_change_origin_; | 674 DefaultSearchChangeOrigin dsp_change_origin_; |
| 685 | 675 |
| 686 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 676 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
| 687 }; | 677 }; |
| 688 | 678 |
| 689 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 679 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
| OLD | NEW |