Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/settings/settings_clear_browsing_data_handler. h" | 5 #include "chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler. h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 namespace settings { | 43 namespace settings { |
| 44 | 44 |
| 45 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) | 45 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) |
| 46 : profile_(Profile::FromWebUI(webui)), | 46 : profile_(Profile::FromWebUI(webui)), |
| 47 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), | 47 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), |
| 48 sync_service_observer_(this), | 48 sync_service_observer_(this), |
| 49 remover_(nullptr), | |
| 50 remover_observer_(this), | 49 remover_observer_(this), |
| 51 show_history_footer_(false), | 50 show_history_footer_(false), |
| 52 show_history_deletion_dialog_(false), | 51 show_history_deletion_dialog_(false), |
| 53 weak_ptr_factory_(this) {} | 52 weak_ptr_factory_(this) {} |
| 54 | 53 |
| 55 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { | 54 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { |
| 56 } | 55 } |
| 57 | 56 |
| 58 void ClearBrowsingDataHandler::RegisterMessages() { | 57 void ClearBrowsingDataHandler::RegisterMessages() { |
| 59 web_ui()->RegisterMessageCallback( | 58 web_ui()->RegisterMessageCallback( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 70 void ClearBrowsingDataHandler::OnJavascriptAllowed() { | 69 void ClearBrowsingDataHandler::OnJavascriptAllowed() { |
| 71 PrefService* prefs = profile_->GetPrefs(); | 70 PrefService* prefs = profile_->GetPrefs(); |
| 72 profile_pref_registrar_.Init(prefs); | 71 profile_pref_registrar_.Init(prefs); |
| 73 profile_pref_registrar_.Add( | 72 profile_pref_registrar_.Add( |
| 74 prefs::kAllowDeletingBrowserHistory, | 73 prefs::kAllowDeletingBrowserHistory, |
| 75 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged, | 74 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged, |
| 76 base::Unretained(this))); | 75 base::Unretained(this))); |
| 77 | 76 |
| 78 if (sync_service_) | 77 if (sync_service_) |
| 79 sync_service_observer_.Add(sync_service_); | 78 sync_service_observer_.Add(sync_service_); |
| 80 | |
| 81 if (!remover_) | |
| 82 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); | |
| 83 | |
| 84 remover_observer_.Add(remover_); | |
| 85 } | 79 } |
| 86 | 80 |
| 87 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { | 81 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { |
| 88 remover_observer_.RemoveAll(); | |
| 89 profile_pref_registrar_.RemoveAll(); | 82 profile_pref_registrar_.RemoveAll(); |
| 90 sync_service_observer_.RemoveAll(); | 83 sync_service_observer_.RemoveAll(); |
| 91 } | 84 } |
| 92 | 85 |
| 93 void ClearBrowsingDataHandler::HandleClearBrowsingData( | 86 void ClearBrowsingDataHandler::HandleClearBrowsingData( |
| 94 const base::ListValue* args) { | 87 const base::ListValue* args) { |
| 95 // We should never be called when the previous clearing has not yet finished. | 88 // We should never be called when the previous clearing from this dialog |
| 96 CHECK(!remover_->is_removing()); | 89 // has not yet finished. |
| 90 CHECK(webui_callback_id_.empty()); | |
| 97 CHECK_EQ(1U, args->GetSize()); | 91 CHECK_EQ(1U, args->GetSize()); |
| 98 CHECK(webui_callback_id_.empty()); | |
| 99 CHECK(args->GetString(0, &webui_callback_id_)); | 92 CHECK(args->GetString(0, &webui_callback_id_)); |
| 100 | 93 |
| 101 PrefService* prefs = profile_->GetPrefs(); | 94 PrefService* prefs = profile_->GetPrefs(); |
| 102 | 95 |
| 103 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; | 96 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
| 104 // Don't try to clear LSO data if it's not supported. | 97 // Don't try to clear LSO data if it's not supported. |
| 105 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) | 98 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) |
| 106 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 99 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
| 107 | 100 |
| 108 int remove_mask = 0; | 101 int remove_mask = 0; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 int checked_other_types = std::count_if( | 159 int checked_other_types = std::count_if( |
| 167 other_types, other_types + num_other_types, | 160 other_types, other_types + num_other_types, |
| 168 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 161 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
| 169 UMA_HISTOGRAM_SPARSE_SLOWLY( | 162 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 170 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 163 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
| 171 checked_other_types); | 164 checked_other_types); |
| 172 } | 165 } |
| 173 | 166 |
| 174 int period_selected = | 167 int period_selected = |
| 175 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 168 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
| 176 remover_->Remove(BrowsingDataRemover::Period( | 169 |
| 177 static_cast<browsing_data::TimePeriod>(period_selected)), | 170 BrowsingDataRemover* remover = |
| 178 remove_mask, origin_mask); | 171 BrowsingDataRemoverFactory::GetForBrowserContext(profile_); |
| 172 DCHECK(remover); | |
| 173 remover_observer_.Add(remover); | |
| 174 remover->RemoveAndReply( | |
| 175 BrowsingDataRemover::Period( | |
| 176 static_cast<browsing_data::TimePeriod>(period_selected)), | |
| 177 remove_mask, origin_mask, this); | |
| 179 } | 178 } |
| 180 | 179 |
| 181 void ClearBrowsingDataHandler::OnBrowsingDataRemoving(bool is_removing) { | 180 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { |
| 182 CallJavascriptFunction("cr.webUIListenerCallback", | 181 remover_observer_.RemoveAll(); |
| 183 base::StringValue("browsing-data-removing"), | |
| 184 base::FundamentalValue(is_removing)); | |
| 185 | 182 |
| 186 if (is_removing || webui_callback_id_.empty()) | 183 DCHECK(!webui_callback_id_.empty()); |
|
Dan Beam
2016/08/16 22:09:08
this could currently fail in the [very uncommon ca
| |
| 187 return; | |
| 188 | 184 |
| 189 PrefService* prefs = profile_->GetPrefs(); | 185 PrefService* prefs = profile_->GetPrefs(); |
| 190 int notice_shown_times = | 186 int notice_shown_times = |
| 191 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); | 187 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
| 192 | 188 |
| 193 // When the deletion is complete, we might show an additional dialog with | 189 // When the deletion is complete, we might show an additional dialog with |
| 194 // a notice about other forms of browsing history. This is the case if | 190 // a notice about other forms of browsing history. This is the case if |
| 195 const bool show_notice = | 191 const bool show_notice = |
| 196 // 1. The dialog is relevant for the user. | 192 // 1. The dialog is relevant for the user. |
| 197 show_history_deletion_dialog_ && | 193 show_history_deletion_dialog_ && |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 counters_.clear(); | 228 counters_.clear(); |
| 233 | 229 |
| 234 for (const std::string& pref : kCounterPrefs) { | 230 for (const std::string& pref : kCounterPrefs) { |
| 235 AddCounter( | 231 AddCounter( |
| 236 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref)); | 232 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref)); |
| 237 } | 233 } |
| 238 | 234 |
| 239 OnStateChanged(); | 235 OnStateChanged(); |
| 240 RefreshHistoryNotice(); | 236 RefreshHistoryNotice(); |
| 241 | 237 |
| 242 ResolveJavascriptCallback(*callback_id, | 238 ResolveJavascriptCallback( |
| 243 base::FundamentalValue(remover_->is_removing())); | 239 *callback_id, |
| 240 base::FundamentalValue(!webui_callback_id_.empty())); | |
| 244 } | 241 } |
| 245 | 242 |
| 246 void ClearBrowsingDataHandler::OnStateChanged() { | 243 void ClearBrowsingDataHandler::OnStateChanged() { |
| 247 CallJavascriptFunction( | 244 CallJavascriptFunction( |
| 248 "cr.webUIListenerCallback", | 245 "cr.webUIListenerCallback", |
| 249 base::StringValue("update-footer"), | 246 base::StringValue("update-footer"), |
| 250 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 247 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
| 251 base::FundamentalValue(show_history_footer_)); | 248 base::FundamentalValue(show_history_footer_)); |
| 252 } | 249 } |
| 253 | 250 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 277 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { | 274 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { |
| 278 show_history_footer_ = show; | 275 show_history_footer_ = show; |
| 279 OnStateChanged(); | 276 OnStateChanged(); |
| 280 | 277 |
| 281 UMA_HISTOGRAM_BOOLEAN( | 278 UMA_HISTOGRAM_BOOLEAN( |
| 282 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 279 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
| 283 show_history_footer_); | 280 show_history_footer_); |
| 284 } | 281 } |
| 285 | 282 |
| 286 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { | 283 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { |
| 287 // This is used by OnBrowsingDataRemoving (when the deletion finishes). | 284 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). |
| 288 show_history_deletion_dialog_ = show; | 285 show_history_deletion_dialog_ = show; |
| 289 } | 286 } |
| 290 | 287 |
| 291 void ClearBrowsingDataHandler::AddCounter( | 288 void ClearBrowsingDataHandler::AddCounter( |
| 292 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { | 289 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { |
| 293 counter->Init(profile_->GetPrefs(), | 290 counter->Init(profile_->GetPrefs(), |
| 294 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, | 291 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, |
| 295 base::Unretained(this))); | 292 base::Unretained(this))); |
| 296 counter->Restart(); | 293 counter->Restart(); |
| 297 counters_.push_back(std::move(counter)); | 294 counters_.push_back(std::move(counter)); |
| 298 } | 295 } |
| 299 | 296 |
| 300 void ClearBrowsingDataHandler::UpdateCounterText( | 297 void ClearBrowsingDataHandler::UpdateCounterText( |
| 301 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 298 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 302 CallJavascriptFunction( | 299 CallJavascriptFunction( |
| 303 "cr.webUIListenerCallback", | 300 "cr.webUIListenerCallback", |
| 304 base::StringValue("update-counter-text"), | 301 base::StringValue("update-counter-text"), |
| 305 base::StringValue(result->source()->GetPrefName()), | 302 base::StringValue(result->source()->GetPrefName()), |
| 306 base::StringValue(GetCounterTextFromResult(result.get()))); | 303 base::StringValue(GetCounterTextFromResult(result.get()))); |
| 307 } | 304 } |
| 308 | 305 |
| 309 } // namespace settings | 306 } // namespace settings |
| OLD | NEW |