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

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

Issue 2581643002: Define a new policy to disable clearing the browsing history from the UI. (Closed)
Patch Set: less headers 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 base::Bind(&ClearBrowsingDataHandler::HandleClearBrowsingData, 93 base::Bind(&ClearBrowsingDataHandler::HandleClearBrowsingData,
94 base::Unretained(this))); 94 base::Unretained(this)));
95 95
96 web_ui()->RegisterMessageCallback( 96 web_ui()->RegisterMessageCallback(
97 "initializeClearBrowsingData", 97 "initializeClearBrowsingData",
98 base::Bind(&ClearBrowsingDataHandler::HandleInitialize, 98 base::Bind(&ClearBrowsingDataHandler::HandleInitialize,
99 base::Unretained(this))); 99 base::Unretained(this)));
100 } 100 }
101 101
102 void ClearBrowsingDataHandler::OnJavascriptAllowed() { 102 void ClearBrowsingDataHandler::OnJavascriptAllowed() {
103 PrefService* prefs = profile_->GetPrefs();
104 profile_pref_registrar_.Init(prefs);
105 profile_pref_registrar_.Add(
106 prefs::kAllowDeletingBrowserHistory,
107 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged,
108 base::Unretained(this)));
109
110 if (sync_service_) 103 if (sync_service_)
111 sync_service_observer_.Add(sync_service_); 104 sync_service_observer_.Add(sync_service_);
112 105
113 DCHECK(counters_.empty()); 106 DCHECK(counters_.empty());
114 for (const std::string& pref : kCounterPrefs) { 107 for (const std::string& pref : kCounterPrefs) {
115 AddCounter( 108 AddCounter(
116 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref)); 109 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref));
117 } 110 }
118 } 111 }
119 112
120 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { 113 void ClearBrowsingDataHandler::OnJavascriptDisallowed() {
121 profile_pref_registrar_.RemoveAll();
122 sync_service_observer_.RemoveAll(); 114 sync_service_observer_.RemoveAll();
123 task_observer_.reset(); 115 task_observer_.reset();
124 counters_.clear(); 116 counters_.clear();
125 } 117 }
126 118
127 void ClearBrowsingDataHandler::HandleClearBrowsingData( 119 void ClearBrowsingDataHandler::HandleClearBrowsingData(
128 const base::ListValue* args) { 120 const base::ListValue* args) {
129 DCHECK(!task_observer_); 121 DCHECK(!task_observer_);
130 122
131 PrefService* prefs = profile_->GetPrefs(); 123 PrefService* prefs = profile_->GetPrefs();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 237
246 UMA_HISTOGRAM_BOOLEAN( 238 UMA_HISTOGRAM_BOOLEAN(
247 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); 239 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice);
248 240
249 ResolveJavascriptCallback( 241 ResolveJavascriptCallback(
250 base::StringValue(webui_callback_id), 242 base::StringValue(webui_callback_id),
251 base::FundamentalValue(show_notice)); 243 base::FundamentalValue(show_notice));
252 task_observer_.reset(); 244 task_observer_.reset();
253 } 245 }
254 246
255 void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() {
256 CallJavascriptFunction(
257 "cr.webUIListenerCallback",
258 base::StringValue("browsing-history-pref-changed"),
259 base::FundamentalValue(
260 profile_->GetPrefs()->GetBoolean(
261 prefs::kAllowDeletingBrowserHistory)));
262 }
263
264 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { 247 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) {
265 AllowJavascript(); 248 AllowJavascript();
266 const base::Value* callback_id; 249 const base::Value* callback_id;
267 CHECK(args->Get(0, &callback_id)); 250 CHECK(args->Get(0, &callback_id));
268 251
269 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. 252 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450.
270 task_observer_.reset(); 253 task_observer_.reset();
271 254
272 OnStateChanged(); 255 OnStateChanged();
273 RefreshHistoryNotice(); 256 RefreshHistoryNotice();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 void ClearBrowsingDataHandler::UpdateCounterText( 317 void ClearBrowsingDataHandler::UpdateCounterText(
335 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 318 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
336 CallJavascriptFunction( 319 CallJavascriptFunction(
337 "cr.webUIListenerCallback", 320 "cr.webUIListenerCallback",
338 base::StringValue("update-counter-text"), 321 base::StringValue("update-counter-text"),
339 base::StringValue(result->source()->GetPrefName()), 322 base::StringValue(result->source()->GetPrefName()),
340 base::StringValue(GetChromeCounterTextFromResult(result.get()))); 323 base::StringValue(GetChromeCounterTextFromResult(result.get())));
341 } 324 }
342 325
343 } // namespace settings 326 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698