Index: chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc |
diff --git a/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc b/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc |
index ea235fab38ea5438c83fe98b847a90568b04d54d..ef318b5c6d75de2d146fba0f7640475f22ef72dd 100644 |
--- a/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc |
+++ b/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc |
@@ -41,14 +41,13 @@ ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) |
: profile_(Profile::FromWebUI(webui)), |
sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), |
sync_service_observer_(this), |
- remover_(nullptr), |
+ remover_(BrowsingDataRemoverFactory::GetForBrowserContext(profile_)), |
Dan Beam
2016/07/07 18:06:49
is there any big penalty for creating this from co
dschuyler
2016/07/20 19:01:15
Good point. Even if the penalty is not big, it's n
|
show_history_footer_(false), |
show_history_deletion_dialog_(false), |
weak_ptr_factory_(this) {} |
ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { |
- if (remover_) |
- remover_->RemoveObserver(this); |
+ remover_->RemoveObserver(this); |
Dan Beam
2016/07/07 18:06:49
can you make this a ScopedObserver like sync_servi
dschuyler
2016/07/20 19:01:14
Done.
|
} |
void ClearBrowsingDataHandler::RegisterMessages() { |
@@ -73,9 +72,12 @@ void ClearBrowsingDataHandler::OnJavascriptAllowed() { |
if (sync_service_) |
sync_service_observer_.Add(sync_service_); |
+ |
+ remover_->AddObserver(this); |
} |
void ClearBrowsingDataHandler::OnJavascriptDisallowed() { |
+ remover_->RemoveObserver(this); |
profile_pref_registrar_.RemoveAll(); |
sync_service_observer_.RemoveAll(); |
} |
@@ -83,7 +85,7 @@ void ClearBrowsingDataHandler::OnJavascriptDisallowed() { |
void ClearBrowsingDataHandler::HandleClearBrowsingData( |
const base::ListValue* args) { |
// We should never be called when the previous clearing has not yet finished. |
- CHECK(!remover_); |
+ CHECK(!remover_->is_removing()); |
CHECK_EQ(1U, args->GetSize()); |
CHECK(webui_callback_id_.empty()); |
CHECK(args->GetString(0, &webui_callback_id_)); |
@@ -163,17 +165,18 @@ void ClearBrowsingDataHandler::HandleClearBrowsingData( |
int period_selected = |
prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
- remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); |
- remover_->AddObserver(this); |
remover_->Remove(BrowsingDataRemover::Period( |
static_cast<browsing_data::TimePeriod>(period_selected)), |
remove_mask, origin_mask); |
} |
-void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { |
- remover_->RemoveObserver(this); |
- remover_ = nullptr; |
+void ClearBrowsingDataHandler::OnBrowsingDataRemoving(bool is_removing) { |
+ CallJavascriptFunction("cr.webUIListenerCallback", |
+ base::StringValue("browsing-data-removing"), |
+ base::FundamentalValue(is_removing)); |
+} |
+void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { |
PrefService* prefs = profile_->GetPrefs(); |
int notice_shown_times = |
prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
@@ -214,6 +217,8 @@ void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() { |
void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
AllowJavascript(); |
+ const base::Value* callback_id; |
+ CHECK(args->Get(0, &callback_id)); |
// TODO(msramek): Simplify this using a factory. |
AddCounter(base::WrapUnique(new AutofillCounter(profile_))); |
@@ -226,6 +231,9 @@ void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
OnStateChanged(); |
RefreshHistoryNotice(); |
+ OnBrowsingDataRemoving(remover_->is_removing()); |
+ |
+ ResolveJavascriptCallback(*callback_id, *base::Value::CreateNullValue()); |
} |
void ClearBrowsingDataHandler::OnStateChanged() { |