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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 std::string extension_id; | 94 std::string extension_id; |
95 std::string extension_name; | 95 std::string extension_name; |
96 std::string extension_keyword; | 96 std::string extension_keyword; |
97 }; | 97 }; |
98 | 98 |
99 explicit TemplateURLService(Profile* profile); | 99 explicit TemplateURLService(Profile* profile); |
100 // The following is for testing. | 100 // The following is for testing. |
101 TemplateURLService(const Initializer* initializers, const int count); | 101 TemplateURLService(const Initializer* initializers, const int count); |
102 virtual ~TemplateURLService(); | 102 virtual ~TemplateURLService(); |
103 | 103 |
| 104 // Saves enough of url to preferences so that it can be loaded from |
| 105 // preferences on start up. |
| 106 static void SaveDefaultSearchProviderToLegacyPrefs(const TemplateURL* url, |
| 107 PrefService* prefs); |
| 108 |
| 109 // Creates a TemplateURLData that was previously saved to prefs via |
| 110 // SaveDefaultSearchProviderToLegacyPrefs or set via policy. |
| 111 // Returns true if successful, false otherwise. |
| 112 // If the user or the policy has opted for no default search, this |
| 113 // returns true but default_provider is set to NULL. |
| 114 // |*is_managed| specifies whether the default is managed via policy. |
| 115 static bool LoadDefaultSearchProviderFromLegacyPrefs( |
| 116 PrefService* prefs, |
| 117 scoped_ptr<TemplateURLData>* default_provider, |
| 118 bool* is_managed); |
| 119 |
104 // Generates a suitable keyword for the specified url, which must be valid. | 120 // Generates a suitable keyword for the specified url, which must be valid. |
105 // This is guaranteed not to return an empty string, since TemplateURLs should | 121 // This is guaranteed not to return an empty string, since TemplateURLs should |
106 // never have an empty keyword. | 122 // never have an empty keyword. |
107 static base::string16 GenerateKeyword(const GURL& url); | 123 static base::string16 GenerateKeyword(const GURL& url); |
108 | 124 |
109 // Removes any unnecessary characters from a user input keyword. | 125 // Removes any unnecessary characters from a user input keyword. |
110 // This removes the leading scheme, "www." and any trailing slash. | 126 // This removes the leading scheme, "www." and any trailing slash. |
111 static base::string16 CleanUserInputKeyword(const base::string16& keyword); | 127 static base::string16 CleanUserInputKeyword(const base::string16& keyword); |
112 | 128 |
113 // Returns the search url for t_url. Returns an empty GURL if t_url has no | 129 // Returns the search url for t_url. Returns an empty GURL if t_url has no |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // loaded, the default search provider is pulled from preferences. | 254 // loaded, the default search provider is pulled from preferences. |
239 // | 255 // |
240 // NOTE: At least in unittest mode, this may return NULL. | 256 // NOTE: At least in unittest mode, this may return NULL. |
241 TemplateURL* GetDefaultSearchProvider(); | 257 TemplateURL* GetDefaultSearchProvider(); |
242 | 258 |
243 // Returns true if the |url| is a search results page from the default search | 259 // Returns true if the |url| is a search results page from the default search |
244 // provider. | 260 // provider. |
245 bool IsSearchResultsPageFromDefaultSearchProvider(const GURL& url); | 261 bool IsSearchResultsPageFromDefaultSearchProvider(const GURL& url); |
246 | 262 |
247 // Returns true if the default search is managed through group policy. | 263 // Returns true if the default search is managed through group policy. |
248 bool is_default_search_managed() const { return is_default_search_managed_; } | 264 bool is_default_search_managed() const { |
| 265 return default_search_provider_source_ == DefaultSearchManager::FROM_POLICY; |
| 266 } |
249 | 267 |
250 // Returns true if the default search provider is controlled by an extension. | 268 // Returns true if the default search provider is controlled by an extension. |
251 bool IsExtensionControlledDefaultSearch(); | 269 bool IsExtensionControlledDefaultSearch(); |
252 | 270 |
253 // Returns the default search specified in the prepopulated data, if it | 271 // Returns the default search specified in the prepopulated data, if it |
254 // exists. If not, returns first URL in |template_urls_|, or NULL if that's | 272 // exists. If not, returns first URL in |template_urls_|, or NULL if that's |
255 // empty. The returned object is owned by TemplateURLService and can be | 273 // empty. The returned object is owned by TemplateURLService and can be |
256 // destroyed at any time so should be used right after the call. | 274 // destroyed at any time so should be used right after the call. |
257 TemplateURL* FindNewDefaultSearchProvider(); | 275 TemplateURL* FindNewDefaultSearchProvider(); |
258 | 276 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); | 421 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); |
404 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 422 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
405 IsLocalTemplateURLBetter); | 423 IsLocalTemplateURLBetter); |
406 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); | 424 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); |
407 | 425 |
408 friend class TemplateURLServiceTestUtilBase; | 426 friend class TemplateURLServiceTestUtilBase; |
409 | 427 |
410 typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap; | 428 typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap; |
411 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; | 429 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; |
412 | 430 |
413 // Declaration of values to be used in an enumerated histogram to tally | |
414 // changes to the default search provider from various entry points. In | |
415 // particular, we use this to see what proportion of changes are from Sync | |
416 // entry points, to help spot erroneous Sync activity. | |
417 enum DefaultSearchChangeOrigin { | |
418 // Various known Sync entry points. | |
419 DSP_CHANGE_SYNC_PREF, | |
420 DSP_CHANGE_SYNC_ADD, | |
421 DSP_CHANGE_SYNC_DELETE, | |
422 DSP_CHANGE_SYNC_NOT_MANAGED, | |
423 // "Other" origins. We differentiate between Sync and not Sync so we know if | |
424 // certain changes were intentionally from the system, or possibly some | |
425 // unintentional change from when we were Syncing. | |
426 DSP_CHANGE_SYNC_UNINTENTIONAL, | |
427 // All changes that don't fall into another category; we can't reorder the | |
428 // list for clarity as this would screw up stat collection. | |
429 DSP_CHANGE_OTHER, | |
430 // Changed through "Profile Reset" feature. | |
431 DSP_CHANGE_PROFILE_RESET, | |
432 // Changed by an extension through the Override Settings API. | |
433 DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION, | |
434 // New DSP during database/prepopulate data load, which was not previously | |
435 // in the known engine set, and with no previous value in prefs. The | |
436 // typical time to see this is during first run. | |
437 DSP_CHANGE_NEW_ENGINE_NO_PREFS, | |
438 // Boundary value. | |
439 DSP_CHANGE_MAX, | |
440 }; | |
441 | |
442 // Helper functor for FindMatchingKeywords(), for finding the range of | 431 // Helper functor for FindMatchingKeywords(), for finding the range of |
443 // keywords which begin with a prefix. | 432 // keywords which begin with a prefix. |
444 class LessWithPrefix; | 433 class LessWithPrefix; |
445 | 434 |
446 void Init(const Initializer* initializers, int num_initializers); | 435 void Init(const Initializer* initializers, int num_initializers); |
447 | 436 |
448 void RemoveFromMaps(TemplateURL* template_url); | 437 void RemoveFromMaps(TemplateURL* template_url); |
449 | 438 |
450 void AddToMaps(TemplateURL* template_url); | 439 void AddToMaps(TemplateURL* template_url); |
451 | 440 |
452 // Sets the keywords. This is used once the keywords have been loaded. | 441 // Sets the keywords. This is used once the keywords have been loaded. |
453 // This does NOT notify the delegate or the database. | 442 // This does NOT notify the delegate or the database. |
454 // | 443 // |
455 // This transfers ownership of the elements in |urls| to |this|, and may | 444 // This transfers ownership of the elements in |urls| to |this|, and may |
456 // delete some elements, so it's not safe for callers to access any elements | 445 // delete some elements, so it's not safe for callers to access any elements |
457 // after calling; to reinforce this, this function clears |urls| on exit. | 446 // after calling; to reinforce this, this function clears |urls| on exit. |
458 void SetTemplateURLs(TemplateURLVector* urls); | 447 void SetTemplateURLs(TemplateURLVector* urls); |
459 | 448 |
460 // Transitions to the loaded state. | 449 // Transitions to the loaded state. |
461 void ChangeToLoadedState(); | 450 void ChangeToLoadedState(); |
462 | 451 |
463 // Saves enough of url to preferences so that it can be loaded from | 452 // Receives notice that the DSE has changed. |
464 // preferences on start up. | 453 void OnDefaultSearchChange(const TemplateURLData* new_dse_data, |
465 void SaveDefaultSearchProviderToPrefs(const TemplateURL* url); | 454 DefaultSearchManager::Source source); |
466 | |
467 // Creates a TemplateURLData that was previously saved to prefs via | |
468 // SaveDefaultSearchProviderToPrefs or set via policy. | |
469 // Returns true if successful, false otherwise. | |
470 // If the user or the policy has opted for no default search, this | |
471 // returns true but default_provider is set to NULL. | |
472 // |*is_managed| specifies whether the default is managed via policy. | |
473 bool LoadDefaultSearchProviderFromPrefs( | |
474 scoped_ptr<TemplateURLData>* default_provider, | |
475 bool* is_managed); | |
476 | |
477 // Clears user preferences describing the default search engine. | |
478 void ClearDefaultProviderFromPrefs(); | |
479 | 455 |
480 // Returns true if there is no TemplateURL that has a search url with the | 456 // Returns true if there is no TemplateURL that has a search url with the |
481 // specified host, or the only TemplateURLs matching the specified host can | 457 // specified host, or the only TemplateURLs matching the specified host can |
482 // be replaced. | 458 // be replaced. |
483 bool CanReplaceKeywordForHost(const std::string& host, | 459 bool CanReplaceKeywordForHost(const std::string& host, |
484 TemplateURL** to_replace); | 460 TemplateURL** to_replace); |
485 | 461 |
486 // Returns true if the TemplateURL is replaceable. This doesn't look at the | 462 // Returns true if the TemplateURL is replaceable. This doesn't look at the |
487 // uniqueness of the keyword or host and is intended to be called after those | 463 // uniqueness of the keyword or host and is intended to be called after those |
488 // checks have been done. This returns true if the TemplateURL doesn't appear | 464 // checks have been done. This returns true if the TemplateURL doesn't appear |
489 // in the default list and is marked as safe_for_autoreplace. | 465 // in the default list and is marked as safe_for_autoreplace. |
490 bool CanReplace(const TemplateURL* t_url); | 466 bool CanReplace(const TemplateURL* t_url); |
491 | 467 |
492 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords. | 468 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords. |
493 TemplateURL* FindNonExtensionTemplateURLForKeyword( | 469 TemplateURL* FindNonExtensionTemplateURLForKeyword( |
494 const base::string16& keyword); | 470 const base::string16& keyword); |
495 | 471 |
496 // Updates the information in |existing_turl| using the information from | 472 // Updates the information in |existing_turl| using the information from |
497 // |new_values|, but the ID for |existing_turl| is retained. Notifying | 473 // |new_values|, but the ID for |existing_turl| is retained. Notifying |
498 // observers is the responsibility of the caller. Returns whether | 474 // observers is the responsibility of the caller. Returns whether |
499 // |existing_turl| was found in |template_urls_| and thus could be updated. | 475 // |existing_turl| was found in |template_urls_| and thus could be updated. |
500 // |old_search_terms_data| is passed to SearchHostToURLsMap::Remove(). | 476 // |old_search_terms_data| is passed to SearchHostToURLsMap::Remove(). |
501 // | 477 // |
502 // NOTE: This should not be called with an extension keyword as there are no | 478 // NOTE: This should not be called with an extension keyword as there are no |
503 // updates needed in that case. | 479 // updates needed in that case. |
504 bool UpdateNoNotify(TemplateURL* existing_turl, | 480 bool UpdateNoNotify(TemplateURL* existing_turl, |
505 const TemplateURL& new_values, | 481 const TemplateURLData& new_values, |
506 const SearchTermsData& old_search_terms_data); | 482 const SearchTermsData& old_search_terms_data); |
507 | 483 |
508 // If the TemplateURL comes from a prepopulated URL available in the current | 484 // If the TemplateURL comes from a prepopulated URL available in the current |
509 // country, update all its fields save for the keyword, short name and id so | 485 // country, update all its fields save for the keyword, short name and id so |
510 // that they match the internal prepopulated URL. TemplateURLs not coming from | 486 // that they match the internal prepopulated URL. TemplateURLs not coming from |
511 // a prepopulated URL are not modified. | 487 // a prepopulated URL are not modified. |
512 static void UpdateTemplateURLIfPrepopulated(TemplateURL* existing_turl, | 488 static void UpdateTemplateURLIfPrepopulated(TemplateURL* existing_turl, |
513 Profile* profile); | 489 Profile* profile); |
514 | 490 |
515 // Returns the preferences we use. | 491 // Returns the preferences we use. |
516 PrefService* GetPrefs(); | 492 PrefService* GetPrefs(); |
517 | 493 |
518 // Iterates through the TemplateURLs to see if one matches the visited url. | 494 // Iterates through the TemplateURLs to see if one matches the visited url. |
519 // For each TemplateURL whose url matches the visited url | 495 // For each TemplateURL whose url matches the visited url |
520 // SetKeywordSearchTermsForURL is invoked. | 496 // SetKeywordSearchTermsForURL is invoked. |
521 void UpdateKeywordSearchTermsForURL( | 497 void UpdateKeywordSearchTermsForURL( |
522 const history::URLVisitedDetails& details); | 498 const history::URLVisitedDetails& details); |
523 | 499 |
524 // If necessary, generates a visit for the site http:// + t_url.keyword(). | 500 // If necessary, generates a visit for the site http:// + t_url.keyword(). |
525 void AddTabToSearchVisit(const TemplateURL& t_url); | 501 void AddTabToSearchVisit(const TemplateURL& t_url); |
526 | 502 |
527 // Invoked when the Google base URL has changed. Updates the mapping for all | 503 // Invoked when the Google base URL has changed. Updates the mapping for all |
528 // TemplateURLs that have a replacement term of {google:baseURL} or | 504 // TemplateURLs that have a replacement term of {google:baseURL} or |
529 // {google:baseSuggestURL}. | 505 // {google:baseSuggestURL}. |
530 void GoogleBaseURLChanged(const GURL& old_base_url); | 506 void GoogleBaseURLChanged(const GURL& old_base_url); |
531 | 507 |
532 // Update the default search. Called at initialization or when a managed | |
533 // preference has changed. | |
534 void UpdateDefaultSearch(); | |
535 | |
536 // Set the default search provider. |url| may be user-selected or | |
537 // automatically selected and may be null. | |
538 // This will assert if the default search is managed. | |
539 void SetDefaultSearchProvider(TemplateURL* url); | |
540 | |
541 // Set the default search provider even if it is managed. |url| may be null. | |
542 // Caller is responsible for notifying observers. Returns whether |url| was | |
543 // found in |template_urls_|. | |
544 // If |url| is an extension-controlled search engine then preferences and the | |
545 // database are left untouched. | |
546 // If |url| is a normal search engine and the existing default search engine | |
547 // is controlled by an extension then |url| is propagated to the database and | |
548 // prefs but the extension-controlled default engine will continue to hide | |
549 // this value until the extension is uninstalled. | |
550 bool SetDefaultSearchProviderNoNotify(TemplateURL* url); | |
551 | |
552 // Adds a new TemplateURL to this model. TemplateURLService will own the | 508 // Adds a new TemplateURL to this model. TemplateURLService will own the |
553 // reference, and delete it when the TemplateURL is removed. | 509 // reference, and delete it when the TemplateURL is removed. |
554 // If |newly_adding| is false, we assume that this TemplateURL was already | 510 // If |newly_adding| is false, we assume that this TemplateURL was already |
555 // part of the model in the past, and therefore we don't need to do things | 511 // part of the model in the past, and therefore we don't need to do things |
556 // like assign it an ID or notify sync. | 512 // like assign it an ID or notify sync. |
557 // This function guarantees that on return the model will not have two | 513 // This function guarantees that on return the model will not have two |
558 // non-extension TemplateURLs with the same keyword. If that means that it | 514 // non-extension TemplateURLs with the same keyword. If that means that it |
559 // cannot add the provided argument, it will delete it and return false. | 515 // cannot add the provided argument, it will delete it and return false. |
560 // Caller is responsible for notifying observers if this function returns | 516 // Caller is responsible for notifying observers if this function returns |
561 // true. | 517 // true. |
562 bool AddNoNotify(TemplateURL* template_url, bool newly_adding); | 518 bool AddNoNotify(TemplateURL* template_url, bool newly_adding); |
563 | 519 |
564 // Removes the keyword from the model. This deletes the supplied TemplateURL. | 520 // Removes the keyword from the model. This deletes the supplied TemplateURL. |
565 // This fails if the supplied template_url is the default search provider. | 521 // This fails if the supplied template_url is the default search provider. |
566 // Caller is responsible for notifying observers. | 522 // Caller is responsible for notifying observers. |
567 void RemoveNoNotify(TemplateURL* template_url); | 523 void RemoveNoNotify(TemplateURL* template_url); |
568 | 524 |
569 // Notify the observers that the model has changed. This is done only if the | 525 // Notify the observers that the model has changed. This is done only if the |
570 // model is loaded. | 526 // model is loaded. |
571 void NotifyObservers(); | 527 void NotifyObservers(); |
572 | 528 |
573 // Removes from the vector any template URL that was created because of | 529 // Updates |template_urls| so that the only "created by policy" entry is |
574 // policy. These TemplateURLs are freed and removed from the database. | 530 // |default_from_prefs|. |default_from_prefs| may be NULL if there is no |
575 // Sets default_search_provider to NULL if it was one of them, unless it is | 531 // policy-defined DSE in effect. |
576 // the same as the current default from preferences and it is managed. | 532 void UpdateProvidersCreatedByPolicy( |
577 void RemoveProvidersCreatedByPolicy( | |
578 TemplateURLVector* template_urls, | 533 TemplateURLVector* template_urls, |
579 TemplateURL** default_search_provider, | 534 const TemplateURLData* default_from_prefs); |
580 TemplateURLData* default_from_prefs); | |
581 | 535 |
582 // Resets the sync GUID of the specified TemplateURL and persists the change | 536 // Resets the sync GUID of the specified TemplateURL and persists the change |
583 // to the database. This does not notify observers. | 537 // to the database. This does not notify observers. |
584 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); | 538 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); |
585 | 539 |
586 // Attempts to generate a unique keyword for |turl| based on its original | 540 // Attempts to generate a unique keyword for |turl| based on its original |
587 // keyword. If its keyword is already unique, that is returned. Otherwise, it | 541 // keyword. If its keyword is already unique, that is returned. Otherwise, it |
588 // tries to return the autogenerated keyword if that is unique to the Service, | 542 // tries to return the autogenerated keyword if that is unique to the Service, |
589 // and finally it repeatedly appends special characters to the keyword until | 543 // and finally it repeatedly appends special characters to the keyword until |
590 // it is unique to the Service. If |force| is true, then this will only | 544 // it is unique to the Service. If |force| is true, then this will only |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 // sent up to Sync. | 582 // sent up to Sync. |
629 // |merge_result| tracks the changes made to the local model. Added/modified/ | 583 // |merge_result| tracks the changes made to the local model. Added/modified/ |
630 // deleted are updated depending on how the |sync_turl| is merged in. | 584 // deleted are updated depending on how the |sync_turl| is merged in. |
631 // This should only be called from MergeDataAndStartSyncing. | 585 // This should only be called from MergeDataAndStartSyncing. |
632 void MergeInSyncTemplateURL(TemplateURL* sync_turl, | 586 void MergeInSyncTemplateURL(TemplateURL* sync_turl, |
633 const SyncDataMap& sync_data, | 587 const SyncDataMap& sync_data, |
634 syncer::SyncChangeList* change_list, | 588 syncer::SyncChangeList* change_list, |
635 SyncDataMap* local_data, | 589 SyncDataMap* local_data, |
636 syncer::SyncMergeResult* merge_result); | 590 syncer::SyncMergeResult* merge_result); |
637 | 591 |
638 // Checks a newly added TemplateURL from Sync by its sync_guid and sets it as | |
639 // the default search provider if we were waiting for it. | |
640 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); | |
641 | |
642 // Retrieve the pending default search provider according to Sync. Returns | |
643 // NULL if there was no pending search provider from Sync. | |
644 TemplateURL* GetPendingSyncedDefaultSearchProvider(); | |
645 | |
646 // Goes through a vector of TemplateURLs and ensure that both the in-memory | 592 // Goes through a vector of TemplateURLs and ensure that both the in-memory |
647 // and database copies have valid sync_guids. This is to fix crbug.com/102038, | 593 // and database copies have valid sync_guids. This is to fix crbug.com/102038, |
648 // where old entries were being pushed to Sync without a sync_guid. | 594 // where old entries were being pushed to Sync without a sync_guid. |
649 void PatchMissingSyncGUIDs(TemplateURLVector* template_urls); | 595 void PatchMissingSyncGUIDs(TemplateURLVector* template_urls); |
650 | 596 |
651 void OnSyncedDefaultSearchProviderGUIDChanged(); | 597 // Adds |template_urls| to |template_urls_|. |
652 | |
653 // Adds |template_urls| to |template_urls_| and sets up the default search | |
654 // provider. If |default_search_provider| is non-NULL, it must refer to one | |
655 // of the |template_urls|, and will be used as the new default. | |
656 // | 598 // |
657 // This transfers ownership of the elements in |template_urls| to |this|, and | 599 // This transfers ownership of the elements in |template_urls| to |this|, and |
658 // may delete some elements, so it's not safe for callers to access any | 600 // may delete some elements, so it's not safe for callers to access any |
659 // elements after calling; to reinforce this, this function clears | 601 // elements after calling; to reinforce this, this function clears |
660 // |template_urls| on exit. | 602 // |template_urls| on exit. |
661 void AddTemplateURLsAndSetupDefaultEngine( | 603 void AddTemplateURLs(TemplateURLVector* template_urls); |
662 TemplateURLVector* template_urls, | |
663 TemplateURL* default_search_provider); | |
664 | |
665 // If there is no current default search provider, sets the default to the | |
666 // result of calling FindNewDefaultSearchProvider(). | |
667 void EnsureDefaultSearchProviderExists(); | |
668 | 604 |
669 // Returns a new TemplateURL for the given extension. | 605 // Returns a new TemplateURL for the given extension. |
670 TemplateURL* CreateTemplateURLForExtension( | 606 TemplateURL* CreateTemplateURLForExtension( |
671 const ExtensionKeyword& extension_keyword) const; | 607 const ExtensionKeyword& extension_keyword) const; |
672 | 608 |
| 609 // Returns the TemplateURL corresponding to |prepopulated_id|, if any. |
| 610 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id) const; |
| 611 |
673 // Returns the TemplateURL associated with |extension_id|, if any. | 612 // Returns the TemplateURL associated with |extension_id|, if any. |
674 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, | 613 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, |
675 TemplateURL::Type type) const; | 614 TemplateURL::Type type) const; |
676 | 615 |
| 616 // Finds the extension-supplied TemplateURL that matches |data|, if any. |
| 617 TemplateURL* FindMatchingExtensionTemplateURL(const TemplateURLData& data, |
| 618 TemplateURL::Type type) const; |
| 619 |
677 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine | 620 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine |
678 // that supports replacement and wants to be default, if any. | 621 // that supports replacement and wants to be default, if any. Notifies the |
679 TemplateURL* FindExtensionDefaultSearchEngine() const; | 622 // DefaultSearchManager, which might change the effective default search |
680 | 623 // engine. |
681 // Sets the default search provider to: | 624 void UpdateExtensionDefaultSearchEngine(); |
682 // (1) BestDefaultExtensionControlledTURL(), if any; or, | |
683 // (2) LoadDefaultSearchProviderFromPrefs(), if we have a TURL with that ID; | |
684 // or, | |
685 // (3) FindNewDefaultSearchProvider(). | |
686 void SetDefaultSearchProviderAfterRemovingDefaultExtension(); | |
687 | 625 |
688 content::NotificationRegistrar notification_registrar_; | 626 content::NotificationRegistrar notification_registrar_; |
689 PrefChangeRegistrar pref_change_registrar_; | |
690 | 627 |
691 // Mapping from keyword to the TemplateURL. | 628 // Mapping from keyword to the TemplateURL. |
692 KeywordToTemplateMap keyword_to_template_map_; | 629 KeywordToTemplateMap keyword_to_template_map_; |
693 | 630 |
694 // Mapping from Sync GUIDs to the TemplateURL. | 631 // Mapping from Sync GUIDs to the TemplateURL. |
695 GUIDToTemplateMap guid_to_template_map_; | 632 GUIDToTemplateMap guid_to_template_map_; |
696 | 633 |
697 TemplateURLVector template_urls_; | 634 TemplateURLVector template_urls_; |
698 | 635 |
699 ObserverList<TemplateURLServiceObserver> model_observers_; | 636 ObserverList<TemplateURLServiceObserver> model_observers_; |
(...skipping 18 matching lines...) Expand all Loading... |
718 WebDataService::Handle load_handle_; | 655 WebDataService::Handle load_handle_; |
719 | 656 |
720 // Service used to store entries. | 657 // Service used to store entries. |
721 scoped_refptr<WebDataService> service_; | 658 scoped_refptr<WebDataService> service_; |
722 | 659 |
723 // All visits that occurred before we finished loading. Once loaded | 660 // All visits that occurred before we finished loading. Once loaded |
724 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. | 661 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. |
725 std::vector<history::URLVisitedDetails> visits_to_add_; | 662 std::vector<history::URLVisitedDetails> visits_to_add_; |
726 | 663 |
727 // Once loaded, the default search provider. This is a pointer to a | 664 // Once loaded, the default search provider. This is a pointer to a |
728 // TemplateURL owned by template_urls_. | 665 // TemplateURL owned by |template_urls_|. |
729 TemplateURL* default_search_provider_; | 666 TemplateURL* default_search_provider_; |
730 | 667 |
731 // The initial search provider extracted from preferences. This is only valid | 668 // A temporary location for the DSE until Web Data has been loaded and it can |
732 // if we haven't been loaded or loading failed. | 669 // be merged into |template_urls_|. |
733 scoped_ptr<TemplateURL> initial_default_search_provider_; | 670 scoped_ptr<TemplateURL> initial_default_search_provider_; |
734 | 671 |
735 // Whether the default search is managed via policy. | 672 // Source of the default search provider. |
736 bool is_default_search_managed_; | 673 DefaultSearchManager::Source default_search_provider_source_; |
737 | 674 |
738 // ID assigned to next TemplateURL added to this model. This is an ever | 675 // ID assigned to next TemplateURL added to this model. This is an ever |
739 // increasing integer that is initialized from the database. | 676 // increasing integer that is initialized from the database. |
740 TemplateURLID next_id_; | 677 TemplateURLID next_id_; |
741 | 678 |
742 // Function returning current time in base::Time units. | 679 // Function returning current time in base::Time units. |
743 TimeProvider* time_provider_; | 680 TimeProvider* time_provider_; |
744 | 681 |
745 // Do we have an active association between the TemplateURLs and sync models? | 682 // Do we have an active association between the TemplateURLs and sync models? |
746 // Set in MergeDataAndStartSyncing, reset in StopSyncing. While this is not | 683 // Set in MergeDataAndStartSyncing, reset in StopSyncing. While this is not |
747 // set, we ignore any local search engine changes (when we start syncing we | 684 // set, we ignore any local search engine changes (when we start syncing we |
748 // will look up the most recent values anyways). | 685 // will look up the most recent values anyways). |
749 bool models_associated_; | 686 bool models_associated_; |
750 | 687 |
751 // Whether we're currently processing changes from the syncer. While this is | 688 // Whether we're currently processing changes from the syncer. While this is |
752 // true, we ignore any local search engine changes, since we triggered them. | 689 // true, we ignore any local search engine changes, since we triggered them. |
753 bool processing_syncer_changes_; | 690 bool processing_syncer_changes_; |
754 | 691 |
755 // Sync's syncer::SyncChange handler. We push all our changes through this. | 692 // Sync's syncer::SyncChange handler. We push all our changes through this. |
756 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 693 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
757 | 694 |
758 // Sync's error handler. We use it to create a sync error. | 695 // Sync's error handler. We use it to create a sync error. |
759 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 696 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
760 | 697 |
761 // Whether or not we are waiting on the default search provider to come in | |
762 // from Sync. This is to facilitate the fact that changes to the value of | |
763 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the | |
764 // TemplateURL entry it refers to, and to handle the case when we want to use | |
765 // the Synced default when the default search provider becomes unmanaged. | |
766 bool pending_synced_default_search_; | |
767 | |
768 // A set of sync GUIDs denoting TemplateURLs that have been removed from this | 698 // A set of sync GUIDs denoting TemplateURLs that have been removed from this |
769 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. | 699 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. |
770 // This set is used to determine what entries from the server we want to | 700 // This set is used to determine what entries from the server we want to |
771 // ignore locally and return a delete command for. | 701 // ignore locally and return a delete command for. |
772 std::set<std::string> pre_sync_deletes_; | 702 std::set<std::string> pre_sync_deletes_; |
773 | 703 |
774 // This is used to log the origin of changes to the default search provider. | |
775 // We set this value to increasingly specific values when we know what is the | |
776 // cause/origin of a default search change. | |
777 DefaultSearchChangeOrigin dsp_change_origin_; | |
778 | |
779 // Stores a list of callbacks to be run after TemplateURLService has loaded. | 704 // Stores a list of callbacks to be run after TemplateURLService has loaded. |
780 base::CallbackList<void(void)> on_loaded_callbacks_; | 705 base::CallbackList<void(void)> on_loaded_callbacks_; |
781 | 706 |
782 // Helper class to manage the default search engine. This will be NULL when | 707 // Helper class to manage the default search engine. This will be NULL when |
783 // using the testing-specific constructor. | 708 // using the testing-specific constructor. |
784 scoped_ptr<DefaultSearchManager> default_search_manager_; | 709 scoped_ptr<DefaultSearchManager> default_search_manager_; |
785 | 710 |
786 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 711 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
787 }; | 712 }; |
788 | 713 |
789 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 714 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |