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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 virtual void OnWebDataServiceRequestDone( | 251 virtual void OnWebDataServiceRequestDone( |
| 252 WebDataService::Handle h, | 252 WebDataService::Handle h, |
| 253 const WDTypedResult* result) OVERRIDE; | 253 const WDTypedResult* result) OVERRIDE; |
| 254 | 254 |
| 255 // Returns the locale-direction-adjusted short name for the given keyword. | 255 // Returns the locale-direction-adjusted short name for the given keyword. |
| 256 // Also sets the out param to indicate whether the keyword belongs to an | 256 // Also sets the out param to indicate whether the keyword belongs to an |
| 257 // extension. | 257 // extension. |
| 258 string16 GetKeywordShortName(const string16& keyword, | 258 string16 GetKeywordShortName(const string16& keyword, |
| 259 bool* is_extension_keyword); | 259 bool* is_extension_keyword); |
| 260 | 260 |
| 261 // content::NotificationObserver method. TemplateURLService listens for three | |
| 262 // notification types: | |
| 263 // . NOTIFY_HISTORY_URL_VISITED: adds keyword search terms if the visit | |
| 264 // corresponds to a keyword. | |
| 265 // . NOTIFY_GOOGLE_URL_UPDATED: updates mapping for any keywords containing | |
| 266 // a google base url replacement term. | |
| 267 // . PREF_CHANGED: checks whether the default search engine has changed. | |
|
SteveT
2012/06/05 15:11:42
nit: Why did you remove this comment? Do we not do
Peter Kasting
2012/06/05 20:49:03
The comment was already inaccurate and incomplete,
| |
| 268 virtual void Observe(int type, | 261 virtual void Observe(int type, |
| 269 const content::NotificationSource& source, | 262 const content::NotificationSource& source, |
| 270 const content::NotificationDetails& details) OVERRIDE; | 263 const content::NotificationDetails& details) OVERRIDE; |
| 271 | 264 |
| 272 // SyncableService implementation. | 265 // SyncableService implementation. |
| 273 | 266 |
| 274 // Returns all syncable TemplateURLs from this model as SyncData. This should | 267 // Returns all syncable TemplateURLs from this model as SyncData. This should |
| 275 // include every search engine and no Extension keywords. | 268 // include every search engine and no Extension keywords. |
| 276 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 269 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; |
| 277 // Process new search engine changes from Sync, merging them into our local | 270 // Process new search engine changes from Sync, merging them into our local |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 // in the default list and is marked as safe_for_autoreplace. | 412 // in the default list and is marked as safe_for_autoreplace. |
| 420 bool CanReplace(const TemplateURL* t_url); | 413 bool CanReplace(const TemplateURL* t_url); |
| 421 | 414 |
| 422 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords. | 415 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords. |
| 423 TemplateURL* FindNonExtensionTemplateURLForKeyword(const string16& keyword); | 416 TemplateURL* FindNonExtensionTemplateURLForKeyword(const string16& keyword); |
| 424 | 417 |
| 425 // Updates the information in |existing_turl| using the information from | 418 // Updates the information in |existing_turl| using the information from |
| 426 // |new_values|, but the ID for |existing_turl| is retained. Notifying | 419 // |new_values|, but the ID for |existing_turl| is retained. Notifying |
| 427 // observers is the responsibility of the caller. Returns whether | 420 // observers is the responsibility of the caller. Returns whether |
| 428 // |existing_turl| was found in |template_urls_| and thus could be updated. | 421 // |existing_turl| was found in |template_urls_| and thus could be updated. |
| 422 // |old_search_terms_data| is passed to SearchHostToURLsMap::Remove(). | |
| 429 // | 423 // |
| 430 // NOTE: This should not be called with an extension keyword as there are no | 424 // NOTE: This should not be called with an extension keyword as there are no |
| 431 // updates needed in that case. | 425 // updates needed in that case. |
| 432 bool UpdateNoNotify(TemplateURL* existing_turl, | 426 bool UpdateNoNotify(TemplateURL* existing_turl, |
| 433 const TemplateURL& new_values); | 427 const TemplateURL& new_values, |
| 428 const SearchTermsData& old_search_terms_data); | |
| 434 | 429 |
| 435 // Returns the preferences we use. | 430 // Returns the preferences we use. |
| 436 PrefService* GetPrefs(); | 431 PrefService* GetPrefs(); |
| 437 | 432 |
| 438 // Iterates through the TemplateURLs to see if one matches the visited url. | 433 // Iterates through the TemplateURLs to see if one matches the visited url. |
| 439 // For each TemplateURL whose url matches the visited url | 434 // For each TemplateURL whose url matches the visited url |
| 440 // SetKeywordSearchTermsForURL is invoked. | 435 // SetKeywordSearchTermsForURL is invoked. |
| 441 void UpdateKeywordSearchTermsForURL( | 436 void UpdateKeywordSearchTermsForURL( |
| 442 const history::URLVisitedDetails& details); | 437 const history::URLVisitedDetails& details); |
| 443 | 438 |
| 444 // If necessary, generates a visit for the site http:// + t_url.keyword(). | 439 // If necessary, generates a visit for the site http:// + t_url.keyword(). |
| 445 void AddTabToSearchVisit(const TemplateURL& t_url); | 440 void AddTabToSearchVisit(const TemplateURL& t_url); |
| 446 | 441 |
| 447 // Adds each of the query terms in the specified url whose key and value are | 442 // Adds each of the query terms in the specified url whose key and value are |
| 448 // non-empty to query_terms. If a query key appears multiple times, the value | 443 // non-empty to query_terms. If a query key appears multiple times, the value |
| 449 // is set to an empty string. Returns true if there is at least one key that | 444 // is set to an empty string. Returns true if there is at least one key that |
| 450 // does not occur multiple times. | 445 // does not occur multiple times. |
| 451 static bool BuildQueryTerms( | 446 static bool BuildQueryTerms( |
| 452 const GURL& url, | 447 const GURL& url, |
| 453 std::map<std::string, std::string>* query_terms); | 448 std::map<std::string, std::string>* query_terms); |
| 454 | 449 |
| 455 // Invoked when the Google base URL has changed. Updates the mapping for all | 450 // Invoked when the Google base URL has changed. Updates the mapping for all |
| 456 // TemplateURLs that have a replacement term of {google:baseURL} or | 451 // TemplateURLs that have a replacement term of {google:baseURL} or |
| 457 // {google:baseSuggestURL}. | 452 // {google:baseSuggestURL}. |
| 458 void GoogleBaseURLChanged(); | 453 void GoogleBaseURLChanged(const GURL& old_base_url); |
| 459 | 454 |
| 460 // Update the default search. Called at initialization or when a managed | 455 // Update the default search. Called at initialization or when a managed |
| 461 // preference has changed. | 456 // preference has changed. |
| 462 void UpdateDefaultSearch(); | 457 void UpdateDefaultSearch(); |
| 463 | 458 |
| 464 // Set the default search provider even if it is managed. |url| may be null. | 459 // Set the default search provider even if it is managed. |url| may be null. |
| 465 // Caller is responsible for notifying observers. Returns whether |url| was | 460 // Caller is responsible for notifying observers. Returns whether |url| was |
| 466 // found in |template_urls_| and thus could be made default. | 461 // found in |template_urls_| and thus could be made default. |
| 467 bool SetDefaultSearchProviderNoNotify(TemplateURL* url); | 462 bool SetDefaultSearchProviderNoNotify(TemplateURL* url); |
| 468 | 463 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 // A set of sync GUIDs denoting TemplateURLs that have been removed from this | 632 // A set of sync GUIDs denoting TemplateURLs that have been removed from this |
| 638 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. | 633 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. |
| 639 // This set is used to determine what entries from the server we want to | 634 // This set is used to determine what entries from the server we want to |
| 640 // ignore locally and return a delete command for. | 635 // ignore locally and return a delete command for. |
| 641 std::set<std::string> pre_sync_deletes_; | 636 std::set<std::string> pre_sync_deletes_; |
| 642 | 637 |
| 643 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 638 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
| 644 }; | 639 }; |
| 645 | 640 |
| 646 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 641 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
| OLD | NEW |