Index: chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
diff --git a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
index 5c8d55722aeff98d7b8e3bde1df11083fb4a7bb0..ad69488bc3c84bd0566f8df8e7b1cfe56baa53be 100644 |
--- a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
+++ b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js |
@@ -21,6 +21,15 @@ Polymer({ |
}, |
/** |
+ * State of this dialog, either "clearBrowsingData" or "importantSites". |
+ * @private |
+ */ |
+ dialogState_: { |
+ type: String, |
+ value: 'clearBrowsingData', |
+ }, |
+ |
+ /** |
* Results of browsing data counters, keyed by the suffix of |
* the corresponding data type deletion preference, as reported |
* by the C++ side. |
@@ -28,9 +37,8 @@ Polymer({ |
*/ |
counters_: { |
type: Object, |
- value: { |
- // Will be filled as results are reported. |
- } |
+ // Will be filled as results are reported. |
+ value: function() { return {}; } |
}, |
/** |
@@ -60,6 +68,19 @@ Polymer({ |
type: Boolean, |
value: false, |
}, |
+ |
+ /** @private {!Array<ImportantSite>} */ |
+ importantSites_: { |
+ type: Array, |
+ value: function() { return []; } |
+ }, |
+ |
+ /** @private */ |
+ importantSitesFlagEnabled_: { |
+ type: Boolean, |
+ value: false, |
+ }, |
+ |
}, |
/** @private {settings.ClearBrowsingDataBrowserProxy} */ |
@@ -80,9 +101,21 @@ Polymer({ |
attached: function() { |
this.browserProxy_ = |
settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); |
- this.browserProxy_.initialize().then(function() { |
- this.$.dialog.showModal(); |
- }.bind(this)); |
+ this.browserProxy_.initialize() |
+ .then(function() { |
+ this.$.dialog.showModal(); |
+ return this.browserProxy_.fetchImportantSites(); |
+ }.bind(this)) |
+ .then(this.receiveImportantSites.bind(this)); |
+ }, |
+ |
+ /** |
+ * @param {!ImportantSitesResponse} result |
+ * @private |
+ */ |
+ receiveImportantSites: function(result) { |
+ this.importantSitesFlagEnabled_ = result.flagEnabled; |
+ this.set('importantSites_', result.importantSites); |
}, |
/** |
@@ -114,24 +147,65 @@ Polymer({ |
}, |
/** |
+ * @param {string} currentDialogState The current dialog state. |
+ * @return {boolean} Whether this is the clear browsing data dialog. |
+ * @private |
+ */ |
+ isClearBrowsingDataDialog_: function(currentDialogState) { |
+ return currentDialogState == 'clearBrowsingData'; |
+ }, |
+ |
+ /** |
+ * @param {string} currentDialogState The current dialog state. |
+ * @return {boolean} Whether this is the important sites dialog. |
+ * @private |
+ */ |
+ isImportantSitesDialog_: function(currentDialogState) { |
+ return currentDialogState == 'importantSites'; |
+ }, |
+ |
+ /** @private */ |
+ shouldShowImportantSites_: function() { |
+ if (this.isImportantSitesDialog_(this.dialogState_)) |
+ return false; |
+ if (!this.importantSitesFlagEnabled_) |
+ return false; |
+ if (!this.$.cookiesCheckbox.checked && !this.$.cacheCheckbox.checked) { |
+ return false; |
+ } |
+ var haveImportantSites = this.importantSites_.length > 0; |
+ chrome.send( |
+ 'metricsHandler:recordBooleanHistogram', |
+ ['History.ClearBrowsingData.ImportantDialogShown', haveImportantSites]); |
+ return haveImportantSites; |
+ }, |
+ |
+ /** |
* Handles the tap on the Clear Data button. |
* @private |
*/ |
onClearBrowsingDataTap_: function() { |
+ if (this.shouldShowImportantSites_()) { |
+ this.dialogState_ = 'importantSites'; |
+ return; |
+ } |
+ |
this.clearingInProgress_ = true; |
- this.browserProxy_.clearBrowsingData().then( |
- /** |
- * @param {boolean} shouldShowNotice Whether we should show the notice |
- * about other forms of browsing history before closing the dialog. |
- */ |
- function(shouldShowNotice) { |
- this.clearingInProgress_ = false; |
- this.showHistoryDeletionDialog_ = shouldShowNotice; |
- |
- if (!shouldShowNotice) |
- this.$.dialog.close(); |
- }.bind(this)); |
+ this.browserProxy_.clearBrowsingData(this.importantSites_) |
+ .then( |
+ /** |
+ * @param {boolean} shouldShowNotice Whether we should show the |
+ * notice about other forms of browsing history before closing the |
+ * dialog. |
+ */ |
+ function(shouldShowNotice) { |
+ this.clearingInProgress_ = false; |
+ this.showHistoryDeletionDialog_ = shouldShowNotice; |
+ |
+ if (!shouldShowNotice) |
+ this.$.dialog.close(); |
+ }.bind(this)); |
}, |
/** @private */ |