Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.mm

Issue 2815513008: [ObjC ARC] Converts ios/chrome/browser/ui/settings:settings_arc to ARC. (Closed)
Patch Set: Removes accidental retain from another CL Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/settings/block_popups_collection_view_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont roller.h" 5 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont roller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/ios/ios_util.h" 10 #include "base/ios/ios_util.h"
11 #import "base/ios/weak_nsobject.h"
12 #include "base/logging.h" 11 #include "base/logging.h"
13 #import "base/mac/bind_objc_block.h" 12 #import "base/mac/bind_objc_block.h"
14 #include "base/mac/foundation_util.h" 13 #include "base/mac/foundation_util.h"
15 #import "base/mac/scoped_nsobject.h"
16 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
19 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
20 #include "components/browser_sync/profile_sync_service.h" 18 #include "components/browser_sync/profile_sync_service.h"
21 #include "components/browsing_data/core/browsing_data_utils.h" 19 #include "components/browsing_data/core/browsing_data_utils.h"
22 #include "components/browsing_data/core/counters/browsing_data_counter.h" 20 #include "components/browsing_data/core/counters/browsing_data_counter.h"
23 #include "components/browsing_data/core/history_notice_utils.h" 21 #include "components/browsing_data/core/history_notice_utils.h"
24 #include "components/browsing_data/core/pref_names.h" 22 #include "components/browsing_data/core/pref_names.h"
25 #include "components/google/core/browser/google_util.h" 23 #include "components/google/core/browser/google_util.h"
(...skipping 28 matching lines...) Expand all
54 #import "ios/chrome/browser/ui/uikit_ui_util.h" 52 #import "ios/chrome/browser/ui/uikit_ui_util.h"
55 #include "ios/chrome/common/channel_info.h" 53 #include "ios/chrome/common/channel_info.h"
56 #include "ios/chrome/grit/ios_chromium_strings.h" 54 #include "ios/chrome/grit/ios_chromium_strings.h"
57 #include "ios/chrome/grit/ios_strings.h" 55 #include "ios/chrome/grit/ios_strings.h"
58 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" 56 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
59 #import "ios/public/provider/chrome/browser/images/branded_image_provider.h" 57 #import "ios/public/provider/chrome/browser/images/branded_image_provider.h"
60 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 58 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
61 #include "ui/base/l10n/l10n_util_mac.h" 59 #include "ui/base/l10n/l10n_util_mac.h"
62 #include "url/gurl.h" 60 #include "url/gurl.h"
63 61
62 #if !defined(__has_feature) || !__has_feature(objc_arc)
63 #error "This file requires ARC support."
64 #endif
65
64 NSString* const kClearBrowsingDataCollectionViewId = 66 NSString* const kClearBrowsingDataCollectionViewId =
65 @"kClearBrowsingDataCollectionViewId"; 67 @"kClearBrowsingDataCollectionViewId";
66 NSString* const kClearBrowsingHistoryCellId = @"kClearBrowsingHistoryCellId"; 68 NSString* const kClearBrowsingHistoryCellId = @"kClearBrowsingHistoryCellId";
67 NSString* const kClearCookiesCellId = @"kClearCookiesCellId"; 69 NSString* const kClearCookiesCellId = @"kClearCookiesCellId";
68 NSString* const kClearCacheCellId = @"kClearCacheCellId"; 70 NSString* const kClearCacheCellId = @"kClearCacheCellId";
69 NSString* const kClearSavedPasswordsCellId = @"kClearSavedPasswordsCellId"; 71 NSString* const kClearSavedPasswordsCellId = @"kClearSavedPasswordsCellId";
70 NSString* const kClearAutofillCellId = @"kClearAutofillCellId"; 72 NSString* const kClearAutofillCellId = @"kClearAutofillCellId";
71 73
72 namespace { 74 namespace {
73 75
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 _timePeriod = static_cast<browsing_data::TimePeriod>(prefValue); 202 _timePeriod = static_cast<browsing_data::TimePeriod>(prefValue);
201 } else { 203 } else {
202 _timePeriod = browsing_data::TimePeriod::ALL_TIME; 204 _timePeriod = browsing_data::TimePeriod::ALL_TIME;
203 } 205 }
204 206
205 self.title = l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE); 207 self.title = l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE);
206 self.collectionViewAccessibilityIdentifier = 208 self.collectionViewAccessibilityIdentifier =
207 kClearBrowsingDataCollectionViewId; 209 kClearBrowsingDataCollectionViewId;
208 210
209 if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) { 211 if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
210 base::WeakNSObject<ClearBrowsingDataCollectionViewController> weakSelf( 212 __weak ClearBrowsingDataCollectionViewController* weakSelf = self;
211 self);
212 void (^dataClearedCallback)( 213 void (^dataClearedCallback)(
213 const IOSChromeBrowsingDataRemover::NotificationDetails&) = 214 const IOSChromeBrowsingDataRemover::NotificationDetails&) =
214 ^(const IOSChromeBrowsingDataRemover::NotificationDetails& details) { 215 ^(const IOSChromeBrowsingDataRemover::NotificationDetails& details) {
215 base::scoped_nsobject<ClearBrowsingDataCollectionViewController> 216 ClearBrowsingDataCollectionViewController* strongSelf = weakSelf;
216 strongSelf([weakSelf retain]);
217 [strongSelf restartCounters:details.removal_mask]; 217 [strongSelf restartCounters:details.removal_mask];
218 }; 218 };
219 _callbackSubscription = 219 _callbackSubscription =
220 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( 220 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
221 base::BindBlock(dataClearedCallback)); 221 base::BindBlockArc(dataClearedCallback));
222 } 222 }
223 223
224 [self loadModel]; 224 [self loadModel];
225 [self restartCounters:IOSChromeBrowsingDataRemover::REMOVE_ALL]; 225 [self restartCounters:IOSChromeBrowsingDataRemover::REMOVE_ALL];
226 } 226 }
227 return self; 227 return self;
228 } 228 }
229 229
230 - (void)viewDidLoad { 230 - (void)viewDidLoad {
231 [super viewDidLoad]; 231 [super viewDidLoad];
232 232
233 SigninManager* signinManager = 233 SigninManager* signinManager =
234 ios::SigninManagerFactory::GetForBrowserState(_browserState); 234 ios::SigninManagerFactory::GetForBrowserState(_browserState);
235 if (!signinManager->IsAuthenticated()) { 235 if (!signinManager->IsAuthenticated()) {
236 return; 236 return;
237 } 237 }
238 238
239 browser_sync::ProfileSyncService* syncService = 239 browser_sync::ProfileSyncService* syncService =
240 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); 240 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
241 history::WebHistoryService* historyService = 241 history::WebHistoryService* historyService =
242 ios::WebHistoryServiceFactory::GetForBrowserState(_browserState); 242 ios::WebHistoryServiceFactory::GetForBrowserState(_browserState);
243 243
244 base::WeakNSObject<ClearBrowsingDataCollectionViewController> weakSelf(self); 244 __weak ClearBrowsingDataCollectionViewController* weakSelf = self;
245 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( 245 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
246 syncService, historyService, base::BindBlock(^(bool shouldShowNotice) { 246 syncService, historyService, base::BindBlockArc(^(bool shouldShowNotice) {
247 base::scoped_nsobject<ClearBrowsingDataCollectionViewController> 247 ClearBrowsingDataCollectionViewController* strongSelf = weakSelf;
248 strongSelf([weakSelf retain]);
249 [strongSelf setShouldShowNoticeAboutOtherFormsOfBrowsingHistory: 248 [strongSelf setShouldShowNoticeAboutOtherFormsOfBrowsingHistory:
250 shouldShowNotice]; 249 shouldShowNotice];
251 })); 250 }));
252 251
253 browsing_data::ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( 252 browsing_data::ShouldPopupDialogAboutOtherFormsOfBrowsingHistory(
254 syncService, historyService, GetChannel(), 253 syncService, historyService, GetChannel(),
255 base::BindBlock(^(bool shouldShowPopup) { 254 base::BindBlockArc(^(bool shouldShowPopup) {
256 base::scoped_nsobject<ClearBrowsingDataCollectionViewController> 255 ClearBrowsingDataCollectionViewController* strongSelf = weakSelf;
257 strongSelf([weakSelf retain]);
258 [strongSelf setShouldPopupDialogAboutOtherFormsOfBrowsingHistory: 256 [strongSelf setShouldPopupDialogAboutOtherFormsOfBrowsingHistory:
259 shouldShowPopup]; 257 shouldShowPopup];
260 })); 258 }));
261 } 259 }
262 260
263 #pragma mark CollectionViewController 261 #pragma mark CollectionViewController
264 262
265 - (void)loadModel { 263 - (void)loadModel {
266 [super loadModel]; 264 [super loadModel];
267 CollectionViewModel* model = self.collectionViewModel; 265 CollectionViewModel* model = self.collectionViewModel;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 ClearDataItem* autofillItem = 319 ClearDataItem* autofillItem =
322 [self clearDataItemWithType:ItemTypeDataTypeAutofill 320 [self clearDataItemWithType:ItemTypeDataTypeAutofill
323 titleID:IDS_IOS_CLEAR_AUTOFILL 321 titleID:IDS_IOS_CLEAR_AUTOFILL
324 mask:IOSChromeBrowsingDataRemover::REMOVE_FORM_DATA 322 mask:IOSChromeBrowsingDataRemover::REMOVE_FORM_DATA
325 prefName:browsing_data::prefs::kDeleteFormData]; 323 prefName:browsing_data::prefs::kDeleteFormData];
326 [model addItem:autofillItem 324 [model addItem:autofillItem
327 toSectionWithIdentifier:SectionIdentifierDataTypes]; 325 toSectionWithIdentifier:SectionIdentifierDataTypes];
328 326
329 // Clear Browsing Data button. 327 // Clear Browsing Data button.
330 [model addSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton]; 328 [model addSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton];
331 CollectionViewTextItem* clearButtonItem = [[[CollectionViewTextItem alloc] 329 CollectionViewTextItem* clearButtonItem = [[CollectionViewTextItem alloc]
332 initWithType:ItemTypeClearBrowsingDataButton] autorelease]; 330 initWithType:ItemTypeClearBrowsingDataButton];
333 clearButtonItem.text = l10n_util::GetNSString(IDS_IOS_CLEAR_BUTTON); 331 clearButtonItem.text = l10n_util::GetNSString(IDS_IOS_CLEAR_BUTTON);
334 clearButtonItem.accessibilityTraits |= UIAccessibilityTraitButton; 332 clearButtonItem.accessibilityTraits |= UIAccessibilityTraitButton;
335 clearButtonItem.textColor = [[MDCPalette cr_redPalette] tint500]; 333 clearButtonItem.textColor = [[MDCPalette cr_redPalette] tint500];
336 [model addItem:clearButtonItem 334 [model addItem:clearButtonItem
337 toSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton]; 335 toSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton];
338 336
339 // Google Account footer. 337 // Google Account footer.
340 SigninManager* signinManager = 338 SigninManager* signinManager =
341 ios::SigninManagerFactory::GetForBrowserState(_browserState); 339 ios::SigninManagerFactory::GetForBrowserState(_browserState);
342 if (signinManager->IsAuthenticated()) { 340 if (signinManager->IsAuthenticated()) {
(...skipping 21 matching lines...) Expand all
364 } 362 }
365 } 363 }
366 364
367 #pragma mark Items 365 #pragma mark Items
368 366
369 - (ClearDataItem*)clearDataItemWithType:(ItemType)itemType 367 - (ClearDataItem*)clearDataItemWithType:(ItemType)itemType
370 titleID:(int)titleMessageID 368 titleID:(int)titleMessageID
371 mask:(int)mask 369 mask:(int)mask
372 prefName:(const char*)prefName { 370 prefName:(const char*)prefName {
373 PrefService* prefs = _browserState->GetPrefs(); 371 PrefService* prefs = _browserState->GetPrefs();
374 ClearDataItem* clearDataItem = 372 ClearDataItem* clearDataItem = [[ClearDataItem alloc] initWithType:itemType];
375 [[[ClearDataItem alloc] initWithType:itemType] autorelease];
376 clearDataItem.text = l10n_util::GetNSString(titleMessageID); 373 clearDataItem.text = l10n_util::GetNSString(titleMessageID);
377 if (prefs->GetBoolean(prefName)) { 374 if (prefs->GetBoolean(prefName)) {
378 clearDataItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; 375 clearDataItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
379 } 376 }
380 clearDataItem.dataTypeMask = mask; 377 clearDataItem.dataTypeMask = mask;
381 clearDataItem.prefName = prefName; 378 clearDataItem.prefName = prefName;
382 clearDataItem.accessibilityIdentifier = 379 clearDataItem.accessibilityIdentifier =
383 [self getAccessibilityIdentifierFromItemType:itemType]; 380 [self getAccessibilityIdentifierFromItemType:itemType];
384 381
385 base::WeakNSObject<ClearBrowsingDataCollectionViewController> weakSelf(self); 382 __weak ClearBrowsingDataCollectionViewController* weakSelf = self;
386 void (^updateUICallback)(const browsing_data::BrowsingDataCounter::Result&) = 383 void (^updateUICallback)(const browsing_data::BrowsingDataCounter::Result&) =
387 ^(const browsing_data::BrowsingDataCounter::Result& result) { 384 ^(const browsing_data::BrowsingDataCounter::Result& result) {
388 base::scoped_nsobject<ClearBrowsingDataCollectionViewController> 385 ClearBrowsingDataCollectionViewController* strongSelf = weakSelf;
389 strongSelf([weakSelf retain]);
390 NSString* counterText = [strongSelf getCounterTextFromResult:result]; 386 NSString* counterText = [strongSelf getCounterTextFromResult:result];
391 [strongSelf updateCounter:itemType detailText:counterText]; 387 [strongSelf updateCounter:itemType detailText:counterText];
392 }; 388 };
393 389
394 [clearDataItem setCounter:BrowsingDataCounterWrapper::CreateCounterWrapper( 390 [clearDataItem setCounter:BrowsingDataCounterWrapper::CreateCounterWrapper(
395 prefName, _browserState, prefs, 391 prefName, _browserState, prefs,
396 base::BindBlock(updateUICallback))]; 392 base::BindBlockArc(updateUICallback))];
397 return clearDataItem; 393 return clearDataItem;
398 } 394 }
399 395
400 - (void)updateCounter:(NSInteger)itemType detailText:(NSString*)detailText { 396 - (void)updateCounter:(NSInteger)itemType detailText:(NSString*)detailText {
401 NSIndexPath* indexPath = [self.collectionViewModel 397 NSIndexPath* indexPath = [self.collectionViewModel
402 indexPathForItemType:itemType 398 indexPathForItemType:itemType
403 sectionIdentifier:SectionIdentifierDataTypes]; 399 sectionIdentifier:SectionIdentifierDataTypes];
404 400
405 CollectionViewModel* model = self.collectionViewModel; 401 CollectionViewModel* model = self.collectionViewModel;
406 if (!model) { 402 if (!model) {
(...skipping 12 matching lines...) Expand all
419 [self.collectionView.collectionViewLayout invalidateLayout]; 415 [self.collectionView.collectionViewLayout invalidateLayout];
420 } 416 }
421 417
422 - (CollectionViewItem*)footerForGoogleAccountSectionItem { 418 - (CollectionViewItem*)footerForGoogleAccountSectionItem {
423 return _shouldShowNoticeAboutOtherFormsOfBrowsingHistory 419 return _shouldShowNoticeAboutOtherFormsOfBrowsingHistory
424 ? [self footerGoogleAccountAndMyActivityItem] 420 ? [self footerGoogleAccountAndMyActivityItem]
425 : [self footerGoogleAccountItem]; 421 : [self footerGoogleAccountItem];
426 } 422 }
427 423
428 - (CollectionViewItem*)footerGoogleAccountItem { 424 - (CollectionViewItem*)footerGoogleAccountItem {
429 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc] 425 CollectionViewFooterItem* footerItem = [[CollectionViewFooterItem alloc]
430 initWithType:ItemTypeFooterGoogleAccount] autorelease]; 426 initWithType:ItemTypeFooterGoogleAccount];
431 footerItem.text = 427 footerItem.text =
432 l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_ACCOUNT); 428 l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_ACCOUNT);
433 UIImage* image = ios::GetChromeBrowserProvider() 429 UIImage* image = ios::GetChromeBrowserProvider()
434 ->GetBrandedImageProvider() 430 ->GetBrandedImageProvider()
435 ->GetClearBrowsingDataAccountActivityImage(); 431 ->GetClearBrowsingDataAccountActivityImage();
436 footerItem.image = image; 432 footerItem.image = image;
437 return footerItem; 433 return footerItem;
438 } 434 }
439 435
440 - (CollectionViewItem*)footerGoogleAccountAndMyActivityItem { 436 - (CollectionViewItem*)footerGoogleAccountAndMyActivityItem {
(...skipping 27 matching lines...) Expand all
468 IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_CLEAR_SYNC_AND_SAVED_SIT E_DATA 464 IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_CLEAR_SYNC_AND_SAVED_SIT E_DATA
469 URL:kClearBrowsingDataLearnMoreURL 465 URL:kClearBrowsingDataLearnMoreURL
470 image:image]; 466 image:image];
471 } 467 }
472 468
473 - (CollectionViewItem*)footerItemWithType:(ItemType)itemType 469 - (CollectionViewItem*)footerItemWithType:(ItemType)itemType
474 titleID:(int)titleMessageID 470 titleID:(int)titleMessageID
475 URL:(const char[])URL 471 URL:(const char[])URL
476 image:(UIImage*)image { 472 image:(UIImage*)image {
477 CollectionViewFooterItem* footerItem = 473 CollectionViewFooterItem* footerItem =
478 [[[CollectionViewFooterItem alloc] initWithType:itemType] autorelease]; 474 [[CollectionViewFooterItem alloc] initWithType:itemType];
479 footerItem.text = l10n_util::GetNSString(titleMessageID); 475 footerItem.text = l10n_util::GetNSString(titleMessageID);
480 footerItem.linkURL = google_util::AppendGoogleLocaleParam( 476 footerItem.linkURL = google_util::AppendGoogleLocaleParam(
481 GURL(URL), GetApplicationContext()->GetApplicationLocale()); 477 GURL(URL), GetApplicationContext()->GetApplicationLocale());
482 footerItem.linkDelegate = self; 478 footerItem.linkDelegate = self;
483 footerItem.image = image; 479 footerItem.image = image;
484 return footerItem; 480 return footerItem;
485 } 481 }
486 482
487 - (CollectionViewItem*)timeRangeItem { 483 - (CollectionViewItem*)timeRangeItem {
488 CollectionViewDetailItem* timeRangeItem = [[[CollectionViewDetailItem alloc] 484 CollectionViewDetailItem* timeRangeItem =
489 initWithType:ItemTypeTimeRange] autorelease]; 485 [[CollectionViewDetailItem alloc] initWithType:ItemTypeTimeRange];
490 timeRangeItem.text = l10n_util::GetNSString( 486 timeRangeItem.text = l10n_util::GetNSString(
491 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_SELECTOR_TITLE); 487 IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_SELECTOR_TITLE);
492 NSString* detailText = [TimeRangeSelectorCollectionViewController 488 NSString* detailText = [TimeRangeSelectorCollectionViewController
493 timePeriodLabelForPrefs:_browserState->GetPrefs()]; 489 timePeriodLabelForPrefs:_browserState->GetPrefs()];
494 DCHECK(detailText); 490 DCHECK(detailText);
495 timeRangeItem.detailText = detailText; 491 timeRangeItem.detailText = detailText;
496 timeRangeItem.accessoryType = 492 timeRangeItem.accessoryType =
497 MDCCollectionViewCellAccessoryDisclosureIndicator; 493 MDCCollectionViewCellAccessoryDisclosureIndicator;
498 timeRangeItem.accessibilityTraits |= UIAccessibilityTraitButton; 494 timeRangeItem.accessibilityTraits |= UIAccessibilityTraitButton;
499 return timeRangeItem; 495 return timeRangeItem;
500 } 496 }
501 497
502 #pragma mark UICollectionViewDelegate 498 #pragma mark UICollectionViewDelegate
503 499
504 - (void)collectionView:(UICollectionView*)collectionView 500 - (void)collectionView:(UICollectionView*)collectionView
505 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 501 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
506 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 502 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
507 NSInteger itemType = 503 NSInteger itemType =
508 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 504 [self.collectionViewModel itemTypeForIndexPath:indexPath];
509 505
510 switch (itemType) { 506 switch (itemType) {
511 case ItemTypeTimeRange: { 507 case ItemTypeTimeRange: {
512 base::scoped_nsobject<UIViewController> controller( 508 UIViewController* controller =
513 [[TimeRangeSelectorCollectionViewController alloc] 509 [[TimeRangeSelectorCollectionViewController alloc]
514 initWithPrefs:_browserState->GetPrefs() 510 initWithPrefs:_browserState->GetPrefs()
515 delegate:self]); 511 delegate:self];
516 [self.navigationController pushViewController:controller animated:YES]; 512 [self.navigationController pushViewController:controller animated:YES];
517 break; 513 break;
518 } 514 }
519 case ItemTypeDataTypeBrowsingHistory: 515 case ItemTypeDataTypeBrowsingHistory:
520 case ItemTypeDataTypeCookiesSiteData: 516 case ItemTypeDataTypeCookiesSiteData:
521 case ItemTypeDataTypeCache: 517 case ItemTypeDataTypeCache:
522 case ItemTypeDataTypeSavedPasswords: 518 case ItemTypeDataTypeSavedPasswords:
523 case ItemTypeDataTypeAutofill: { 519 case ItemTypeDataTypeAutofill: {
524 // Toggle the checkmark. 520 // Toggle the checkmark.
525 // TODO(crbug.com/631486): Custom checkmark animation to be implemented. 521 // TODO(crbug.com/631486): Custom checkmark animation to be implemented.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 for (ClearDataItem* dataTypeItem in dataTypeItems) { 601 for (ClearDataItem* dataTypeItem in dataTypeItems) {
606 DCHECK([dataTypeItem isKindOfClass:[ClearDataItem class]]); 602 DCHECK([dataTypeItem isKindOfClass:[ClearDataItem class]]);
607 if (dataTypeItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark) { 603 if (dataTypeItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark) {
608 dataTypeMaskToRemove |= dataTypeItem.dataTypeMask; 604 dataTypeMaskToRemove |= dataTypeItem.dataTypeMask;
609 } 605 }
610 } 606 }
611 if (dataTypeMaskToRemove == 0) { 607 if (dataTypeMaskToRemove == 0) {
612 // Nothing to clear (no data types selected). 608 // Nothing to clear (no data types selected).
613 return YES; 609 return YES;
614 } 610 }
615 base::WeakNSObject<ClearBrowsingDataCollectionViewController> weakSelf(self); 611 __weak ClearBrowsingDataCollectionViewController* weakSelf = self;
616 UIAlertController* alertController = [UIAlertController 612 UIAlertController* alertController = [UIAlertController
617 alertControllerWithTitle:nil 613 alertControllerWithTitle:nil
618 message:nil 614 message:nil
619 preferredStyle:UIAlertControllerStyleActionSheet]; 615 preferredStyle:UIAlertControllerStyleActionSheet];
620 616
621 UIAlertAction* clearDataAction = [UIAlertAction 617 UIAlertAction* clearDataAction = [UIAlertAction
622 actionWithTitle:l10n_util::GetNSString(IDS_IOS_CLEAR_BUTTON) 618 actionWithTitle:l10n_util::GetNSString(IDS_IOS_CLEAR_BUTTON)
623 style:UIAlertActionStyleDestructive 619 style:UIAlertActionStyleDestructive
624 handler:^(UIAlertAction* action) { 620 handler:^(UIAlertAction* action) {
625 [weakSelf clearDataForDataTypes:dataTypeMaskToRemove]; 621 [weakSelf clearDataForDataTypes:dataTypeMaskToRemove];
626 }]; 622 }];
627 clearDataAction.accessibilityLabel = 623 clearDataAction.accessibilityLabel =
628 l10n_util::GetNSString(IDS_IOS_CONFIRM_CLEAR_BUTTON); 624 l10n_util::GetNSString(IDS_IOS_CONFIRM_CLEAR_BUTTON);
629 UIAlertAction* cancelAction = 625 UIAlertAction* cancelAction =
630 [UIAlertAction actionWithTitle:l10n_util::GetNSString(IDS_CANCEL) 626 [UIAlertAction actionWithTitle:l10n_util::GetNSString(IDS_CANCEL)
631 style:UIAlertActionStyleCancel 627 style:UIAlertActionStyleCancel
632 handler:nil]; 628 handler:nil];
633 [alertController addAction:clearDataAction]; 629 [alertController addAction:clearDataAction];
634 [alertController addAction:cancelAction]; 630 [alertController addAction:cancelAction];
635 [self presentViewController:alertController animated:YES completion:nil]; 631 [self presentViewController:alertController animated:YES completion:nil];
636 return YES; 632 return YES;
637 } 633 }
638 634
639 - (void)clearDataForDataTypes:(int)dataTypeMask { 635 - (void)clearDataForDataTypes:(int)dataTypeMask {
640 DCHECK(dataTypeMask); 636 DCHECK(dataTypeMask);
641 base::scoped_nsobject<ClearBrowsingDataCommand> command( 637 ClearBrowsingDataCommand* command =
642 [[ClearBrowsingDataCommand alloc] initWithBrowserState:_browserState 638 [[ClearBrowsingDataCommand alloc] initWithBrowserState:_browserState
643 mask:dataTypeMask 639 mask:dataTypeMask
644 timePeriod:_timePeriod]); 640 timePeriod:_timePeriod];
645 [self chromeExecuteCommand:command]; 641 [self chromeExecuteCommand:command];
646 642
647 if (!!(dataTypeMask && IOSChromeBrowsingDataRemover::REMOVE_HISTORY)) { 643 if (!!(dataTypeMask && IOSChromeBrowsingDataRemover::REMOVE_HISTORY)) {
648 [self showBrowsingHistoryRemovedDialog]; 644 [self showBrowsingHistoryRemovedDialog];
649 } 645 }
650 } 646 }
651 647
652 - (void)showBrowsingHistoryRemovedDialog { 648 - (void)showBrowsingHistoryRemovedDialog {
653 PrefService* prefs = _browserState->GetPrefs(); 649 PrefService* prefs = _browserState->GetPrefs();
654 int noticeShownTimes = prefs->GetInteger( 650 int noticeShownTimes = prefs->GetInteger(
(...skipping 20 matching lines...) Expand all
675 NSString* title = 671 NSString* title =
676 l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_TITLE); 672 l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_TITLE);
677 NSString* message = l10n_util::GetNSString( 673 NSString* message = l10n_util::GetNSString(
678 IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_DESCRIPTION); 674 IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_DESCRIPTION);
679 675
680 UIAlertController* alertController = 676 UIAlertController* alertController =
681 [UIAlertController alertControllerWithTitle:title 677 [UIAlertController alertControllerWithTitle:title
682 message:message 678 message:message
683 preferredStyle:UIAlertControllerStyleAlert]; 679 preferredStyle:UIAlertControllerStyleAlert];
684 680
685 base::WeakNSObject<ClearBrowsingDataCollectionViewController> weakSelf(self); 681 __weak ClearBrowsingDataCollectionViewController* weakSelf = self;
686 UIAlertAction* openMyActivityAction = [UIAlertAction 682 UIAlertAction* openMyActivityAction = [UIAlertAction
687 actionWithTitle: 683 actionWithTitle:
688 l10n_util::GetNSString( 684 l10n_util::GetNSString(
689 IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_OPEN_HISTORY_BUTTON) 685 IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_OPEN_HISTORY_BUTTON)
690 style:UIAlertActionStyleDefault 686 style:UIAlertActionStyleDefault
691 handler:^(UIAlertAction* action) { 687 handler:^(UIAlertAction* action) {
692 [weakSelf openMyActivityLink]; 688 [weakSelf openMyActivityLink];
693 }]; 689 }];
694 690
695 UIAlertAction* okAction = [UIAlertAction 691 UIAlertAction* okAction = [UIAlertAction
696 actionWithTitle:l10n_util::GetNSString( 692 actionWithTitle:l10n_util::GetNSString(
697 IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_OK_BUTTON) 693 IDS_IOS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_OK_BUTTON)
698 style:UIAlertActionStyleCancel 694 style:UIAlertActionStyleCancel
699 handler:nil]; 695 handler:nil];
700 [alertController addAction:openMyActivityAction]; 696 [alertController addAction:openMyActivityAction];
701 [alertController addAction:okAction]; 697 [alertController addAction:okAction];
702 [self presentViewController:alertController animated:YES completion:nil]; 698 [self presentViewController:alertController animated:YES completion:nil];
703 } 699 }
704 700
705 - (void)openMyActivityLink { 701 - (void)openMyActivityLink {
706 base::scoped_nsobject<OpenUrlCommand> openMyActivityCommand( 702 OpenUrlCommand* openMyActivityCommand =
707 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL(kGoogleMyAccountURL)]); 703 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL(kGoogleMyAccountURL)];
708 openMyActivityCommand.get().tag = IDC_CLOSE_SETTINGS_AND_OPEN_URL; 704 openMyActivityCommand.tag = IDC_CLOSE_SETTINGS_AND_OPEN_URL;
709 [self chromeExecuteCommand:openMyActivityCommand]; 705 [self chromeExecuteCommand:openMyActivityCommand];
710 } 706 }
711 707
712 - (NSString*)getAccessibilityIdentifierFromItemType:(NSInteger)itemType { 708 - (NSString*)getAccessibilityIdentifierFromItemType:(NSInteger)itemType {
713 switch (itemType) { 709 switch (itemType) {
714 case ItemTypeDataTypeBrowsingHistory: 710 case ItemTypeDataTypeBrowsingHistory:
715 return kClearBrowsingHistoryCellId; 711 return kClearBrowsingHistoryCellId;
716 case ItemTypeDataTypeCookiesSiteData: 712 case ItemTypeDataTypeCookiesSiteData:
717 return kClearCookiesCellId; 713 return kClearCookiesCellId;
718 case ItemTypeDataTypeCache: 714 case ItemTypeDataTypeCache:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 &result) 773 &result)
778 ->Value(); 774 ->Value();
779 775
780 // Three cases: Nonzero result for the entire cache, nonzero result for 776 // Three cases: Nonzero result for the entire cache, nonzero result for
781 // a subset of cache (i.e. a finite time interval), and almost zero (less 777 // a subset of cache (i.e. a finite time interval), and almost zero (less
782 // than 1 MB). There is no exact information that the cache is empty so that 778 // than 1 MB). There is no exact information that the cache is empty so that
783 // falls into the almost zero case, which is displayed as less than 1 MB. 779 // falls into the almost zero case, which is displayed as less than 1 MB.
784 // Because of this, the lowest unit that can be used is MB. 780 // Because of this, the lowest unit that can be used is MB.
785 static const int kBytesInAMegabyte = 1 << 20; 781 static const int kBytesInAMegabyte = 1 << 20;
786 if (cacheSizeBytes >= kBytesInAMegabyte) { 782 if (cacheSizeBytes >= kBytesInAMegabyte) {
787 base::scoped_nsobject<NSByteCountFormatter> formatter( 783 NSByteCountFormatter* formatter = [[NSByteCountFormatter alloc] init];
788 [[NSByteCountFormatter alloc] init]); 784 formatter.allowedUnits = NSByteCountFormatterUseAll &
789 formatter.get().allowedUnits = NSByteCountFormatterUseAll & 785 (~NSByteCountFormatterUseBytes) &
790 (~NSByteCountFormatterUseBytes) & 786 (~NSByteCountFormatterUseKB);
791 (~NSByteCountFormatterUseKB); 787 formatter.countStyle = NSByteCountFormatterCountStyleMemory;
792 formatter.get().countStyle = NSByteCountFormatterCountStyleMemory;
793 NSString* formattedSize = [formatter stringFromByteCount:cacheSizeBytes]; 788 NSString* formattedSize = [formatter stringFromByteCount:cacheSizeBytes];
794 return (_timePeriod == browsing_data::TimePeriod::ALL_TIME) 789 return (_timePeriod == browsing_data::TimePeriod::ALL_TIME)
795 ? formattedSize 790 ? formattedSize
796 : l10n_util::GetNSStringF( 791 : l10n_util::GetNSStringF(
797 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, 792 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE,
798 base::SysNSStringToUTF16(formattedSize)); 793 base::SysNSStringToUTF16(formattedSize));
799 } 794 }
800 return l10n_util::GetNSString(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); 795 return l10n_util::GetNSString(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY);
801 } 796 }
802 return base::SysUTF16ToNSString( 797 return base::SysUTF16ToNSString(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 874
880 #pragma mark TimeRangeSelectorCollectionViewControllerDelegate 875 #pragma mark TimeRangeSelectorCollectionViewControllerDelegate
881 876
882 - (void)timeRangeSelectorViewController: 877 - (void)timeRangeSelectorViewController:
883 (TimeRangeSelectorCollectionViewController*)collectionViewController 878 (TimeRangeSelectorCollectionViewController*)collectionViewController
884 didSelectTimePeriod:(browsing_data::TimePeriod)timePeriod { 879 didSelectTimePeriod:(browsing_data::TimePeriod)timePeriod {
885 _timePeriod = timePeriod; 880 _timePeriod = timePeriod;
886 } 881 }
887 882
888 @end 883 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/settings/block_popups_collection_view_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698