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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/environment.h" 9 #include "base/environment.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/search_engines/util.h" 31 #include "chrome/browser/search_engines/util.h"
32 #include "chrome/browser/sync/api/sync_change.h" 32 #include "chrome/browser/sync/api/sync_change.h"
33 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h" 33 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h"
34 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
35 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/env_vars.h" 36 #include "chrome/common/env_vars.h"
37 #include "chrome/common/extensions/extension.h" 37 #include "chrome/common/extensions/extension.h"
38 #include "chrome/common/guid.h" 38 #include "chrome/common/guid.h"
39 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
40 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
41 #include "content/common/notification_service.h" 41 #include "content/public/browser/notification_service.h"
42 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
43 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
44 44
45 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet; 45 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
46 typedef TemplateURLService::SyncDataMap SyncDataMap; 46 typedef TemplateURLService::SyncDataMap SyncDataMap;
47 47
48 namespace { 48 namespace {
49 49
50 // String in the URL that is replaced by the search term. 50 // String in the URL that is replaced by the search term.
51 const char kSearchTermParameter[] = "{searchTerms}"; 51 const char kSearchTermParameter[] = "{searchTerms}";
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 // db, which will mean we no longer need this notification and the history 920 // db, which will mean we no longer need this notification and the history
921 // backend can handle automatically adding the search terms as the user 921 // backend can handle automatically adding the search terms as the user
922 // navigates. 922 // navigates.
923 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, 923 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
924 content::Source<Profile>(profile_->GetOriginalProfile())); 924 content::Source<Profile>(profile_->GetOriginalProfile()));
925 PrefService* prefs = GetPrefs(); 925 PrefService* prefs = GetPrefs();
926 default_search_prefs_.reset( 926 default_search_prefs_.reset(
927 PrefSetObserver::CreateDefaultSearchPrefSetObserver(prefs, this)); 927 PrefSetObserver::CreateDefaultSearchPrefSetObserver(prefs, this));
928 } 928 }
929 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 929 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
930 NotificationService::AllSources()); 930 content::NotificationService::AllSources());
931 931
932 if (num_initializers > 0) { 932 if (num_initializers > 0) {
933 // This path is only hit by test code and is used to simulate a loaded 933 // This path is only hit by test code and is used to simulate a loaded
934 // TemplateURLService. 934 // TemplateURLService.
935 ChangeToLoadedState(); 935 ChangeToLoadedState();
936 936
937 // Add specific initializers, if any. 937 // Add specific initializers, if any.
938 for (int i(0); i < num_initializers; ++i) { 938 for (int i(0); i < num_initializers; ++i) {
939 DCHECK(initializers[i].keyword); 939 DCHECK(initializers[i].keyword);
940 DCHECK(initializers[i].url); 940 DCHECK(initializers[i].url);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 1036
1037 void TemplateURLService::ChangeToLoadedState() { 1037 void TemplateURLService::ChangeToLoadedState() {
1038 DCHECK(!loaded_); 1038 DCHECK(!loaded_);
1039 1039
1040 UIThreadSearchTermsData search_terms_data; 1040 UIThreadSearchTermsData search_terms_data;
1041 provider_map_.Init(template_urls_, search_terms_data); 1041 provider_map_.Init(template_urls_, search_terms_data);
1042 loaded_ = true; 1042 loaded_ = true;
1043 } 1043 }
1044 1044
1045 void TemplateURLService::NotifyLoaded() { 1045 void TemplateURLService::NotifyLoaded() {
1046 NotificationService::current()->Notify( 1046 content::NotificationService::current()->Notify(
1047 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 1047 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
1048 content::Source<TemplateURLService>(this), 1048 content::Source<TemplateURLService>(this),
1049 NotificationService::NoDetails()); 1049 content::NotificationService::NoDetails());
1050 1050
1051 for (size_t i = 0; i < pending_extension_ids_.size(); ++i) { 1051 for (size_t i = 0; i < pending_extension_ids_.size(); ++i) {
1052 const Extension* extension = profile_->GetExtensionService()-> 1052 const Extension* extension = profile_->GetExtensionService()->
1053 GetExtensionById(pending_extension_ids_[i], true); 1053 GetExtensionById(pending_extension_ids_[i], true);
1054 if (extension) 1054 if (extension)
1055 RegisterExtensionKeyword(extension); 1055 RegisterExtensionKeyword(extension);
1056 } 1056 }
1057 pending_extension_ids_.clear(); 1057 pending_extension_ids_.clear();
1058 } 1058 }
1059 1059
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 1545
1546 if (service_.get()) 1546 if (service_.get())
1547 service_->RemoveKeyword(*template_url); 1547 service_->RemoveKeyword(*template_url);
1548 1548
1549 // Inform sync of the deletion. 1549 // Inform sync of the deletion.
1550 ProcessTemplateURLChange(template_url, SyncChange::ACTION_DELETE); 1550 ProcessTemplateURLChange(template_url, SyncChange::ACTION_DELETE);
1551 1551
1552 if (profile_) { 1552 if (profile_) {
1553 content::Source<Profile> source(profile_); 1553 content::Source<Profile> source(profile_);
1554 TemplateURLID id = template_url->id(); 1554 TemplateURLID id = template_url->id();
1555 NotificationService::current()->Notify( 1555 content::NotificationService::current()->Notify(
1556 chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, 1556 chrome::NOTIFICATION_TEMPLATE_URL_REMOVED,
1557 source, 1557 source,
1558 content::Details<TemplateURLID>(&id)); 1558 content::Details<TemplateURLID>(&id));
1559 } 1559 }
1560 1560
1561 // We own the TemplateURL and need to delete it. 1561 // We own the TemplateURL and need to delete it.
1562 delete template_url; 1562 delete template_url;
1563 } 1563 }
1564 1564
1565 void TemplateURLService::NotifyObservers() { 1565 void TemplateURLService::NotifyObservers() {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } else { 1714 } else {
1715 // Change the local TURL's GUID to the server's GUID and push an update to 1715 // Change the local TURL's GUID to the server's GUID and push an update to
1716 // Sync. This ensures that the rest of local_url's fields are sync'd up to 1716 // Sync. This ensures that the rest of local_url's fields are sync'd up to
1717 // the server, and the next time local_url is synced, it is recognized by 1717 // the server, and the next time local_url is synced, it is recognized by
1718 // having the same GUID. 1718 // having the same GUID.
1719 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); 1719 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid());
1720 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); 1720 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl);
1721 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); 1721 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data));
1722 } 1722 }
1723 } 1723 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698