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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java

Issue 2671743002: Separate state of basic and advanced tab in CBD dialog (Closed)
Patch Set: fix .classpath file Created 3 years, 10 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 package org.chromium.chrome.browser.preferences.privacy; 5 package org.chromium.chrome.browser.preferences.privacy;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.ProgressDialog; 8 import android.app.ProgressDialog;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.Bundle; 10 import android.os.Bundle;
11 import android.preference.Preference; 11 import android.preference.Preference;
12 import android.preference.PreferenceFragment; 12 import android.preference.PreferenceFragment;
13 import android.support.annotation.Nullable; 13 import android.support.annotation.Nullable;
14 import android.widget.ListView; 14 import android.widget.ListView;
15 15
16 import org.chromium.base.VisibleForTesting; 16 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.metrics.RecordHistogram; 17 import org.chromium.base.metrics.RecordHistogram;
18 import org.chromium.base.metrics.RecordUserAction; 18 import org.chromium.base.metrics.RecordUserAction;
19 import org.chromium.chrome.R; 19 import org.chromium.chrome.R;
20 import org.chromium.chrome.browser.ChromeFeatureList; 20 import org.chromium.chrome.browser.ChromeFeatureList;
21 import org.chromium.chrome.browser.browsing_data.BrowsingDataType; 21 import org.chromium.chrome.browser.browsing_data.BrowsingDataType;
22 import org.chromium.chrome.browser.browsing_data.ClearBrowsingDataPreferenceType ;
22 import org.chromium.chrome.browser.browsing_data.TimePeriod; 23 import org.chromium.chrome.browser.browsing_data.TimePeriod;
23 import org.chromium.chrome.browser.help.HelpAndFeedback; 24 import org.chromium.chrome.browser.help.HelpAndFeedback;
24 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; 25 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
25 import org.chromium.chrome.browser.preferences.ButtonPreference; 26 import org.chromium.chrome.browser.preferences.ButtonPreference;
26 import org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreferen ce; 27 import org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreferen ce;
27 import org.chromium.chrome.browser.preferences.PrefServiceBridge; 28 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
28 import org.chromium.chrome.browser.preferences.SpinnerPreference; 29 import org.chromium.chrome.browser.preferences.SpinnerPreference;
29 import org.chromium.chrome.browser.preferences.TextMessageWithLinkAndIconPrefere nce; 30 import org.chromium.chrome.browser.preferences.TextMessageWithLinkAndIconPrefere nce;
30 import org.chromium.chrome.browser.preferences.privacy.BrowsingDataCounterBridge .BrowsingDataCounterCallback; 31 import org.chromium.chrome.browser.preferences.privacy.BrowsingDataCounterBridge .BrowsingDataCounterCallback;
31 import org.chromium.chrome.browser.profiles.Profile; 32 import org.chromium.chrome.browser.profiles.Profile;
(...skipping 27 matching lines...) Expand all
59 60
60 public Item(ClearBrowsingDataPreferences parent, 61 public Item(ClearBrowsingDataPreferences parent,
61 DialogOption option, 62 DialogOption option,
62 ClearBrowsingDataCheckBoxPreference checkbox, 63 ClearBrowsingDataCheckBoxPreference checkbox,
63 boolean selected, 64 boolean selected,
64 boolean enabled) { 65 boolean enabled) {
65 super(); 66 super();
66 mParent = parent; 67 mParent = parent;
67 mOption = option; 68 mOption = option;
68 mCheckbox = checkbox; 69 mCheckbox = checkbox;
69 mCounter = new BrowsingDataCounterBridge(this, mOption.getDataType() ); 70 mCounter = new BrowsingDataCounterBridge(
71 this, mOption.getDataType(), mParent.getPreferenceType());
70 72
71 mCheckbox.setOnPreferenceClickListener(this); 73 mCheckbox.setOnPreferenceClickListener(this);
72 mCheckbox.setEnabled(enabled); 74 mCheckbox.setEnabled(enabled);
73 mCheckbox.setChecked(selected); 75 mCheckbox.setChecked(selected);
74 76
75 if (!ClearBrowsingDataTabsFragment.isFeatureEnabled()) { 77 if (!ClearBrowsingDataTabsFragment.isFeatureEnabled()) {
76 // No summary when unchecked. The redesigned basic and advanced 78 // No summary when unchecked. The redesigned basic and advanced
77 // CBD views will always show the checkbox summary. 79 // CBD views will always show the checkbox summary.
78 mCheckbox.setSummaryOff(""); 80 mCheckbox.setSummaryOff("");
79 } 81 }
(...skipping 11 matching lines...) Expand all
91 return mCheckbox.isChecked(); 93 return mCheckbox.isChecked();
92 } 94 }
93 95
94 @Override 96 @Override
95 public boolean onPreferenceClick(Preference preference) { 97 public boolean onPreferenceClick(Preference preference) {
96 assert mCheckbox == preference; 98 assert mCheckbox == preference;
97 99
98 mParent.updateButtonState(); 100 mParent.updateButtonState();
99 mShouldAnnounceCounterResult = true; 101 mShouldAnnounceCounterResult = true;
100 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreference( 102 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreference(
101 mOption.getDataType(), mCheckbox.isChecked()); 103 mOption.getDataType(), mParent.getPreferenceType(), mCheckbo x.isChecked());
102 return true; 104 return true;
103 } 105 }
104 106
105 @Override 107 @Override
106 public void onCounterFinished(String result) { 108 public void onCounterFinished(String result) {
107 mCheckbox.setSummaryOn(result); 109 mCheckbox.setSummaryOn(result);
108 if (ClearBrowsingDataTabsFragment.isFeatureEnabled()) { 110 if (ClearBrowsingDataTabsFragment.isFeatureEnabled()) {
109 mCheckbox.setSummaryOff(result); 111 mCheckbox.setSummaryOff(result);
110 } 112 }
111 if (mShouldAnnounceCounterResult) { 113 if (mShouldAnnounceCounterResult) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return new DialogOption[] { 294 return new DialogOption[] {
293 DialogOption.CLEAR_HISTORY, 295 DialogOption.CLEAR_HISTORY,
294 DialogOption.CLEAR_COOKIES_AND_SITE_DATA, 296 DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
295 DialogOption.CLEAR_CACHE, 297 DialogOption.CLEAR_CACHE,
296 DialogOption.CLEAR_PASSWORDS, 298 DialogOption.CLEAR_PASSWORDS,
297 DialogOption.CLEAR_FORM_DATA 299 DialogOption.CLEAR_FORM_DATA
298 }; 300 };
299 } 301 }
300 302
301 /** 303 /**
304 * Returns whether this preference page is a basic or advanced tab in order to use separate
msramek 2017/02/08 10:55:55 // This method returns 1 or 2. int method() { retu
dullweber 2017/02/08 23:03:18 ahh right, that's stupid :D Should be solved now,
305 * preferences.
306 */
307 protected int getPreferenceType() {
308 return ClearBrowsingDataPreferenceType.DEFAULT;
309 }
310
311 /**
302 * Returns the Array of time periods. Options are displayed in the same orde r as they appear 312 * Returns the Array of time periods. Options are displayed in the same orde r as they appear
303 * in the array. 313 * in the array.
304 */ 314 */
305 private TimePeriodSpinnerOption[] getTimePeriodSpinnerOptions() { 315 private TimePeriodSpinnerOption[] getTimePeriodSpinnerOptions() {
306 Activity activity = getActivity(); 316 Activity activity = getActivity();
307 317
308 TimePeriodSpinnerOption[] options = new TimePeriodSpinnerOption[] { 318 TimePeriodSpinnerOption[] options = new TimePeriodSpinnerOption[] {
309 new TimePeriodSpinnerOption(TimePeriod.LAST_HOUR, 319 new TimePeriodSpinnerOption(TimePeriod.LAST_HOUR,
310 activity.getString(R.string.clear_browsing_data_period_h our)), 320 activity.getString(R.string.clear_browsing_data_period_h our)),
311 new TimePeriodSpinnerOption(TimePeriod.LAST_DAY, 321 new TimePeriodSpinnerOption(TimePeriod.LAST_DAY,
312 activity.getString(R.string.clear_browsing_data_period_d ay)), 322 activity.getString(R.string.clear_browsing_data_period_d ay)),
313 new TimePeriodSpinnerOption(TimePeriod.LAST_WEEK, 323 new TimePeriodSpinnerOption(TimePeriod.LAST_WEEK,
314 activity.getString(R.string.clear_browsing_data_period_w eek)), 324 activity.getString(R.string.clear_browsing_data_period_w eek)),
315 new TimePeriodSpinnerOption(TimePeriod.FOUR_WEEKS, 325 new TimePeriodSpinnerOption(TimePeriod.FOUR_WEEKS,
316 activity.getString(R.string.clear_browsing_data_period_f our_weeks)), 326 activity.getString(R.string.clear_browsing_data_period_f our_weeks)),
317 new TimePeriodSpinnerOption(TimePeriod.ALL_TIME, 327 new TimePeriodSpinnerOption(TimePeriod.ALL_TIME,
318 activity.getString(R.string.clear_browsing_data_period_e verything))}; 328 activity.getString(R.string.clear_browsing_data_period_e verything))};
319 329
320 return options; 330 return options;
321 } 331 }
322 332
323 /** 333 /**
324 * Decides whether a given dialog option should be selected when the dialog is initialized. 334 * Decides whether a given dialog option should be selected when the dialog is initialized.
325 * 335 *
326 * @param option The option in question. 336 * @param option The option in question.
327 * @return boolean Whether the given option should be preselected. 337 * @return boolean Whether the given option should be preselected.
328 */ 338 */
329 private boolean isOptionSelectedByDefault(DialogOption option) { 339 private boolean isOptionSelectedByDefault(DialogOption option) {
330 return PrefServiceBridge.getInstance().getBrowsingDataDeletionPreference ( 340 return PrefServiceBridge.getInstance().getBrowsingDataDeletionPreference (
331 option.getDataType()); 341 option.getDataType(), getPreferenceType());
332 } 342 }
333 343
334 /** 344 /**
335 * Called when clearing browsing data completes. 345 * Called when clearing browsing data completes.
336 * Implements the ChromePreferences.OnClearBrowsingDataListener interface. 346 * Implements the ChromePreferences.OnClearBrowsingDataListener interface.
337 */ 347 */
338 @Override 348 @Override
339 public void onBrowsingDataCleared() { 349 public void onBrowsingDataCleared() {
340 if (getActivity() == null) return; 350 if (getActivity() == null) return;
341 351
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 @Override 419 @Override
410 public boolean onPreferenceChange(Preference preference, Object value) { 420 public boolean onPreferenceChange(Preference preference, Object value) {
411 if (preference.getKey().equals(PREF_TIME_RANGE)) { 421 if (preference.getKey().equals(PREF_TIME_RANGE)) {
412 // Inform the items that a recalculation is going to happen as a res ult of the time 422 // Inform the items that a recalculation is going to happen as a res ult of the time
413 // period change. 423 // period change.
414 for (Item item : mItems) { 424 for (Item item : mItems) {
415 item.setShouldAnnounceCounterResult(false); 425 item.setShouldAnnounceCounterResult(false);
416 } 426 }
417 427
418 PrefServiceBridge.getInstance().setBrowsingDataDeletionTimePeriod( 428 PrefServiceBridge.getInstance().setBrowsingDataDeletionTimePeriod(
419 ((TimePeriodSpinnerOption) value).getTimePeriod()); 429 getPreferenceType(), ((TimePeriodSpinnerOption) value).getTi mePeriod());
420 return true; 430 return true;
421 } 431 }
422 return false; 432 return false;
423 } 433 }
424 434
425 /** 435 /**
426 * Disable the "Clear" button if none of the options are selected. Otherwise , enable it. 436 * Disable the "Clear" button if none of the options are selected. Otherwise , enable it.
427 */ 437 */
428 protected void updateButtonState() { 438 protected void updateButtonState() {
429 ButtonPreference clearButton = (ButtonPreference) findPreference(PREF_CL EAR_BUTTON); 439 ButtonPreference clearButton = (ButtonPreference) findPreference(PREF_CL EAR_BUTTON);
(...skipping 20 matching lines...) Expand all
450 DialogOption[] options = getDialogOptions(); 460 DialogOption[] options = getDialogOptions();
451 mItems = new Item[options.length]; 461 mItems = new Item[options.length];
452 for (int i = 0; i < options.length; i++) { 462 for (int i = 0; i < options.length; i++) {
453 boolean enabled = true; 463 boolean enabled = true;
454 464
455 // It is possible to disable the deletion of browsing history. 465 // It is possible to disable the deletion of browsing history.
456 if (options[i] == DialogOption.CLEAR_HISTORY 466 if (options[i] == DialogOption.CLEAR_HISTORY
457 && !PrefServiceBridge.getInstance().canDeleteBrowsingHistory ()) { 467 && !PrefServiceBridge.getInstance().canDeleteBrowsingHistory ()) {
458 enabled = false; 468 enabled = false;
459 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreferenc e( 469 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreferenc e(
460 DialogOption.CLEAR_HISTORY.getDataType(), false); 470 DialogOption.CLEAR_HISTORY.getDataType(),
471 ClearBrowsingDataPreferenceType.DEFAULT, false);
461 } 472 }
462 473
463 mItems[i] = new Item( 474 mItems[i] = new Item(
464 this, 475 this,
465 options[i], 476 options[i],
466 (ClearBrowsingDataCheckBoxPreference) findPreference(options[i]. getPreferenceKey()), 477 (ClearBrowsingDataCheckBoxPreference) findPreference(options[i]. getPreferenceKey()),
467 isOptionSelectedByDefault(options[i]), 478 isOptionSelectedByDefault(options[i]),
468 enabled); 479 enabled);
469 } 480 }
470 481
471 // Not all checkboxes defined in the layout are necessarily handled by t his class 482 // Not all checkboxes defined in the layout are necessarily handled by t his class
472 // or a particular subclass. Hide those that are not. 483 // or a particular subclass. Hide those that are not.
473 EnumSet<DialogOption> unboundOptions = EnumSet.allOf(DialogOption.class) ; 484 EnumSet<DialogOption> unboundOptions = EnumSet.allOf(DialogOption.class) ;
474 unboundOptions.removeAll(Arrays.asList(getDialogOptions())); 485 unboundOptions.removeAll(Arrays.asList(getDialogOptions()));
475 for (DialogOption option : unboundOptions) { 486 for (DialogOption option : unboundOptions) {
476 getPreferenceScreen().removePreference(findPreference(option.getPref erenceKey())); 487 getPreferenceScreen().removePreference(findPreference(option.getPref erenceKey()));
477 } 488 }
478 489
479 // The time range selection spinner. 490 // The time range selection spinner.
480 SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME _RANGE); 491 SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME _RANGE);
481 spinner.setOnPreferenceChangeListener(this); 492 spinner.setOnPreferenceChangeListener(this);
482 TimePeriodSpinnerOption[] spinnerOptions = getTimePeriodSpinnerOptions() ; 493 TimePeriodSpinnerOption[] spinnerOptions = getTimePeriodSpinnerOptions() ;
483 int selectedTimePeriod = 494 int selectedTimePeriod = PrefServiceBridge.getInstance().getBrowsingData DeletionTimePeriod(
484 PrefServiceBridge.getInstance().getBrowsingDataDeletionTimePerio d(); 495 getPreferenceType());
485 int spinnerOptionIndex = -1; 496 int spinnerOptionIndex = -1;
486 for (int i = 0; i < spinnerOptions.length; ++i) { 497 for (int i = 0; i < spinnerOptions.length; ++i) {
487 if (spinnerOptions[i].getTimePeriod() == selectedTimePeriod) { 498 if (spinnerOptions[i].getTimePeriod() == selectedTimePeriod) {
488 spinnerOptionIndex = i; 499 spinnerOptionIndex = i;
489 break; 500 break;
490 } 501 }
491 } 502 }
492 assert spinnerOptionIndex != -1; 503 assert spinnerOptionIndex != -1;
493 spinner.setOptions(spinnerOptions, spinnerOptionIndex); 504 spinner.setOptions(spinnerOptions, spinnerOptionIndex);
494 505
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 "History.ClearBrowsingData.ImportantIgnoredPercent", 686 "History.ClearBrowsingData.ImportantIgnoredPercent",
676 ignoredDomains.length * IMPORTANT_SITES_PERCENTAGE_BUCKE T_COUNT 687 ignoredDomains.length * IMPORTANT_SITES_PERCENTAGE_BUCKE T_COUNT
677 / mSortedImportantDomains.length, 688 / mSortedImportantDomains.length,
678 IMPORTANT_SITES_PERCENTAGE_BUCKET_COUNT + 1); 689 IMPORTANT_SITES_PERCENTAGE_BUCKET_COUNT + 1);
679 } 690 }
680 clearBrowsingData(getSelectedOptions(), deselectedDomains, deselecte dDomainReasons, 691 clearBrowsingData(getSelectedOptions(), deselectedDomains, deselecte dDomainReasons,
681 ignoredDomains, ignoredDomainReasons); 692 ignoredDomains, ignoredDomainReasons);
682 } 693 }
683 } 694 }
684 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698