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

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: 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());
Dan Beam 2016/11/29 06:18:58 nit: I suppose this is OK, but why can't we just .
tommycli 2016/11/30 15:59:35 Clearing would be also harmless, but clearing tell
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();
tommycli 2016/11/29 01:08:12 This was the missing line that caused the crashes.
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
262 task_observer_.reset();
tommycli 2016/11/29 01:08:12 This was not necessary right? Reading the code --
Dan Beam 2016/11/29 06:18:58 in theory, though a renderer crash might affect th
tommycli 2016/11/30 15:59:35 I see. I restored it and added a comment.
263 counters_.clear();
264
265 for (const std::string& pref : kCounterPrefs) {
266 AddCounter(
267 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref));
268 }
269
270 OnStateChanged(); 269 OnStateChanged();
271 RefreshHistoryNotice(); 270 RefreshHistoryNotice();
272 271
273 ResolveJavascriptCallback( 272 ResolveJavascriptCallback(
274 *callback_id, 273 *callback_id,
275 *base::Value::CreateNullValue() /* Promise<void> */); 274 *base::Value::CreateNullValue() /* Promise<void> */);
276 } 275 }
277 276
278 void ClearBrowsingDataHandler::OnStateChanged() { 277 void ClearBrowsingDataHandler::OnStateChanged() {
279 CallJavascriptFunction( 278 CallJavascriptFunction(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 void ClearBrowsingDataHandler::UpdateCounterText( 331 void ClearBrowsingDataHandler::UpdateCounterText(
333 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 332 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
334 CallJavascriptFunction( 333 CallJavascriptFunction(
335 "cr.webUIListenerCallback", 334 "cr.webUIListenerCallback",
336 base::StringValue("update-counter-text"), 335 base::StringValue("update-counter-text"),
337 base::StringValue(result->source()->GetPrefName()), 336 base::StringValue(result->source()->GetPrefName()),
338 base::StringValue(GetChromeCounterTextFromResult(result.get()))); 337 base::StringValue(GetChromeCounterTextFromResult(result.get())));
339 } 338 }
340 339
341 } // namespace settings 340 } // 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