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

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

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years, 1 month 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 "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"
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 // Policy has been updated, so the default search prefs may be different. 912 // Policy has been updated, so the default search prefs may be different.
913 // Reload the default search provider from them. 913 // Reload the default search provider from them.
914 // TODO(pkasting): Rather than communicating via prefs, we should eventually 914 // TODO(pkasting): Rather than communicating via prefs, we should eventually
915 // observe policy changes directly. 915 // observe policy changes directly.
916 UpdateDefaultSearch(); 916 UpdateDefaultSearch();
917 } else if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) { 917 } else if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) {
918 if (loaded_) { 918 if (loaded_) {
919 GoogleBaseURLChanged( 919 GoogleBaseURLChanged(
920 content::Details<GoogleURLTracker::UpdatedDetails>(details)->first); 920 content::Details<GoogleURLTracker::UpdatedDetails>(details)->first);
921 } 921 }
922 } else if (type == chrome::NOTIFICATION_PREF_CHANGED) {
923 // Listen for changes to the default search from Sync.
924 DCHECK_EQ(std::string(prefs::kSyncedDefaultSearchProviderGUID),
925 *content::Details<std::string>(details).ptr());
926 PrefService* prefs = GetPrefs();
927 TemplateURL* new_default_search = GetTemplateURLForGUID(
928 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID));
929 if (new_default_search && !is_default_search_managed_) {
930 if (new_default_search != GetDefaultSearchProvider()) {
931 AutoReset<DefaultSearchChangeOrigin> change_origin(
932 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF);
933 SetDefaultSearchProvider(new_default_search);
934 pending_synced_default_search_ = false;
935 }
936 } else {
937 // If it's not there, or if default search is currently managed, set a
938 // flag to indicate that we waiting on the search engine entry to come
939 // in through Sync.
940 pending_synced_default_search_ = true;
941 }
942 UpdateDefaultSearch();
943 } else { 922 } else {
944 NOTREACHED(); 923 NOTREACHED();
945 } 924 }
946 } 925 }
947 926
927 void TemplateURLService::OnPreferenceChanged(PrefServiceBase* service,
928 const std::string& pref_name) {
929 // Listen for changes to the default search from Sync.
930 DCHECK_EQ(prefs::kSyncedDefaultSearchProviderGUID, pref_name);
931 PrefService* prefs = GetPrefs();
932 TemplateURL* new_default_search = GetTemplateURLForGUID(
933 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID));
934 if (new_default_search && !is_default_search_managed_) {
935 if (new_default_search != GetDefaultSearchProvider()) {
936 AutoReset<DefaultSearchChangeOrigin> change_origin(
937 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF);
938 SetDefaultSearchProvider(new_default_search);
939 pending_synced_default_search_ = false;
940 }
941 } else {
942 // If it's not there, or if default search is currently managed, set a
943 // flag to indicate that we waiting on the search engine entry to come
944 // in through Sync.
945 pending_synced_default_search_ = true;
946 }
947 UpdateDefaultSearch();
948 }
949
948 syncer::SyncDataList TemplateURLService::GetAllSyncData( 950 syncer::SyncDataList TemplateURLService::GetAllSyncData(
949 syncer::ModelType type) const { 951 syncer::ModelType type) const {
950 DCHECK_EQ(syncer::SEARCH_ENGINES, type); 952 DCHECK_EQ(syncer::SEARCH_ENGINES, type);
951 953
952 syncer::SyncDataList current_data; 954 syncer::SyncDataList current_data;
953 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); 955 for (TemplateURLVector::const_iterator iter = template_urls_.begin();
954 iter != template_urls_.end(); ++iter) { 956 iter != template_urls_.end(); ++iter) {
955 // We don't sync extension keywords. 957 // We don't sync extension keywords.
956 // TODO(mpcomplete): If we allow editing extension keywords, then those 958 // TODO(mpcomplete): If we allow editing extension keywords, then those
957 // should be persisted to disk and synced. 959 // should be persisted to disk and synced.
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 // TODO(mpcomplete): If we allow editing extension keywords, then those 2545 // TODO(mpcomplete): If we allow editing extension keywords, then those
2544 // should be persisted to disk and synced. 2546 // should be persisted to disk and synced.
2545 if (template_url->sync_guid().empty() && 2547 if (template_url->sync_guid().empty() &&
2546 !template_url->IsExtensionKeyword()) { 2548 !template_url->IsExtensionKeyword()) {
2547 template_url->data_.sync_guid = base::GenerateGUID(); 2549 template_url->data_.sync_guid = base::GenerateGUID();
2548 if (service_.get()) 2550 if (service_.get())
2549 service_->UpdateKeyword(template_url->data()); 2551 service_->UpdateKeyword(template_url->data());
2550 } 2552 }
2551 } 2553 }
2552 } 2554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698