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

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: 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.h"
28 #include "chrome/browser/google/google_url_tracker_factory.h"
28 #include "chrome/browser/history/history_notifications.h" 29 #include "chrome/browser/history/history_notifications.h"
29 #include "chrome/browser/history/history_service.h" 30 #include "chrome/browser/history/history_service.h"
30 #include "chrome/browser/history/history_service_factory.h" 31 #include "chrome/browser/history/history_service_factory.h"
31 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/rlz/rlz.h" 33 #include "chrome/browser/rlz/rlz.h"
33 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 34 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
34 #include "chrome/browser/search_engines/search_terms_data.h" 35 #include "chrome/browser/search_engines/search_terms_data.h"
35 #include "chrome/browser/search_engines/template_url.h" 36 #include "chrome/browser/search_engines/template_url.h"
36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 37 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
37 #include "chrome/browser/search_engines/template_url_service_observer.h" 38 #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; 974 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION;
974 return template_url->AdjustedShortNameForLocaleDirection(); 975 return template_url->AdjustedShortNameForLocaleDirection();
975 } 976 }
976 *is_omnibox_api_extension_keyword = false; 977 *is_omnibox_api_extension_keyword = false;
977 return base::string16(); 978 return base::string16();
978 } 979 }
979 980
980 void TemplateURLService::Observe(int type, 981 void TemplateURLService::Observe(int type,
981 const content::NotificationSource& source, 982 const content::NotificationSource& source,
982 const content::NotificationDetails& details) { 983 const content::NotificationDetails& details) {
983 if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED) { 984 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED);
984 content::Details<history::URLVisitedDetails> visit_details(details); 985 content::Details<history::URLVisitedDetails> visit_details(details);
985 if (!loaded_) 986 if (!loaded_)
986 visits_to_add_.push_back(*visit_details.ptr()); 987 visits_to_add_.push_back(*visit_details.ptr());
987 else 988 else
988 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); 989 UpdateKeywordSearchTermsForURL(*visit_details.ptr());
989 } else { 990 }
990 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); 991
991 if (loaded_) { 992 void TemplateURLService::OnGoogleURLUpdated(GURL old_url, GURL new_url) {
992 GoogleBaseURLChanged( 993 if (loaded_) {
993 content::Details<GoogleURLTracker::UpdatedDetails>(details)->first); 994 GoogleBaseURLChanged(old_url);
994 }
995 } 995 }
996 } 996 }
997 997
998 void TemplateURLService::Shutdown() { 998 void TemplateURLService::Shutdown() {
999 // This check has to be done at Shutdown() instead of in the dtor to ensure 999 // 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 1000 // that no clients of WebDataService are holding ptrs to it after the first
1001 // phase of the KeyedService Shutdown() process. 1001 // phase of the KeyedService Shutdown() process.
1002 if (load_handle_) { 1002 if (load_handle_) {
1003 DCHECK(service_.get()); 1003 DCHECK(service_.get());
1004 service_->CancelRequest(load_handle_); 1004 service_->CancelRequest(load_handle_);
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 int num_initializers) { 1501 int num_initializers) {
1502 // Register for notifications. 1502 // Register for notifications.
1503 if (profile_) { 1503 if (profile_) {
1504 // TODO(sky): bug 1166191. The keywords should be moved into the history 1504 // 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 1505 // 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 1506 // backend can handle automatically adding the search terms as the user
1507 // navigates. 1507 // navigates.
1508 content::Source<Profile> profile_source(profile_->GetOriginalProfile()); 1508 content::Source<Profile> profile_source(profile_->GetOriginalProfile());
1509 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, 1509 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
1510 profile_source); 1510 profile_source);
1511 notification_registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 1511 GoogleURLTracker* google_url_tracker =
1512 profile_source); 1512 GoogleURLTrackerFactory::GetForProfile(profile_);
1513 if (google_url_tracker) {
1514 google_url_updated_subscription_ =
1515 google_url_tracker->RegisterCallback(base::Bind(
1516 &TemplateURLService::OnGoogleURLUpdated, base::Unretained(this)));
1517 }
1513 pref_change_registrar_.Init(GetPrefs()); 1518 pref_change_registrar_.Init(GetPrefs());
1514 pref_change_registrar_.Add( 1519 pref_change_registrar_.Add(
1515 prefs::kSyncedDefaultSearchProviderGUID, 1520 prefs::kSyncedDefaultSearchProviderGUID,
1516 base::Bind( 1521 base::Bind(
1517 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged, 1522 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged,
1518 base::Unretained(this))); 1523 base::Unretained(this)));
1519 } 1524 }
1520 1525
1521 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER; 1526 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER;
1522 TemplateURLData* dse = 1527 TemplateURLData* dse =
(...skipping 967 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

Powered by Google App Engine
This is Rietveld 408576698