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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); | 525 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); |
526 | 526 |
527 // Attempts to generate a unique keyword for |turl| based on its original | 527 // 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 | 528 // 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, | 529 // 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 | 530 // 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 | 531 // it is unique to the Service. If |force| is true, then this will only |
532 // execute the special character appending functionality. | 532 // execute the special character appending functionality. |
533 string16 UniquifyKeyword(const TemplateURL& turl, bool force); | 533 string16 UniquifyKeyword(const TemplateURL& turl, bool force); |
534 | 534 |
| 535 // Adds |sync_turl| into the local model, possibly removing or updating a |
| 536 // local TemplateURL to make room for it. This expects |sync_turl| to be a new |
| 537 // entry from Sync, not currently known to the local model. |sync_data| should |
| 538 // be a SyncDataMap where the contents are entries initially known to Sync |
| 539 // during MergeDataAndStartSyncing. Any necessary updates to Sync will be |
| 540 // appended to |change_list|. This can include updates on local TemplateURLs, |
| 541 // if they are already synced. |initial_data| should be a SyncDataMap of the |
| 542 // entries known to the local model during MergeDataAndStartSyncing. If |
| 543 // |sync_turl| replaces a local entry, that entry is removed from |
| 544 // |initial_data| to prevent it from being sent up to Sync. |
| 545 void MergeInSyncTemplateURL(TemplateURL* sync_turl, |
| 546 SyncDataMap& sync_data, |
| 547 syncer::SyncChangeList* change_list, |
| 548 SyncDataMap* initial_data); |
| 549 |
535 // Given a TemplateURL from Sync (cloud) and a local, non-extension | 550 // Given a TemplateURL from Sync (cloud) and a local, non-extension |
536 // TemplateURL with the same keyword, selects "better" and "worse" entries: | 551 // TemplateURL with the same keyword, selects "better" and "worse" entries: |
537 // * If one of the TemplateURLs is replaceable and the other is not, the | 552 // * If one of the TemplateURLs is replaceable and the other is not, the |
538 // non-replaceable entry is better. | 553 // non-replaceable entry is better. |
539 // * Otherwise, if |local_turl| was created by policy, is the default | 554 // * Otherwise, if |local_turl| was created by policy, is the default |
540 // provider, or was modified more recently, it is better. | 555 // provider, or was modified more recently, it is better. |
541 // * Otherwise |sync_turl| is better. | 556 // * Otherwise |sync_turl| is better. |
542 // Then resolves the conflict: | 557 // Then resolves the conflict: |
543 // * If the "worse" entry is |sync_turl|, and it is replaceable, add a | 558 // * If the "worse" entry is |sync_turl|, and it is replaceable, add a |
544 // syncer::SyncChange to delete it, and return false. | 559 // syncer::SyncChange to delete it, and return false. |
545 // * If the "worse" entry is |local_turl|, and it is replaceable, remove it | 560 // * If the "worse" entry is |local_turl|, and it is replaceable, remove it |
546 // from the service and return true. | 561 // from the service and return true. |
547 // * Otherwise, uniquify the keyword of the "worse" entry. If it is | 562 // * Otherwise, uniquify the keyword of the "worse" entry. If it is |
548 // |local_turl|, update it within the service. Add a SyncChange to update | 563 // |local_turl|, update it within the service. Add a SyncChange to update |
549 // things (always for |sync_turl|, sometimes for |local_turl|; see | 564 // things (always for |sync_turl|, sometimes for |local_turl|; see |
550 // comments in implementation), and return true. | 565 // comments in implementation), and return true. |
551 // When the function returns true, callers can then go ahead and add or update | 566 // When the function returns true, callers can then go ahead and add or update |
552 // |sync_turl| within the service. If it returns false, callers must not add | 567 // |sync_turl| within the service. If it returns false, callers must not add |
553 // the |sync_turl|, and must Remove() the |sync_turl| if it was being updated. | 568 // the |sync_turl|, and must Remove() the |sync_turl| if it was being updated. |
554 // (Be careful; calling Remove() could add an ACTION_DELETE sync change, which | 569 // (Be careful; calling Remove() could add an ACTION_DELETE sync change, which |
555 // this function has already done. Make sure to avoid duplicates.) | 570 // this function has already done. Make sure to avoid duplicates.) |
556 // | 571 // |
557 // Note that we never call this for conflicts with extension keywords because | 572 // Note that we never call this for conflicts with extension keywords because |
558 // other code (e.g. AddToMaps()) is responsible for correctly prioritizing | 573 // other code (e.g. AddToMaps()) is responsible for correctly prioritizing |
559 // extension- vs. non-extension-based TemplateURLs with the same keyword. | 574 // extension- vs. non-extension-based TemplateURLs with the same keyword. |
560 bool ResolveSyncKeywordConflict(TemplateURL* sync_turl, | 575 bool ResolveSyncKeywordConflict(TemplateURL* sync_turl, |
561 TemplateURL* local_turl, | 576 TemplateURL* local_turl, |
562 syncer::SyncChangeList* change_list); | 577 syncer::SyncChangeList* change_list); |
563 | 578 |
| 579 // Given two synced TemplateURLs with a conflicting keyword, one of which |
| 580 // needs to be added to or updated in the local model (|sync_turl|) and one |
| 581 // which is already known to the local model (|local_turl|), prepares the |
| 582 // local model so that |sync_turl| can be added to it, or applied as an update |
| 583 // to an existing TemplateURL. Since both entries are known to Sync and one of |
| 584 // their keywords will change, an ACTION_UPDATE will be appended to |
| 585 // |change_list| to reflect this change. Note that |local_turl| must not be an |
| 586 // extension keyword. |
| 587 void ResolveSyncKeywordConflict2(TemplateURL* sync_turl, |
| 588 TemplateURL* local_turl, |
| 589 syncer::SyncChangeList* change_list); |
| 590 |
564 // Returns a TemplateURL from the service that has the same keyword and search | 591 // Returns a TemplateURL from the service that has the same keyword and search |
565 // URL as |sync_turl|, if it exists. | 592 // URL as |sync_turl|, if it exists. |
566 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); | 593 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); |
567 | 594 |
568 // Given a TemplateURL from the cloud and a local matching duplicate found by | 595 // Given a TemplateURL from the cloud and a local matching duplicate found by |
569 // FindDuplicateOfSyncTemplateURL, merges the two. If |sync_turl| is newer, | 596 // FindDuplicateOfSyncTemplateURL, merges the two. If |sync_turl| is newer, |
570 // this replaces |local_turl| with |sync_turl| using the service's Remove and | 597 // this replaces |local_turl| with |sync_turl| using the service's Remove and |
571 // Add. If |local_turl| is newer, this replaces |sync_turl| with |local_turl| | 598 // Add. If |local_turl| is newer, this replaces |sync_turl| with |local_turl| |
572 // through through adding appropriate SyncChanges to |change_list|. This | 599 // through through adding appropriate SyncChanges to |change_list|. This |
573 // method takes ownership of |sync_turl|, and adds it to the model if it is | 600 // method takes ownership of |sync_turl|, and adds it to the model if it is |
574 // newer, so the caller must release it if need be. | 601 // newer, so the caller must release it if need be. |
| 602 // TODO Update document to describe |sync_data|. |
575 void MergeSyncAndLocalURLDuplicates(TemplateURL* sync_turl, | 603 void MergeSyncAndLocalURLDuplicates(TemplateURL* sync_turl, |
576 TemplateURL* local_turl, | 604 TemplateURL* local_turl, |
| 605 SyncDataMap& sync_data, |
577 syncer::SyncChangeList* change_list); | 606 syncer::SyncChangeList* change_list); |
578 | 607 |
579 // Checks a newly added TemplateURL from Sync by its sync_guid and sets it as | 608 // 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. | 609 // the default search provider if we were waiting for it. |
581 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); | 610 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); |
582 | 611 |
583 // Retrieve the pending default search provider according to Sync. Returns | 612 // Retrieve the pending default search provider according to Sync. Returns |
584 // NULL if there was no pending search provider from Sync. | 613 // NULL if there was no pending search provider from Sync. |
585 TemplateURL* GetPendingSyncedDefaultSearchProvider(); | 614 TemplateURL* GetPendingSyncedDefaultSearchProvider(); |
586 | 615 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 | 709 |
681 // This is used to log the origin of changes to the default search provider. | 710 // 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 | 711 // We set this value to increasingly specific values when we know what is the |
683 // cause/origin of a default search change. | 712 // cause/origin of a default search change. |
684 DefaultSearchChangeOrigin dsp_change_origin_; | 713 DefaultSearchChangeOrigin dsp_change_origin_; |
685 | 714 |
686 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 715 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
687 }; | 716 }; |
688 | 717 |
689 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 718 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |