Chromium Code Reviews| Index: chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc |
| diff --git a/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc b/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc |
| index 45441d16bed031a96f012199886f8af1023d4e04..0b672a49546c6e9827eb50d91c0430dc255625f5 100644 |
| --- a/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc |
| +++ b/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc |
| @@ -4,23 +4,34 @@ |
| #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h" |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| #include "base/callback.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_vector.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| #include "base/values.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/google/google_util.h" |
| +#include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" |
| +#include "chrome/browser/profile_resetter/profile_reset_global_error.h" |
| +#include "chrome/browser/profile_resetter/profile_resetter.h" |
| +#include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| #include "chrome/browser/search_engines/template_url_service.h" |
| #include "chrome/browser/search_engines/template_url_service_factory.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_finder.h" |
| +#include "chrome/browser/ui/global_error/global_error_service.h" |
| +#include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_service.h" |
| #if defined(OS_WIN) |
| #include "chrome/browser/enumerate_modules_model_win.h" |
| -#include "chrome/browser/install_module_verifier_win.h" |
| #endif |
| namespace { |
| @@ -64,8 +75,13 @@ scoped_ptr<base::DictionaryValue> BuildSubTreeFromTemplateURL( |
| // AutomaticProfileResetterDelegateImpl -------------------------------------- |
| AutomaticProfileResetterDelegateImpl::AutomaticProfileResetterDelegateImpl( |
| - TemplateURLService* template_url_service) |
| - : template_url_service_(template_url_service) { |
| + Profile* profile, |
| + ProfileResetter::ResettableFlags resettable_aspects) |
| + : profile_(profile), |
| + global_error_service_(GlobalErrorServiceFactory::GetForProfile(profile_)), |
| + template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
| + resettable_aspects_(resettable_aspects) { |
| + DCHECK(profile_); |
| if (template_url_service_) { |
| template_url_service_->AddObserver(this); |
| // Needed so that |template_url_service_ready_event_| will be signaled even |
| @@ -120,6 +136,35 @@ void AutomaticProfileResetterDelegateImpl:: |
| template_url_service_ready_event_.Post(FROM_HERE, ready_callback); |
| } |
| +void AutomaticProfileResetterDelegateImpl:: |
| + FetchBrandcodedDefaultSettingsIfNeeded() { |
| + if (brandcoded_config_fetcher_ || |
| + brandcoded_defaults_fetched_event_.is_signaled()) |
|
MAD
2013/11/11 16:38:32
add {} when condition is more than 1 line.
engedy
2013/11/13 00:40:44
Hmm. Other code in this directory seems to followi
|
| + return; |
| + |
| + std::string brandcode; |
| + google_util::GetBrand(&brandcode); |
| + if (brandcode.empty()) { |
| + brandcoded_defaults_.reset(new BrandcodedDefaultSettings); |
| + brandcoded_defaults_fetched_event_.Signal(); |
| + return; |
| + } |
| + |
| + brandcoded_config_fetcher_.reset(new BrandcodeConfigFetcher( |
| + base::Bind( |
| + &AutomaticProfileResetterDelegateImpl::OnBrandcodedDefaultsFetched, |
| + base::Unretained(this)), |
| + GURL("https://tools.google.com/service/update2"), |
| + brandcode)); |
| +} |
| + |
| +void AutomaticProfileResetterDelegateImpl:: |
| + RequestCallbackWhenBrandcodedDefaultsAreFetched( |
| + const base::Closure& ready_callback) const { |
| + DCHECK(!ready_callback.is_null()); |
| + brandcoded_defaults_fetched_event_.Post(FROM_HERE, ready_callback); |
| +} |
| + |
| scoped_ptr<base::ListValue> AutomaticProfileResetterDelegateImpl:: |
| GetLoadedModuleNameDigests() const { |
| DCHECK(modules_have_been_enumerated_event_.is_signaled()); |
| @@ -161,7 +206,6 @@ bool AutomaticProfileResetterDelegateImpl:: |
| scoped_ptr<base::ListValue> AutomaticProfileResetterDelegateImpl:: |
| GetPrepopulatedSearchProvidersDetails() const { |
| - DCHECK(template_url_service_); |
| size_t default_search_index = 0; |
| ScopedVector<TemplateURL> engines( |
| TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| @@ -173,8 +217,47 @@ scoped_ptr<base::ListValue> AutomaticProfileResetterDelegateImpl:: |
| return engines_details_list.Pass(); |
| } |
| -void AutomaticProfileResetterDelegateImpl::ShowPrompt() { |
| - // TODO(engedy): Call the UI from here once we have it. |
| +bool AutomaticProfileResetterDelegateImpl::ShowPrompt() { |
| + DCHECK(global_error_service_); |
| + |
| + if (!ProfileResetGlobalError::IsSupportedOnPlatform()) |
| + return false; |
| + |
| + ProfileResetGlobalError* global_error = new ProfileResetGlobalError(profile_); |
| + global_error_service_->AddGlobalError(global_error); |
| + |
| + // Do not try to show bubble if another GlobalError is already showing one. |
| + const GlobalErrorService::GlobalErrorList& global_errors( |
| + global_error_service_->errors()); |
| + GlobalErrorService::GlobalErrorList::const_iterator it; |
| + for (it = global_errors.begin(); it != global_errors.end(); ++it) { |
| + if ((*it)->GetBubbleView()) |
| + break; |
| + } |
| + if (it == global_errors.end()) { |
| + Browser* browser = chrome::FindTabbedBrowser( |
| + profile_, |
| + false /*match_original_profiles*/, |
| + chrome::GetActiveDesktop()); |
| + if (browser) |
| + global_error->ShowBubbleView(browser); |
| + } |
| + return true; |
| +} |
| + |
| +void AutomaticProfileResetterDelegateImpl::TriggerProfileSettingsReset( |
| + bool send_feedback, |
| + const base::Closure& completion) { |
| + DCHECK(!profile_resetter_); |
| + DCHECK(!completion.is_null()); |
| + |
| + profile_resetter_.reset(new ProfileResetter(profile_)); |
| + FetchBrandcodedDefaultSettingsIfNeeded(); |
| + RequestCallbackWhenBrandcodedDefaultsAreFetched(base::Bind( |
| + &AutomaticProfileResetterDelegateImpl::RunProfileSettingsReset, |
| + AsWeakPtr(), |
| + send_feedback, |
| + completion)); |
| } |
| void AutomaticProfileResetterDelegateImpl::OnTemplateURLServiceChanged() { |
| @@ -185,6 +268,18 @@ void AutomaticProfileResetterDelegateImpl::OnTemplateURLServiceChanged() { |
| template_url_service_ready_event_.Signal(); |
| } |
| +void AutomaticProfileResetterDelegateImpl::DismissPrompt() { |
| + DCHECK(global_error_service_); |
| + GlobalError* global_error = |
| + global_error_service_->GetGlobalErrorByMenuItemCommandID( |
| + IDC_SHOW_SETTINGS_RESET_BUBBLE); |
| + if (global_error) { |
| + // This will also close/destroy the Bubble UI if it is currently shown. |
| + global_error_service_->RemoveGlobalError(global_error); |
| + delete global_error; |
| + } |
| +} |
| + |
| void AutomaticProfileResetterDelegateImpl::Observe( |
| int type, |
| const content::NotificationSource& source, |
| @@ -198,3 +293,54 @@ void AutomaticProfileResetterDelegateImpl::Observe( |
| modules_have_been_enumerated_event_.Signal(); |
| } |
| } |
| + |
| +void AutomaticProfileResetterDelegateImpl::SendFeedback( |
| + const std::string& report) const { |
| + SendSettingsFeedback(report, profile_, PROFILE_RESET_PROMPT); |
| +} |
| + |
| +void AutomaticProfileResetterDelegateImpl::RunProfileSettingsReset( |
| + bool send_feedback, |
| + const base::Closure& completion) { |
| + DCHECK(brandcoded_defaults_); |
| + scoped_ptr<ResettableSettingsSnapshot> old_settings_snapshot( |
| + send_feedback ? new ResettableSettingsSnapshot(profile_) : NULL); |
| + profile_resetter_->Reset( |
| + resettable_aspects_, |
| + brandcoded_defaults_.Pass(), |
| + base::Bind(&AutomaticProfileResetterDelegateImpl:: |
| + OnProfileSettingsResetCompleted, |
| + AsWeakPtr(), |
| + completion, |
| + base::Passed(&old_settings_snapshot))); |
| +} |
| + |
| +void AutomaticProfileResetterDelegateImpl:: |
| + OnBrandcodedDefaultsFetched() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(brandcoded_config_fetcher_); |
| + DCHECK(!brandcoded_config_fetcher_->IsActive()); |
| + brandcoded_defaults_ = brandcoded_config_fetcher_->GetSettings(); |
| + if (!brandcoded_defaults_) |
| + brandcoded_defaults_.reset(new BrandcodedDefaultSettings); |
| + brandcoded_defaults_fetched_event_.Signal(); |
| +} |
| + |
| +void AutomaticProfileResetterDelegateImpl::OnProfileSettingsResetCompleted( |
| + const base::Closure& user_callback, |
| + scoped_ptr<ResettableSettingsSnapshot> old_settings_snapshot) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + if (old_settings_snapshot) { |
| + ResettableSettingsSnapshot new_settings_snapshot(profile_); |
| + int difference = |
| + old_settings_snapshot->FindDifferentFields(new_settings_snapshot); |
| + if (difference) { |
| + old_settings_snapshot->Subtract(new_settings_snapshot); |
| + std::string report = |
| + SerializeSettingsReport(*old_settings_snapshot, difference); |
| + SendFeedback(report); |
| + } |
| + } |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, FROM_HERE, user_callback); |
| +} |