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

Unified Diff: chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc

Issue 62193002: Integrate UI and reset logic into AutomaticProfileResetter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win compile error introduce by rebase. Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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 e793669b66949bd7155f9f211e5a34683a400a31..63e49209c318e9c07ee888a2f3451ae0d4d5880a 100644
--- a/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc
+++ b/chrome/browser/profile_resetter/automatic_profile_resetter_delegate.cc
@@ -6,6 +6,8 @@
#include <string>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/logging.h"
#include "base/md5.h"
@@ -13,11 +15,21 @@
#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"
@@ -95,8 +107,13 @@ void ExtractLoadedModuleNameDigests(
// 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
@@ -151,6 +168,34 @@ 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();
+ } else {
+ 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());
@@ -188,7 +233,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(
@@ -200,8 +244,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::TriggerPrompt() {
+ 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() {
@@ -212,6 +295,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,
@@ -225,3 +320,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);
+}

Powered by Google App Engine
This is Rietveld 408576698