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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // retains ownership of it. | 134 // retains ownership of it. |
135 const TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid) const; | 135 const TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid) const; |
136 | 136 |
137 // Returns the first TemplateURL found with a URL using the specified |host|, | 137 // Returns the first TemplateURL found with a URL using the specified |host|, |
138 // or NULL if there are no such TemplateURLs | 138 // or NULL if there are no such TemplateURLs |
139 const TemplateURL* GetTemplateURLForHost(const std::string& host) const; | 139 const TemplateURL* GetTemplateURLForHost(const std::string& host) const; |
140 | 140 |
141 // Takes ownership of |template_url| and adds it to this model. | 141 // Takes ownership of |template_url| and adds it to this model. |
142 void Add(TemplateURL* template_url); | 142 void Add(TemplateURL* template_url); |
143 | 143 |
| 144 // Like Add(), but overwrites the |template_url|'s values with the provided |
| 145 // ones. |
| 146 void AddWithOverrides(const TemplateURL* template_url, |
| 147 const string16& short_name, |
| 148 const string16& keyword, |
| 149 const std::string& url); |
| 150 |
144 // Removes the keyword from the model. This deletes the supplied TemplateURL. | 151 // Removes the keyword from the model. This deletes the supplied TemplateURL. |
145 // This fails if the supplied template_url is the default search provider. | 152 // This fails if the supplied template_url is the default search provider. |
146 void Remove(const TemplateURL* template_url); | 153 void Remove(const TemplateURL* template_url); |
147 | 154 |
148 // Removes all auto-generated keywords that were created on or after the | 155 // Removes all auto-generated keywords that were created on or after the |
149 // date passed in. | 156 // date passed in. |
150 void RemoveAutoGeneratedSince(base::Time created_after); | 157 void RemoveAutoGeneratedSince(base::Time created_after); |
151 | 158 |
152 // Removes all auto-generated keywords that were created in the specified | 159 // Removes all auto-generated keywords that were created in the specified |
153 // range. | 160 // range. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // does nothing. | 290 // does nothing. |
284 void ProcessTemplateURLChange(const TemplateURL* turl, | 291 void ProcessTemplateURLChange(const TemplateURL* turl, |
285 SyncChange::SyncChangeType type); | 292 SyncChange::SyncChangeType type); |
286 | 293 |
287 Profile* profile() const { return profile_; } | 294 Profile* profile() const { return profile_; } |
288 | 295 |
289 // Returns a SyncData with a sync representation of the search engine data | 296 // Returns a SyncData with a sync representation of the search engine data |
290 // from |turl|. | 297 // from |turl|. |
291 static SyncData CreateSyncDataFromTemplateURL(const TemplateURL& turl); | 298 static SyncData CreateSyncDataFromTemplateURL(const TemplateURL& turl); |
292 | 299 |
293 // Returns a heap-allocated TemplateURL, populated by |sync_data|'s fields. | 300 // Creates a new heap-allocated TemplateURL* which is populated by overlaying |
294 // This does the opposite of CreateSyncDataFromTemplateURL. The caller owns | 301 // |sync_data| atop |existing_turl|. |existing_turl| may be NULL; if not it |
295 // the returned TemplateURL*. | 302 // remains unmodified. The caller owns the returned TemplateURL*. |
296 static TemplateURL* CreateTemplateURLFromSyncData(const SyncData& sync_data); | 303 static TemplateURL* CreateTemplateURLFromTemplateURLAndSyncData( |
| 304 const TemplateURL* existing_turl, |
| 305 const SyncData& sync_data); |
297 | 306 |
298 // Returns a map mapping Sync GUIDs to pointers to SyncData. | 307 // Returns a map mapping Sync GUIDs to pointers to SyncData. |
299 static SyncDataMap CreateGUIDToSyncDataMap(const SyncDataList& sync_data); | 308 static SyncDataMap CreateGUIDToSyncDataMap(const SyncDataList& sync_data); |
300 | 309 |
301 #if defined(UNIT_TEST) | 310 #if defined(UNIT_TEST) |
302 // Set a different time provider function, such as | 311 // Set a different time provider function, such as |
303 // base::MockTimeProvider::StaticNow, when testing calls to base::Time::Now. | 312 // base::MockTimeProvider::StaticNow, when testing calls to base::Time::Now. |
304 void set_time_provider(TimeProvider* time_provider) { | 313 void set_time_provider(TimeProvider* time_provider) { |
305 time_provider_ = time_provider; | 314 time_provider_ = time_provider; |
306 } | 315 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 509 |
501 // Retrieve the pending default search provider according to Sync. Returns | 510 // Retrieve the pending default search provider according to Sync. Returns |
502 // NULL if there was no pending search provider from Sync. | 511 // NULL if there was no pending search provider from Sync. |
503 const TemplateURL* GetPendingSyncedDefaultSearchProvider(); | 512 const TemplateURL* GetPendingSyncedDefaultSearchProvider(); |
504 | 513 |
505 // Goes through a vector of TemplateURLs and ensure that both the in-memory | 514 // Goes through a vector of TemplateURLs and ensure that both the in-memory |
506 // and database copies have valid sync_guids. This is to fix crbug.com/102038, | 515 // and database copies have valid sync_guids. This is to fix crbug.com/102038, |
507 // where old entries were being pushed to Sync without a sync_guid. | 516 // where old entries were being pushed to Sync without a sync_guid. |
508 void PatchMissingSyncGUIDs(std::vector<TemplateURL*>* template_urls); | 517 void PatchMissingSyncGUIDs(std::vector<TemplateURL*>* template_urls); |
509 | 518 |
510 // Overwrites |dst|'s synced fields with values from |sync_data|. This does | |
511 // commit |dst| to the TemplateURLService. | |
512 static void UpdateTemplateURLWithSyncData(TemplateURL* dst, | |
513 const SyncData& sync_data); | |
514 | |
515 content::NotificationRegistrar registrar_; | 519 content::NotificationRegistrar registrar_; |
516 | 520 |
517 // Mapping from keyword to the TemplateURL. | 521 // Mapping from keyword to the TemplateURL. |
518 KeywordToTemplateMap keyword_to_template_map_; | 522 KeywordToTemplateMap keyword_to_template_map_; |
519 | 523 |
520 // Mapping from Sync GUIDs to the TemplateURL. | 524 // Mapping from Sync GUIDs to the TemplateURL. |
521 GUIDToTemplateMap guid_to_template_map_; | 525 GUIDToTemplateMap guid_to_template_map_; |
522 | 526 |
523 TemplateURLVector template_urls_; | 527 TemplateURLVector template_urls_; |
524 | 528 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 // from Sync. This is to facilitate the fact that changes to the value of | 594 // from Sync. This is to facilitate the fact that changes to the value of |
591 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the | 595 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the |
592 // TemplateURL entry it refers to, and to handle the case when we want to use | 596 // TemplateURL entry it refers to, and to handle the case when we want to use |
593 // the Synced default when the default search provider becomes unmanaged. | 597 // the Synced default when the default search provider becomes unmanaged. |
594 bool pending_synced_default_search_; | 598 bool pending_synced_default_search_; |
595 | 599 |
596 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 600 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
597 }; | 601 }; |
598 | 602 |
599 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 603 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |