| OLD | NEW |
| 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/google/google_url_tracker.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 11 #include "chrome/browser/search_engines/template_url_service.h" |
| 12 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 13 #include "chrome/common/chrome_notification_types.h" |
| 9 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 10 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 11 | 16 |
| 12 ProfileResetter::ProfileResetter(Profile* profile) | 17 ProfileResetter::ProfileResetter(Profile* profile) |
| 13 : profile_(profile), | 18 : profile_(profile), |
| 19 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
| 14 pending_reset_flags_(0) { | 20 pending_reset_flags_(0) { |
| 15 DCHECK(CalledOnValidThread()); | 21 DCHECK(CalledOnValidThread()); |
| 22 DCHECK(profile_); |
| 23 DCHECK(template_url_service_); |
| 24 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 25 content::Source<TemplateURLService>(template_url_service_)); |
| 16 } | 26 } |
| 17 | 27 |
| 18 ProfileResetter::~ProfileResetter() {} | 28 ProfileResetter::~ProfileResetter() {} |
| 19 | 29 |
| 20 void ProfileResetter::Reset(ProfileResetter::ResettableFlags resettable_flags, | 30 void ProfileResetter::Reset(ProfileResetter::ResettableFlags resettable_flags, |
| 21 ExtensionHandling extension_handling, | 31 ExtensionHandling extension_handling, |
| 22 const base::Closure& callback) { | 32 const base::Closure& callback) { |
| 23 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 24 | 34 |
| 25 // We should never be called with unknown flags. | 35 // We should never be called with unknown flags. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 84 } |
| 75 | 85 |
| 76 void ProfileResetter::MarkAsDone(Resettable resettable) { | 86 void ProfileResetter::MarkAsDone(Resettable resettable) { |
| 77 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
| 78 | 88 |
| 79 // Check that we are never called twice or unexpectedly. | 89 // Check that we are never called twice or unexpectedly. |
| 80 CHECK(pending_reset_flags_ & resettable); | 90 CHECK(pending_reset_flags_ & resettable); |
| 81 | 91 |
| 82 pending_reset_flags_ &= ~resettable; | 92 pending_reset_flags_ &= ~resettable; |
| 83 | 93 |
| 84 if (!pending_reset_flags_) | 94 if (!pending_reset_flags_) { |
| 85 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 95 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 86 callback_); | 96 callback_); |
| 97 callback_.Reset(); |
| 98 } |
| 87 } | 99 } |
| 88 | 100 |
| 89 void ProfileResetter::ResetDefaultSearchEngine() { | 101 void ProfileResetter::ResetDefaultSearchEngine() { |
| 90 DCHECK(CalledOnValidThread()); | 102 DCHECK(CalledOnValidThread()); |
| 91 NOTIMPLEMENTED(); | 103 |
| 92 // TODO(battre/vabr): Implement | 104 // If TemplateURLServiceFactory is ready we can clean it right now. |
| 93 MarkAsDone(DEFAULT_SEARCH_ENGINE); | 105 // Otherwise, load it and continue from ProfileResetter::Observe. |
| 106 if (template_url_service_->loaded()) { |
| 107 // Reset Google search URL. |
| 108 PrefService* prefs = profile_->GetPrefs(); |
| 109 DCHECK(prefs); |
| 110 prefs->ClearPref(prefs::kLastPromptedGoogleURL); |
| 111 GoogleURLTracker::RequestServerCheck(profile_); |
| 112 |
| 113 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(profile_); |
| 114 template_url_service_->ResetNonExtensionURLs(); |
| 115 |
| 116 MarkAsDone(DEFAULT_SEARCH_ENGINE); |
| 117 } else { |
| 118 template_url_service_->Load(); |
| 119 } |
| 94 } | 120 } |
| 95 | 121 |
| 96 void ProfileResetter::ResetHomepage() { | 122 void ProfileResetter::ResetHomepage() { |
| 97 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
| 98 PrefService* prefs = profile_->GetPrefs(); | 124 PrefService* prefs = profile_->GetPrefs(); |
| 99 DCHECK(prefs); | 125 DCHECK(prefs); |
| 100 prefs->ClearPref(prefs::kHomePageIsNewTabPage); | 126 prefs->ClearPref(prefs::kHomePageIsNewTabPage); |
| 101 prefs->ClearPref(prefs::kHomePage); | 127 prefs->ClearPref(prefs::kHomePage); |
| 102 prefs->ClearPref(prefs::kShowHomeButton); | 128 prefs->ClearPref(prefs::kShowHomeButton); |
| 103 MarkAsDone(HOMEPAGE); | 129 MarkAsDone(HOMEPAGE); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 | 152 |
| 127 void ProfileResetter::ResetStartPage() { | 153 void ProfileResetter::ResetStartPage() { |
| 128 DCHECK(CalledOnValidThread()); | 154 DCHECK(CalledOnValidThread()); |
| 129 PrefService* prefs = profile_->GetPrefs(); | 155 PrefService* prefs = profile_->GetPrefs(); |
| 130 DCHECK(prefs); | 156 DCHECK(prefs); |
| 131 prefs->ClearPref(prefs::kRestoreOnStartup); | 157 prefs->ClearPref(prefs::kRestoreOnStartup); |
| 132 prefs->ClearPref(prefs::kURLsToRestoreOnStartup); | 158 prefs->ClearPref(prefs::kURLsToRestoreOnStartup); |
| 133 prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true); | 159 prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true); |
| 134 MarkAsDone(STARTUP_PAGE); | 160 MarkAsDone(STARTUP_PAGE); |
| 135 } | 161 } |
| 162 |
| 163 void ProfileResetter::Observe(int type, |
| 164 const content::NotificationSource& source, |
| 165 const content::NotificationDetails& details) { |
| 166 DCHECK(CalledOnValidThread()); |
| 167 // TemplateURLService has loaded. If we need to clean search engines, it's |
| 168 // time to go on. |
| 169 if (pending_reset_flags_ & DEFAULT_SEARCH_ENGINE) |
| 170 ResetDefaultSearchEngine(); |
| 171 } |
| OLD | NEW |