| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // Just like GenerateSearchURL except that it takes SearchTermsData to supply | 130 // Just like GenerateSearchURL except that it takes SearchTermsData to supply |
| 131 // the data for some search terms, e.g. so this can be used on threads other | 131 // the data for some search terms, e.g. so this can be used on threads other |
| 132 // than the UI thread. See the various TemplateURLRef::XXXUsingTermsData() | 132 // than the UI thread. See the various TemplateURLRef::XXXUsingTermsData() |
| 133 // functions. | 133 // functions. |
| 134 static GURL GenerateSearchURLUsingTermsData( | 134 static GURL GenerateSearchURLUsingTermsData( |
| 135 const TemplateURL* t_url, | 135 const TemplateURL* t_url, |
| 136 const SearchTermsData& search_terms_data); | 136 const SearchTermsData& search_terms_data); |
| 137 | 137 |
| 138 // Saves enough of url to |prefs| so that it can be loaded from preferences on | 138 // Saves enough of url to |prefs| so that it can be loaded from preferences on |
| 139 // start up. | 139 // start up. |
| 140 static void SaveDefaultSearchProviderToPrefs(const TemplateURL* url, | 140 void SaveDefaultSearchProviderToPrefs(const TemplateURL* url, |
| 141 PrefService* prefs); | 141 PrefService* prefs) const; |
| 142 | 142 |
| 143 // Returns true if there is no TemplateURL that conflicts with the | 143 // Returns true if there is no TemplateURL that conflicts with the |
| 144 // keyword/url pair, or there is one but it can be replaced. If there is an | 144 // keyword/url pair, or there is one but it can be replaced. If there is an |
| 145 // existing keyword that can be replaced and template_url_to_replace is | 145 // existing keyword that can be replaced and template_url_to_replace is |
| 146 // non-NULL, template_url_to_replace is set to the keyword to replace. | 146 // non-NULL, template_url_to_replace is set to the keyword to replace. |
| 147 // | 147 // |
| 148 // url gives the url of the search query. The url is used to avoid generating | 148 // url gives the url of the search query. The url is used to avoid generating |
| 149 // a TemplateURL for an existing TemplateURL that shares the same host. | 149 // a TemplateURL for an existing TemplateURL that shares the same host. |
| 150 bool CanReplaceKeyword(const base::string16& keyword, | 150 bool CanReplaceKeyword(const base::string16& keyword, |
| 151 const GURL& url, | 151 const GURL& url, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 168 // The caller should not try to delete the returned pointer; the data store | 168 // The caller should not try to delete the returned pointer; the data store |
| 169 // retains ownership of it. | 169 // retains ownership of it. |
| 170 TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid); | 170 TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid); |
| 171 | 171 |
| 172 // Returns the first TemplateURL found with a URL using the specified |host|, | 172 // Returns the first TemplateURL found with a URL using the specified |host|, |
| 173 // or NULL if there are no such TemplateURLs | 173 // or NULL if there are no such TemplateURLs |
| 174 TemplateURL* GetTemplateURLForHost(const std::string& host); | 174 TemplateURL* GetTemplateURLForHost(const std::string& host); |
| 175 | 175 |
| 176 // Takes ownership of |template_url| and adds it to this model. For obvious | 176 // Takes ownership of |template_url| and adds it to this model. For obvious |
| 177 // reasons, it is illegal to Add() the same |template_url| pointer twice. | 177 // reasons, it is illegal to Add() the same |template_url| pointer twice. |
| 178 // Returns true if the Add is successful. | 178 void Add(TemplateURL* template_url); |
| 179 bool Add(TemplateURL* template_url); | |
| 180 | 179 |
| 181 // Like Add(), but overwrites the |template_url|'s values with the provided | 180 // Like Add(), but overwrites the |template_url|'s values with the provided |
| 182 // ones. | 181 // ones. |
| 183 void AddAndSetProfile(TemplateURL* template_url, Profile* profile); | 182 void AddAndSetProfile(TemplateURL* template_url, Profile* profile); |
| 184 void AddWithOverrides(TemplateURL* template_url, | 183 void AddWithOverrides(TemplateURL* template_url, |
| 185 const base::string16& short_name, | 184 const base::string16& short_name, |
| 186 const base::string16& keyword, | 185 const base::string16& keyword, |
| 187 const std::string& url); | 186 const std::string& url); |
| 188 | 187 |
| 189 // Add the search engine of type NORMAL_CONTROLLED_BY_EXTENSION. | 188 // Add the search engine of type NORMAL_CONTROLLED_BY_EXTENSION. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // loaded, the default search provider is pulled from preferences. | 254 // loaded, the default search provider is pulled from preferences. |
| 256 // | 255 // |
| 257 // NOTE: At least in unittest mode, this may return NULL. | 256 // NOTE: At least in unittest mode, this may return NULL. |
| 258 TemplateURL* GetDefaultSearchProvider(); | 257 TemplateURL* GetDefaultSearchProvider(); |
| 259 | 258 |
| 260 // 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 |
| 261 // provider. | 260 // provider. |
| 262 bool IsSearchResultsPageFromDefaultSearchProvider(const GURL& url); | 261 bool IsSearchResultsPageFromDefaultSearchProvider(const GURL& url); |
| 263 | 262 |
| 264 // Returns true if the default search is managed through group policy. | 263 // Returns true if the default search is managed through group policy. |
| 265 bool is_default_search_managed() const { | 264 bool is_default_search_managed() const { return is_default_search_managed_; } |
| 266 return default_search_provider_source_ == DefaultSearchManager::FROM_POLICY; | |
| 267 } | |
| 268 | 265 |
| 269 // Returns true if the default search provider is controlled by an extension. | 266 // Returns true if the default search provider is controlled by an extension. |
| 270 bool IsExtensionControlledDefaultSearch(); | 267 bool IsExtensionControlledDefaultSearch(); |
| 271 | 268 |
| 272 // Returns the default search specified in the prepopulated data, if it | 269 // Returns the default search specified in the prepopulated data, if it |
| 273 // exists. If not, returns first URL in |template_urls_|, or NULL if that's | 270 // exists. If not, returns first URL in |template_urls_|, or NULL if that's |
| 274 // empty. The returned object is owned by TemplateURLService and can be | 271 // empty. The returned object is owned by TemplateURLService and can be |
| 275 // destroyed at any time so should be used right after the call. | 272 // destroyed at any time so should be used right after the call. |
| 276 TemplateURL* FindNewDefaultSearchProvider(); | 273 TemplateURL* FindNewDefaultSearchProvider(); |
| 277 | 274 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 static TemplateURL* CreateTemplateURLFromTemplateURLAndSyncData( | 377 static TemplateURL* CreateTemplateURLFromTemplateURLAndSyncData( |
| 381 Profile* profile, | 378 Profile* profile, |
| 382 TemplateURL* existing_turl, | 379 TemplateURL* existing_turl, |
| 383 const syncer::SyncData& sync_data, | 380 const syncer::SyncData& sync_data, |
| 384 syncer::SyncChangeList* change_list); | 381 syncer::SyncChangeList* change_list); |
| 385 | 382 |
| 386 // Returns a map mapping Sync GUIDs to pointers to syncer::SyncData. | 383 // Returns a map mapping Sync GUIDs to pointers to syncer::SyncData. |
| 387 static SyncDataMap CreateGUIDToSyncDataMap( | 384 static SyncDataMap CreateGUIDToSyncDataMap( |
| 388 const syncer::SyncDataList& sync_data); | 385 const syncer::SyncDataList& sync_data); |
| 389 | 386 |
| 390 // Indicates whether the pre-populated TemplateURLs should be disabled. May | |
| 391 // only be true in tests. | |
| 392 static bool fallback_search_engines_disabled() { | |
| 393 return g_fallback_search_engines_disabled; | |
| 394 } | |
| 395 | |
| 396 #if defined(UNIT_TEST) | 387 #if defined(UNIT_TEST) |
| 397 // Disables the pre-populated TemplateURLs for testing purposes. | 388 // Set a different time provider function, such as |
| 398 static void set_fallback_search_engines_disabled(bool disabled) { | 389 // base::MockTimeProvider::StaticNow, when testing calls to base::Time::Now. |
| 399 g_fallback_search_engines_disabled = disabled; | |
| 400 } | |
| 401 | |
| 402 // Sets a different time provider function, such as | |
| 403 // base::MockTimeProvider::StaticNow, for testing calls to base::Time::Now. | |
| 404 void set_time_provider(TimeProvider* time_provider) { | 390 void set_time_provider(TimeProvider* time_provider) { |
| 405 time_provider_ = time_provider; | 391 time_provider_ = time_provider; |
| 406 } | 392 } |
| 407 #endif | 393 #endif |
| 408 | 394 |
| 409 protected: | 395 protected: |
| 410 // Cover method for the method of the same name on the HistoryService. | 396 // Cover method for the method of the same name on the HistoryService. |
| 411 // url is the one that was visited with the given search terms. | 397 // url is the one that was visited with the given search terms. |
| 412 // | 398 // |
| 413 // This exists and is virtual for testing. | 399 // This exists and is virtual for testing. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // This does NOT notify the delegate or the database. | 465 // This does NOT notify the delegate or the database. |
| 480 // | 466 // |
| 481 // This transfers ownership of the elements in |urls| to |this|, and may | 467 // This transfers ownership of the elements in |urls| to |this|, and may |
| 482 // delete some elements, so it's not safe for callers to access any elements | 468 // delete some elements, so it's not safe for callers to access any elements |
| 483 // after calling; to reinforce this, this function clears |urls| on exit. | 469 // after calling; to reinforce this, this function clears |urls| on exit. |
| 484 void SetTemplateURLs(TemplateURLVector* urls); | 470 void SetTemplateURLs(TemplateURLVector* urls); |
| 485 | 471 |
| 486 // Transitions to the loaded state. | 472 // Transitions to the loaded state. |
| 487 void ChangeToLoadedState(); | 473 void ChangeToLoadedState(); |
| 488 | 474 |
| 489 // Called by DefaultSearchManager when the effective default search engine has | 475 // Clears user preferences describing the default search engine. |
| 490 // changed. | 476 void ClearDefaultProviderFromPrefs(); |
| 491 void OnDefaultSearchChange(const TemplateURLData* new_dse_data, | |
| 492 DefaultSearchManager::Source source); | |
| 493 | |
| 494 // Applies a DSE change. May be called at startup or after transitioning to | |
| 495 // the loaded state. | |
| 496 void ApplyDefaultSearchChange(const TemplateURLData* new_dse_data, | |
| 497 DefaultSearchManager::Source source); | |
| 498 | 477 |
| 499 // Returns true if there is no TemplateURL that has a search url with the | 478 // Returns true if there is no TemplateURL that has a search url with the |
| 500 // specified host, or the only TemplateURLs matching the specified host can | 479 // specified host, or the only TemplateURLs matching the specified host can |
| 501 // be replaced. | 480 // be replaced. |
| 502 bool CanReplaceKeywordForHost(const std::string& host, | 481 bool CanReplaceKeywordForHost(const std::string& host, |
| 503 TemplateURL** to_replace); | 482 TemplateURL** to_replace); |
| 504 | 483 |
| 505 // Returns true if the TemplateURL is replaceable. This doesn't look at the | 484 // Returns true if the TemplateURL is replaceable. This doesn't look at the |
| 506 // uniqueness of the keyword or host and is intended to be called after those | 485 // uniqueness of the keyword or host and is intended to be called after those |
| 507 // checks have been done. This returns true if the TemplateURL doesn't appear | 486 // checks have been done. This returns true if the TemplateURL doesn't appear |
| (...skipping 16 matching lines...) Expand all Loading... |
| 524 const TemplateURL& new_values, | 503 const TemplateURL& new_values, |
| 525 const SearchTermsData& old_search_terms_data); | 504 const SearchTermsData& old_search_terms_data); |
| 526 | 505 |
| 527 // If the TemplateURL comes from a prepopulated URL available in the current | 506 // If the TemplateURL comes from a prepopulated URL available in the current |
| 528 // country, update all its fields save for the keyword, short name and id so | 507 // country, update all its fields save for the keyword, short name and id so |
| 529 // that they match the internal prepopulated URL. TemplateURLs not coming from | 508 // that they match the internal prepopulated URL. TemplateURLs not coming from |
| 530 // a prepopulated URL are not modified. | 509 // a prepopulated URL are not modified. |
| 531 static void UpdateTemplateURLIfPrepopulated(TemplateURL* existing_turl, | 510 static void UpdateTemplateURLIfPrepopulated(TemplateURL* existing_turl, |
| 532 Profile* profile); | 511 Profile* profile); |
| 533 | 512 |
| 534 // If the TemplateURL's sync GUID matches the kSyncedDefaultSearchProviderGUID | |
| 535 // preference it will be used to update the DSE in memory and as persisted in | |
| 536 // preferences. | |
| 537 void MaybeUpdateDSEAfterSync(TemplateURL* synced_turl); | |
| 538 | |
| 539 // Returns the preferences we use. | 513 // Returns the preferences we use. |
| 540 PrefService* GetPrefs(); | 514 PrefService* GetPrefs(); |
| 541 | 515 |
| 542 // Iterates through the TemplateURLs to see if one matches the visited url. | 516 // Iterates through the TemplateURLs to see if one matches the visited url. |
| 543 // For each TemplateURL whose url matches the visited url | 517 // For each TemplateURL whose url matches the visited url |
| 544 // SetKeywordSearchTermsForURL is invoked. | 518 // SetKeywordSearchTermsForURL is invoked. |
| 545 void UpdateKeywordSearchTermsForURL( | 519 void UpdateKeywordSearchTermsForURL( |
| 546 const history::URLVisitedDetails& details); | 520 const history::URLVisitedDetails& details); |
| 547 | 521 |
| 548 // If necessary, generates a visit for the site http:// + t_url.keyword(). | 522 // If necessary, generates a visit for the site http:// + t_url.keyword(). |
| 549 void AddTabToSearchVisit(const TemplateURL& t_url); | 523 void AddTabToSearchVisit(const TemplateURL& t_url); |
| 550 | 524 |
| 551 // Invoked when the Google base URL has changed. Updates the mapping for all | 525 // Invoked when the Google base URL has changed. Updates the mapping for all |
| 552 // TemplateURLs that have a replacement term of {google:baseURL} or | 526 // TemplateURLs that have a replacement term of {google:baseURL} or |
| 553 // {google:baseSuggestURL}. | 527 // {google:baseSuggestURL}. |
| 554 void GoogleBaseURLChanged(const GURL& old_base_url); | 528 void GoogleBaseURLChanged(const GURL& old_base_url); |
| 555 | 529 |
| 530 // Update the default search. Called at initialization or when a managed |
| 531 // preference has changed. |
| 532 void UpdateDefaultSearch(); |
| 533 |
| 534 // Set the default search provider. |url| may be user-selected or |
| 535 // automatically selected and may be null. |
| 536 // This will assert if the default search is managed. |
| 537 void SetDefaultSearchProvider(TemplateURL* url); |
| 538 |
| 539 // Set the default search provider even if it is managed. |url| may be null. |
| 540 // Caller is responsible for notifying observers. Returns whether |url| was |
| 541 // found in |template_urls_|. |
| 542 // If |url| is an extension-controlled search engine then preferences and the |
| 543 // database are left untouched. |
| 544 // If |url| is a normal search engine and the existing default search engine |
| 545 // is controlled by an extension then |url| is propagated to the database and |
| 546 // prefs but the extension-controlled default engine will continue to hide |
| 547 // this value until the extension is uninstalled. |
| 548 bool SetDefaultSearchProviderNoNotify(TemplateURL* url); |
| 549 |
| 556 // Adds a new TemplateURL to this model. TemplateURLService will own the | 550 // Adds a new TemplateURL to this model. TemplateURLService will own the |
| 557 // reference, and delete it when the TemplateURL is removed. | 551 // reference, and delete it when the TemplateURL is removed. |
| 558 // If |newly_adding| is false, we assume that this TemplateURL was already | 552 // If |newly_adding| is false, we assume that this TemplateURL was already |
| 559 // part of the model in the past, and therefore we don't need to do things | 553 // part of the model in the past, and therefore we don't need to do things |
| 560 // like assign it an ID or notify sync. | 554 // like assign it an ID or notify sync. |
| 561 // This function guarantees that on return the model will not have two | 555 // This function guarantees that on return the model will not have two |
| 562 // non-extension TemplateURLs with the same keyword. If that means that it | 556 // non-extension TemplateURLs with the same keyword. If that means that it |
| 563 // cannot add the provided argument, it will delete it and return false. | 557 // cannot add the provided argument, it will delete it and return false. |
| 564 // Caller is responsible for notifying observers if this function returns | 558 // Caller is responsible for notifying observers if this function returns |
| 565 // true. | 559 // true. |
| 566 bool AddNoNotify(TemplateURL* template_url, bool newly_adding); | 560 bool AddNoNotify(TemplateURL* template_url, bool newly_adding); |
| 567 | 561 |
| 568 // Removes the keyword from the model. This deletes the supplied TemplateURL. | 562 // Removes the keyword from the model. This deletes the supplied TemplateURL. |
| 569 // This fails if the supplied template_url is the default search provider. | 563 // This fails if the supplied template_url is the default search provider. |
| 570 // Caller is responsible for notifying observers. | 564 // Caller is responsible for notifying observers. |
| 571 void RemoveNoNotify(TemplateURL* template_url); | 565 void RemoveNoNotify(TemplateURL* template_url); |
| 572 | 566 |
| 573 // Like ResetTemplateURL(), but instead of notifying observers, returns | 567 // Like ResetTemplateURL(), but instead of notifying observers, returns |
| 574 // whether anything has changed. | 568 // whether anything has changed. |
| 575 bool ResetTemplateURLNoNotify(TemplateURL* url, | 569 bool ResetTemplateURLNoNotify(TemplateURL* url, |
| 576 const base::string16& title, | 570 const base::string16& title, |
| 577 const base::string16& keyword, | 571 const base::string16& keyword, |
| 578 const std::string& search_url); | 572 const std::string& search_url); |
| 579 | 573 |
| 580 // Notify the observers that the model has changed. This is done only if the | 574 // Notify the observers that the model has changed. This is done only if the |
| 581 // model is loaded. | 575 // model is loaded. |
| 582 void NotifyObservers(); | 576 void NotifyObservers(); |
| 583 | 577 |
| 584 // Updates |template_urls| so that the only "created by policy" entry is | 578 // Removes from the vector any template URL that was created because of |
| 585 // |default_from_prefs|. |default_from_prefs| may be NULL if there is no | 579 // policy. These TemplateURLs are freed and removed from the database. |
| 586 // policy-defined DSE in effect. | 580 // Sets default_search_provider to NULL if it was one of them, unless it is |
| 587 void UpdateProvidersCreatedByPolicy( | 581 // the same as the current default from preferences and it is managed. |
| 582 void RemoveProvidersCreatedByPolicy( |
| 588 TemplateURLVector* template_urls, | 583 TemplateURLVector* template_urls, |
| 589 const TemplateURLData* default_from_prefs); | 584 TemplateURL** default_search_provider, |
| 585 TemplateURLData* default_from_prefs); |
| 590 | 586 |
| 591 // Resets the sync GUID of the specified TemplateURL and persists the change | 587 // Resets the sync GUID of the specified TemplateURL and persists the change |
| 592 // to the database. This does not notify observers. | 588 // to the database. This does not notify observers. |
| 593 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); | 589 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); |
| 594 | 590 |
| 595 // Attempts to generate a unique keyword for |turl| based on its original | 591 // Attempts to generate a unique keyword for |turl| based on its original |
| 596 // keyword. If its keyword is already unique, that is returned. Otherwise, it | 592 // keyword. If its keyword is already unique, that is returned. Otherwise, it |
| 597 // tries to return the autogenerated keyword if that is unique to the Service, | 593 // tries to return the autogenerated keyword if that is unique to the Service, |
| 598 // and finally it repeatedly appends special characters to the keyword until | 594 // and finally it repeatedly appends special characters to the keyword until |
| 599 // it is unique to the Service. If |force| is true, then this will only | 595 // 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... |
| 637 // sent up to Sync. | 633 // sent up to Sync. |
| 638 // |merge_result| tracks the changes made to the local model. Added/modified/ | 634 // |merge_result| tracks the changes made to the local model. Added/modified/ |
| 639 // deleted are updated depending on how the |sync_turl| is merged in. | 635 // deleted are updated depending on how the |sync_turl| is merged in. |
| 640 // This should only be called from MergeDataAndStartSyncing. | 636 // This should only be called from MergeDataAndStartSyncing. |
| 641 void MergeInSyncTemplateURL(TemplateURL* sync_turl, | 637 void MergeInSyncTemplateURL(TemplateURL* sync_turl, |
| 642 const SyncDataMap& sync_data, | 638 const SyncDataMap& sync_data, |
| 643 syncer::SyncChangeList* change_list, | 639 syncer::SyncChangeList* change_list, |
| 644 SyncDataMap* local_data, | 640 SyncDataMap* local_data, |
| 645 syncer::SyncMergeResult* merge_result); | 641 syncer::SyncMergeResult* merge_result); |
| 646 | 642 |
| 643 // Checks a newly added TemplateURL from Sync by its sync_guid and sets it as |
| 644 // the default search provider if we were waiting for it. |
| 645 void SetDefaultSearchProviderIfNewlySynced(const std::string& guid); |
| 646 |
| 647 // Retrieve the pending default search provider according to Sync. Returns |
| 648 // NULL if there was no pending search provider from Sync. |
| 649 TemplateURL* GetPendingSyncedDefaultSearchProvider(); |
| 650 |
| 647 // Goes through a vector of TemplateURLs and ensure that both the in-memory | 651 // Goes through a vector of TemplateURLs and ensure that both the in-memory |
| 648 // and database copies have valid sync_guids. This is to fix crbug.com/102038, | 652 // and database copies have valid sync_guids. This is to fix crbug.com/102038, |
| 649 // where old entries were being pushed to Sync without a sync_guid. | 653 // where old entries were being pushed to Sync without a sync_guid. |
| 650 void PatchMissingSyncGUIDs(TemplateURLVector* template_urls); | 654 void PatchMissingSyncGUIDs(TemplateURLVector* template_urls); |
| 651 | 655 |
| 652 void OnSyncedDefaultSearchProviderGUIDChanged(); | 656 void OnSyncedDefaultSearchProviderGUIDChanged(); |
| 653 | 657 |
| 654 // Adds |template_urls| to |template_urls_|. | 658 // Adds |template_urls| to |template_urls_| and sets up the default search |
| 659 // provider. If |default_search_provider| is non-NULL, it must refer to one |
| 660 // of the |template_urls|, and will be used as the new default. |
| 655 // | 661 // |
| 656 // This transfers ownership of the elements in |template_urls| to |this|, and | 662 // This transfers ownership of the elements in |template_urls| to |this|, and |
| 657 // may delete some elements, so it's not safe for callers to access any | 663 // may delete some elements, so it's not safe for callers to access any |
| 658 // elements after calling; to reinforce this, this function clears | 664 // elements after calling; to reinforce this, this function clears |
| 659 // |template_urls| on exit. | 665 // |template_urls| on exit. |
| 660 void AddTemplateURLs(TemplateURLVector* template_urls); | 666 void AddTemplateURLsAndSetupDefaultEngine( |
| 667 TemplateURLVector* template_urls, |
| 668 TemplateURL* default_search_provider); |
| 669 |
| 670 // If there is no current default search provider, sets the default to the |
| 671 // result of calling FindNewDefaultSearchProvider(). |
| 672 void EnsureDefaultSearchProviderExists(); |
| 661 | 673 |
| 662 // Returns a new TemplateURL for the given extension. | 674 // Returns a new TemplateURL for the given extension. |
| 663 TemplateURL* CreateTemplateURLForExtension( | 675 TemplateURL* CreateTemplateURLForExtension( |
| 664 const ExtensionKeyword& extension_keyword); | 676 const ExtensionKeyword& extension_keyword); |
| 665 | 677 |
| 666 // Returns the TemplateURL corresponding to |prepopulated_id|, if any. | |
| 667 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id); | |
| 668 | |
| 669 // Returns the TemplateURL associated with |extension_id|, if any. | 678 // Returns the TemplateURL associated with |extension_id|, if any. |
| 670 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, | 679 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, |
| 671 TemplateURL::Type type); | 680 TemplateURL::Type type); |
| 672 | 681 |
| 673 // Finds the extension-supplied TemplateURL that matches |data|, if any. | 682 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine |
| 674 TemplateURL* FindMatchingExtensionTemplateURL(const TemplateURLData& data, | 683 // that supports replacement and wants to be default, if any. |
| 675 TemplateURL::Type type); | 684 TemplateURL* FindExtensionDefaultSearchEngine() const; |
| 676 | 685 |
| 677 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine | 686 // Sets the default search provider to: |
| 678 // that supports replacement and wants to be default, if any. Notifies the | 687 // (1) BestDefaultExtensionControlledTURL(), if any; or, |
| 679 // DefaultSearchManager, which might change the effective default search | 688 // (2) LoadDefaultSearchProviderFromPrefs(), if we have a TURL with that ID; |
| 680 // engine. | 689 // or, |
| 681 void UpdateExtensionDefaultSearchEngine(); | 690 // (3) FindNewDefaultSearchProvider(). |
| 691 void SetDefaultSearchProviderAfterRemovingDefaultExtension(); |
| 682 | 692 |
| 683 content::NotificationRegistrar notification_registrar_; | 693 content::NotificationRegistrar notification_registrar_; |
| 684 PrefChangeRegistrar pref_change_registrar_; | 694 PrefChangeRegistrar pref_change_registrar_; |
| 685 | 695 |
| 686 // Mapping from keyword to the TemplateURL. | 696 // Mapping from keyword to the TemplateURL. |
| 687 KeywordToTemplateMap keyword_to_template_map_; | 697 KeywordToTemplateMap keyword_to_template_map_; |
| 688 | 698 |
| 689 // Mapping from Sync GUIDs to the TemplateURL. | 699 // Mapping from Sync GUIDs to the TemplateURL. |
| 690 GUIDToTemplateMap guid_to_template_map_; | 700 GUIDToTemplateMap guid_to_template_map_; |
| 691 | 701 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 718 scoped_refptr<WebDataService> service_; | 728 scoped_refptr<WebDataService> service_; |
| 719 | 729 |
| 720 // All visits that occurred before we finished loading. Once loaded | 730 // All visits that occurred before we finished loading. Once loaded |
| 721 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. | 731 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. |
| 722 std::vector<history::URLVisitedDetails> visits_to_add_; | 732 std::vector<history::URLVisitedDetails> visits_to_add_; |
| 723 | 733 |
| 724 // Once loaded, the default search provider. This is a pointer to a | 734 // Once loaded, the default search provider. This is a pointer to a |
| 725 // TemplateURL owned by |template_urls_|. | 735 // TemplateURL owned by |template_urls_|. |
| 726 TemplateURL* default_search_provider_; | 736 TemplateURL* default_search_provider_; |
| 727 | 737 |
| 728 // A temporary location for the DSE until Web Data has been loaded and it can | 738 // The initial search provider extracted from preferences. This is only valid |
| 729 // be merged into |template_urls_|. | 739 // if we haven't been loaded or loading failed. |
| 730 scoped_ptr<TemplateURL> initial_default_search_provider_; | 740 scoped_ptr<TemplateURL> initial_default_search_provider_; |
| 731 | 741 |
| 732 // Source of the default search provider. | 742 // Whether the default search is managed via policy. |
| 733 DefaultSearchManager::Source default_search_provider_source_; | 743 bool is_default_search_managed_; |
| 734 | 744 |
| 735 // ID assigned to next TemplateURL added to this model. This is an ever | 745 // ID assigned to next TemplateURL added to this model. This is an ever |
| 736 // increasing integer that is initialized from the database. | 746 // increasing integer that is initialized from the database. |
| 737 TemplateURLID next_id_; | 747 TemplateURLID next_id_; |
| 738 | 748 |
| 739 // Function returning current time in base::Time units. | 749 // Function returning current time in base::Time units. |
| 740 TimeProvider* time_provider_; | 750 TimeProvider* time_provider_; |
| 741 | 751 |
| 742 // Do we have an active association between the TemplateURLs and sync models? | 752 // Do we have an active association between the TemplateURLs and sync models? |
| 743 // Set in MergeDataAndStartSyncing, reset in StopSyncing. While this is not | 753 // Set in MergeDataAndStartSyncing, reset in StopSyncing. While this is not |
| 744 // set, we ignore any local search engine changes (when we start syncing we | 754 // set, we ignore any local search engine changes (when we start syncing we |
| 745 // will look up the most recent values anyways). | 755 // will look up the most recent values anyways). |
| 746 bool models_associated_; | 756 bool models_associated_; |
| 747 | 757 |
| 748 // Whether we're currently processing changes from the syncer. While this is | 758 // Whether we're currently processing changes from the syncer. While this is |
| 749 // true, we ignore any local search engine changes, since we triggered them. | 759 // true, we ignore any local search engine changes, since we triggered them. |
| 750 bool processing_syncer_changes_; | 760 bool processing_syncer_changes_; |
| 751 | 761 |
| 752 // Sync's syncer::SyncChange handler. We push all our changes through this. | 762 // Sync's syncer::SyncChange handler. We push all our changes through this. |
| 753 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 763 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 754 | 764 |
| 755 // Sync's error handler. We use it to create a sync error. | 765 // Sync's error handler. We use it to create a sync error. |
| 756 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 766 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
| 757 | 767 |
| 768 // Whether or not we are waiting on the default search provider to come in |
| 769 // from Sync. This is to facilitate the fact that changes to the value of |
| 770 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the |
| 771 // TemplateURL entry it refers to, and to handle the case when we want to use |
| 772 // the Synced default when the default search provider becomes unmanaged. |
| 773 bool pending_synced_default_search_; |
| 774 |
| 758 // A set of sync GUIDs denoting TemplateURLs that have been removed from this | 775 // A set of sync GUIDs denoting TemplateURLs that have been removed from this |
| 759 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. | 776 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. |
| 760 // This set is used to determine what entries from the server we want to | 777 // This set is used to determine what entries from the server we want to |
| 761 // ignore locally and return a delete command for. | 778 // ignore locally and return a delete command for. |
| 762 std::set<std::string> pre_sync_deletes_; | 779 std::set<std::string> pre_sync_deletes_; |
| 763 | 780 |
| 764 // This is used to log the origin of changes to the default search provider. | 781 // This is used to log the origin of changes to the default search provider. |
| 765 // We set this value to increasingly specific values when we know what is the | 782 // We set this value to increasingly specific values when we know what is the |
| 766 // cause/origin of a default search change. | 783 // cause/origin of a default search change. |
| 767 DefaultSearchChangeOrigin dsp_change_origin_; | 784 DefaultSearchChangeOrigin dsp_change_origin_; |
| 768 | 785 |
| 769 // Stores a list of callbacks to be run after TemplateURLService has loaded. | 786 // Stores a list of callbacks to be run after TemplateURLService has loaded. |
| 770 base::CallbackList<void(void)> on_loaded_callbacks_; | 787 base::CallbackList<void(void)> on_loaded_callbacks_; |
| 771 | 788 |
| 772 // Helper class to manage the default search engine. | 789 // Helper class to manage the default search engine. |
| 773 DefaultSearchManager default_search_manager_; | 790 DefaultSearchManager default_search_manager_; |
| 774 | 791 |
| 775 // Used to disable the prepopulated search engines in tests. | |
| 776 static bool g_fallback_search_engines_disabled; | |
| 777 | |
| 778 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 792 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
| 779 }; | 793 }; |
| 780 | 794 |
| 781 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 795 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
| OLD | NEW |