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

Side by Side Diff: chrome/browser/profile_resetter/profile_resetter.cc

Issue 23710022: Convert NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED to CallbackList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/profile_resetter/profile_resetter.h" 5 #include "chrome/browser/profile_resetter/profile_resetter.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/browsing_data/browsing_data_helper.h" 8 #include "chrome/browser/browsing_data/browsing_data_helper.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/extensions/management_policy.h" 12 #include "chrome/browser/extensions/management_policy.h"
14 #include "chrome/browser/google/google_url_tracker.h" 13 #include "chrome/browser/google/google_url_tracker.h"
15 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" 14 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
16 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/search_engines/search_terms_data.h" 16 #include "chrome/browser/search_engines/search_terms_data.h"
18 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 17 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
19 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 19 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_iterator.h" 21 #include "chrome/browser/ui/browser_iterator.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_source.h"
27 25
28 ProfileResetter::ProfileResetter(Profile* profile) 26 ProfileResetter::ProfileResetter(Profile* profile)
29 : profile_(profile), 27 : profile_(profile),
30 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), 28 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
31 pending_reset_flags_(0), 29 pending_reset_flags_(0),
32 cookies_remover_(NULL) { 30 cookies_remover_(NULL) {
33 DCHECK(CalledOnValidThread()); 31 DCHECK(CalledOnValidThread());
34 DCHECK(profile_); 32 DCHECK(profile_);
35 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
36 content::Source<TemplateURLService>(template_url_service_));
37 } 33 }
38 34
39 ProfileResetter::~ProfileResetter() { 35 ProfileResetter::~ProfileResetter() {
40 if (cookies_remover_) 36 if (cookies_remover_)
41 cookies_remover_->RemoveObserver(this); 37 cookies_remover_->RemoveObserver(this);
42 } 38 }
43 39
44 void ProfileResetter::Reset( 40 void ProfileResetter::Reset(
45 ProfileResetter::ResettableFlags resettable_flags, 41 ProfileResetter::ResettableFlags resettable_flags,
46 scoped_ptr<BrandcodedDefaultSettings> master_settings, 42 scoped_ptr<BrandcodedDefaultSettings> master_settings,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Check that we are never called twice or unexpectedly. 97 // Check that we are never called twice or unexpectedly.
102 CHECK(pending_reset_flags_ & resettable); 98 CHECK(pending_reset_flags_ & resettable);
103 99
104 pending_reset_flags_ &= ~resettable; 100 pending_reset_flags_ &= ~resettable;
105 101
106 if (!pending_reset_flags_) { 102 if (!pending_reset_flags_) {
107 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 103 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
108 callback_); 104 callback_);
109 callback_.Reset(); 105 callback_.Reset();
110 master_settings_.reset(); 106 master_settings_.reset();
107 template_url_service_sub_.reset();
111 } 108 }
112 } 109 }
113 110
114 void ProfileResetter::ResetDefaultSearchEngine() { 111 void ProfileResetter::ResetDefaultSearchEngine() {
115 DCHECK(CalledOnValidThread()); 112 DCHECK(CalledOnValidThread());
116 DCHECK(template_url_service_); 113 DCHECK(template_url_service_);
117
118 // If TemplateURLServiceFactory is ready we can clean it right now. 114 // If TemplateURLServiceFactory is ready we can clean it right now.
119 // Otherwise, load it and continue from ProfileResetter::Observe. 115 // Otherwise, load it and continue from ProfileResetter::Observe.
120 if (template_url_service_->loaded()) { 116 if (template_url_service_->loaded()) {
121 PrefService* prefs = profile_->GetPrefs(); 117 PrefService* prefs = profile_->GetPrefs();
122 DCHECK(prefs); 118 DCHECK(prefs);
123 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(profile_); 119 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(profile_);
124 scoped_ptr<ListValue> search_engines( 120 scoped_ptr<ListValue> search_engines(
125 master_settings_->GetSearchProviderOverrides()); 121 master_settings_->GetSearchProviderOverrides());
126 if (search_engines) { 122 if (search_engines) {
127 // This Chrome distribution channel provides a custom search engine. We 123 // This Chrome distribution channel provides a custom search engine. We
128 // must reset to it. 124 // must reset to it.
129 ListPrefUpdate update(prefs, prefs::kSearchProviderOverrides); 125 ListPrefUpdate update(prefs, prefs::kSearchProviderOverrides);
130 update->Swap(search_engines.get()); 126 update->Swap(search_engines.get());
131 } 127 }
132 128
133 template_url_service_->RepairPrepopulatedSearchEngines(); 129 template_url_service_->RepairPrepopulatedSearchEngines();
134 130
135 // Reset Google search URL. 131 // Reset Google search URL.
136 prefs->ClearPref(prefs::kLastPromptedGoogleURL); 132 prefs->ClearPref(prefs::kLastPromptedGoogleURL);
137 const TemplateURL* default_search_provider = 133 const TemplateURL* default_search_provider =
138 template_url_service_->GetDefaultSearchProvider(); 134 template_url_service_->GetDefaultSearchProvider();
139 if (default_search_provider && 135 if (default_search_provider &&
140 default_search_provider->url_ref().HasGoogleBaseURLs()) 136 default_search_provider->url_ref().HasGoogleBaseURLs())
141 GoogleURLTracker::RequestServerCheck(profile_, true); 137 GoogleURLTracker::RequestServerCheck(profile_, true);
142 138
143 MarkAsDone(DEFAULT_SEARCH_ENGINE); 139 MarkAsDone(DEFAULT_SEARCH_ENGINE);
144 } else { 140 } else {
141 template_url_service_sub_ =
142 template_url_service_->RegisterOnLoadedCallback(
143 base::Bind(&ProfileResetter::OnTemplateURLServiceLoaded,
144 base::Unretained(this)));
145 template_url_service_->Load(); 145 template_url_service_->Load();
146 } 146 }
147 } 147 }
148 148
149 void ProfileResetter::ResetHomepage() { 149 void ProfileResetter::ResetHomepage() {
150 DCHECK(CalledOnValidThread()); 150 DCHECK(CalledOnValidThread());
151 PrefService* prefs = profile_->GetPrefs(); 151 PrefService* prefs = profile_->GetPrefs();
152 DCHECK(prefs); 152 DCHECK(prefs);
153 std::string homepage; 153 std::string homepage;
154 bool homepage_is_ntp, show_home_button; 154 bool homepage_is_ntp, show_home_button;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // reverse direction is correct. 242 // reverse direction is correct.
243 for (int i = tab_model->count() - 1; i >= 0; --i) { 243 for (int i = tab_model->count() - 1; i >= 0; --i) {
244 if (tab_model->IsTabPinned(i) && !tab_model->IsAppTab(i)) 244 if (tab_model->IsTabPinned(i) && !tab_model->IsAppTab(i))
245 tab_model->SetTabPinned(i, false); 245 tab_model->SetTabPinned(i, false);
246 } 246 }
247 } 247 }
248 } 248 }
249 MarkAsDone(PINNED_TABS); 249 MarkAsDone(PINNED_TABS);
250 } 250 }
251 251
252 void ProfileResetter::Observe(int type, 252 void ProfileResetter::OnTemplateURLServiceLoaded() {
253 const content::NotificationSource& source,
254 const content::NotificationDetails& details) {
255 DCHECK(CalledOnValidThread());
256 // TemplateURLService has loaded. If we need to clean search engines, it's 253 // TemplateURLService has loaded. If we need to clean search engines, it's
257 // time to go on. 254 // time to go on.
255 DCHECK(CalledOnValidThread());
256 template_url_service_sub_.reset();
258 if (pending_reset_flags_ & DEFAULT_SEARCH_ENGINE) 257 if (pending_reset_flags_ & DEFAULT_SEARCH_ENGINE)
259 ResetDefaultSearchEngine(); 258 ResetDefaultSearchEngine();
260 } 259 }
261 260
262 void ProfileResetter::OnBrowsingDataRemoverDone() { 261 void ProfileResetter::OnBrowsingDataRemoverDone() {
263 cookies_remover_ = NULL; 262 cookies_remover_ = NULL;
264 MarkAsDone(COOKIES_AND_SITE_DATA); 263 MarkAsDone(COOKIES_AND_SITE_DATA);
265 } 264 }
OLDNEW
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter.h ('k') | chrome/browser/search_engines/template_url_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698