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

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 + fix for instant unittests 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 if (google_url_tracker) {
1507 google_url_updated_subscription_ =
1508 google_url_tracker->RegisterCallback(base::Bind(
1509 &TemplateURLService::OnGoogleURLUpdated, base::Unretained(this)));
1510 }
1513 pref_change_registrar_.Init(GetPrefs()); 1511 pref_change_registrar_.Init(GetPrefs());
1514 pref_change_registrar_.Add( 1512 pref_change_registrar_.Add(
1515 prefs::kSyncedDefaultSearchProviderGUID, 1513 prefs::kSyncedDefaultSearchProviderGUID,
1516 base::Bind( 1514 base::Bind(
1517 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged, 1515 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged,
1518 base::Unretained(this))); 1516 base::Unretained(this)));
1519 } 1517 }
1520 1518
1521 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER; 1519 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER;
1522 TemplateURLData* dse = 1520 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 1906 // need to reset the keyword to an appropriate local value when this
1909 // change arrives; see CreateTemplateURLFromTemplateURLAndSyncData(). 1907 // change arrives; see CreateTemplateURLFromTemplateURLAndSyncData().
1910 UpdateNoNotify(t_url, updated_turl, 1908 UpdateNoNotify(t_url, updated_turl,
1911 OldBaseURLSearchTermsData(t_url->profile(), old_base_url.spec())); 1909 OldBaseURLSearchTermsData(t_url->profile(), old_base_url.spec()));
1912 } 1910 }
1913 } 1911 }
1914 if (something_changed) 1912 if (something_changed)
1915 NotifyObservers(); 1913 NotifyObservers();
1916 } 1914 }
1917 1915
1916 void TemplateURLService::OnGoogleURLUpdated(GURL old_url, GURL new_url) {
1917 if (loaded_) {
Peter Kasting 2014/05/16 22:24:23 Nit: No {}
1918 GoogleBaseURLChanged(old_url);
1919 }
1920 }
1921
1918 void TemplateURLService::OnDefaultSearchChange( 1922 void TemplateURLService::OnDefaultSearchChange(
1919 const TemplateURLData* data, 1923 const TemplateURLData* data,
1920 DefaultSearchManager::Source source) { 1924 DefaultSearchManager::Source source) {
1921 if (GetPrefs() && (source == DefaultSearchManager::FROM_USER) && 1925 if (GetPrefs() && (source == DefaultSearchManager::FROM_USER) &&
1922 ((source != default_search_provider_source_) || 1926 ((source != default_search_provider_source_) ||
1923 !IdenticalSyncGUIDs(data, GetDefaultSearchProvider()))) { 1927 !IdenticalSyncGUIDs(data, GetDefaultSearchProvider()))) {
1924 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, 1928 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID,
1925 data->sync_guid); 1929 data->sync_guid);
1926 } 1930 }
1927 ApplyDefaultSearchChange(data, source); 1931 ApplyDefaultSearchChange(data, source);
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 2494
2491 if (most_recently_intalled_default) { 2495 if (most_recently_intalled_default) {
2492 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2496 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2493 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2497 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2494 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2498 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2495 most_recently_intalled_default->data()); 2499 most_recently_intalled_default->data());
2496 } else { 2500 } else {
2497 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2501 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2498 } 2502 }
2499 } 2503 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698