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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // | 58 // |
59 // TemplateURLService takes ownership of any TemplateURL passed to it. If there | 59 // TemplateURLService takes ownership of any TemplateURL passed to it. If there |
60 // is a WebDataService, deletion is handled by WebDataService, otherwise | 60 // is a WebDataService, deletion is handled by WebDataService, otherwise |
61 // TemplateURLService handles deletion. | 61 // TemplateURLService handles deletion. |
62 | 62 |
63 class TemplateURLService : public WebDataServiceConsumer, | 63 class TemplateURLService : public WebDataServiceConsumer, |
64 public BrowserContextKeyedService, | 64 public BrowserContextKeyedService, |
65 public content::NotificationObserver, | 65 public content::NotificationObserver, |
66 public syncer::SyncableService { | 66 public syncer::SyncableService { |
67 public: | 67 public: |
| 68 typedef std::map<string16, TemplateURL*> KeywordToTemplateMap; |
68 typedef std::map<std::string, std::string> QueryTerms; | 69 typedef std::map<std::string, std::string> QueryTerms; |
69 typedef std::vector<TemplateURL*> TemplateURLVector; | 70 typedef std::vector<TemplateURL*> TemplateURLVector; |
70 // Type for a static function pointer that acts as a time source. | 71 // Type for a static function pointer that acts as a time source. |
71 typedef base::Time(TimeProvider)(); | 72 typedef base::Time(TimeProvider)(); |
72 typedef std::map<std::string, syncer::SyncData> SyncDataMap; | 73 typedef std::map<std::string, syncer::SyncData> SyncDataMap; |
73 | 74 |
74 // Struct used for initializing the data store with fake data. | 75 // Struct used for initializing the data store with fake data. |
75 // Each initializer is mapped to a TemplateURL. | 76 // Each initializer is mapped to a TemplateURL. |
76 struct Initializer { | 77 struct Initializer { |
77 const char* const keyword; | 78 const char* const keyword; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // keyword/url pair, or there is one but it can be replaced. If there is an | 112 // keyword/url pair, or there is one but it can be replaced. If there is an |
112 // existing keyword that can be replaced and template_url_to_replace is | 113 // existing keyword that can be replaced and template_url_to_replace is |
113 // non-NULL, template_url_to_replace is set to the keyword to replace. | 114 // non-NULL, template_url_to_replace is set to the keyword to replace. |
114 // | 115 // |
115 // url gives the url of the search query. The url is used to avoid generating | 116 // url gives the url of the search query. The url is used to avoid generating |
116 // a TemplateURL for an existing TemplateURL that shares the same host. | 117 // a TemplateURL for an existing TemplateURL that shares the same host. |
117 bool CanReplaceKeyword(const string16& keyword, | 118 bool CanReplaceKeyword(const string16& keyword, |
118 const GURL& url, | 119 const GURL& url, |
119 TemplateURL** template_url_to_replace); | 120 TemplateURL** template_url_to_replace); |
120 | 121 |
121 // Returns (in |matches|) all keywords beginning with |prefix|, sorted | 122 // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|, |
122 // shortest-first. If support_replacement_only is true, only keywords that | 123 // sorted shortest keyword-first. If |support_replacement_only| is true, only |
123 // support replacement are returned. | 124 // TemplateURLs that support replacement are returned. |
124 void FindMatchingKeywords(const string16& prefix, | 125 void FindMatchingKeywords(const string16& prefix, |
125 bool support_replacement_only, | 126 bool support_replacement_only, |
126 std::vector<string16>* matches) const; | 127 TemplateURLVector* matches) const; |
127 | 128 |
128 // Looks up |keyword| and returns the element it maps to. Returns NULL if | 129 // Looks up |keyword| and returns the element it maps to. Returns NULL if |
129 // the keyword was not found. | 130 // the keyword was not found. |
130 // The caller should not try to delete the returned pointer; the data store | 131 // The caller should not try to delete the returned pointer; the data store |
131 // retains ownership of it. | 132 // retains ownership of it. |
132 TemplateURL* GetTemplateURLForKeyword(const string16& keyword); | 133 TemplateURL* GetTemplateURLForKeyword(const string16& keyword); |
133 | 134 |
134 // Returns that TemplateURL with the specified GUID, or NULL if not found. | 135 // Returns that TemplateURL with the specified GUID, or NULL if not found. |
135 // The caller should not try to delete the returned pointer; the data store | 136 // The caller should not try to delete the returned pointer; the data store |
136 // retains ownership of it. | 137 // retains ownership of it. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); | 358 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); |
358 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 359 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
359 ResolveSyncKeywordConflict); | 360 ResolveSyncKeywordConflict); |
360 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); | 361 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); |
361 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 362 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
362 IsLocalTemplateURLBetter); | 363 IsLocalTemplateURLBetter); |
363 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); | 364 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); |
364 | 365 |
365 friend class TemplateURLServiceTestUtil; | 366 friend class TemplateURLServiceTestUtil; |
366 | 367 |
367 typedef std::map<string16, TemplateURL*> KeywordToTemplateMap; | |
368 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; | 368 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; |
369 | 369 |
370 // Declaration of values to be used in an enumerated histogram to tally | 370 // Declaration of values to be used in an enumerated histogram to tally |
371 // changes to the default search provider from various entry points. In | 371 // changes to the default search provider from various entry points. In |
372 // particular, we use this to see what proportion of changes are from Sync | 372 // particular, we use this to see what proportion of changes are from Sync |
373 // entry points, to help spot erroneous Sync activity. | 373 // entry points, to help spot erroneous Sync activity. |
374 enum DefaultSearchChangeOrigin { | 374 enum DefaultSearchChangeOrigin { |
375 // Various known Sync entry points. | 375 // Various known Sync entry points. |
376 DSP_CHANGE_SYNC_PREF, | 376 DSP_CHANGE_SYNC_PREF, |
377 DSP_CHANGE_SYNC_ADD, | 377 DSP_CHANGE_SYNC_ADD, |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 | 689 |
690 // This is used to log the origin of changes to the default search provider. | 690 // This is used to log the origin of changes to the default search provider. |
691 // We set this value to increasingly specific values when we know what is the | 691 // We set this value to increasingly specific values when we know what is the |
692 // cause/origin of a default search change. | 692 // cause/origin of a default search change. |
693 DefaultSearchChangeOrigin dsp_change_origin_; | 693 DefaultSearchChangeOrigin dsp_change_origin_; |
694 | 694 |
695 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 695 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
696 }; | 696 }; |
697 | 697 |
698 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 698 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |