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

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

Issue 7230053: Modify TemplateURLRef to remove unknown URL parameters, but only when it represents a prepopulate... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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) 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_H_ 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // {google:baseURL} or {google:baseSuggestURL}. 128 // {google:baseURL} or {google:baseSuggestURL}.
129 bool HasGoogleBaseURLs() const; 129 bool HasGoogleBaseURLs() const;
130 130
131 // Returns true if both refs are NULL or have the same values. 131 // Returns true if both refs are NULL or have the same values.
132 static bool SameUrlRefs(const TemplateURLRef* ref1, 132 static bool SameUrlRefs(const TemplateURLRef* ref1,
133 const TemplateURLRef* ref2); 133 const TemplateURLRef* ref2);
134 134
135 // Collects metrics whether searches through Google are sent with RLZ string. 135 // Collects metrics whether searches through Google are sent with RLZ string.
136 void CollectRLZMetrics() const; 136 void CollectRLZMetrics() const;
137 137
138 // Sets whether this URL is pre-populated or not.
139 void set_prepopulated(bool prepopulated) { prepopulated_ = prepopulated; }
140
138 private: 141 private:
139 friend class SearchHostToURLsMapTest; 142 friend class SearchHostToURLsMapTest;
140 friend class TemplateURL; 143 friend class TemplateURL;
141 friend class TemplateURLServiceTestUtil; 144 friend class TemplateURLServiceTestUtil;
142 friend class TemplateURLTest; 145 friend class TemplateURLTest;
146 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse);
143 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); 147 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown);
144 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); 148 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown);
145 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterReallyUnknown);
146 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); 149 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty);
147 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); 150 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd);
148 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); 151 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters);
149 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); 152 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters);
150 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNestedParameter); 153 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNestedParameter);
151 154
152 // Enumeration of the known types. 155 // Enumeration of the known types.
153 enum ReplacementType { 156 enum ReplacementType {
154 ENCODING, 157 ENCODING,
155 GOOGLE_ACCEPTED_SUGGESTION, 158 GOOGLE_ACCEPTED_SUGGESTION,
(...skipping 24 matching lines...) Expand all
180 // Resets the url. 183 // Resets the url.
181 void Set(const std::string& url, int index_offset, int page_offset); 184 void Set(const std::string& url, int index_offset, int page_offset);
182 185
183 // Parses the parameter in url at the specified offset. start/end specify the 186 // Parses the parameter in url at the specified offset. start/end specify the
184 // range of the parameter in the url, including the braces. If the parameter 187 // range of the parameter in the url, including the braces. If the parameter
185 // is valid, url is updated to reflect the appropriate parameter. If 188 // is valid, url is updated to reflect the appropriate parameter. If
186 // the parameter is one of the known parameters an element is added to 189 // the parameter is one of the known parameters an element is added to
187 // replacements indicating the type and range of the element. The original 190 // replacements indicating the type and range of the element. The original
188 // parameter is erased from the url. 191 // parameter is erased from the url.
189 // 192 //
190 // If the parameter is not a known parameter, it's not erased and false is 193 // If the parameter is not a known parameter, false is returned. If this is a
191 // returned. 194 // prepopulated URL, the parameter is erased, otherwise it is left alone.
192 bool ParseParameter(size_t start, 195 bool ParseParameter(size_t start,
193 size_t end, 196 size_t end,
194 std::string* url, 197 std::string* url,
195 Replacements* replacements) const; 198 Replacements* replacements) const;
196 199
197 // Parses the specified url, replacing parameters as necessary. If 200 // Parses the specified url, replacing parameters as necessary. If
198 // successful, valid is set to true, and the parsed url is returned. For all 201 // successful, valid is set to true, and the parsed url is returned. For all
199 // known parameters that are encountered an entry is added to replacements. 202 // known parameters that are encountered an entry is added to replacements.
200 // If there is an error parsing the url, valid is set to false, and an empty 203 // If there is an error parsing the url, valid is set to false, and an empty
201 // string is returned. 204 // string is returned.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 248
246 // The replaceable parts of url (parsed_url_). These are ordered by index 249 // The replaceable parts of url (parsed_url_). These are ordered by index
247 // into the string, and may be empty. 250 // into the string, and may be empty.
248 mutable Replacements replacements_; 251 mutable Replacements replacements_;
249 252
250 // Host, path and key of the search term. These are only set if the url 253 // Host, path and key of the search term. These are only set if the url
251 // contains one search term. 254 // contains one search term.
252 mutable std::string host_; 255 mutable std::string host_;
253 mutable std::string path_; 256 mutable std::string path_;
254 mutable std::string search_term_key_; 257 mutable std::string search_term_key_;
258
259 // Whether the contained URL is a pre-populated URL.
260 bool prepopulated_;
255 }; 261 };
256 262
257 // Describes the relevant portions of a single OSD document. 263 // Describes the relevant portions of a single OSD document.
258 class TemplateURL { 264 class TemplateURL {
259 public: 265 public:
260 // Describes a single image reference. Each TemplateURL may have 266 // Describes a single image reference. Each TemplateURL may have
261 // any number (including 0) of ImageRefs. 267 // any number (including 0) of ImageRefs.
262 // 268 //
263 // If a TemplateURL has no images, the favicon for the generated URL 269 // If a TemplateURL has no images, the favicon for the generated URL
264 // should be used. 270 // should be used.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 473 }
468 474
469 void set_logo_id(int logo_id) { logo_id_ = logo_id; } 475 void set_logo_id(int logo_id) { logo_id_ = logo_id; }
470 int logo_id() const { return logo_id_; } 476 int logo_id() const { return logo_id_; }
471 477
472 // Returns the unique identifier of this TemplateURL. The unique ID is set 478 // Returns the unique identifier of this TemplateURL. The unique ID is set
473 // by the TemplateURLService when the TemplateURL is added to it. 479 // by the TemplateURLService when the TemplateURL is added to it.
474 TemplateURLID id() const { return id_; } 480 TemplateURLID id() const { return id_; }
475 481
476 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0. 482 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0.
477 void set_prepopulate_id(int id) { prepopulate_id_ = id; } 483 // SetPrepopulateId also sets any TemplateURLRef's prepopulated flag to true
484 // if |id| > 0 and false otherwise.
485 void SetPrepopulateId(int id);
478 int prepopulate_id() const { return prepopulate_id_; } 486 int prepopulate_id() const { return prepopulate_id_; }
479 487
480 std::string GetExtensionId() const; 488 std::string GetExtensionId() const;
481 bool IsExtensionKeyword() const; 489 bool IsExtensionKeyword() const;
482 490
483 private: 491 private:
484 friend void MergeEnginesFromPrepopulateData( 492 friend void MergeEnginesFromPrepopulateData(
485 PrefService* prefs, 493 PrefService* prefs,
486 WebDataService* service, 494 WebDataService* service,
487 std::vector<TemplateURL*>* template_urls, 495 std::vector<TemplateURL*>* template_urls,
488 const TemplateURL** default_search_provider); 496 const TemplateURL** default_search_provider);
489 friend class KeywordTable; 497 friend class KeywordTable;
490 friend class KeywordTableTest; 498 friend class KeywordTableTest;
491 friend class SearchHostToURLsMap; 499 friend class SearchHostToURLsMap;
492 friend class TemplateURLService; 500 friend class TemplateURLService;
493 501
494 // Invalidates cached values on this object and its child TemplateURLRefs. 502 // Invalidates cached values on this object and its child TemplateURLRefs.
495 void InvalidateCachedValues() const; 503 void InvalidateCachedValues() const;
496 504
505 // Sets all TemplateURLRefs prepopulated flags.
506 void SetTemplateURLRefsPrepopulated(bool prepopulated);
507
497 // Unique identifier, used when archived to the database. 508 // Unique identifier, used when archived to the database.
498 void set_id(TemplateURLID id) { id_ = id; } 509 void set_id(TemplateURLID id) { id_ = id; }
499 510
500 string16 short_name_; 511 string16 short_name_;
501 string16 description_; 512 string16 description_;
502 TemplateURLRef suggestions_url_; 513 TemplateURLRef suggestions_url_;
503 TemplateURLRef url_; 514 TemplateURLRef url_;
504 TemplateURLRef instant_url_; 515 TemplateURLRef instant_url_;
505 GURL originating_url_; 516 GURL originating_url_;
506 mutable string16 keyword_; 517 mutable string16 keyword_;
(...skipping 14 matching lines...) Expand all
521 bool created_by_policy_; 532 bool created_by_policy_;
522 int usage_count_; 533 int usage_count_;
523 SearchEngineType search_engine_type_; 534 SearchEngineType search_engine_type_;
524 int logo_id_; 535 int logo_id_;
525 int prepopulate_id_; 536 int prepopulate_id_;
526 537
527 // TODO(sky): Add date last parsed OSD file. 538 // TODO(sky): Add date last parsed OSD file.
528 }; 539 };
529 540
530 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 541 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698