Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: chrome/browser/search_engines/template_url_service.h

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

Powered by Google App Engine
This is Rietveld 408576698