Commit d6700521 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] sync clear browsing settings for multi-window

Bug: 1079425
Change-Id: Ib39c9280714bd7f386d74979d9849f832957ad0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2270063
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786302}
parent 90a19e49
......@@ -10,7 +10,7 @@
#include "base/ios/block_types.h"
class ChromeBrowserState;
@class ListItem;
@class TableViewItem;
namespace browsing_data {
enum class TimePeriod;
......@@ -24,8 +24,9 @@ enum class BrowsingDataRemoveMask;
timePeriod:(browsing_data::TimePeriod)timePeriod
removeMask:(BrowsingDataRemoveMask)removeMask
completionBlock:(ProceduralBlock)completionBlock;
// Updates contents of a cell for a given item.
- (void)updateCellsForItem:(ListItem*)item;
// Updates contents of a cell for a given item. Set reload to NO if a simple
// reconfigre is enough.
- (void)updateCellsForItem:(TableViewItem*)item reload:(BOOL)reload;
// Indicate to user that data has been cleared.
- (void)showBrowsingHistoryRemovedDialog;
......
......@@ -128,6 +128,14 @@ static NSDictionary* _imageNamesByItemTypes = @{
@property(nonatomic, strong) TableViewDetailIconItem* tableViewTimeRangeItem;
@property(nonatomic, strong)
TableViewClearBrowsingDataItem* browsingHistoryItem;
@property(nonatomic, strong)
TableViewClearBrowsingDataItem* cookiesSiteDataItem;
@property(nonatomic, strong) TableViewClearBrowsingDataItem* cacheItem;
@property(nonatomic, strong) TableViewClearBrowsingDataItem* savedPasswordsItem;
@property(nonatomic, strong) TableViewClearBrowsingDataItem* autofillItem;
@property(nonatomic, strong)
BrowsingDataCounterWrapperProducer* counterWrapperProducer;
......@@ -172,6 +180,17 @@ static NSDictionary* _imageNamesByItemTypes = @{
_prefObserverBridge.reset(new PrefObserverBridge(self));
_prefObserverBridge->ObserveChangesForPreference(
browsing_data::prefs::kDeleteTimePeriod, &_prefChangeRegistrar);
_prefObserverBridge->ObserveChangesForPreference(
browsing_data::prefs::kDeleteBrowsingHistory, &_prefChangeRegistrar);
_prefObserverBridge->ObserveChangesForPreference(
browsing_data::prefs::kDeleteCookies, &_prefChangeRegistrar);
_prefObserverBridge->ObserveChangesForPreference(
browsing_data::prefs::kDeleteCache, &_prefChangeRegistrar);
_prefObserverBridge->ObserveChangesForPreference(
browsing_data::prefs::kDeletePasswords, &_prefChangeRegistrar);
_prefObserverBridge->ObserveChangesForPreference(
browsing_data::prefs::kDeleteFormData, &_prefChangeRegistrar);
}
return self;
}
......@@ -193,45 +212,46 @@ static NSDictionary* _imageNamesByItemTypes = @{
- (void)addClearBrowsingDataItemsToModel:(ListModel*)model {
// Data types section.
[model addSectionWithIdentifier:SectionIdentifierDataTypes];
ListItem* browsingHistoryItem =
self.browsingHistoryItem =
[self clearDataItemWithType:ItemTypeDataTypeBrowsingHistory
titleID:IDS_IOS_CLEAR_BROWSING_HISTORY
mask:BrowsingDataRemoveMask::REMOVE_HISTORY
prefName:browsing_data::prefs::kDeleteBrowsingHistory];
[model addItem:browsingHistoryItem
[model addItem:self.browsingHistoryItem
toSectionWithIdentifier:SectionIdentifierDataTypes];
// This data type doesn't currently have an associated counter, but displays
// an explanatory text instead.
ListItem* cookiesSiteDataItem =
self.cookiesSiteDataItem =
[self clearDataItemWithType:ItemTypeDataTypeCookiesSiteData
titleID:IDS_IOS_CLEAR_COOKIES
mask:BrowsingDataRemoveMask::REMOVE_SITE_DATA
prefName:browsing_data::prefs::kDeleteCookies];
[model addItem:cookiesSiteDataItem
[model addItem:self.cookiesSiteDataItem
toSectionWithIdentifier:SectionIdentifierDataTypes];
ListItem* cacheItem =
self.cacheItem =
[self clearDataItemWithType:ItemTypeDataTypeCache
titleID:IDS_IOS_CLEAR_CACHE
mask:BrowsingDataRemoveMask::REMOVE_CACHE
prefName:browsing_data::prefs::kDeleteCache];
[model addItem:cacheItem toSectionWithIdentifier:SectionIdentifierDataTypes];
[model addItem:self.cacheItem
toSectionWithIdentifier:SectionIdentifierDataTypes];
ListItem* savedPasswordsItem =
self.savedPasswordsItem =
[self clearDataItemWithType:ItemTypeDataTypeSavedPasswords
titleID:IDS_IOS_CLEAR_SAVED_PASSWORDS
mask:BrowsingDataRemoveMask::REMOVE_PASSWORDS
prefName:browsing_data::prefs::kDeletePasswords];
[model addItem:savedPasswordsItem
[model addItem:self.savedPasswordsItem
toSectionWithIdentifier:SectionIdentifierDataTypes];
ListItem* autofillItem =
self.autofillItem =
[self clearDataItemWithType:ItemTypeDataTypeAutofill
titleID:IDS_IOS_CLEAR_AUTOFILL
mask:BrowsingDataRemoveMask::REMOVE_FORM_DATA
prefName:browsing_data::prefs::kDeleteFormData];
[model addItem:autofillItem
[model addItem:self.autofillItem
toSectionWithIdentifier:SectionIdentifierDataTypes];
}
......@@ -379,7 +399,8 @@ static NSDictionary* _imageNamesByItemTypes = @{
// Creates item of type |itemType| with |mask| of data to be cleared if
// selected, |prefName|, and |titleId| of item.
- (ListItem*)clearDataItemWithType:(ClearBrowsingDataItemType)itemType
- (TableViewClearBrowsingDataItem*)
clearDataItemWithType:(ClearBrowsingDataItemType)itemType
titleID:(int)titleMessageID
mask:(BrowsingDataRemoveMask)mask
prefName:(const char*)prefName {
......@@ -412,7 +433,8 @@ static NSDictionary* _imageNamesByItemTypes = @{
^(const browsing_data::BrowsingDataCounter::Result& result) {
weakTableClearDataItem.detailText =
[weakSelf counterTextFromResult:result];
[weakSelf.consumer updateCellsForItem:weakTableClearDataItem];
[weakSelf.consumer updateCellsForItem:weakTableClearDataItem
reload:YES];
});
std::unique_ptr<BrowsingDataCounterWrapper> counter =
[self.counterWrapperProducer
......@@ -425,13 +447,13 @@ static NSDictionary* _imageNamesByItemTypes = @{
return clearDataItem;
}
- (ListItem*)footerForGoogleAccountSectionItem {
- (TableViewItem*)footerForGoogleAccountSectionItem {
return _shouldShowNoticeAboutOtherFormsOfBrowsingHistory
? [self footerGoogleAccountAndMyActivityItem]
: [self footerGoogleAccountItem];
}
- (ListItem*)footerGoogleAccountItem {
- (TableViewItem*)footerGoogleAccountItem {
TableViewTextLinkItem* footerItem =
[[TableViewTextLinkItem alloc] initWithType:ItemTypeFooterGoogleAccount];
footerItem.text =
......@@ -439,7 +461,7 @@ static NSDictionary* _imageNamesByItemTypes = @{
return footerItem;
}
- (ListItem*)footerGoogleAccountAndMyActivityItem {
- (TableViewItem*)footerGoogleAccountAndMyActivityItem {
UIImage* image = ios::GetChromeBrowserProvider()
->GetBrandedImageProvider()
->GetClearBrowsingDataAccountActivityImage();
......@@ -450,7 +472,7 @@ static NSDictionary* _imageNamesByItemTypes = @{
image:image];
}
- (ListItem*)footerSavedSiteDataItem {
- (TableViewItem*)footerSavedSiteDataItem {
UIImage* image = ios::GetChromeBrowserProvider()
->GetBrandedImageProvider()
->GetClearBrowsingDataSiteDataImage();
......@@ -461,7 +483,7 @@ static NSDictionary* _imageNamesByItemTypes = @{
image:image];
}
- (ListItem*)footerClearSyncAndSavedSiteDataItem {
- (TableViewItem*)footerClearSyncAndSavedSiteDataItem {
UIImage* infoIcon = [ChromeIcon infoIcon];
UIImage* image = TintImage(infoIcon, [[MDCPalette greyPalette] tint500]);
return [self
......@@ -472,7 +494,7 @@ static NSDictionary* _imageNamesByItemTypes = @{
image:image];
}
- (ListItem*)footerItemWithType:(ClearBrowsingDataItemType)itemType
- (TableViewItem*)footerItemWithType:(ClearBrowsingDataItemType)itemType
titleID:(int)titleMessageID
URL:(const char[])URL
image:(UIImage*)image {
......@@ -581,7 +603,7 @@ static NSDictionary* _imageNamesByItemTypes = @{
return;
}
ListItem* footerItem = [self footerForGoogleAccountSectionItem];
TableViewItem* footerItem = [self footerForGoogleAccountSectionItem];
// TODO(crbug.com/650424): Simplify with setFooter:inSection: when the bug in
// MDC is fixed.
// Remove the footer if there is one in that section.
......@@ -598,17 +620,36 @@ static NSDictionary* _imageNamesByItemTypes = @{
// Add the new footer.
[model addItem:footerItem
toSectionWithIdentifier:SectionIdentifierGoogleAccount];
[self.consumer updateCellsForItem:footerItem];
[self.consumer updateCellsForItem:footerItem reload:YES];
}
#pragma mark - PrefObserverDelegate
- (void)onPreferenceChanged:(const std::string&)preferenceName {
DCHECK(preferenceName == browsing_data::prefs::kDeleteTimePeriod);
NSString* detailText = [TimeRangeSelectorTableViewController
timePeriodLabelForPrefs:self.browserState->GetPrefs()];
PrefService* prefs = self.browserState->GetPrefs();
if (preferenceName == browsing_data::prefs::kDeleteTimePeriod) {
NSString* detailText =
[TimeRangeSelectorTableViewController timePeriodLabelForPrefs:prefs];
self.tableViewTimeRangeItem.detailText = detailText;
[self.consumer updateCellsForItem:self.tableViewTimeRangeItem];
[self.consumer updateCellsForItem:self.tableViewTimeRangeItem reload:YES];
} else if (preferenceName == browsing_data::prefs::kDeleteBrowsingHistory) {
self.browsingHistoryItem.checked = prefs->GetBoolean(preferenceName);
[self.consumer updateCellsForItem:self.browsingHistoryItem reload:NO];
} else if (preferenceName == browsing_data::prefs::kDeleteCookies) {
self.cookiesSiteDataItem.checked = prefs->GetBoolean(preferenceName);
[self.consumer updateCellsForItem:self.cookiesSiteDataItem reload:NO];
} else if (preferenceName == browsing_data::prefs::kDeleteCache) {
self.cacheItem.checked = prefs->GetBoolean(preferenceName);
[self.consumer updateCellsForItem:self.cacheItem reload:NO];
} else if (preferenceName == browsing_data::prefs::kDeletePasswords) {
self.savedPasswordsItem.checked = prefs->GetBoolean(preferenceName);
[self.consumer updateCellsForItem:self.savedPasswordsItem reload:NO];
} else if (preferenceName == browsing_data::prefs::kDeleteFormData) {
self.autofillItem.checked = prefs->GetBoolean(preferenceName);
[self.consumer updateCellsForItem:self.autofillItem reload:NO];
} else {
DCHECK(false) << "Unxpected clear browsing data item type.";
}
}
#pragma mark BrowsingDataRemoverObserving
......
......@@ -168,18 +168,6 @@
self.navigationController.toolbarHidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// Write data type cell selection states back to the browser state.
NSArray* dataTypeItems = [self.tableViewModel
itemsInSectionWithIdentifier:SectionIdentifierDataTypes];
for (TableViewClearBrowsingDataItem* dataTypeItem in dataTypeItems) {
DCHECK([dataTypeItem isKindOfClass:[TableViewClearBrowsingDataItem class]]);
self.browserState->GetPrefs()->SetBoolean(dataTypeItem.prefName,
dataTypeItem.checked);
}
}
- (void)loadModel {
[super loadModel];
[self.dataManager loadModel:self.tableViewModel];
......@@ -276,9 +264,10 @@
DCHECK([item isKindOfClass:[TableViewClearBrowsingDataItem class]]);
TableViewClearBrowsingDataItem* clearBrowsingDataItem =
base::mac::ObjCCastStrict<TableViewClearBrowsingDataItem>(item);
clearBrowsingDataItem.checked = !clearBrowsingDataItem.checked;
[self reconfigureCellsForItems:@[ clearBrowsingDataItem ]];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
self.browserState->GetPrefs()->SetBoolean(clearBrowsingDataItem.prefName,
!clearBrowsingDataItem.checked);
// UI update will be trigerred by data manager.
break;
}
default:
......@@ -297,15 +286,22 @@
#pragma mark - ClearBrowsingDataConsumer
- (void)updateCellsForItem:(ListItem*)item {
- (void)updateCellsForItem:(TableViewItem*)item reload:(BOOL)reload {
if (self.suppressTableViewUpdates)
return;
if (!reload) {
[self reconfigureCellsForItems:@[ item ]];
NSIndexPath* indexPath = [self.tableViewModel
indexPathForItem:static_cast<TableViewItem*>(item)];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
} else {
// Reload the item instead of reconfiguring it. This might update
// TableViewTextLinkItems which which can have different number of lines,
// thus the cell height needs to adapt accordingly.
[self reloadCellsForItems:@[ item ]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (void)removeBrowsingDataForBrowserState:(ChromeBrowserState*)browserState
......
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