OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_MODEL_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_H_ |
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_H_ | 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // notification message. | 52 // notification message. |
53 // | 53 // |
54 // TemplateURLModel takes ownership of any TemplateURL passed to it. If there | 54 // TemplateURLModel takes ownership of any TemplateURL passed to it. If there |
55 // is a WebDataService, deletion is handled by WebDataService, otherwise | 55 // is a WebDataService, deletion is handled by WebDataService, otherwise |
56 // TemplateURLModel handles deletion. | 56 // TemplateURLModel handles deletion. |
57 | 57 |
58 class TemplateURLModel : public WebDataServiceConsumer, | 58 class TemplateURLModel : public WebDataServiceConsumer, |
59 public NotificationObserver { | 59 public NotificationObserver { |
60 public: | 60 public: |
61 typedef std::map<std::string, std::string> QueryTerms; | 61 typedef std::map<std::string, std::string> QueryTerms; |
| 62 typedef std::vector<const TemplateURL*> TemplateURLVector; |
62 | 63 |
63 // Struct used for initializing the data store with fake data. | 64 // Struct used for initializing the data store with fake data. |
64 // Each initializer is mapped to a TemplateURL. | 65 // Each initializer is mapped to a TemplateURL. |
65 struct Initializer { | 66 struct Initializer { |
66 const char* const keyword; | 67 const char* const keyword; |
67 const char* const url; | 68 const char* const url; |
68 const char* const content; | 69 const char* const content; |
69 }; | 70 }; |
70 | 71 |
71 explicit TemplateURLModel(Profile* profile); | 72 explicit TemplateURLModel(Profile* profile); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 void UnregisterExtensionKeyword(const Extension* extension); | 151 void UnregisterExtensionKeyword(const Extension* extension); |
151 | 152 |
152 // Returns the TemplateURL associated with the keyword for this extension. | 153 // Returns the TemplateURL associated with the keyword for this extension. |
153 // This works by checking the extension ID, not the keyword, so it will work | 154 // This works by checking the extension ID, not the keyword, so it will work |
154 // even if the user changed the keyword. | 155 // even if the user changed the keyword. |
155 const TemplateURL* GetTemplateURLForExtension( | 156 const TemplateURL* GetTemplateURLForExtension( |
156 const Extension* extension) const; | 157 const Extension* extension) const; |
157 | 158 |
158 // Returns the set of URLs describing the keywords. The elements are owned | 159 // Returns the set of URLs describing the keywords. The elements are owned |
159 // by TemplateURLModel and should not be deleted. | 160 // by TemplateURLModel and should not be deleted. |
160 std::vector<const TemplateURL*> GetTemplateURLs() const; | 161 TemplateURLVector GetTemplateURLs() const; |
161 | 162 |
162 // Increment the usage count of a keyword. | 163 // Increment the usage count of a keyword. |
163 // Called when a URL is loaded that was generated from a keyword. | 164 // Called when a URL is loaded that was generated from a keyword. |
164 void IncrementUsageCount(const TemplateURL* url); | 165 void IncrementUsageCount(const TemplateURL* url); |
165 | 166 |
166 // Resets the title, keyword and search url of the specified TemplateURL. | 167 // Resets the title, keyword and search url of the specified TemplateURL. |
167 // The TemplateURL is marked as not replaceable. | 168 // The TemplateURL is marked as not replaceable. |
168 void ResetTemplateURL(const TemplateURL* url, | 169 void ResetTemplateURL(const TemplateURL* url, |
169 const string16& title, | 170 const string16& title, |
170 const string16& keyword, | 171 const string16& keyword, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, TestManagedDefaultSearch); | 252 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, TestManagedDefaultSearch); |
252 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, | 253 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, |
253 UpdateKeywordSearchTermsForURL); | 254 UpdateKeywordSearchTermsForURL); |
254 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, | 255 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, |
255 DontUpdateKeywordSearchForNonReplaceable); | 256 DontUpdateKeywordSearchForNonReplaceable); |
256 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, ChangeGoogleBaseValue); | 257 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, ChangeGoogleBaseValue); |
257 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, MergeDeletesUnusedProviders); | 258 FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, MergeDeletesUnusedProviders); |
258 friend class TemplateURLModelTestUtil; | 259 friend class TemplateURLModelTestUtil; |
259 | 260 |
260 typedef std::map<string16, const TemplateURL*> KeywordToTemplateMap; | 261 typedef std::map<string16, const TemplateURL*> KeywordToTemplateMap; |
261 typedef std::vector<const TemplateURL*> TemplateURLVector; | |
262 | 262 |
263 // Helper functor for FindMatchingKeywords(), for finding the range of | 263 // Helper functor for FindMatchingKeywords(), for finding the range of |
264 // keywords which begin with a prefix. | 264 // keywords which begin with a prefix. |
265 class LessWithPrefix; | 265 class LessWithPrefix; |
266 | 266 |
267 void Init(const Initializer* initializers, int num_initializers); | 267 void Init(const Initializer* initializers, int num_initializers); |
268 | 268 |
269 void RemoveFromMaps(const TemplateURL* template_url); | 269 void RemoveFromMaps(const TemplateURL* template_url); |
270 | 270 |
271 // Removes the supplied template_url from the keyword maps. This searches | 271 // Removes the supplied template_url from the keyword maps. This searches |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 // increasing integer that is initialized from the database. | 426 // increasing integer that is initialized from the database. |
427 TemplateURLID next_id_; | 427 TemplateURLID next_id_; |
428 | 428 |
429 // List of extension IDs waiting for Load to have keywords registered. | 429 // List of extension IDs waiting for Load to have keywords registered. |
430 std::vector<std::string> pending_extension_ids_; | 430 std::vector<std::string> pending_extension_ids_; |
431 | 431 |
432 DISALLOW_COPY_AND_ASSIGN(TemplateURLModel); | 432 DISALLOW_COPY_AND_ASSIGN(TemplateURLModel); |
433 }; | 433 }; |
434 | 434 |
435 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_H_ | 435 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_H_ |
OLD | NEW |