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

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

Issue 10381016: Remove the "autogenerate keyword" bit on TemplateURL. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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) 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_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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // whatever fields are desired, then create an immutable TemplateURL from it. 231 // whatever fields are desired, then create an immutable TemplateURL from it.
232 struct TemplateURLData { 232 struct TemplateURLData {
233 TemplateURLData(); 233 TemplateURLData();
234 ~TemplateURLData(); 234 ~TemplateURLData();
235 235
236 // A short description of the template. This is the name we show to the user 236 // A short description of the template. This is the name we show to the user
237 // in various places that use TemplateURLs. For example, the location bar 237 // in various places that use TemplateURLs. For example, the location bar
238 // shows this when the user selects a substituting match. 238 // shows this when the user selects a substituting match.
239 string16 short_name; 239 string16 short_name;
240 240
241 // The shortcut for this TemplateURL. May be empty. 241 // The shortcut for this TemplateURL. |keyword| must be non-empty.
242 void SetKeyword(const string16& keyword); 242 void SetKeyword(const string16& keyword);
243 const string16& keyword(TemplateURL* t_url) const; 243 const string16& keyword() const { return keyword_; }
244 // TODO(pkasting): This should only be necessary until we eliminate keyword
245 // autogeneration.
246 const string16& raw_keyword() const { return keyword_; }
247
248 // Whether to autogenerate a keyword in TemplateURL::GetKeyword(). Most
249 // consumers should not need this.
250 // NOTE: Calling SetKeyword() turns this back off. Manual and automatic
251 // keywords are mutually exclusive.
252 void SetAutogenerateKeyword(bool autogenerate_keyword);
253 bool autogenerate_keyword() const { return autogenerate_keyword_; }
254
255 // Ensures that the keyword is generated. Most consumers should not need this
256 // because it is done automatically. Use this method on the UI thread, so
257 // the keyword may be accessed on another thread.
258 void EnsureKeyword(TemplateURL* t_url) const;
259 244
260 // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because 245 // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because
261 // it requires substitutions first). This must be non-empty. 246 // it requires substitutions first). This must be non-empty.
262 void SetURL(const std::string& url); 247 void SetURL(const std::string& url);
263 const std::string& url() const { return url_; } 248 const std::string& url() const { return url_; }
264 249
265 // Optional additional raw URLs. 250 // Optional additional raw URLs.
266 std::string suggestions_url; 251 std::string suggestions_url;
267 std::string instant_url; 252 std::string instant_url;
268 253
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0. 303 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0.
319 int prepopulate_id; 304 int prepopulate_id;
320 305
321 // The primary unique identifier for Sync. This set on all TemplateURLs 306 // The primary unique identifier for Sync. This set on all TemplateURLs
322 // regardless of whether they have been associated with Sync. 307 // regardless of whether they have been associated with Sync.
323 std::string sync_guid; 308 std::string sync_guid;
324 309
325 private: 310 private:
326 // Private so we can enforce using the setters and thus enforce that these 311 // Private so we can enforce using the setters and thus enforce that these
327 // fields are never empty. 312 // fields are never empty.
328 // TODO(pkasting): |keyword_| is temporarily still allowed to be empty. 313 string16 keyword_;
329 mutable string16 keyword_;
330 std::string url_; 314 std::string url_;
331
332 // TODO(pkasting): These fields will go away soon.
333 bool autogenerate_keyword_;
334 // True if the keyword was generated. This is used to avoid multiple attempts
335 // if generating a keyword failed.
336 mutable bool keyword_generated_;
337 }; 315 };
338 316
339 317
340 // TemplateURL ---------------------------------------------------------------- 318 // TemplateURL ----------------------------------------------------------------
341 319
342 // A TemplateURL represents a single "search engine", defined primarily as a 320 // A TemplateURL represents a single "search engine", defined primarily as a
343 // subset of the Open Search Description Document 321 // subset of the Open Search Description Document
344 // (http://www.opensearch.org/Specifications/OpenSearch) plus some extensions. 322 // (http://www.opensearch.org/Specifications/OpenSearch) plus some extensions.
345 // One TemplateURL contains several TemplateURLRefs, which correspond to various 323 // One TemplateURL contains several TemplateURLRefs, which correspond to various
346 // different capabilities (e.g. doing searches or getting suggestions), as well 324 // different capabilities (e.g. doing searches or getting suggestions), as well
(...skipping 18 matching lines...) Expand all
365 static GURL GenerateFaviconURL(const GURL& url); 343 static GURL GenerateFaviconURL(const GURL& url);
366 344
367 Profile* profile() { return profile_; } 345 Profile* profile() { return profile_; }
368 const TemplateURLData& data() const { return data_; } 346 const TemplateURLData& data() const { return data_; }
369 347
370 const string16& short_name() const { return data_.short_name; } 348 const string16& short_name() const { return data_.short_name; }
371 // An accessor for the short_name, but adjusted so it can be appropriately 349 // An accessor for the short_name, but adjusted so it can be appropriately
372 // displayed even if it is LTR and the UI is RTL. 350 // displayed even if it is LTR and the UI is RTL.
373 string16 AdjustedShortNameForLocaleDirection() const; 351 string16 AdjustedShortNameForLocaleDirection() const;
374 352
375 const string16& keyword() const { 353 const string16& keyword() const { return data_.keyword(); }
376 // TODO(pkasting): See comment on EnsureKeyword() below.
377 return data_.keyword(const_cast<TemplateURL*>(this));
378 }
379 bool autogenerate_keyword() const {
380 return data_.autogenerate_keyword();
381 }
382 void EnsureKeyword() const {
383 // TODO(pkasting): EnsureKeyword() will die soon so it's not worth jumping
384 // through hoops to fix this const_cast<>().
385 data_.EnsureKeyword(const_cast<TemplateURL*>(this));
386 }
387 354
388 const std::string& url() const { return data_.url(); } 355 const std::string& url() const { return data_.url(); }
389 const std::string& suggestions_url() const { return data_.suggestions_url; } 356 const std::string& suggestions_url() const { return data_.suggestions_url; }
390 const std::string& instant_url() const { return data_.instant_url; } 357 const std::string& instant_url() const { return data_.instant_url; }
391 const GURL& favicon_url() const { return data_.favicon_url; } 358 const GURL& favicon_url() const { return data_.favicon_url; }
392 359
393 const GURL& originating_url() const { return data_.originating_url; } 360 const GURL& originating_url() const { return data_.originating_url; }
394 361
395 bool show_in_default_list() const { return data_.show_in_default_list; } 362 bool show_in_default_list() const { return data_.show_in_default_list; }
396 // Returns true if show_in_default_list() is true and this TemplateURL has a 363 // Returns true if show_in_default_list() is true and this TemplateURL has a
(...skipping 25 matching lines...) Expand all
422 } 389 }
423 const TemplateURLRef& instant_url_ref() const { return instant_url_ref_; } 390 const TemplateURLRef& instant_url_ref() const { return instant_url_ref_; }
424 391
425 // Returns true if |url| supports replacement. 392 // Returns true if |url| supports replacement.
426 bool SupportsReplacement() const; 393 bool SupportsReplacement() const;
427 394
428 // Like SupportsReplacement but usable on threads other than the UI thread. 395 // Like SupportsReplacement but usable on threads other than the UI thread.
429 bool SupportsReplacementUsingTermsData( 396 bool SupportsReplacementUsingTermsData(
430 const SearchTermsData& search_terms_data) const; 397 const SearchTermsData& search_terms_data) const;
431 398
399 // Returns true if this TemplateURL uses Google base URLs and has a keyword
400 // of "google.TLD". We use this to decide whether we can automatically
401 // update the keyword to reflect the current Google base URL TLD.
402 bool IsGoogleSearchURLWithReplaceableKeyword() const;
403
432 std::string GetExtensionId() const; 404 std::string GetExtensionId() const;
433 bool IsExtensionKeyword() const; 405 bool IsExtensionKeyword() const;
434 406
435 private: 407 private:
436 friend class TemplateURLService; 408 friend class TemplateURLService;
437 409
438 void SetURL(const std::string& url); 410 void SetURL(const std::string& url);
439 void SetPrepopulateId(int id); 411 void SetPrepopulateId(int id);
440 412
413 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|.
SteveT 2012/05/07 18:17:47 Would it be more clear here to state that "resetti
Peter Kasting 2012/05/07 19:39:14 Added some comments.
414 // The |force| parameter is useful when the existing keyword is known to be
415 // a placeholder.
416 void ResetKeywordIfNecessary(bool force);
417
441 // Invalidates cached values on this object and its child TemplateURLRefs. 418 // Invalidates cached values on this object and its child TemplateURLRefs.
442 void InvalidateCachedValues(); 419 void InvalidateCachedValues();
443 420
444 Profile* profile_; 421 Profile* profile_;
445 TemplateURLData data_; 422 TemplateURLData data_;
446 TemplateURLRef url_ref_; 423 TemplateURLRef url_ref_;
447 TemplateURLRef suggestions_url_ref_; 424 TemplateURLRef suggestions_url_ref_;
448 TemplateURLRef instant_url_ref_; 425 TemplateURLRef instant_url_ref_;
449 426
450 // TODO(sky): Add date last parsed OSD file. 427 // TODO(sky): Add date last parsed OSD file.
451 }; 428 };
452 429
453 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 430 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698