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