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

Side by Side Diff: chrome/browser/search_engines/template_url_service.cc

Issue 11415292: [Search] No longer reverting omnibox text on instant search (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: indent Created 8 years 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
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 #include "chrome/browser/search_engines/template_url_service.h" 5 #include "chrome/browser/search_engines/template_url_service.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/string_split.h" 16 #include "base/string_split.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_system.h" 21 #include "chrome/browser/extensions/extension_system.h"
22 #include "chrome/browser/google/google_url_tracker.h" 22 #include "chrome/browser/google/google_url_tracker.h"
23 #include "chrome/browser/google/google_util.h"
23 #include "chrome/browser/history/history.h" 24 #include "chrome/browser/history/history.h"
24 #include "chrome/browser/history/history_notifications.h" 25 #include "chrome/browser/history/history_notifications.h"
25 #include "chrome/browser/history/history_service_factory.h" 26 #include "chrome/browser/history/history_service_factory.h"
26 #include "chrome/browser/net/url_fixer_upper.h" 27 #include "chrome/browser/net/url_fixer_upper.h"
27 #include "chrome/browser/prefs/pref_service.h" 28 #include "chrome/browser/prefs/pref_service.h"
28 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/protector/base_setting_change.h" 30 #include "chrome/browser/protector/base_setting_change.h"
30 #include "chrome/browser/protector/protector_service.h" 31 #include "chrome/browser/protector/protector_service.h"
31 #include "chrome/browser/protector/protector_service_factory.h" 32 #include "chrome/browser/protector/protector_service_factory.h"
32 #include "chrome/browser/protector/protector_utils.h" 33 #include "chrome/browser/protector/protector_utils.h"
33 #include "chrome/browser/rlz/rlz.h" 34 #include "chrome/browser/rlz/rlz.h"
34 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 35 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
35 #include "chrome/browser/search_engines/search_terms_data.h" 36 #include "chrome/browser/search_engines/search_terms_data.h"
36 #include "chrome/browser/search_engines/template_url.h" 37 #include "chrome/browser/search_engines/template_url.h"
37 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 38 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
38 #include "chrome/browser/search_engines/template_url_service_observer.h" 39 #include "chrome/browser/search_engines/template_url_service_observer.h"
39 #include "chrome/browser/search_engines/util.h" 40 #include "chrome/browser/search_engines/util.h"
41 #include "chrome/browser/ui/search/search.h"
40 #include "chrome/browser/webdata/web_data_service_factory.h" 42 #include "chrome/browser/webdata/web_data_service_factory.h"
41 #include "chrome/common/chrome_notification_types.h" 43 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
43 #include "chrome/common/env_vars.h" 45 #include "chrome/common/env_vars.h"
44 #include "chrome/common/extensions/extension.h" 46 #include "chrome/common/extensions/extension.h"
45 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
46 #include "chrome/common/url_constants.h" 48 #include "chrome/common/url_constants.h"
47 #include "content/public/browser/notification_service.h" 49 #include "content/public/browser/notification_service.h"
48 #include "extensions/common/constants.h" 50 #include "extensions/common/constants.h"
49 #include "net/base/net_util.h" 51 #include "net/base/net_util.h"
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 LessWithPrefix())); 433 LessWithPrefix()));
432 434
433 // Return vector of matching keywords. 435 // Return vector of matching keywords.
434 for (KeywordToTemplateMap::const_iterator i(match_range.first); 436 for (KeywordToTemplateMap::const_iterator i(match_range.first);
435 i != match_range.second; ++i) { 437 i != match_range.second; ++i) {
436 if (!support_replacement_only || i->second->url_ref().SupportsReplacement()) 438 if (!support_replacement_only || i->second->url_ref().SupportsReplacement())
437 matches->push_back(i->first); 439 matches->push_back(i->first);
438 } 440 }
439 } 441 }
440 442
443 string16 TemplateURLService::TryToExtractSearchTermsFromURL(GURL url) {
sky 2012/12/12 22:41:57 How about making this a function in chrome/browser
Mathieu 2012/12/12 23:37:24 I thought it fit nicely here since it already used
sky 2012/12/13 00:48:18 This uses public state of TemplateURLService. Its
444 TemplateURL *template_url = GetDefaultSearchProvider();
445 if (!template_url)
446 return string16();
447
448 // Ensure instant extended API is enabled and query URL is HTTPS.
449 if (!template_url->profile_ ||
sky 2012/12/12 22:41:57 Why are you using template_url->profile_ instead o
Mathieu 2012/12/12 23:37:24 Done.
450 !chrome::search::IsInstantExtendedAPIEnabled(template_url->profile_) ||
451 !url.SchemeIs(chrome::kHttpsScheme) ||
452 !google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()))
453 return string16();
454
455 string16 result;
456 template_url->ExtractSearchTermsFromURL(url, &result);
457 return result;
458 }
459
441 TemplateURL* TemplateURLService::GetTemplateURLForKeyword( 460 TemplateURL* TemplateURLService::GetTemplateURLForKeyword(
442 const string16& keyword) { 461 const string16& keyword) {
443 KeywordToTemplateMap::const_iterator elem( 462 KeywordToTemplateMap::const_iterator elem(
444 keyword_to_template_map_.find(keyword)); 463 keyword_to_template_map_.find(keyword));
445 if (elem != keyword_to_template_map_.end()) 464 if (elem != keyword_to_template_map_.end())
446 return elem->second; 465 return elem->second;
447 return ((!loaded_ || load_failed_) && 466 return ((!loaded_ || load_failed_) &&
448 initial_default_search_provider_.get() && 467 initial_default_search_provider_.get() &&
449 (initial_default_search_provider_->keyword() == keyword)) ? 468 (initial_default_search_provider_->keyword() == keyword)) ?
450 initial_default_search_provider_.get() : NULL; 469 initial_default_search_provider_.get() : NULL;
(...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 // TODO(mpcomplete): If we allow editing extension keywords, then those 2582 // TODO(mpcomplete): If we allow editing extension keywords, then those
2564 // should be persisted to disk and synced. 2583 // should be persisted to disk and synced.
2565 if (template_url->sync_guid().empty() && 2584 if (template_url->sync_guid().empty() &&
2566 !template_url->IsExtensionKeyword()) { 2585 !template_url->IsExtensionKeyword()) {
2567 template_url->data_.sync_guid = base::GenerateGUID(); 2586 template_url->data_.sync_guid = base::GenerateGUID();
2568 if (service_.get()) 2587 if (service_.get())
2569 service_->UpdateKeyword(template_url->data()); 2588 service_->UpdateKeyword(template_url->data());
2570 } 2589 }
2571 } 2590 }
2572 } 2591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698