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 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); |
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 | 360 |
367 friend class TemplateURLServiceTestUtil; | 361 friend class TemplateURLServiceTestUtil; |
368 | 362 |
369 typedef std::map<string16, TemplateURL*> KeywordToTemplateMap; | 363 typedef std::map<string16, TemplateURL*> KeywordToTemplateMap; |
370 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; | 364 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; |
371 typedef std::list<std::string> PendingExtensionIDs; | 365 typedef std::list<std::string> PendingExtensionIDs; |
372 | 366 |
373 // Declaration of values to be used in an enumerated histogram to tally | 367 // Declaration of values to be used in an enumerated histogram to tally |
374 // changes to the default search provider from various entry points. In | 368 // 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 | 369 // 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); | 519 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); |
526 | 520 |
527 // Attempts to generate a unique keyword for |turl| based on its original | 521 // 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 | 522 // 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, | 523 // 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 | 524 // 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 | 525 // it is unique to the Service. If |force| is true, then this will only |
532 // execute the special character appending functionality. | 526 // execute the special character appending functionality. |
533 string16 UniquifyKeyword(const TemplateURL& turl, bool force); | 527 string16 UniquifyKeyword(const TemplateURL& turl, bool force); |
534 | 528 |
535 // Given a TemplateURL from Sync (cloud) and a local, non-extension | 529 // Returns true iff |local_turl| is considered "better" than |sync_turl| for |
536 // TemplateURL with the same keyword, selects "better" and "worse" entries: | 530 // 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 | 531 // known to the local model (though it may already be synced), and |sync_turl| |
538 // non-replaceable entry is better. | 532 // 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 | 533 // The criteria for if |local_turl| is better than |sync_turl| is whether any |
540 // provider, or was modified more recently, it is better. | 534 // of the following are true: |
541 // * Otherwise |sync_turl| is better. | 535 // * |local_turl|'s last_modified timestamp is newer than sync_turl. |
542 // Then resolves the conflict: | 536 // * |local_turl| is created by policy. |
543 // * If the "worse" entry is |sync_turl|, and it is replaceable, add a | 537 // * |local_turl| is the local default search provider. |
544 // syncer::SyncChange to delete it, and return false. | 538 bool IsLocalTemplateURLBetter(const TemplateURL* local_turl, |
545 // * If the "worse" entry is |local_turl|, and it is replaceable, remove it | 539 const TemplateURL* sync_turl); |
546 // from the service and return true. | 540 |
547 // * Otherwise, uniquify the keyword of the "worse" entry. If it is | 541 // Given two synced TemplateURLs with a conflicting keyword, one of which |
548 // |local_turl|, update it within the service. Add a SyncChange to update | 542 // 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 | 543 // and one which is already known to the local model (|applied_sync_turl|), |
550 // comments in implementation), and return true. | 544 // 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 | 545 // or applied as an update to an existing TemplateURL. |
552 // |sync_turl| within the service. If it returns false, callers must not add | 546 // 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. | 547 // 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 | 548 // Note that |applied_sync_turl| must not be an extension keyword. |
555 // this function has already done. Make sure to avoid duplicates.) | 549 void ResolveSyncKeywordConflict(TemplateURL* unapplied_sync_turl, |
556 // | 550 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); | 551 syncer::SyncChangeList* change_list); |
563 | 552 |
564 // Returns a TemplateURL from the service that has the same keyword and search | 553 // Adds |sync_turl| into the local model, possibly removing or updating a |
565 // URL as |sync_turl|, if it exists. | 554 // local TemplateURL to make room for it. This expects |sync_turl| to be a new |
566 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); | 555 // entry from Sync, not currently known to the local model. |sync_data| should |
567 | 556 // 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 | 557 // during MergeDataAndStartSyncing. |
569 // FindDuplicateOfSyncTemplateURL, merges the two. If |sync_turl| is newer, | 558 // 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 | 559 // 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| | 560 // |initial_data| should be a SyncDataMap of the entries known to the local |
572 // through through adding appropriate SyncChanges to |change_list|. This | 561 // 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 | 562 // entry, that entry is removed from |initial_data| to prevent it from being |
574 // newer, so the caller must release it if need be. | 563 // sent up to Sync. |
575 void MergeSyncAndLocalURLDuplicates(TemplateURL* sync_turl, | 564 // This should only be called from MergeDataAndStartSyncing. |
576 TemplateURL* local_turl, | 565 void MergeInSyncTemplateURL(TemplateURL* sync_turl, |
577 syncer::SyncChangeList* change_list); | 566 const SyncDataMap& sync_data, |
| 567 syncer::SyncChangeList* change_list, |
| 568 SyncDataMap* local_data); |
578 | 569 |
579 // Checks a newly added TemplateURL from Sync by its sync_guid and sets it as | 570 // 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. | 571 // the default search provider if we were waiting for it. |
581 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); | 572 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); |
582 | 573 |
583 // Retrieve the pending default search provider according to Sync. Returns | 574 // Retrieve the pending default search provider according to Sync. Returns |
584 // NULL if there was no pending search provider from Sync. | 575 // NULL if there was no pending search provider from Sync. |
585 TemplateURL* GetPendingSyncedDefaultSearchProvider(); | 576 TemplateURL* GetPendingSyncedDefaultSearchProvider(); |
586 | 577 |
587 // Goes through a vector of TemplateURLs and ensure that both the in-memory | 578 // 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 | 671 |
681 // This is used to log the origin of changes to the default search provider. | 672 // 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 | 673 // We set this value to increasingly specific values when we know what is the |
683 // cause/origin of a default search change. | 674 // cause/origin of a default search change. |
684 DefaultSearchChangeOrigin dsp_change_origin_; | 675 DefaultSearchChangeOrigin dsp_change_origin_; |
685 | 676 |
686 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 677 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
687 }; | 678 }; |
688 | 679 |
689 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 680 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |