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

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

Powered by Google App Engine
This is Rietveld 408576698