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

Side by Side Diff: chrome/browser/ui/webui/options/clear_browser_data_handler.cc

Issue 1420013004: Polish the result communication and display of the browsing data counters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options/clear_browser_data_handler.h" 5 #include "chrome/browser/ui/webui/options/clear_browser_data_handler.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.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 "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/string_number_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/app/chrome_command_ids.h" 17 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/browsing_data/browsing_data_counter.h" 19 #include "chrome/browser/browsing_data/browsing_data_counter.h"
19 #include "chrome/browser/browsing_data/browsing_data_helper.h" 20 #include "chrome/browser/browsing_data/browsing_data_helper.h"
20 #include "chrome/browser/browsing_data/browsing_data_remover.h" 21 #include "chrome/browser/browsing_data/browsing_data_remover.h"
21 #include "chrome/browser/browsing_data/cache_counter.h" 22 #include "chrome/browser/browsing_data/cache_counter.h"
22 #include "chrome/browser/browsing_data/history_counter.h" 23 #include "chrome/browser/browsing_data/history_counter.h"
23 #include "chrome/browser/browsing_data/passwords_counter.h" 24 #include "chrome/browser/browsing_data/passwords_counter.h"
24 #include "chrome/browser/prefs/incognito_mode_prefs.h" 25 #include "chrome/browser/prefs/incognito_mode_prefs.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/sync/profile_sync_service_factory.h" 27 #include "chrome/browser/sync/profile_sync_service_factory.h"
27 #include "chrome/browser/ui/accelerator_utils.h" 28 #include "chrome/browser/ui/accelerator_utils.h"
28 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
30 #include "chrome/grit/generated_resources.h" 31 #include "chrome/grit/generated_resources.h"
31 #include "chrome/grit/locale_settings.h" 32 #include "chrome/grit/locale_settings.h"
32 #include "components/google/core/browser/google_util.h" 33 #include "components/google/core/browser/google_util.h"
33 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
34 #include "content/public/browser/web_ui.h" 35 #include "content/public/browser/web_ui.h"
35 #include "ui/base/accelerators/accelerator.h" 36 #include "ui/base/accelerators/accelerator.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/text/bytes_formatting.h"
37 #include "ui/events/keycodes/keyboard_codes.h" 39 #include "ui/events/keycodes/keyboard_codes.h"
38 40
39 namespace { 41 namespace {
40 42
41 const char kClearBrowsingDataLearnMoreUrl[] = 43 const char kClearBrowsingDataLearnMoreUrl[] =
42 "https://support.google.com/chrome/?p=settings_clear_browsing_data"; 44 "https://support.google.com/chrome/?p=settings_clear_browsing_data";
43 45
44 bool AreCountersEnabled() { 46 bool AreCountersEnabled() {
45 return base::CommandLine::ForCurrentProcess()->HasSwitch( 47 return base::CommandLine::ForCurrentProcess()->HasSwitch(
46 switches::kEnableClearBrowsingDataCounters); 48 switches::kEnableClearBrowsingDataCounters);
(...skipping 20 matching lines...) Expand all
67 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs); 69 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs);
68 pepper_flash_settings_enabled_.Init(prefs::kPepperFlashSettingsEnabled, 70 pepper_flash_settings_enabled_.Init(prefs::kPepperFlashSettingsEnabled,
69 prefs); 71 prefs);
70 allow_deleting_browser_history_.Init( 72 allow_deleting_browser_history_.Init(
71 prefs::kAllowDeletingBrowserHistory, 73 prefs::kAllowDeletingBrowserHistory,
72 prefs, 74 prefs,
73 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged, 75 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged,
74 base::Unretained(this))); 76 base::Unretained(this)));
75 77
76 if (AreCountersEnabled()) { 78 if (AreCountersEnabled()) {
77 AddCounter(make_scoped_ptr(new PasswordsCounter()), 79 AddCounter(make_scoped_ptr(new PasswordsCounter()));
78 IDS_DEL_PASSWORDS_COUNTER); 80 AddCounter(make_scoped_ptr(new HistoryCounter()));
79 AddCounter(make_scoped_ptr(new HistoryCounter()), 81 AddCounter(make_scoped_ptr(new CacheCounter()));
80 IDS_DEL_BROWSING_HISTORY_COUNTER);
81 AddCounter(make_scoped_ptr(new CacheCounter()), IDS_DEL_CACHE_COUNTER);
82 82
83 sync_service_ = 83 sync_service_ =
84 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 84 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
85 if (sync_service_) 85 if (sync_service_)
86 sync_service_->AddObserver(this); 86 sync_service_->AddObserver(this);
87 } 87 }
88 } 88 }
89 89
90 void ClearBrowserDataHandler::InitializePage() { 90 void ClearBrowserDataHandler::InitializePage() {
91 web_ui()->CallJavascriptFunction( 91 web_ui()->CallJavascriptFunction(
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.doneClearing"); 301 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.doneClearing");
302 } 302 }
303 303
304 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { 304 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() {
305 web_ui()->CallJavascriptFunction( 305 web_ui()->CallJavascriptFunction(
306 "ClearBrowserDataOverlay.setAllowDeletingHistory", 306 "ClearBrowserDataOverlay.setAllowDeletingHistory",
307 base::FundamentalValue(*allow_deleting_browser_history_)); 307 base::FundamentalValue(*allow_deleting_browser_history_));
308 } 308 }
309 309
310 void ClearBrowserDataHandler::AddCounter( 310 void ClearBrowserDataHandler::AddCounter(
311 scoped_ptr<BrowsingDataCounter> counter, int text_grd_id) { 311 scoped_ptr<BrowsingDataCounter> counter) {
312 DCHECK(AreCountersEnabled()); 312 DCHECK(AreCountersEnabled());
313 313
314 counter->Init( 314 counter->Init(
315 Profile::FromWebUI(web_ui()), 315 Profile::FromWebUI(web_ui()),
316 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, 316 base::Bind(&ClearBrowserDataHandler::UpdateCounterText,
317 base::Unretained(this), 317 base::Unretained(this)));
318 counter->GetPrefName(),
319 text_grd_id));
320 counters_.push_back(counter.Pass()); 318 counters_.push_back(counter.Pass());
321 } 319 }
322 320
323 void ClearBrowserDataHandler::UpdateCounterText( 321 void ClearBrowserDataHandler::UpdateCounterText(
324 const std::string& pref_name, 322 scoped_ptr<BrowsingDataCounter::Result> result) {
325 int text_grd_id,
326 bool finished,
327 BrowsingDataCounter::ResultInt count) {
328 DCHECK(AreCountersEnabled()); 323 DCHECK(AreCountersEnabled());
329 base::string16 text = finished 324 base::string16 text;
330 ? l10n_util::GetPluralStringFUTF16(text_grd_id, count) 325 std::string pref_name = result->source()->GetPrefName();
331 : l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); 326
327 if (!result->finished()) {
328 // The counter is still counting.
329 text = l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING);
330
331 } else if (pref_name == prefs::kDeletePasswords) {
332 // Passwords counter.
333 BrowsingDataCounter::ResultInt value = result->value();
334 text = value > 0
335 ? l10n_util::GetPluralStringFUTF16(IDS_DEL_PASSWORDS_COUNTER, value)
336 : l10n_util::GetStringUTF16(IDS_DEL_PASSWORDS_COUNTER_EMPTY);
337
338 } else if (pref_name == prefs::kDeleteCache) {
339 // Cache counter.
340 BrowsingDataCounter::ResultInt value = result->value();
Bernhard Bauer 2015/11/02 16:15:27 Name this variable so that it reflects what the va
msramek 2015/11/02 20:54:06 Done. Here and elsewhere.
341
342 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
343 BrowsingDataRemover::TimePeriod time_period =
344 static_cast<BrowsingDataRemover::TimePeriod>(
345 prefs->GetInteger(prefs::kDeleteTimePeriod));
346
347 // Three cases: Nonzero result for the entire cache, nonzero result for
348 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB).
349 static const int kBInMB = 1024 * 1024;
Bernhard Bauer 2015/11/02 16:15:27 The name of this variable isn't really right. This
msramek 2015/11/02 20:54:06 Hmm, haven't heard of that. In fact, https://googl
Bernhard Bauer 2015/11/03 10:11:19 Hm, I can't find any explicit mention in the style
msramek 2015/11/03 10:55:45 Yes :-) I wanted to be concise (although it's just
350 if (value >= kBInMB) {
351 base::string16 formatted_size = ui::FormatBytes(value);
352 text = time_period == BrowsingDataRemover::EVERYTHING
353 ? formatted_size
354 : l10n_util::GetStringFUTF16(IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE,
355 formatted_size);
356 } else {
357 text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY);
358 }
359
360 } else if (pref_name == prefs::kDeleteBrowsingHistory) {
361 // History counter.
362 HistoryCounter::HistoryResult* history_result =
363 static_cast<HistoryCounter::HistoryResult*>(result.get());
364 BrowsingDataCounter::ResultInt value = history_result->value();
365 bool has_synced_visits = history_result->has_synced_visits();
366
367 // Four cases: [zero|nonzero] [local|web] result.
368 if (value > 0) {
369 text = has_synced_visits
370 ? l10n_util::GetPluralStringFUTF16(
371 IDS_DEL_BROWSING_HISTORY_COUNTER_SYNCED, value)
372 : l10n_util::GetPluralStringFUTF16(
373 IDS_DEL_BROWSING_HISTORY_COUNTER, value);
374 } else {
375 text = has_synced_visits
376 ? l10n_util::GetStringUTF16(
377 IDS_DEL_BROWSING_HISTORY_COUNTER_SYNCED_ONLY)
378 : l10n_util::GetStringUTF16(
379 IDS_DEL_BROWSING_HISTORY_COUNTER_EMPTY);
380 }
381 }
332 382
333 web_ui()->CallJavascriptFunction( 383 web_ui()->CallJavascriptFunction(
334 "ClearBrowserDataOverlay.updateCounter", 384 "ClearBrowserDataOverlay.updateCounter",
335 base::StringValue(pref_name), 385 base::StringValue(pref_name),
336 base::StringValue(text)); 386 base::StringValue(text));
337 } 387 }
338 388
339 void ClearBrowserDataHandler::OnStateChanged() { 389 void ClearBrowserDataHandler::OnStateChanged() {
340 web_ui()->CallJavascriptFunction( 390 web_ui()->CallJavascriptFunction(
341 "ClearBrowserDataOverlay.updateSyncWarning", 391 "ClearBrowserDataOverlay.updateSyncWarning",
342 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive())); 392 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()));
343 } 393 }
344 394
345 } // namespace options 395 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698