Index: ios/chrome/browser/ui/settings/privacy_collection_view_controller.mm |
diff --git a/ios/chrome/browser/ui/settings/privacy_collection_view_controller.mm b/ios/chrome/browser/ui/settings/privacy_collection_view_controller.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..96ab7e8926721f81cac34ed8581a0f754b4c00d3 |
--- /dev/null |
+++ b/ios/chrome/browser/ui/settings/privacy_collection_view_controller.mm |
@@ -0,0 +1,518 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" |
+ |
+#include "base/ios/ios_util.h" |
+#include "base/ios/weak_nsobject.h" |
+#include "base/logging.h" |
+#import "base/mac/foundation_util.h" |
+#include "base/mac/scoped_nsobject.h" |
+#include "components/google/core/browser/google_util.h" |
+#include "components/handoff/pref_names_ios.h" |
+#include "components/metrics/metrics_pref_names.h" |
+#include "components/prefs/pref_change_registrar.h" |
+#include "components/prefs/pref_service.h" |
+#include "components/signin/core/browser/signin_manager.h" |
+#include "components/strings/grit/components_strings.h" |
+#include "ios/chrome/browser/application_context.h" |
+#import "ios/chrome/browser/autofill/autofill_controller.h" |
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
+#include "ios/chrome/browser/chrome_url_constants.h" |
+#include "ios/chrome/browser/experimental_flags.h" |
+#include "ios/chrome/browser/physical_web/physical_web_constants.h" |
+#include "ios/chrome/browser/pref_names.h" |
+#import "ios/chrome/browser/prefs/pref_observer_bridge.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h" |
+#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
+#import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_mediator.h" |
+#import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" |
+#import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.h" |
+#import "ios/chrome/browser/ui/settings/contextual_search_collection_view_controller.h" |
+#import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controller.h" |
+#import "ios/chrome/browser/ui/settings/do_not_track_collection_view_controller.h" |
+#import "ios/chrome/browser/ui/settings/handoff_collection_view_controller.h" |
+#import "ios/chrome/browser/ui/settings/physical_web_collection_view_controller.h" |
+#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" |
+#import "ios/chrome/browser/ui/settings/settings_utils.h" |
+#import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" |
+#include "ios/chrome/browser/ui/ui_util.h" |
+#include "ios/chrome/grit/ios_chromium_strings.h" |
+#include "ios/chrome/grit/ios_strings.h" |
+#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h" |
+#include "ios/web/public/web_capabilities.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/l10n/l10n_util_mac.h" |
+#include "url/gurl.h" |
+ |
+NSString* const kPrivacyCollectionViewId = @"kPrivacyCollectionViewId"; |
+ |
+namespace { |
+ |
+typedef NS_ENUM(NSInteger, SectionIdentifier) { |
+ SectionIdentifierOtherDevices = kSectionIdentifierEnumZero, |
+ SectionIdentifierWebServices, |
+ SectionIdentifierWebServicesFooter, |
+ SectionIdentifierClearBrowsingData, |
+}; |
+ |
+typedef NS_ENUM(NSInteger, ItemType) { |
+ ItemTypeOtherDevicesHeader = kItemTypeEnumZero, |
+ ItemTypeOtherDevicesHandoff, |
+ ItemTypeWebServicesHeader, |
+ ItemTypeWebServicesFooter, |
+ ItemTypeWebServicesShowSuggestions, |
+ ItemTypeWebServicesTouchToSearch, |
+ ItemTypeWebServicesSendUsageData, |
+ ItemTypeWebServicesDoNotTrack, |
+ ItemTypeWebServicesPhysicalWeb, |
+ ItemTypeClearBrowsingDataClear, |
+}; |
+ |
+} // namespace |
+ |
+@interface PrivacyCollectionViewController ()<BooleanObserver, |
+ PrefObserverDelegate> { |
+ ios::ChromeBrowserState* _browserState; // weak |
+ base::scoped_nsobject<PrefBackedBoolean> _suggestionsEnabled; |
+ // The item related to the switch for the show suggestions setting. |
+ base::scoped_nsobject<CollectionViewSwitchItem> _showSuggestionsItem; |
+ base::scoped_nsobject<TouchToSearchPermissionsMediator> |
+ _touchToSearchPermissions; |
+ |
+ // Pref observer to track changes to prefs. |
+ std::unique_ptr<PrefObserverBridge> _prefObserverBridge; |
+ // Registrar for pref changes notifications. |
+ PrefChangeRegistrar _prefChangeRegistrar; |
+ PrefChangeRegistrar _prefChangeRegistrarApplicationContext; |
+ |
+ // Updatable Items |
+ base::scoped_nsobject<CollectionViewDetailItem> _handoffDetailItem; |
+ base::scoped_nsobject<CollectionViewDetailItem> _sendUsageDetailItem; |
+} |
+ |
+// Initialization methods for various model items. |
+- (CollectionViewItem*)handoffDetailItem; |
+- (CollectionViewSwitchItem*)showSuggestionsSwitchItem; |
+- (CollectionViewItem*)showSuggestionsFooterItem; |
+- (CollectionViewItem*)clearBrowsingDetailItem; |
+- (CollectionViewItem*)sendUsageDetailItem; |
+- (CollectionViewItem*)physicalWebDetailItem; |
+- (CollectionViewItem*)contextualSearchDetailItem; |
+- (CollectionViewItem*)doNotTrackDetailItem; |
+ |
+@end |
+ |
+@implementation PrivacyCollectionViewController |
+ |
+#pragma mark - Initialization |
+ |
+- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
+ DCHECK(browserState); |
+ self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
+ if (self) { |
+ _browserState = browserState; |
+ self.title = |
+ l10n_util::GetNSString(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); |
+ self.collectionViewAccessibilityIdentifier = kPrivacyCollectionViewId; |
+ _suggestionsEnabled.reset([[PrefBackedBoolean alloc] |
+ initWithPrefService:_browserState->GetPrefs() |
+ prefName:prefs::kSearchSuggestEnabled]); |
+ [_suggestionsEnabled setObserver:self]; |
+ |
+ PrefService* prefService = _browserState->GetPrefs(); |
+ |
+ _prefChangeRegistrar.Init(prefService); |
+ _prefChangeRegistrarApplicationContext.Init( |
+ GetApplicationContext()->GetLocalState()); |
+ _prefObserverBridge.reset(new PrefObserverBridge(self)); |
+ // Register to observe any changes on Perf backed values displayed by the |
+ // screen. |
+ _prefObserverBridge->ObserveChangesForPreference( |
+ prefs::kIosHandoffToOtherDevices, &_prefChangeRegistrar); |
+ _prefObserverBridge->ObserveChangesForPreference( |
+ metrics::prefs::kMetricsReportingEnabled, |
+ &_prefChangeRegistrarApplicationContext); |
+ _prefObserverBridge->ObserveChangesForPreference( |
+ prefs::kMetricsReportingWifiOnly, |
+ &_prefChangeRegistrarApplicationContext); |
+ |
+ [self loadModel]; |
+ } |
+ return self; |
+} |
+ |
+- (void)dealloc { |
+ [_suggestionsEnabled setObserver:nil]; |
+ [super dealloc]; |
+} |
+ |
+#pragma mark - SettingsRootCollectionViewController |
+ |
+- (void)loadModel { |
+ [super loadModel]; |
+ |
+ CollectionViewModel* model = self.collectionViewModel; |
+ |
+ // Other Devices Section |
+ [model addSectionWithIdentifier:SectionIdentifierOtherDevices]; |
+ CollectionViewTextItem* otherDevicesHeader = [[[CollectionViewTextItem alloc] |
+ initWithType:ItemTypeOtherDevicesHeader] autorelease]; |
+ otherDevicesHeader.text = |
+ l10n_util::GetNSString(IDS_IOS_OPTIONS_CONTINUITY_LABEL); |
+ [model setHeader:otherDevicesHeader |
+ forSectionWithIdentifier:SectionIdentifierOtherDevices]; |
+ [model addItem:[self handoffDetailItem] |
+ toSectionWithIdentifier:SectionIdentifierOtherDevices]; |
+ |
+ // Web Services Section |
+ [model addSectionWithIdentifier:SectionIdentifierWebServices]; |
+ CollectionViewTextItem* webServicesHeader = [[[CollectionViewTextItem alloc] |
+ initWithType:ItemTypeWebServicesHeader] autorelease]; |
+ webServicesHeader.text = |
+ l10n_util::GetNSString(IDS_IOS_OPTIONS_WEB_SERVICES_LABEL); |
+ [model setHeader:webServicesHeader |
+ forSectionWithIdentifier:SectionIdentifierWebServices]; |
+ _showSuggestionsItem.reset([[self showSuggestionsSwitchItem] retain]); |
+ [model addItem:_showSuggestionsItem |
+ toSectionWithIdentifier:SectionIdentifierWebServices]; |
+ |
+ if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) { |
+ [model addItem:[self contextualSearchDetailItem] |
+ toSectionWithIdentifier:SectionIdentifierWebServices]; |
+ } |
+ |
+#if defined(GOOGLE_CHROME_BUILD) |
+ [model addItem:[self sendUsageDetailItem] |
+ toSectionWithIdentifier:SectionIdentifierWebServices]; |
+#endif |
+ |
+ if (web::IsDoNotTrackSupported()) { |
+ [model addItem:[self doNotTrackDetailItem] |
+ toSectionWithIdentifier:SectionIdentifierWebServices]; |
+ } |
+ |
+ if (experimental_flags::IsPhysicalWebEnabled()) { |
+ [model addItem:[self physicalWebDetailItem] |
+ toSectionWithIdentifier:SectionIdentifierWebServices]; |
+ } |
+ |
+ // Footer Section |
+ [model addSectionWithIdentifier:SectionIdentifierWebServicesFooter]; |
+ [model addItem:[self showSuggestionsFooterItem] |
+ toSectionWithIdentifier:SectionIdentifierWebServicesFooter]; |
+ |
+ // Clear Browsing Section |
+ [model addSectionWithIdentifier:SectionIdentifierClearBrowsingData]; |
+ [model addItem:[self clearBrowsingDetailItem] |
+ toSectionWithIdentifier:SectionIdentifierClearBrowsingData]; |
+} |
+ |
+#pragma mark - Model Objects |
+ |
+- (CollectionViewItem*)handoffDetailItem { |
+ NSString* detailText = |
+ _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) |
+ ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
+ : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
+ _handoffDetailItem.reset( |
+ [[self detailItemWithType:ItemTypeOtherDevicesHandoff |
+ titleId:IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES |
+ detailText:detailText] retain]); |
+ |
+ return _handoffDetailItem; |
+} |
+ |
+- (CollectionViewSwitchItem*)showSuggestionsSwitchItem { |
+ CollectionViewSwitchItem* showSuggestionsSwitchItem = |
+ [[[CollectionViewSwitchItem alloc] |
+ initWithType:ItemTypeWebServicesShowSuggestions] autorelease]; |
+ showSuggestionsSwitchItem.text = |
+ l10n_util::GetNSString(IDS_IOS_OPTIONS_SEARCH_URL_SUGGESTIONS); |
+ showSuggestionsSwitchItem.on = [_suggestionsEnabled value]; |
+ |
+ return showSuggestionsSwitchItem; |
+} |
+ |
+- (CollectionViewItem*)showSuggestionsFooterItem { |
+ CollectionViewFooterItem* showSuggestionsFooterItem = |
+ [[[CollectionViewFooterItem alloc] initWithType:ItemTypeWebServicesFooter] |
+ autorelease]; |
+ showSuggestionsFooterItem.text = |
+ l10n_util::GetNSString(IDS_IOS_OPTIONS_PRIVACY_FOOTER); |
+ showSuggestionsFooterItem.linkURL = google_util::AppendGoogleLocaleParam( |
+ GURL(kPrivacyLearnMoreURL), |
+ GetApplicationContext()->GetApplicationLocale()); |
+ showSuggestionsFooterItem.linkDelegate = self; |
+ |
+ return showSuggestionsFooterItem; |
+} |
+ |
+- (CollectionViewItem*)clearBrowsingDetailItem { |
+ return [self detailItemWithType:ItemTypeClearBrowsingDataClear |
+ titleId:IDS_IOS_CLEAR_BROWSING_DATA_TITLE |
+ detailText:nil]; |
+} |
+ |
+- (CollectionViewItem*)sendUsageDetailItem { |
+ NSString* detailText = [DataplanUsageCollectionViewController |
+ currentLabelForPreference:GetApplicationContext()->GetLocalState() |
+ basePref:metrics::prefs::kMetricsReportingEnabled |
+ wifiPref:prefs::kMetricsReportingWifiOnly]; |
+ _sendUsageDetailItem.reset( |
+ [[self detailItemWithType:ItemTypeWebServicesSendUsageData |
+ titleId:IDS_IOS_OPTIONS_SEND_USAGE_DATA |
+ detailText:detailText] retain]); |
+ |
+ return _sendUsageDetailItem; |
+} |
+ |
+- (CollectionViewItem*)physicalWebDetailItem { |
+ PrefService* prefService = GetApplicationContext()->GetLocalState(); |
+ int preferenceState = prefService->GetInteger(prefs::kIosPhysicalWebEnabled); |
+ BOOL enabled = [PhysicalWebCollectionViewController |
+ shouldEnableForPreferenceState:preferenceState]; |
+ NSString* detailText = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
+ : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
+ return [self detailItemWithType:ItemTypeWebServicesPhysicalWeb |
+ titleId:IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB |
+ detailText:detailText]; |
+} |
+ |
+- (CollectionViewItem*)contextualSearchDetailItem { |
+ _touchToSearchPermissions.reset([[TouchToSearchPermissionsMediator alloc] |
+ initWithBrowserState:_browserState]); |
+ NSString* detailText = |
+ [_touchToSearchPermissions preferenceState] == TouchToSearch::DISABLED |
+ ? l10n_util::GetNSString(IDS_IOS_SETTING_OFF) |
+ : l10n_util::GetNSString(IDS_IOS_SETTING_ON); |
+ return [self detailItemWithType:ItemTypeWebServicesTouchToSearch |
+ titleId:IDS_IOS_CONTEXTUAL_SEARCH_TITLE |
+ detailText:detailText]; |
+} |
+ |
+- (CollectionViewItem*)doNotTrackDetailItem { |
+ NSString* detailText = |
+ _browserState->GetPrefs()->GetBoolean(prefs::kEnableDoNotTrack) |
+ ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
+ : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
+ return [self detailItemWithType:ItemTypeWebServicesDoNotTrack |
+ titleId:IDS_IOS_OPTIONS_DO_NOT_TRACK_MOBILE |
+ detailText:detailText]; |
+} |
+ |
+- (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type |
+ titleId:(NSInteger)titleId |
+ detailText:(NSString*)detailText { |
+ CollectionViewDetailItem* detailItem = |
+ [[[CollectionViewDetailItem alloc] initWithType:type] autorelease]; |
+ detailItem.text = l10n_util::GetNSString(titleId); |
+ detailItem.detailText = detailText; |
+ detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; |
+ detailItem.accessibilityTraits |= UIAccessibilityTraitButton; |
+ |
+ return detailItem; |
+} |
+ |
+#pragma mark UICollectionViewDataSource |
+ |
+- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
+ cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
+ UICollectionViewCell* cell = |
+ [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
+ |
+ NSInteger itemType = |
+ [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
+ |
+ if (itemType == ItemTypeWebServicesShowSuggestions) { |
+ CollectionViewSwitchCell* switchCell = |
+ base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell); |
+ [switchCell.switchView addTarget:self |
+ action:@selector(showSuggestionsToggled:) |
+ forControlEvents:UIControlEventValueChanged]; |
+ } |
+ |
+ return cell; |
+} |
+ |
+- (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView |
+ viewForSupplementaryElementOfKind:(NSString*)kind |
+ atIndexPath:(NSIndexPath*)indexPath { |
+ UICollectionReusableView* view = [super collectionView:collectionView |
+ viewForSupplementaryElementOfKind:kind |
+ atIndexPath:indexPath]; |
+ |
+ MDCCollectionViewTextCell* textCell = |
+ base::mac::ObjCCast<MDCCollectionViewTextCell>(view); |
+ if (textCell) { |
+ textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; |
+ } |
+ return view; |
+} |
+ |
+#pragma mark UICollectionViewDelegate |
+- (void)collectionView:(UICollectionView*)collectionView |
+ didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
+ [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
+ NSInteger itemType = |
+ [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
+ |
+ // Items that push a new view controller. |
+ base::scoped_nsobject<UIViewController> controller; |
+ |
+ switch (itemType) { |
+ case ItemTypeOtherDevicesHandoff: |
+ controller.reset([[HandoffCollectionViewController alloc] |
+ initWithBrowserState:_browserState]); |
+ break; |
+ case ItemTypeWebServicesTouchToSearch: |
+ controller.reset([[ContextualSearchCollectionViewController alloc] |
+ initWithPermissions:_touchToSearchPermissions]); |
+ break; |
+ case ItemTypeWebServicesSendUsageData: |
+ controller.reset([[DataplanUsageCollectionViewController alloc] |
+ initWithPrefs:GetApplicationContext()->GetLocalState() |
+ basePref:metrics::prefs::kMetricsReportingEnabled |
+ wifiPref:prefs::kMetricsReportingWifiOnly |
+ title:l10n_util::GetNSString( |
+ IDS_IOS_OPTIONS_SEND_USAGE_DATA)]); |
+ break; |
+ case ItemTypeWebServicesDoNotTrack: |
+ controller.reset([[DoNotTrackCollectionViewController alloc] |
+ initWithPrefs:_browserState->GetPrefs()]); |
+ break; |
+ case ItemTypeWebServicesPhysicalWeb: |
+ controller.reset([[PhysicalWebCollectionViewController alloc] |
+ initWithPrefs:GetApplicationContext()->GetLocalState()]); |
+ break; |
+ case ItemTypeClearBrowsingDataClear: |
+ controller.reset([[ClearBrowsingDataCollectionViewController alloc] |
+ initWithBrowserState:_browserState]); |
+ break; |
+ case ItemTypeWebServicesShowSuggestions: |
+ default: |
+ break; |
+ } |
+ |
+ if (controller.get()) { |
+ [self.navigationController pushViewController:controller animated:YES]; |
+ } |
+} |
+ |
+#pragma mark MDCCollectionViewStylingDelegate |
+ |
+- (BOOL)collectionView:(UICollectionView*)collectionView |
+ shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath { |
+ NSInteger sectionIdentifier = |
+ [self.collectionViewModel sectionIdentifierForSection:indexPath.section]; |
+ |
+ if (sectionIdentifier == SectionIdentifierWebServicesFooter) { |
+ return YES; |
+ } |
+ return NO; |
+} |
+ |
+- (BOOL)collectionView:(UICollectionView*)collectionView |
+ hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
+ NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
+ switch (type) { |
+ case ItemTypeWebServicesFooter: |
+ case ItemTypeWebServicesShowSuggestions: |
+ return YES; |
+ default: |
+ return NO; |
+ } |
+} |
+ |
+- (CGFloat)collectionView:(UICollectionView*)collectionView |
+ cellHeightAtIndexPath:(NSIndexPath*)indexPath { |
+ CollectionViewItem* item = |
+ [self.collectionViewModel itemAtIndexPath:indexPath]; |
+ |
+ if (item.type == ItemTypeWebServicesFooter) |
+ return [MDCCollectionViewCell |
+ cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
+ forItem:item]; |
+ return MDCCellDefaultOneLineHeight; |
+} |
+ |
+- (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView |
+ cellStyleForSection:(NSInteger)section { |
+ NSInteger sectionIdentifier = |
+ [self.collectionViewModel sectionIdentifierForSection:section]; |
+ |
+ if (sectionIdentifier == SectionIdentifierWebServicesFooter) { |
+ return MDCCollectionViewCellStyleDefault; |
+ } |
+ |
+ return self.styler.cellStyle; |
+} |
+ |
+#pragma mark - BooleanObserver |
+ |
+- (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { |
+ DCHECK_EQ(observableBoolean, _suggestionsEnabled.get()); |
+ |
+ // Update the item. |
+ _showSuggestionsItem.get().on = [_suggestionsEnabled value]; |
+ |
+ // Update the cell. |
+ [self reconfigureCellsForItems:@[ _showSuggestionsItem ] |
+ inSectionWithIdentifier:SectionIdentifierWebServices]; |
+} |
+ |
+#pragma mark - Actions |
+ |
+- (void)showSuggestionsToggled:(UISwitch*)sender { |
+ NSIndexPath* switchPath = [self.collectionViewModel |
+ indexPathForItemType:ItemTypeWebServicesShowSuggestions |
+ sectionIdentifier:SectionIdentifierWebServices]; |
+ |
+ CollectionViewSwitchItem* switchItem = |
+ base::mac::ObjCCastStrict<CollectionViewSwitchItem>( |
+ [self.collectionViewModel itemAtIndexPath:switchPath]); |
+ CollectionViewSwitchCell* switchCell = |
+ base::mac::ObjCCastStrict<CollectionViewSwitchCell>( |
+ [self.collectionView cellForItemAtIndexPath:switchPath]); |
+ |
+ DCHECK_EQ(switchCell.switchView, sender); |
+ BOOL isOn = switchCell.switchView.isOn; |
+ switchItem.on = isOn; |
+ [_suggestionsEnabled setValue:isOn]; |
+} |
+ |
+#pragma mark - PrefObserverDelegate |
+ |
+- (void)onPreferenceChanged:(const std::string&)preferenceName { |
+ if (preferenceName == prefs::kIosHandoffToOtherDevices) { |
+ NSString* detailText = |
+ _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) |
+ ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
+ : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
+ _handoffDetailItem.get().detailText = detailText; |
+ [self reconfigureCellsForItems:@[ _handoffDetailItem ] |
+ inSectionWithIdentifier:SectionIdentifierOtherDevices]; |
+ return; |
+ } |
+ |
+ if (preferenceName == metrics::prefs::kMetricsReportingEnabled || |
+ preferenceName == prefs::kMetricsReportingWifiOnly) { |
+ NSString* detailText = [DataplanUsageCollectionViewController |
+ currentLabelForPreference:GetApplicationContext()->GetLocalState() |
+ basePref:metrics::prefs::kMetricsReportingEnabled |
+ wifiPref:prefs::kMetricsReportingWifiOnly]; |
+ |
+ _sendUsageDetailItem.get().detailText = detailText; |
+ |
+ [self reconfigureCellsForItems:@[ _sendUsageDetailItem ] |
+ inSectionWithIdentifier:SectionIdentifierWebServices]; |
+ return; |
+ } |
+} |
+ |
+@end |