OLD | NEW |
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.ClearBrowsingDataTab; |
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.historyreport.AppIndexingReporter; | 25 import org.chromium.chrome.browser.historyreport.AppIndexingReporter; |
25 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 26 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
26 import org.chromium.chrome.browser.preferences.ButtonPreference; | 27 import org.chromium.chrome.browser.preferences.ButtonPreference; |
27 import org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreferen
ce; | 28 import org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreferen
ce; |
28 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 29 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
29 import org.chromium.chrome.browser.preferences.SpinnerPreference; | 30 import org.chromium.chrome.browser.preferences.SpinnerPreference; |
30 import org.chromium.chrome.browser.preferences.TextMessageWithLinkAndIconPrefere
nce; | 31 import org.chromium.chrome.browser.preferences.TextMessageWithLinkAndIconPrefere
nce; |
31 import org.chromium.chrome.browser.preferences.privacy.BrowsingDataCounterBridge
.BrowsingDataCounterCallback; | 32 import org.chromium.chrome.browser.preferences.privacy.BrowsingDataCounterBridge
.BrowsingDataCounterCallback; |
(...skipping 28 matching lines...) Expand all Loading... |
60 | 61 |
61 public Item(ClearBrowsingDataPreferences parent, | 62 public Item(ClearBrowsingDataPreferences parent, |
62 DialogOption option, | 63 DialogOption option, |
63 ClearBrowsingDataCheckBoxPreference checkbox, | 64 ClearBrowsingDataCheckBoxPreference checkbox, |
64 boolean selected, | 65 boolean selected, |
65 boolean enabled) { | 66 boolean enabled) { |
66 super(); | 67 super(); |
67 mParent = parent; | 68 mParent = parent; |
68 mOption = option; | 69 mOption = option; |
69 mCheckbox = checkbox; | 70 mCheckbox = checkbox; |
70 mCounter = new BrowsingDataCounterBridge(this, mOption.getDataType()
); | 71 mCounter = new BrowsingDataCounterBridge( |
| 72 this, mOption.getDataType(), mParent.getPreferenceType()); |
71 | 73 |
72 mCheckbox.setOnPreferenceClickListener(this); | 74 mCheckbox.setOnPreferenceClickListener(this); |
73 mCheckbox.setEnabled(enabled); | 75 mCheckbox.setEnabled(enabled); |
74 mCheckbox.setChecked(selected); | 76 mCheckbox.setChecked(selected); |
75 | 77 |
76 if (!ClearBrowsingDataTabsFragment.isFeatureEnabled()) { | 78 if (!ClearBrowsingDataTabsFragment.isFeatureEnabled()) { |
77 // No summary when unchecked. The redesigned basic and advanced | 79 // No summary when unchecked. The redesigned basic and advanced |
78 // CBD views will always show the checkbox summary. | 80 // CBD views will always show the checkbox summary. |
79 mCheckbox.setSummaryOff(""); | 81 mCheckbox.setSummaryOff(""); |
80 } | 82 } |
(...skipping 11 matching lines...) Expand all Loading... |
92 return mCheckbox.isChecked(); | 94 return mCheckbox.isChecked(); |
93 } | 95 } |
94 | 96 |
95 @Override | 97 @Override |
96 public boolean onPreferenceClick(Preference preference) { | 98 public boolean onPreferenceClick(Preference preference) { |
97 assert mCheckbox == preference; | 99 assert mCheckbox == preference; |
98 | 100 |
99 mParent.updateButtonState(); | 101 mParent.updateButtonState(); |
100 mShouldAnnounceCounterResult = true; | 102 mShouldAnnounceCounterResult = true; |
101 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreference( | 103 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreference( |
102 mOption.getDataType(), mCheckbox.isChecked()); | 104 mOption.getDataType(), mParent.getPreferenceType(), mCheckbo
x.isChecked()); |
103 return true; | 105 return true; |
104 } | 106 } |
105 | 107 |
106 @Override | 108 @Override |
107 public void onCounterFinished(String result) { | 109 public void onCounterFinished(String result) { |
108 mCheckbox.setSummaryOn(result); | 110 mCheckbox.setSummaryOn(result); |
109 if (ClearBrowsingDataTabsFragment.isFeatureEnabled()) { | 111 if (ClearBrowsingDataTabsFragment.isFeatureEnabled()) { |
110 mCheckbox.setSummaryOff(result); | 112 mCheckbox.setSummaryOff(result); |
111 } | 113 } |
112 if (mShouldAnnounceCounterResult) { | 114 if (mShouldAnnounceCounterResult) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 return new DialogOption[] { | 298 return new DialogOption[] { |
297 DialogOption.CLEAR_HISTORY, | 299 DialogOption.CLEAR_HISTORY, |
298 DialogOption.CLEAR_COOKIES_AND_SITE_DATA, | 300 DialogOption.CLEAR_COOKIES_AND_SITE_DATA, |
299 DialogOption.CLEAR_CACHE, | 301 DialogOption.CLEAR_CACHE, |
300 DialogOption.CLEAR_PASSWORDS, | 302 DialogOption.CLEAR_PASSWORDS, |
301 DialogOption.CLEAR_FORM_DATA | 303 DialogOption.CLEAR_FORM_DATA |
302 }; | 304 }; |
303 } | 305 } |
304 | 306 |
305 /** | 307 /** |
| 308 * Returns whether this preference page is a basic or advanced tab in order
to use separate |
| 309 * preferences. |
| 310 */ |
| 311 protected int getPreferenceType() { |
| 312 return ClearBrowsingDataTab.ADVANCED; |
| 313 } |
| 314 |
| 315 /** |
306 * Returns the Array of time periods. Options are displayed in the same orde
r as they appear | 316 * Returns the Array of time periods. Options are displayed in the same orde
r as they appear |
307 * in the array. | 317 * in the array. |
308 */ | 318 */ |
309 private TimePeriodSpinnerOption[] getTimePeriodSpinnerOptions() { | 319 private TimePeriodSpinnerOption[] getTimePeriodSpinnerOptions() { |
310 Activity activity = getActivity(); | 320 Activity activity = getActivity(); |
311 | 321 |
312 TimePeriodSpinnerOption[] options = new TimePeriodSpinnerOption[] { | 322 TimePeriodSpinnerOption[] options = new TimePeriodSpinnerOption[] { |
313 new TimePeriodSpinnerOption(TimePeriod.LAST_HOUR, | 323 new TimePeriodSpinnerOption(TimePeriod.LAST_HOUR, |
314 activity.getString(R.string.clear_browsing_data_period_h
our)), | 324 activity.getString(R.string.clear_browsing_data_period_h
our)), |
315 new TimePeriodSpinnerOption(TimePeriod.LAST_DAY, | 325 new TimePeriodSpinnerOption(TimePeriod.LAST_DAY, |
316 activity.getString(R.string.clear_browsing_data_period_d
ay)), | 326 activity.getString(R.string.clear_browsing_data_period_d
ay)), |
317 new TimePeriodSpinnerOption(TimePeriod.LAST_WEEK, | 327 new TimePeriodSpinnerOption(TimePeriod.LAST_WEEK, |
318 activity.getString(R.string.clear_browsing_data_period_w
eek)), | 328 activity.getString(R.string.clear_browsing_data_period_w
eek)), |
319 new TimePeriodSpinnerOption(TimePeriod.FOUR_WEEKS, | 329 new TimePeriodSpinnerOption(TimePeriod.FOUR_WEEKS, |
320 activity.getString(R.string.clear_browsing_data_period_f
our_weeks)), | 330 activity.getString(R.string.clear_browsing_data_period_f
our_weeks)), |
321 new TimePeriodSpinnerOption(TimePeriod.ALL_TIME, | 331 new TimePeriodSpinnerOption(TimePeriod.ALL_TIME, |
322 activity.getString(R.string.clear_browsing_data_period_e
verything))}; | 332 activity.getString(R.string.clear_browsing_data_period_e
verything))}; |
323 | 333 |
324 return options; | 334 return options; |
325 } | 335 } |
326 | 336 |
327 /** | 337 /** |
328 * Decides whether a given dialog option should be selected when the dialog
is initialized. | 338 * Decides whether a given dialog option should be selected when the dialog
is initialized. |
329 * | 339 * |
330 * @param option The option in question. | 340 * @param option The option in question. |
331 * @return boolean Whether the given option should be preselected. | 341 * @return boolean Whether the given option should be preselected. |
332 */ | 342 */ |
333 private boolean isOptionSelectedByDefault(DialogOption option) { | 343 private boolean isOptionSelectedByDefault(DialogOption option) { |
334 return PrefServiceBridge.getInstance().getBrowsingDataDeletionPreference
( | 344 return PrefServiceBridge.getInstance().getBrowsingDataDeletionPreference
( |
335 option.getDataType()); | 345 option.getDataType(), getPreferenceType()); |
336 } | 346 } |
337 | 347 |
338 /** | 348 /** |
339 * Called when clearing browsing data completes. | 349 * Called when clearing browsing data completes. |
340 * Implements the ChromePreferences.OnClearBrowsingDataListener interface. | 350 * Implements the ChromePreferences.OnClearBrowsingDataListener interface. |
341 */ | 351 */ |
342 @Override | 352 @Override |
343 public void onBrowsingDataCleared() { | 353 public void onBrowsingDataCleared() { |
344 if (getActivity() == null) return; | 354 if (getActivity() == null) return; |
345 | 355 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 @Override | 423 @Override |
414 public boolean onPreferenceChange(Preference preference, Object value) { | 424 public boolean onPreferenceChange(Preference preference, Object value) { |
415 if (preference.getKey().equals(PREF_TIME_RANGE)) { | 425 if (preference.getKey().equals(PREF_TIME_RANGE)) { |
416 // Inform the items that a recalculation is going to happen as a res
ult of the time | 426 // Inform the items that a recalculation is going to happen as a res
ult of the time |
417 // period change. | 427 // period change. |
418 for (Item item : mItems) { | 428 for (Item item : mItems) { |
419 item.setShouldAnnounceCounterResult(false); | 429 item.setShouldAnnounceCounterResult(false); |
420 } | 430 } |
421 | 431 |
422 PrefServiceBridge.getInstance().setBrowsingDataDeletionTimePeriod( | 432 PrefServiceBridge.getInstance().setBrowsingDataDeletionTimePeriod( |
423 ((TimePeriodSpinnerOption) value).getTimePeriod()); | 433 getPreferenceType(), ((TimePeriodSpinnerOption) value).getTi
mePeriod()); |
424 return true; | 434 return true; |
425 } | 435 } |
426 return false; | 436 return false; |
427 } | 437 } |
428 | 438 |
429 /** | 439 /** |
430 * Disable the "Clear" button if none of the options are selected. Otherwise
, enable it. | 440 * Disable the "Clear" button if none of the options are selected. Otherwise
, enable it. |
431 */ | 441 */ |
432 protected void updateButtonState() { | 442 protected void updateButtonState() { |
433 ButtonPreference clearButton = (ButtonPreference) findPreference(PREF_CL
EAR_BUTTON); | 443 ButtonPreference clearButton = (ButtonPreference) findPreference(PREF_CL
EAR_BUTTON); |
(...skipping 20 matching lines...) Expand all Loading... |
454 DialogOption[] options = getDialogOptions(); | 464 DialogOption[] options = getDialogOptions(); |
455 mItems = new Item[options.length]; | 465 mItems = new Item[options.length]; |
456 for (int i = 0; i < options.length; i++) { | 466 for (int i = 0; i < options.length; i++) { |
457 boolean enabled = true; | 467 boolean enabled = true; |
458 | 468 |
459 // It is possible to disable the deletion of browsing history. | 469 // It is possible to disable the deletion of browsing history. |
460 if (options[i] == DialogOption.CLEAR_HISTORY | 470 if (options[i] == DialogOption.CLEAR_HISTORY |
461 && !PrefServiceBridge.getInstance().canDeleteBrowsingHistory
()) { | 471 && !PrefServiceBridge.getInstance().canDeleteBrowsingHistory
()) { |
462 enabled = false; | 472 enabled = false; |
463 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreferenc
e( | 473 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreferenc
e( |
464 DialogOption.CLEAR_HISTORY.getDataType(), false); | 474 DialogOption.CLEAR_HISTORY.getDataType(), ClearBrowsingD
ataTab.BASIC, |
| 475 false); |
| 476 PrefServiceBridge.getInstance().setBrowsingDataDeletionPreferenc
e( |
| 477 DialogOption.CLEAR_HISTORY.getDataType(), ClearBrowsingD
ataTab.ADVANCED, |
| 478 false); |
465 } | 479 } |
466 | 480 |
467 mItems[i] = new Item( | 481 mItems[i] = new Item( |
468 this, | 482 this, |
469 options[i], | 483 options[i], |
470 (ClearBrowsingDataCheckBoxPreference) findPreference(options[i].
getPreferenceKey()), | 484 (ClearBrowsingDataCheckBoxPreference) findPreference(options[i].
getPreferenceKey()), |
471 isOptionSelectedByDefault(options[i]), | 485 isOptionSelectedByDefault(options[i]), |
472 enabled); | 486 enabled); |
473 } | 487 } |
474 | 488 |
475 // Not all checkboxes defined in the layout are necessarily handled by t
his class | 489 // Not all checkboxes defined in the layout are necessarily handled by t
his class |
476 // or a particular subclass. Hide those that are not. | 490 // or a particular subclass. Hide those that are not. |
477 EnumSet<DialogOption> unboundOptions = EnumSet.allOf(DialogOption.class)
; | 491 EnumSet<DialogOption> unboundOptions = EnumSet.allOf(DialogOption.class)
; |
478 unboundOptions.removeAll(Arrays.asList(getDialogOptions())); | 492 unboundOptions.removeAll(Arrays.asList(getDialogOptions())); |
479 for (DialogOption option : unboundOptions) { | 493 for (DialogOption option : unboundOptions) { |
480 getPreferenceScreen().removePreference(findPreference(option.getPref
erenceKey())); | 494 getPreferenceScreen().removePreference(findPreference(option.getPref
erenceKey())); |
481 } | 495 } |
482 | 496 |
483 // The time range selection spinner. | 497 // The time range selection spinner. |
484 SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME
_RANGE); | 498 SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME
_RANGE); |
485 spinner.setOnPreferenceChangeListener(this); | 499 spinner.setOnPreferenceChangeListener(this); |
486 TimePeriodSpinnerOption[] spinnerOptions = getTimePeriodSpinnerOptions()
; | 500 TimePeriodSpinnerOption[] spinnerOptions = getTimePeriodSpinnerOptions()
; |
487 int selectedTimePeriod = | 501 int selectedTimePeriod = PrefServiceBridge.getInstance().getBrowsingData
DeletionTimePeriod( |
488 PrefServiceBridge.getInstance().getBrowsingDataDeletionTimePerio
d(); | 502 getPreferenceType()); |
489 int spinnerOptionIndex = -1; | 503 int spinnerOptionIndex = -1; |
490 for (int i = 0; i < spinnerOptions.length; ++i) { | 504 for (int i = 0; i < spinnerOptions.length; ++i) { |
491 if (spinnerOptions[i].getTimePeriod() == selectedTimePeriod) { | 505 if (spinnerOptions[i].getTimePeriod() == selectedTimePeriod) { |
492 spinnerOptionIndex = i; | 506 spinnerOptionIndex = i; |
493 break; | 507 break; |
494 } | 508 } |
495 } | 509 } |
496 assert spinnerOptionIndex != -1; | 510 assert spinnerOptionIndex != -1; |
497 spinner.setOptions(spinnerOptions, spinnerOptionIndex); | 511 spinner.setOptions(spinnerOptions, spinnerOptionIndex); |
498 | 512 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 "History.ClearBrowsingData.ImportantIgnoredPercent", | 693 "History.ClearBrowsingData.ImportantIgnoredPercent", |
680 ignoredDomains.length * IMPORTANT_SITES_PERCENTAGE_BUCKE
T_COUNT | 694 ignoredDomains.length * IMPORTANT_SITES_PERCENTAGE_BUCKE
T_COUNT |
681 / mSortedImportantDomains.length, | 695 / mSortedImportantDomains.length, |
682 IMPORTANT_SITES_PERCENTAGE_BUCKET_COUNT + 1); | 696 IMPORTANT_SITES_PERCENTAGE_BUCKET_COUNT + 1); |
683 } | 697 } |
684 clearBrowsingData(getSelectedOptions(), deselectedDomains, deselecte
dDomainReasons, | 698 clearBrowsingData(getSelectedOptions(), deselectedDomains, deselecte
dDomainReasons, |
685 ignoredDomains, ignoredDomainReasons); | 699 ignoredDomains, ignoredDomainReasons); |
686 } | 700 } |
687 } | 701 } |
688 } | 702 } |
OLD | NEW |