| 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 29 matching lines...) Expand all Loading... |
| 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), | 49 remover_(nullptr), |
| 50 remover_observer_(this), |
| 50 show_history_footer_(false), | 51 show_history_footer_(false), |
| 51 show_history_deletion_dialog_(false), | 52 show_history_deletion_dialog_(false), |
| 52 weak_ptr_factory_(this) {} | 53 weak_ptr_factory_(this) {} |
| 53 | 54 |
| 54 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { | 55 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { |
| 55 if (remover_) | |
| 56 remover_->RemoveObserver(this); | |
| 57 } | 56 } |
| 58 | 57 |
| 59 void ClearBrowsingDataHandler::RegisterMessages() { | 58 void ClearBrowsingDataHandler::RegisterMessages() { |
| 60 web_ui()->RegisterMessageCallback( | 59 web_ui()->RegisterMessageCallback( |
| 61 "clearBrowsingData", | 60 "clearBrowsingData", |
| 62 base::Bind(&ClearBrowsingDataHandler::HandleClearBrowsingData, | 61 base::Bind(&ClearBrowsingDataHandler::HandleClearBrowsingData, |
| 63 base::Unretained(this))); | 62 base::Unretained(this))); |
| 64 | 63 |
| 65 web_ui()->RegisterMessageCallback( | 64 web_ui()->RegisterMessageCallback( |
| 66 "initializeClearBrowsingData", | 65 "initializeClearBrowsingData", |
| 67 base::Bind(&ClearBrowsingDataHandler::HandleInitialize, | 66 base::Bind(&ClearBrowsingDataHandler::HandleInitialize, |
| 68 base::Unretained(this))); | 67 base::Unretained(this))); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void ClearBrowsingDataHandler::OnJavascriptAllowed() { | 70 void ClearBrowsingDataHandler::OnJavascriptAllowed() { |
| 72 PrefService* prefs = profile_->GetPrefs(); | 71 PrefService* prefs = profile_->GetPrefs(); |
| 73 profile_pref_registrar_.Init(prefs); | 72 profile_pref_registrar_.Init(prefs); |
| 74 profile_pref_registrar_.Add( | 73 profile_pref_registrar_.Add( |
| 75 prefs::kAllowDeletingBrowserHistory, | 74 prefs::kAllowDeletingBrowserHistory, |
| 76 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged, | 75 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged, |
| 77 base::Unretained(this))); | 76 base::Unretained(this))); |
| 78 | 77 |
| 79 if (sync_service_) | 78 if (sync_service_) |
| 80 sync_service_observer_.Add(sync_service_); | 79 sync_service_observer_.Add(sync_service_); |
| 80 |
| 81 if (!remover_) |
| 82 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); |
| 83 |
| 84 remover_observer_.Add(remover_); |
| 81 } | 85 } |
| 82 | 86 |
| 83 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { | 87 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { |
| 88 remover_observer_.RemoveAll(); |
| 84 profile_pref_registrar_.RemoveAll(); | 89 profile_pref_registrar_.RemoveAll(); |
| 85 sync_service_observer_.RemoveAll(); | 90 sync_service_observer_.RemoveAll(); |
| 86 } | 91 } |
| 87 | 92 |
| 88 void ClearBrowsingDataHandler::HandleClearBrowsingData( | 93 void ClearBrowsingDataHandler::HandleClearBrowsingData( |
| 89 const base::ListValue* args) { | 94 const base::ListValue* args) { |
| 90 // We should never be called when the previous clearing has not yet finished. | 95 // We should never be called when the previous clearing has not yet finished. |
| 91 CHECK(!remover_); | 96 CHECK(!remover_->is_removing()); |
| 92 CHECK_EQ(1U, args->GetSize()); | 97 CHECK_EQ(1U, args->GetSize()); |
| 93 CHECK(webui_callback_id_.empty()); | 98 CHECK(webui_callback_id_.empty()); |
| 94 CHECK(args->GetString(0, &webui_callback_id_)); | 99 CHECK(args->GetString(0, &webui_callback_id_)); |
| 95 | 100 |
| 96 PrefService* prefs = profile_->GetPrefs(); | 101 PrefService* prefs = profile_->GetPrefs(); |
| 97 | 102 |
| 98 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; | 103 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
| 99 // Don't try to clear LSO data if it's not supported. | 104 // Don't try to clear LSO data if it's not supported. |
| 100 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) | 105 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) |
| 101 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 106 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 int checked_other_types = std::count_if( | 166 int checked_other_types = std::count_if( |
| 162 other_types, other_types + num_other_types, | 167 other_types, other_types + num_other_types, |
| 163 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 168 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
| 164 UMA_HISTOGRAM_SPARSE_SLOWLY( | 169 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 165 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 170 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
| 166 checked_other_types); | 171 checked_other_types); |
| 167 } | 172 } |
| 168 | 173 |
| 169 int period_selected = | 174 int period_selected = |
| 170 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 175 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
| 171 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); | |
| 172 remover_->AddObserver(this); | |
| 173 remover_->Remove(BrowsingDataRemover::Period( | 176 remover_->Remove(BrowsingDataRemover::Period( |
| 174 static_cast<browsing_data::TimePeriod>(period_selected)), | 177 static_cast<browsing_data::TimePeriod>(period_selected)), |
| 175 remove_mask, origin_mask); | 178 remove_mask, origin_mask); |
| 176 } | 179 } |
| 177 | 180 |
| 178 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { | 181 void ClearBrowsingDataHandler::OnBrowsingDataRemoving(bool is_removing) { |
| 179 remover_->RemoveObserver(this); | 182 CallJavascriptFunction("cr.webUIListenerCallback", |
| 180 remover_ = nullptr; | 183 base::StringValue("browsing-data-removing"), |
| 184 base::FundamentalValue(is_removing)); |
| 185 |
| 186 if (is_removing || webui_callback_id_.empty()) |
| 187 return; |
| 181 | 188 |
| 182 PrefService* prefs = profile_->GetPrefs(); | 189 PrefService* prefs = profile_->GetPrefs(); |
| 183 int notice_shown_times = | 190 int notice_shown_times = |
| 184 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); | 191 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
| 185 | 192 |
| 186 // When the deletion is complete, we might show an additional dialog with | 193 // When the deletion is complete, we might show an additional dialog with |
| 187 // a notice about other forms of browsing history. This is the case if | 194 // a notice about other forms of browsing history. This is the case if |
| 188 const bool show_notice = | 195 const bool show_notice = |
| 189 // 1. The dialog is relevant for the user. | 196 // 1. The dialog is relevant for the user. |
| 190 show_history_deletion_dialog_ && | 197 show_history_deletion_dialog_ && |
| (...skipping 21 matching lines...) Expand all Loading... |
| 212 CallJavascriptFunction( | 219 CallJavascriptFunction( |
| 213 "cr.webUIListenerCallback", | 220 "cr.webUIListenerCallback", |
| 214 base::StringValue("browsing-history-pref-changed"), | 221 base::StringValue("browsing-history-pref-changed"), |
| 215 base::FundamentalValue( | 222 base::FundamentalValue( |
| 216 profile_->GetPrefs()->GetBoolean( | 223 profile_->GetPrefs()->GetBoolean( |
| 217 prefs::kAllowDeletingBrowserHistory))); | 224 prefs::kAllowDeletingBrowserHistory))); |
| 218 } | 225 } |
| 219 | 226 |
| 220 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 227 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
| 221 AllowJavascript(); | 228 AllowJavascript(); |
| 229 const base::Value* callback_id; |
| 230 CHECK(args->Get(0, &callback_id)); |
| 231 |
| 232 counters_.clear(); |
| 222 | 233 |
| 223 for (const std::string& pref : kCounterPrefs) { | 234 for (const std::string& pref : kCounterPrefs) { |
| 224 AddCounter( | 235 AddCounter( |
| 225 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref)); | 236 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref)); |
| 226 } | 237 } |
| 227 | 238 |
| 228 OnStateChanged(); | 239 OnStateChanged(); |
| 229 RefreshHistoryNotice(); | 240 RefreshHistoryNotice(); |
| 241 |
| 242 ResolveJavascriptCallback(*callback_id, |
| 243 base::FundamentalValue(remover_->is_removing())); |
| 230 } | 244 } |
| 231 | 245 |
| 232 void ClearBrowsingDataHandler::OnStateChanged() { | 246 void ClearBrowsingDataHandler::OnStateChanged() { |
| 233 CallJavascriptFunction( | 247 CallJavascriptFunction( |
| 234 "cr.webUIListenerCallback", | 248 "cr.webUIListenerCallback", |
| 235 base::StringValue("update-footer"), | 249 base::StringValue("update-footer"), |
| 236 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 250 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
| 237 base::FundamentalValue(show_history_footer_)); | 251 base::FundamentalValue(show_history_footer_)); |
| 238 } | 252 } |
| 239 | 253 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 263 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { | 277 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { |
| 264 show_history_footer_ = show; | 278 show_history_footer_ = show; |
| 265 OnStateChanged(); | 279 OnStateChanged(); |
| 266 | 280 |
| 267 UMA_HISTOGRAM_BOOLEAN( | 281 UMA_HISTOGRAM_BOOLEAN( |
| 268 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 282 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
| 269 show_history_footer_); | 283 show_history_footer_); |
| 270 } | 284 } |
| 271 | 285 |
| 272 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { | 286 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { |
| 273 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). | 287 // This is used by OnBrowsingDataRemoving (when the deletion finishes). |
| 274 show_history_deletion_dialog_ = show; | 288 show_history_deletion_dialog_ = show; |
| 275 } | 289 } |
| 276 | 290 |
| 277 void ClearBrowsingDataHandler::AddCounter( | 291 void ClearBrowsingDataHandler::AddCounter( |
| 278 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { | 292 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { |
| 279 counter->Init(profile_->GetPrefs(), | 293 counter->Init(profile_->GetPrefs(), |
| 280 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, | 294 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, |
| 281 base::Unretained(this))); | 295 base::Unretained(this))); |
| 282 counter->Restart(); | 296 counter->Restart(); |
| 283 counters_.push_back(std::move(counter)); | 297 counters_.push_back(std::move(counter)); |
| 284 } | 298 } |
| 285 | 299 |
| 286 void ClearBrowsingDataHandler::UpdateCounterText( | 300 void ClearBrowsingDataHandler::UpdateCounterText( |
| 287 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 301 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 288 CallJavascriptFunction( | 302 CallJavascriptFunction( |
| 289 "cr.webUIListenerCallback", | 303 "cr.webUIListenerCallback", |
| 290 base::StringValue("update-counter-text"), | 304 base::StringValue("update-counter-text"), |
| 291 base::StringValue(result->source()->GetPrefName()), | 305 base::StringValue(result->source()->GetPrefName()), |
| 292 base::StringValue(GetCounterTextFromResult(result.get()))); | 306 base::StringValue(GetCounterTextFromResult(result.get()))); |
| 293 } | 307 } |
| 294 | 308 |
| 295 } // namespace settings | 309 } // namespace settings |
| OLD | NEW |