Commit f285088b authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Only show cookie exception when signed in

We should only show the exception about not getting signed out when
the user is actually signed in and cookies will be recreated on
deletion.

Bug: 860290
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I03577189ec114513c2a341b4cf05eab47a8339fb
Reviewed-on: https://chromium-review.googlesource.com/1136293Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Reviewed-by: default avatarDave Schuyler <dschuyler@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575209}
parent 52ab194d
......@@ -10,10 +10,14 @@
#include "chrome/browser/browsing_data/counters/media_licenses_counter.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/browsing_data/core/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/bytes_formatting.h"
......@@ -36,6 +40,24 @@ base::string16 FormatBytesMBOrHigher(
bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true);
}
bool ShouldShowCookieException(Profile* profile) {
if (AccountConsistencyModeManager::IsMirrorEnabledForProfile(profile)) {
auto* signin_manager = SigninManagerFactory::GetForProfile(profile);
return signin_manager->IsAuthenticated();
}
if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile)) {
auto* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
std::vector<std::string> accounts = token_service->GetAccounts();
bool has_valid_token = std::any_of(
accounts.begin(), accounts.end(), [&](std::string account_id) {
return !token_service->RefreshTokenHasError(account_id);
});
return has_valid_token;
}
return false;
}
base::string16 GetChromeCounterTextFromResult(
const browsing_data::BrowsingDataCounter::Result* result,
Profile* profile) {
......@@ -86,16 +108,10 @@ base::string16 GetChromeCounterTextFromResult(
->Value();
// Determines whether or not to show the count with exception message.
int del_cookie_counter_msg_id = IDS_DEL_COOKIES_COUNTER_ADVANCED;
#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
if (AccountConsistencyModeManager::IsMirrorEnabledForProfile(profile)) {
#else
if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile)) {
#endif
del_cookie_counter_msg_id =
IDS_DEL_COOKIES_COUNTER_ADVANCED_WITH_EXCEPTION;
}
int del_cookie_counter_msg_id =
ShouldShowCookieException(profile)
? IDS_DEL_COOKIES_COUNTER_ADVANCED_WITH_EXCEPTION
: IDS_DEL_COOKIES_COUNTER_ADVANCED;
return l10n_util::GetPluralStringFUTF16(del_cookie_counter_msg_id, origins);
}
......
......@@ -11,6 +11,10 @@
class Profile;
// Whether the exception about not being signed out of your Google profile
// should be shown.
bool ShouldShowCookieException(Profile* profile);
// Constructs the text to be displayed by a counter from the given |result|.
base::string16 GetChromeCounterTextFromResult(
const browsing_data::BrowsingDataCounter::Result* result,
......
......@@ -138,7 +138,10 @@
class="cookies-checkbox"
pref="{{prefs.browser.clear_data.cookies_basic}}"
label="$i18n{clearCookies}"
sub-label="$i18n{clearCookiesSummary}"
sub-label="[[cookiesCheckboxLabel_(
shouldShowCookieException_,
'$i18nPolymer{clearCookiesSummary}',
'$i18nPolymer{clearCookiesSummarySignedIn}')]]"
disabled="[[clearingInProgress_]]">
</settings-checkbox>
<settings-checkbox id="cacheCheckboxBasic"
......
......@@ -88,6 +88,12 @@ Polymer({
value: false,
},
/** @private */
shouldShowCookieException_: {
type: Boolean,
value: false,
},
/**
* Time in ms, when the dialog was opened.
* @private
......@@ -165,35 +171,55 @@ Polymer({
*
* @param {boolean} signedIn Whether the user is signed in.
* @param {boolean} syncing Whether the user is syncing history.
* @param {boolean} shouldShowCookieException Whether the exception about not
* being signed out of your Google account should be shown.
* @private
*/
updateSyncState_: function(signedIn, syncing) {
updateSyncState_: function(signedIn, syncing, shouldShowCookieException) {
this.isSignedIn_ = signedIn;
this.isSyncingHistory_ = syncing;
this.shouldShowCookieException_ = shouldShowCookieException;
this.$.clearBrowsingDataDialog.classList.add('fully-rendered');
},
/**
* Choose a summary checkbox label.
* Choose a label for the history checkbox.
* @param {boolean} isSignedIn
* @param {boolean} isSyncingHistory
* @param {string} historySummary
* @param {string} historySummarySigned
* @param {string} historySummarySignedIn
* @param {string} historySummarySynced
* @return {string}
* @private
*/
browsingCheckboxLabel_: function(
isSignedIn, isSyncingHistory, historySummary, historySummarySigned,
isSignedIn, isSyncingHistory, historySummary, historySummarySignedIn,
historySummarySynced) {
if (isSyncingHistory) {
return historySummarySynced;
} else if (isSignedIn) {
return historySummarySigned;
return historySummarySignedIn;
}
return historySummary;
},
/**
* Choose a label for the cookie checkbox.
* @param {boolean} shouldShowCookieException
* @param {string} cookiesSummary
* @param {string} cookiesSummarySignedIn
* @return {string}
* @private
*/
cookiesCheckboxLabel_: function(
shouldShowCookieException, cookiesSummary, cookiesSummarySignedIn) {
if (shouldShowCookieException) {
return cookiesSummarySignedIn;
}
return cookiesSummary;
},
/**
* Choose a content/site settings label.
* @param {string} siteSettings
......
......@@ -504,21 +504,6 @@ void AddChangePasswordStrings(content::WebUIDataSource* html_source) {
void AddClearBrowsingDataStrings(content::WebUIDataSource* html_source,
Profile* profile) {
int clear_cookies_summary_msg_id =
IDS_SETTINGS_CLEAR_COOKIES_AND_SITE_DATA_SUMMARY_BASIC;
#if defined(OS_CHROMEOS)
if (AccountConsistencyModeManager::IsMirrorEnabledForProfile(profile)) {
clear_cookies_summary_msg_id =
IDS_SETTINGS_CLEAR_COOKIES_AND_SITE_DATA_SUMMARY_BASIC_WITH_EXCEPTION;
}
#else // !defined(OS_CHROMEOS)
if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile)) {
clear_cookies_summary_msg_id =
IDS_SETTINGS_CLEAR_COOKIES_AND_SITE_DATA_SUMMARY_BASIC_WITH_EXCEPTION;
}
#endif
LocalizedString localized_strings[] = {
{"clearTimeRange", IDS_SETTINGS_CLEAR_PERIOD_TITLE},
{"clearBrowsingHistory", IDS_SETTINGS_CLEAR_BROWSING_HISTORY},
......@@ -527,7 +512,10 @@ void AddClearBrowsingDataStrings(content::WebUIDataSource* html_source,
{"clearDownloadHistory", IDS_SETTINGS_CLEAR_DOWNLOAD_HISTORY},
{"clearCache", IDS_SETTINGS_CLEAR_CACHE},
{"clearCookies", IDS_SETTINGS_CLEAR_COOKIES},
{"clearCookiesSummary", clear_cookies_summary_msg_id},
{"clearCookiesSummary",
IDS_SETTINGS_CLEAR_COOKIES_AND_SITE_DATA_SUMMARY_BASIC},
{"clearCookiesSummarySignedIn",
IDS_SETTINGS_CLEAR_COOKIES_AND_SITE_DATA_SUMMARY_BASIC_WITH_EXCEPTION},
{"clearCookiesCounter", IDS_DEL_COOKIES_COUNTER},
{"clearCookiesFlash", IDS_SETTINGS_CLEAR_COOKIES_FLASH},
{"clearPasswords", IDS_SETTINGS_CLEAR_PASSWORDS},
......
......@@ -333,7 +333,8 @@ void ClearBrowsingDataHandler::UpdateSyncState() {
base::Value(signin_manager && signin_manager->IsAuthenticated()),
base::Value(sync_service_ && sync_service_->IsSyncActive() &&
sync_service_->GetActiveDataTypes().Has(
syncer::HISTORY_DELETE_DIRECTIVES)));
syncer::HISTORY_DELETE_DIRECTIVES)),
base::Value(ShouldShowCookieException(profile_)));
}
void ClearBrowsingDataHandler::RefreshHistoryNotice() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment