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

Side by Side Diff: chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc

Issue 2536003003: MD Settings: Fix WebUI lifecycle issues in Clear Browsing Data handler. (Closed)
Patch Set: address dbeam comments Created 4 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 void ClearBrowsingDataHandler::OnJavascriptAllowed() { 102 void ClearBrowsingDataHandler::OnJavascriptAllowed() {
103 PrefService* prefs = profile_->GetPrefs(); 103 PrefService* prefs = profile_->GetPrefs();
104 profile_pref_registrar_.Init(prefs); 104 profile_pref_registrar_.Init(prefs);
105 profile_pref_registrar_.Add( 105 profile_pref_registrar_.Add(
106 prefs::kAllowDeletingBrowserHistory, 106 prefs::kAllowDeletingBrowserHistory,
107 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged, 107 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged,
108 base::Unretained(this))); 108 base::Unretained(this)));
109 109
110 if (sync_service_) 110 if (sync_service_)
111 sync_service_observer_.Add(sync_service_); 111 sync_service_observer_.Add(sync_service_);
112
113 DCHECK(counters_.empty());
114 for (const std::string& pref : kCounterPrefs) {
115 AddCounter(
116 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref));
117 }
112 } 118 }
113 119
114 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { 120 void ClearBrowsingDataHandler::OnJavascriptDisallowed() {
115 profile_pref_registrar_.RemoveAll(); 121 profile_pref_registrar_.RemoveAll();
116 sync_service_observer_.RemoveAll(); 122 sync_service_observer_.RemoveAll();
117 task_observer_.reset(); 123 task_observer_.reset();
124 counters_.clear();
118 } 125 }
119 126
120 void ClearBrowsingDataHandler::HandleClearBrowsingData( 127 void ClearBrowsingDataHandler::HandleClearBrowsingData(
121 const base::ListValue* args) { 128 const base::ListValue* args) {
122 DCHECK(!task_observer_); 129 DCHECK(!task_observer_);
123 130
124 PrefService* prefs = profile_->GetPrefs(); 131 PrefService* prefs = profile_->GetPrefs();
125 132
126 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; 133 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
127 // Don't try to clear LSO data if it's not supported. 134 // Don't try to clear LSO data if it's not supported.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 base::FundamentalValue( 259 base::FundamentalValue(
253 profile_->GetPrefs()->GetBoolean( 260 profile_->GetPrefs()->GetBoolean(
254 prefs::kAllowDeletingBrowserHistory))); 261 prefs::kAllowDeletingBrowserHistory)));
255 } 262 }
256 263
257 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { 264 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) {
258 AllowJavascript(); 265 AllowJavascript();
259 const base::Value* callback_id; 266 const base::Value* callback_id;
260 CHECK(args->Get(0, &callback_id)); 267 CHECK(args->Get(0, &callback_id));
261 268
269 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450.
262 task_observer_.reset(); 270 task_observer_.reset();
263 counters_.clear();
264
265 for (const std::string& pref : kCounterPrefs) {
266 AddCounter(
267 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref));
268 }
269 271
270 OnStateChanged(); 272 OnStateChanged();
271 RefreshHistoryNotice(); 273 RefreshHistoryNotice();
272 274
273 ResolveJavascriptCallback( 275 ResolveJavascriptCallback(
274 *callback_id, 276 *callback_id,
275 *base::Value::CreateNullValue() /* Promise<void> */); 277 *base::Value::CreateNullValue() /* Promise<void> */);
276 } 278 }
277 279
278 void ClearBrowsingDataHandler::OnStateChanged() { 280 void ClearBrowsingDataHandler::OnStateChanged() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 void ClearBrowsingDataHandler::UpdateCounterText( 334 void ClearBrowsingDataHandler::UpdateCounterText(
333 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 335 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
334 CallJavascriptFunction( 336 CallJavascriptFunction(
335 "cr.webUIListenerCallback", 337 "cr.webUIListenerCallback",
336 base::StringValue("update-counter-text"), 338 base::StringValue("update-counter-text"),
337 base::StringValue(result->source()->GetPrefName()), 339 base::StringValue(result->source()->GetPrefName()),
338 base::StringValue(GetChromeCounterTextFromResult(result.get()))); 340 base::StringValue(GetChromeCounterTextFromResult(result.get())));
339 } 341 }
340 342
341 } // namespace settings 343 } // namespace settings
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698