Chromium Code Reviews| 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/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/template_url_prepopulate_data.h" | 16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 18 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
| 19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 20 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_iterator.h" | 20 #include "chrome/browser/ui/browser_iterator.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/notification_source.h" | |
| 26 | 24 |
| 27 ProfileResetter::ProfileResetter(Profile* profile) | 25 ProfileResetter::ProfileResetter(Profile* profile) |
| 28 : profile_(profile), | 26 : profile_(profile), |
| 29 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), | 27 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
| 30 pending_reset_flags_(0), | 28 pending_reset_flags_(0), |
| 31 cookies_remover_(NULL) { | 29 cookies_remover_(NULL) { |
| 32 DCHECK(CalledOnValidThread()); | 30 DCHECK(CalledOnValidThread()); |
| 33 DCHECK(profile_); | 31 DCHECK(profile_); |
| 34 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | |
| 35 content::Source<TemplateURLService>(template_url_service_)); | |
| 36 } | 32 } |
| 37 | 33 |
| 38 ProfileResetter::~ProfileResetter() { | 34 ProfileResetter::~ProfileResetter() { |
| 39 if (cookies_remover_) | 35 if (cookies_remover_) |
| 40 cookies_remover_->RemoveObserver(this); | 36 cookies_remover_->RemoveObserver(this); |
| 41 } | 37 } |
| 42 | 38 |
| 43 void ProfileResetter::Reset( | 39 void ProfileResetter::Reset( |
| 44 ProfileResetter::ResettableFlags resettable_flags, | 40 ProfileResetter::ResettableFlags resettable_flags, |
| 45 scoped_ptr<BrandcodedDefaultSettings> master_settings, | 41 scoped_ptr<BrandcodedDefaultSettings> master_settings, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // Check that we are never called twice or unexpectedly. | 91 // Check that we are never called twice or unexpectedly. |
| 96 CHECK(pending_reset_flags_ & resettable); | 92 CHECK(pending_reset_flags_ & resettable); |
| 97 | 93 |
| 98 pending_reset_flags_ &= ~resettable; | 94 pending_reset_flags_ &= ~resettable; |
| 99 | 95 |
| 100 if (!pending_reset_flags_) { | 96 if (!pending_reset_flags_) { |
| 101 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 97 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 102 callback_); | 98 callback_); |
| 103 callback_.Reset(); | 99 callback_.Reset(); |
| 104 master_settings_.reset(); | 100 master_settings_.reset(); |
| 101 template_url_service_sub_.reset(); | |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 | 104 |
| 108 void ProfileResetter::ResetDefaultSearchEngine() { | 105 void ProfileResetter::ResetDefaultSearchEngine() { |
| 109 DCHECK(CalledOnValidThread()); | 106 DCHECK(CalledOnValidThread()); |
| 110 DCHECK(template_url_service_); | 107 DCHECK(template_url_service_); |
| 111 | |
| 112 // If TemplateURLServiceFactory is ready we can clean it right now. | 108 // If TemplateURLServiceFactory is ready we can clean it right now. |
| 113 // Otherwise, load it and continue from ProfileResetter::Observe. | 109 // Otherwise, load it and continue from ProfileResetter::Observe. |
| 114 if (template_url_service_->loaded()) { | 110 if (template_url_service_->loaded()) { |
| 115 PrefService* prefs = profile_->GetPrefs(); | 111 PrefService* prefs = profile_->GetPrefs(); |
| 116 DCHECK(prefs); | 112 DCHECK(prefs); |
| 117 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(profile_); | 113 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(profile_); |
| 118 scoped_ptr<ListValue> search_engines( | 114 scoped_ptr<ListValue> search_engines( |
| 119 master_settings_->GetSearchProviderOverrides()); | 115 master_settings_->GetSearchProviderOverrides()); |
| 120 if (search_engines) { | 116 if (search_engines) { |
| 121 // This Chrome distribution channel provides a custom search engine. We | 117 // This Chrome distribution channel provides a custom search engine. We |
| 122 // must reset to it. | 118 // must reset to it. |
| 123 ListPrefUpdate update(prefs, prefs::kSearchProviderOverrides); | 119 ListPrefUpdate update(prefs, prefs::kSearchProviderOverrides); |
| 124 update->Swap(search_engines.get()); | 120 update->Swap(search_engines.get()); |
| 125 } | 121 } |
| 126 | 122 |
| 127 template_url_service_->ResetURLs(); | 123 template_url_service_->ResetURLs(); |
| 128 | 124 |
| 129 // Reset Google search URL. | 125 // Reset Google search URL. |
| 130 prefs->ClearPref(prefs::kLastPromptedGoogleURL); | 126 prefs->ClearPref(prefs::kLastPromptedGoogleURL); |
| 131 const TemplateURL* default_search_provider = | 127 const TemplateURL* default_search_provider = |
| 132 template_url_service_->GetDefaultSearchProvider(); | 128 template_url_service_->GetDefaultSearchProvider(); |
| 133 if (default_search_provider && | 129 if (default_search_provider && |
| 134 default_search_provider->url_ref().HasGoogleBaseURLs()) | 130 default_search_provider->url_ref().HasGoogleBaseURLs()) |
| 135 GoogleURLTracker::RequestServerCheck(profile_, true); | 131 GoogleURLTracker::RequestServerCheck(profile_, true); |
| 136 | 132 |
| 137 MarkAsDone(DEFAULT_SEARCH_ENGINE); | 133 MarkAsDone(DEFAULT_SEARCH_ENGINE); |
| 138 } else { | 134 } else { |
| 135 template_url_service_sub_ = | |
| 136 template_url_service_->RegisterOnLoadedCallback( | |
| 137 base::Bind(&ProfileResetter::OnTemplateURLServiceLoaded, | |
| 138 base::Unretained(this))); | |
| 139 template_url_service_->Load(); | 139 template_url_service_->Load(); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ProfileResetter::ResetHomepage() { | 143 void ProfileResetter::ResetHomepage() { |
| 144 DCHECK(CalledOnValidThread()); | 144 DCHECK(CalledOnValidThread()); |
| 145 PrefService* prefs = profile_->GetPrefs(); | 145 PrefService* prefs = profile_->GetPrefs(); |
| 146 DCHECK(prefs); | 146 DCHECK(prefs); |
| 147 std::string homepage; | 147 std::string homepage; |
| 148 bool homepage_is_ntp, show_home_button; | 148 bool homepage_is_ntp, show_home_button; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 // reverse direction is correct. | 240 // reverse direction is correct. |
| 241 for (int i = tab_model->count() - 1; i >= 0; --i) { | 241 for (int i = tab_model->count() - 1; i >= 0; --i) { |
| 242 if (tab_model->IsTabPinned(i) && !tab_model->IsAppTab(i)) | 242 if (tab_model->IsTabPinned(i) && !tab_model->IsAppTab(i)) |
| 243 tab_model->SetTabPinned(i, false); | 243 tab_model->SetTabPinned(i, false); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 MarkAsDone(PINNED_TABS); | 247 MarkAsDone(PINNED_TABS); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void ProfileResetter::Observe(int type, | 250 void ProfileResetter::OnTemplateURLServiceLoaded() { |
| 251 const content::NotificationSource& source, | |
| 252 const content::NotificationDetails& details) { | |
| 253 DCHECK(CalledOnValidThread()); | |
| 254 // TemplateURLService has loaded. If we need to clean search engines, it's | 251 // TemplateURLService has loaded. If we need to clean search engines, it's |
|
Avi (use Gerrit)
2013/10/02 22:27:52
Was the drop of the thread DCHECK intentional? Mig
Cait (Slow)
2013/10/03 15:36:45
Done.
| |
| 255 // time to go on. | 252 // time to go on. |
| 253 template_url_service_sub_.reset(); | |
| 256 if (pending_reset_flags_ & DEFAULT_SEARCH_ENGINE) | 254 if (pending_reset_flags_ & DEFAULT_SEARCH_ENGINE) |
| 257 ResetDefaultSearchEngine(); | 255 ResetDefaultSearchEngine(); |
| 258 } | 256 } |
| 259 | 257 |
| 260 void ProfileResetter::OnBrowsingDataRemoverDone() { | 258 void ProfileResetter::OnBrowsingDataRemoverDone() { |
| 261 cookies_remover_ = NULL; | 259 cookies_remover_ = NULL; |
| 262 MarkAsDone(COOKIES_AND_SITE_DATA); | 260 MarkAsDone(COOKIES_AND_SITE_DATA); |
| 263 } | 261 } |
| OLD | NEW |