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

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

Issue 287103002: Introduce ability to register callback with GoogleURLTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review Created 6 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 #include "chrome/browser/search_engines/template_url_service.h" 5 #include "chrome/browser/search_engines/template_url_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/environment.h" 13 #include "base/environment.h"
14 #include "base/guid.h" 14 #include "base/guid.h"
15 #include "base/i18n/case_conversion.h" 15 #include "base/i18n/case_conversion.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/extensions/extension_service.h" 26 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/google/google_url_tracker.h" 27 #include "chrome/browser/google/google_url_tracker_factory.h"
28 #include "chrome/browser/history/history_notifications.h" 28 #include "chrome/browser/history/history_notifications.h"
29 #include "chrome/browser/history/history_service.h" 29 #include "chrome/browser/history/history_service.h"
30 #include "chrome/browser/history/history_service_factory.h" 30 #include "chrome/browser/history/history_service_factory.h"
31 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/rlz/rlz.h" 32 #include "chrome/browser/rlz/rlz.h"
33 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 33 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
34 #include "chrome/browser/search_engines/search_terms_data.h" 34 #include "chrome/browser/search_engines/search_terms_data.h"
35 #include "chrome/browser/search_engines/template_url.h" 35 #include "chrome/browser/search_engines/template_url.h"
36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
37 #include "chrome/browser/search_engines/template_url_service_observer.h" 37 #include "chrome/browser/search_engines/template_url_service_observer.h"
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; 973 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION;
974 return template_url->AdjustedShortNameForLocaleDirection(); 974 return template_url->AdjustedShortNameForLocaleDirection();
975 } 975 }
976 *is_omnibox_api_extension_keyword = false; 976 *is_omnibox_api_extension_keyword = false;
977 return base::string16(); 977 return base::string16();
978 } 978 }
979 979
980 void TemplateURLService::Observe(int type, 980 void TemplateURLService::Observe(int type,
981 const content::NotificationSource& source, 981 const content::NotificationSource& source,
982 const content::NotificationDetails& details) { 982 const content::NotificationDetails& details) {
983 if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED) { 983 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED);
984 content::Details<history::URLVisitedDetails> visit_details(details); 984 content::Details<history::URLVisitedDetails> visit_details(details);
985 if (!loaded_) 985 if (!loaded_)
986 visits_to_add_.push_back(*visit_details.ptr()); 986 visits_to_add_.push_back(*visit_details.ptr());
987 else 987 else
988 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); 988 UpdateKeywordSearchTermsForURL(*visit_details.ptr());
989 } else {
990 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
991 if (loaded_) {
992 GoogleBaseURLChanged(
993 content::Details<GoogleURLTracker::UpdatedDetails>(details)->first);
994 }
995 }
996 } 989 }
997 990
998 void TemplateURLService::Shutdown() { 991 void TemplateURLService::Shutdown() {
999 // This check has to be done at Shutdown() instead of in the dtor to ensure 992 // This check has to be done at Shutdown() instead of in the dtor to ensure
1000 // that no clients of WebDataService are holding ptrs to it after the first 993 // that no clients of WebDataService are holding ptrs to it after the first
1001 // phase of the KeyedService Shutdown() process. 994 // phase of the KeyedService Shutdown() process.
1002 if (load_handle_) { 995 if (load_handle_) {
1003 DCHECK(service_.get()); 996 DCHECK(service_.get());
1004 service_->CancelRequest(load_handle_); 997 service_->CancelRequest(load_handle_);
1005 } 998 }
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 int num_initializers) { 1494 int num_initializers) {
1502 // Register for notifications. 1495 // Register for notifications.
1503 if (profile_) { 1496 if (profile_) {
1504 // TODO(sky): bug 1166191. The keywords should be moved into the history 1497 // TODO(sky): bug 1166191. The keywords should be moved into the history
1505 // db, which will mean we no longer need this notification and the history 1498 // db, which will mean we no longer need this notification and the history
1506 // backend can handle automatically adding the search terms as the user 1499 // backend can handle automatically adding the search terms as the user
1507 // navigates. 1500 // navigates.
1508 content::Source<Profile> profile_source(profile_->GetOriginalProfile()); 1501 content::Source<Profile> profile_source(profile_->GetOriginalProfile());
1509 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, 1502 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
1510 profile_source); 1503 profile_source);
1511 notification_registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 1504 GoogleURLTracker* google_url_tracker =
1512 profile_source); 1505 GoogleURLTrackerFactory::GetForProfile(profile_);
1506
1507 // GoogleURLTracker is not created in tests.
1508 if (google_url_tracker) {
1509 google_url_updated_subscription_ =
1510 google_url_tracker->RegisterCallback(base::Bind(
1511 &TemplateURLService::OnGoogleURLUpdated, base::Unretained(this)));
1512 }
1513 pref_change_registrar_.Init(GetPrefs()); 1513 pref_change_registrar_.Init(GetPrefs());
1514 pref_change_registrar_.Add( 1514 pref_change_registrar_.Add(
1515 prefs::kSyncedDefaultSearchProviderGUID, 1515 prefs::kSyncedDefaultSearchProviderGUID,
1516 base::Bind( 1516 base::Bind(
1517 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged, 1517 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged,
1518 base::Unretained(this))); 1518 base::Unretained(this)));
1519 } 1519 }
1520 1520
1521 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER; 1521 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER;
1522 TemplateURLData* dse = 1522 TemplateURLData* dse =
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 // need to reset the keyword to an appropriate local value when this 1908 // need to reset the keyword to an appropriate local value when this
1909 // change arrives; see CreateTemplateURLFromTemplateURLAndSyncData(). 1909 // change arrives; see CreateTemplateURLFromTemplateURLAndSyncData().
1910 UpdateNoNotify(t_url, updated_turl, 1910 UpdateNoNotify(t_url, updated_turl,
1911 OldBaseURLSearchTermsData(t_url->profile(), old_base_url.spec())); 1911 OldBaseURLSearchTermsData(t_url->profile(), old_base_url.spec()));
1912 } 1912 }
1913 } 1913 }
1914 if (something_changed) 1914 if (something_changed)
1915 NotifyObservers(); 1915 NotifyObservers();
1916 } 1916 }
1917 1917
1918 void TemplateURLService::OnGoogleURLUpdated(GURL old_url, GURL new_url) {
1919 if (loaded_)
1920 GoogleBaseURLChanged(old_url);
1921 }
1922
1918 void TemplateURLService::OnDefaultSearchChange( 1923 void TemplateURLService::OnDefaultSearchChange(
1919 const TemplateURLData* data, 1924 const TemplateURLData* data,
1920 DefaultSearchManager::Source source) { 1925 DefaultSearchManager::Source source) {
1921 if (GetPrefs() && (source == DefaultSearchManager::FROM_USER) && 1926 if (GetPrefs() && (source == DefaultSearchManager::FROM_USER) &&
1922 ((source != default_search_provider_source_) || 1927 ((source != default_search_provider_source_) ||
1923 !IdenticalSyncGUIDs(data, GetDefaultSearchProvider()))) { 1928 !IdenticalSyncGUIDs(data, GetDefaultSearchProvider()))) {
1924 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, 1929 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID,
1925 data->sync_guid); 1930 data->sync_guid);
1926 } 1931 }
1927 ApplyDefaultSearchChange(data, source); 1932 ApplyDefaultSearchChange(data, source);
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 2495
2491 if (most_recently_intalled_default) { 2496 if (most_recently_intalled_default) {
2492 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2497 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2493 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2498 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2494 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2499 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2495 most_recently_intalled_default->data()); 2500 most_recently_intalled_default->data());
2496 } else { 2501 } else {
2497 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2502 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2498 } 2503 }
2499 } 2504 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.h ('k') | chrome/browser/search_engines/template_url_service_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698