| 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..367824b237b77b752d21c0fef6eab609c1b4b084 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,12 @@ scoped_ptr<base::DictionaryValue> BuildSubTreeFromTemplateURL(
|
| // AutomaticProfileResetterDelegateImpl --------------------------------------
|
|
|
| AutomaticProfileResetterDelegateImpl::AutomaticProfileResetterDelegateImpl(
|
| - TemplateURLService* template_url_service)
|
| - : template_url_service_(template_url_service) {
|
| + Profile* profile)
|
| + : profile_(profile),
|
| + global_error_service_(GlobalErrorServiceFactory::GetForProfile(profile_)),
|
| + template_url_service_(
|
| + TemplateURLServiceFactory::GetForProfile(profile_)) {
|
| + 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 +135,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())
|
| + 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 +205,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(
|
| @@ -174,7 +217,37 @@ scoped_ptr<base::ListValue> AutomaticProfileResetterDelegateImpl::
|
| }
|
|
|
| void AutomaticProfileResetterDelegateImpl::ShowPrompt() {
|
| - // TODO(engedy): Call the UI from here once we have it.
|
| + DCHECK(global_error_service_);
|
| + 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());
|
| + for (GlobalErrorService::GlobalErrorList::const_iterator
|
| + it = global_errors.begin(); it != global_errors.end(); ++it) {
|
| + if ((*it)->GetBubbleView())
|
| + return;
|
| + }
|
| + Browser* browser = chrome::FindTabbedBrowser(
|
| + profile_, false /*match_original_profiles*/, chrome::GetActiveDesktop());
|
| + if (browser)
|
| + global_error->ShowBubbleView(browser);
|
| +}
|
| +
|
| +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 +258,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 +283,48 @@ void AutomaticProfileResetterDelegateImpl::Observe(
|
| modules_have_been_enumerated_event_.Signal();
|
| }
|
| }
|
| +
|
| +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(
|
| + ProfileResetter::ALL,
|
| + 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();
|
| + 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);
|
| + SendSettingsFeedback(report, profile_, PROFILE_RESET_PROMPT);
|
| + }
|
| + }
|
| + if (!user_callback.is_null())
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI, FROM_HERE, user_callback);
|
| +}
|
|
|