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

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

Issue 2098633002: Migrate the one-time notice into the MD settings CBD dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_counters
Patch Set: Initialize to false. Created 4 years, 5 months 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"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
13 #include "chrome/browser/browsing_data/autofill_counter.h" 13 #include "chrome/browser/browsing_data/autofill_counter.h"
14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" 14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h"
15 #include "chrome/browser/browsing_data/browsing_data_helper.h" 15 #include "chrome/browser/browsing_data/browsing_data_helper.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
17 #include "chrome/browser/browsing_data/cache_counter.h" 17 #include "chrome/browser/browsing_data/cache_counter.h"
18 #include "chrome/browser/browsing_data/downloads_counter.h" 18 #include "chrome/browser/browsing_data/downloads_counter.h"
19 #include "chrome/browser/browsing_data/history_counter.h" 19 #include "chrome/browser/browsing_data/history_counter.h"
20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" 20 #include "chrome/browser/browsing_data/hosted_apps_counter.h"
21 #include "chrome/browser/browsing_data/passwords_counter.h" 21 #include "chrome/browser/browsing_data/passwords_counter.h"
22 #include "chrome/browser/history/web_history_service_factory.h" 22 #include "chrome/browser/history/web_history_service_factory.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h" 23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/common/channel_info.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "components/browsing_data_ui/history_notice_utils.h" 26 #include "components/browsing_data_ui/history_notice_utils.h"
26 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
27 #include "content/public/browser/web_ui.h" 28 #include "content/public/browser/web_ui.h"
28 29
30 namespace {
31
32 const int kMaxTimesHistoryNoticeShown = 1;
33
34 }
35
29 namespace settings { 36 namespace settings {
30 37
31 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) 38 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui)
32 : profile_(Profile::FromWebUI(webui)), 39 : profile_(Profile::FromWebUI(webui)),
33 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), 40 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)),
34 sync_service_observer_(this), 41 sync_service_observer_(this),
35 remover_(nullptr), 42 remover_(nullptr),
36 should_show_history_footer_(false), 43 show_history_footer_(false),
44 show_history_deletion_dialog_(false),
37 weak_ptr_factory_(this) {} 45 weak_ptr_factory_(this) {}
38 46
39 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { 47 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() {
40 if (remover_) 48 if (remover_)
41 remover_->RemoveObserver(this); 49 remover_->RemoveObserver(this);
42 } 50 }
43 51
44 void ClearBrowsingDataHandler::RegisterMessages() { 52 void ClearBrowsingDataHandler::RegisterMessages() {
45 web_ui()->RegisterMessageCallback( 53 web_ui()->RegisterMessageCallback(
46 "clearBrowsingData", 54 "clearBrowsingData",
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 remover_->AddObserver(this); 167 remover_->AddObserver(this);
160 remover_->Remove( 168 remover_->Remove(
161 BrowsingDataRemover::Period( 169 BrowsingDataRemover::Period(
162 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)), 170 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)),
163 remove_mask, origin_mask); 171 remove_mask, origin_mask);
164 } 172 }
165 173
166 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { 174 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() {
167 remover_->RemoveObserver(this); 175 remover_->RemoveObserver(this);
168 remover_ = nullptr; 176 remover_ = nullptr;
177
178 PrefService* prefs = profile_->GetPrefs();
179 int notice_shown_times =
180 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes);
181
182 // When the deletion is complete, we might show an additional dialog with
183 // a notice about other forms of browsing history. This is the case if
184 const bool show_notice =
185 // 1. The dialog is relevant for the user.
186 show_history_deletion_dialog_ &&
187 // 2. The notice has been shown less than |kMaxTimesHistoryNoticeShown|.
188 notice_shown_times < kMaxTimesHistoryNoticeShown &&
189 // 3. The selected data types contained browsing history.
190 prefs->GetBoolean(prefs::kDeleteBrowsingHistory);
191
192 if (show_notice) {
193 // Increment the preference.
194 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes,
195 notice_shown_times + 1);
196 }
197
198 UMA_HISTOGRAM_BOOLEAN(
199 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice);
200
169 ResolveJavascriptCallback( 201 ResolveJavascriptCallback(
170 base::StringValue(webui_callback_id_), 202 base::StringValue(webui_callback_id_),
171 *base::Value::CreateNullValue()); 203 base::FundamentalValue(show_notice));
172 webui_callback_id_.clear(); 204 webui_callback_id_.clear();
173 } 205 }
174 206
175 void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() { 207 void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() {
176 CallJavascriptFunction( 208 CallJavascriptFunction(
177 "cr.webUIListenerCallback", 209 "cr.webUIListenerCallback",
178 base::StringValue("browsing-history-pref-changed"), 210 base::StringValue("browsing-history-pref-changed"),
179 base::FundamentalValue( 211 base::FundamentalValue(
180 profile_->GetPrefs()->GetBoolean( 212 profile_->GetPrefs()->GetBoolean(
181 prefs::kAllowDeletingBrowserHistory))); 213 prefs::kAllowDeletingBrowserHistory)));
(...skipping 12 matching lines...) Expand all
194 226
195 OnStateChanged(); 227 OnStateChanged();
196 RefreshHistoryNotice(); 228 RefreshHistoryNotice();
197 } 229 }
198 230
199 void ClearBrowsingDataHandler::OnStateChanged() { 231 void ClearBrowsingDataHandler::OnStateChanged() {
200 CallJavascriptFunction( 232 CallJavascriptFunction(
201 "cr.webUIListenerCallback", 233 "cr.webUIListenerCallback",
202 base::StringValue("update-footer"), 234 base::StringValue("update-footer"),
203 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), 235 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()),
204 base::FundamentalValue(should_show_history_footer_)); 236 base::FundamentalValue(show_history_footer_));
205 } 237 }
206 238
207 void ClearBrowsingDataHandler::RefreshHistoryNotice() { 239 void ClearBrowsingDataHandler::RefreshHistoryNotice() {
208 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( 240 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
209 sync_service_, 241 sync_service_,
210 WebHistoryServiceFactory::GetForProfile(profile_), 242 WebHistoryServiceFactory::GetForProfile(profile_),
211 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryNotice, 243 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryNotice,
212 weak_ptr_factory_.GetWeakPtr())); 244 weak_ptr_factory_.GetWeakPtr()));
245
246 // If the dialog with history notice has been shown less than
247 // |kMaxTimesHistoryNoticeShown| times, we might have to show it when the
248 // user deletes history. Find out if the conditions are met.
249 int notice_shown_times = profile_->GetPrefs()->
250 GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes);
251
252 if (notice_shown_times < kMaxTimesHistoryNoticeShown) {
253 browsing_data_ui::ShouldPopupDialogAboutOtherFormsOfBrowsingHistory(
254 sync_service_,
255 WebHistoryServiceFactory::GetForProfile(profile_),
256 chrome::GetChannel(),
257 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryDeletionDialog,
258 weak_ptr_factory_.GetWeakPtr()));
259 }
213 } 260 }
214 261
215 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { 262 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) {
216 should_show_history_footer_ = show; 263 show_history_footer_ = show;
217 OnStateChanged(); 264 OnStateChanged();
218 265
219 UMA_HISTOGRAM_BOOLEAN( 266 UMA_HISTOGRAM_BOOLEAN(
220 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", 267 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated",
221 should_show_history_footer_); 268 show_history_footer_);
269 }
270
271 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) {
272 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes).
273 show_history_deletion_dialog_ = show;
222 } 274 }
223 275
224 void ClearBrowsingDataHandler::AddCounter( 276 void ClearBrowsingDataHandler::AddCounter(
225 std::unique_ptr<BrowsingDataCounter> counter) { 277 std::unique_ptr<BrowsingDataCounter> counter) {
226 counter->Init( 278 counter->Init(
227 profile_, 279 profile_,
228 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, 280 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText,
229 base::Unretained(this))); 281 base::Unretained(this)));
230 counter->Restart(); 282 counter->Restart();
231 counters_.push_back(std::move(counter)); 283 counters_.push_back(std::move(counter));
232 } 284 }
233 285
234 void ClearBrowsingDataHandler::UpdateCounterText( 286 void ClearBrowsingDataHandler::UpdateCounterText(
235 std::unique_ptr<BrowsingDataCounter::Result> result) { 287 std::unique_ptr<BrowsingDataCounter::Result> result) {
236 CallJavascriptFunction( 288 CallJavascriptFunction(
237 "cr.webUIListenerCallback", 289 "cr.webUIListenerCallback",
238 base::StringValue("update-counter-text"), 290 base::StringValue("update-counter-text"),
239 base::StringValue(result->source()->GetPrefName()), 291 base::StringValue(result->source()->GetPrefName()),
240 base::StringValue(GetCounterTextFromResult(result.get()))); 292 base::StringValue(GetCounterTextFromResult(result.get())));
241 } 293 }
242 294
243 } // namespace settings 295 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698