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

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

Issue 2813223002: [ObjC ARC] Converts ios/chrome/browser/ui/settings:settings to ARC. (Closed)
Patch Set: reabse Created 3 years, 7 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
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/settings_collection_view_controller.h" 5 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #import "base/ios/weak_nsobject.h"
10 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
11 #import "base/mac/scoped_nsobject.h"
12 #include "base/metrics/user_metrics.h" 10 #include "base/metrics/user_metrics.h"
13 #include "base/scoped_observer.h" 11 #include "base/scoped_observer.h"
14 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
15 #include "components/autofill/core/common/autofill_pref_names.h" 13 #include "components/autofill/core/common/autofill_pref_names.h"
16 #include "components/browser_sync/profile_sync_service.h" 14 #include "components/browser_sync/profile_sync_service.h"
17 #include "components/keyed_service/core/service_access_type.h" 15 #include "components/keyed_service/core/service_access_type.h"
18 #include "components/password_manager/core/browser/password_store.h" 16 #include "components/password_manager/core/browser/password_store.h"
19 #include "components/password_manager/core/common/password_manager_pref_names.h" 17 #include "components/password_manager/core/common/password_manager_pref_names.h"
20 #include "components/prefs/pref_change_registrar.h" 18 #include "components/prefs/pref_change_registrar.h"
21 #include "components/prefs/pref_service.h" 19 #include "components/prefs/pref_service.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #import "ios/chrome/browser/ui/settings/voicesearch_collection_view_controller.h " 66 #import "ios/chrome/browser/ui/settings/voicesearch_collection_view_controller.h "
69 #import "ios/chrome/browser/ui/sync/sync_util.h" 67 #import "ios/chrome/browser/ui/sync/sync_util.h"
70 #import "ios/chrome/browser/ui/uikit_ui_util.h" 68 #import "ios/chrome/browser/ui/uikit_ui_util.h"
71 #include "ios/chrome/browser/voice/speech_input_locale_config.h" 69 #include "ios/chrome/browser/voice/speech_input_locale_config.h"
72 #include "ios/chrome/grit/ios_chromium_strings.h" 70 #include "ios/chrome/grit/ios_chromium_strings.h"
73 #include "ios/chrome/grit/ios_strings.h" 71 #include "ios/chrome/grit/ios_strings.h"
74 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" 72 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
75 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" 73 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
76 #import "ios/public/provider/chrome/browser/signin/signin_resources_provider.h" 74 #import "ios/public/provider/chrome/browser/signin/signin_resources_provider.h"
77 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h" 75 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h"
76 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
78 #include "ui/base/l10n/l10n_util_mac.h" 77 #include "ui/base/l10n/l10n_util_mac.h"
79 78
79 #if !defined(__has_feature) || !__has_feature(objc_arc)
80 #error "This file requires ARC support."
81 #endif
82
80 NSString* const kSettingsCollectionViewId = @"kSettingsCollectionViewId"; 83 NSString* const kSettingsCollectionViewId = @"kSettingsCollectionViewId";
81 NSString* const kSettingsSignInCellId = @"kSettingsSignInCellId"; 84 NSString* const kSettingsSignInCellId = @"kSettingsSignInCellId";
82 NSString* const kSettingsAccountCellId = @"kSettingsAccountCellId"; 85 NSString* const kSettingsAccountCellId = @"kSettingsAccountCellId";
83 NSString* const kSettingsSearchEngineCellId = @"Search Engine"; 86 NSString* const kSettingsSearchEngineCellId = @"Search Engine";
84 NSString* const kSettingsVoiceSearchCellId = @"Voice Search Settings"; 87 NSString* const kSettingsVoiceSearchCellId = @"Voice Search Settings";
85 88
86 @interface SettingsCollectionViewController (NotificationBridgeDelegate) 89 @interface SettingsCollectionViewController (NotificationBridgeDelegate)
87 // Notifies this controller that the sign in state has changed. 90 // Notifies this controller that the sign in state has changed.
88 - (void)onSignInStateChanged; 91 - (void)onSignInStateChanged;
89 @end 92 @end
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 ~SigninObserverBridge() override{}; 139 ~SigninObserverBridge() override{};
137 140
138 // SigninManagerBase::Observer implementation: 141 // SigninManagerBase::Observer implementation:
139 void GoogleSigninSucceeded(const std::string& account_id, 142 void GoogleSigninSucceeded(const std::string& account_id,
140 const std::string& username, 143 const std::string& username,
141 const std::string& password) override; 144 const std::string& password) override;
142 void GoogleSignedOut(const std::string& account_id, 145 void GoogleSignedOut(const std::string& account_id,
143 const std::string& username) override; 146 const std::string& username) override;
144 147
145 private: 148 private:
146 base::WeakNSObject<SettingsCollectionViewController> owner_; 149 __weak SettingsCollectionViewController* owner_;
147 ScopedObserver<SigninManager, SigninObserverBridge> observer_; 150 ScopedObserver<SigninManager, SigninObserverBridge> observer_;
148 }; 151 };
149 152
150 SigninObserverBridge::SigninObserverBridge( 153 SigninObserverBridge::SigninObserverBridge(
151 ios::ChromeBrowserState* browserState, 154 ios::ChromeBrowserState* browserState,
152 SettingsCollectionViewController* owner) 155 SettingsCollectionViewController* owner)
153 : owner_(owner), observer_(this) { 156 : owner_(owner), observer_(this) {
154 DCHECK(owner_); 157 DCHECK(owner_);
155 SigninManager* sigin_manager = 158 SigninManager* sigin_manager =
156 ios::SigninManagerFactory::GetForBrowserState(browserState); 159 ios::SigninManagerFactory::GetForBrowserState(browserState);
(...skipping 24 matching lines...) Expand all
181 PrefObserverDelegate, 184 PrefObserverDelegate,
182 SigninPromoViewConsumer> { 185 SigninPromoViewConsumer> {
183 // The main browser state that hold the settings. Never off the record. 186 // The main browser state that hold the settings. Never off the record.
184 ios::ChromeBrowserState* _mainBrowserState; // weak 187 ios::ChromeBrowserState* _mainBrowserState; // weak
185 188
186 // The current browser state. It is either |_mainBrowserState| 189 // The current browser state. It is either |_mainBrowserState|
187 // or |_mainBrowserState->GetOffTheRecordChromeBrowserState()|. 190 // or |_mainBrowserState->GetOffTheRecordChromeBrowserState()|.
188 ios::ChromeBrowserState* _currentBrowserState; // weak 191 ios::ChromeBrowserState* _currentBrowserState; // weak
189 std::unique_ptr<SigninObserverBridge> _notificationBridge; 192 std::unique_ptr<SigninObserverBridge> _notificationBridge;
190 std::unique_ptr<SyncObserverBridge> _syncObserverBridge; 193 std::unique_ptr<SyncObserverBridge> _syncObserverBridge;
191 base::scoped_nsobject<SigninInteractionController> 194 SigninInteractionController* _signinInteractionController;
192 _signinInteractionController;
193 // Whether the impression of the Signin button has already been recorded. 195 // Whether the impression of the Signin button has already been recorded.
194 BOOL _hasRecordedSigninImpression; 196 BOOL _hasRecordedSigninImpression;
195 // PrefBackedBoolean for ShowMemoryDebugTools switch. 197 // PrefBackedBoolean for ShowMemoryDebugTools switch.
196 base::scoped_nsobject<PrefBackedBoolean> _showMemoryDebugToolsEnabled; 198 PrefBackedBoolean* _showMemoryDebugToolsEnabled;
197 // The item related to the switch for the show suggestions setting. 199 // The item related to the switch for the show suggestions setting.
198 base::scoped_nsobject<CollectionViewSwitchItem> _showMemoryDebugToolsItem; 200 CollectionViewSwitchItem* _showMemoryDebugToolsItem;
199 201
200 // Mediator to configure the sign-in promo cell. Also used to received 202 // Mediator to configure the sign-in promo cell. Also used to received
201 // identity update notifications. 203 // identity update notifications.
202 base::scoped_nsobject<SigninPromoViewMediator> _signinPromoViewMediator; 204 SigninPromoViewMediator* _signinPromoViewMediator;
203 205
204 // Cached resized profile image. 206 // Cached resized profile image.
205 base::scoped_nsobject<UIImage> _resizedImage; 207 UIImage* _resizedImage;
206 base::WeakNSObject<UIImage> _oldImage; 208 __weak UIImage* _oldImage;
207 209
208 // Identity object and observer used for Account Item refresh. 210 // Identity object and observer used for Account Item refresh.
209 base::scoped_nsobject<ChromeIdentity> _identity; 211 ChromeIdentity* _identity;
210 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; 212 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver;
211 213
212 // PrefMember for voice locale code. 214 // PrefMember for voice locale code.
213 StringPrefMember _voiceLocaleCode; 215 StringPrefMember _voiceLocaleCode;
214 // Pref observer to track changes to prefs. 216 // Pref observer to track changes to prefs.
215 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; 217 std::unique_ptr<PrefObserverBridge> _prefObserverBridge;
216 // TODO(crbug.com/662435): Refactor PrefObserverBridge so it owns the 218 // TODO(crbug.com/662435): Refactor PrefObserverBridge so it owns the
217 // PrefChangeRegistrar. 219 // PrefChangeRegistrar.
218 // Registrar for pref changes notifications. 220 // Registrar for pref changes notifications.
219 PrefChangeRegistrar _prefChangeRegistrar; 221 PrefChangeRegistrar _prefChangeRegistrar;
220 222
221 // Updatable Items. 223 // Updatable Items.
222 base::scoped_nsobject<CollectionViewDetailItem> _voiceSearchDetailItem; 224 CollectionViewDetailItem* _voiceSearchDetailItem;
223 base::scoped_nsobject<CollectionViewDetailItem> _defaultSearchEngineItem; 225 CollectionViewDetailItem* _defaultSearchEngineItem;
224 base::scoped_nsobject<CollectionViewDetailItem> _savePasswordsDetailItem; 226 CollectionViewDetailItem* _savePasswordsDetailItem;
225 base::scoped_nsobject<CollectionViewDetailItem> _autoFillDetailItem; 227 CollectionViewDetailItem* _autoFillDetailItem;
226 } 228 }
227 229
228 // Stops observing browser state services. This is required during the shutdown 230 // Stops observing browser state services. This is required during the shutdown
229 // phase to avoid observing services for a profile that is being killed. 231 // phase to avoid observing services for a profile that is being killed.
230 - (void)stopBrowserStateServiceObservers; 232 - (void)stopBrowserStateServiceObservers;
231 233
232 @end 234 @end
233 235
234 @implementation SettingsCollectionViewController 236 @implementation SettingsCollectionViewController
235 237
(...skipping 12 matching lines...) Expand all
248 _currentBrowserState = currentBrowserState; 250 _currentBrowserState = currentBrowserState;
249 self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE); 251 self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE);
250 self.collectionViewAccessibilityIdentifier = kSettingsCollectionViewId; 252 self.collectionViewAccessibilityIdentifier = kSettingsCollectionViewId;
251 _notificationBridge.reset( 253 _notificationBridge.reset(
252 new SigninObserverBridge(_mainBrowserState, self)); 254 new SigninObserverBridge(_mainBrowserState, self));
253 syncer::SyncService* syncService = 255 syncer::SyncService* syncService =
254 IOSChromeProfileSyncServiceFactory::GetForBrowserState( 256 IOSChromeProfileSyncServiceFactory::GetForBrowserState(
255 _mainBrowserState); 257 _mainBrowserState);
256 _syncObserverBridge.reset(new SyncObserverBridge(self, syncService)); 258 _syncObserverBridge.reset(new SyncObserverBridge(self, syncService));
257 259
258 _showMemoryDebugToolsEnabled.reset([[PrefBackedBoolean alloc] 260 _showMemoryDebugToolsEnabled = [[PrefBackedBoolean alloc]
259 initWithPrefService:GetApplicationContext()->GetLocalState() 261 initWithPrefService:GetApplicationContext()->GetLocalState()
260 prefName:prefs::kShowMemoryDebuggingTools]); 262 prefName:prefs::kShowMemoryDebuggingTools];
261 [_showMemoryDebugToolsEnabled setObserver:self]; 263 [_showMemoryDebugToolsEnabled setObserver:self];
262 264
263 AuthenticationService* authService = 265 AuthenticationService* authService =
264 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState); 266 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState);
265 _identity.reset([authService->GetAuthenticatedIdentity() retain]); 267 _identity = authService->GetAuthenticatedIdentity();
266 _identityServiceObserver.reset( 268 _identityServiceObserver.reset(
267 new ChromeIdentityServiceObserverBridge(self)); 269 new ChromeIdentityServiceObserverBridge(self));
268 270
269 PrefService* prefService = _mainBrowserState->GetPrefs(); 271 PrefService* prefService = _mainBrowserState->GetPrefs();
270 272
271 _voiceLocaleCode.Init(prefs::kVoiceSearchLocale, prefService); 273 _voiceLocaleCode.Init(prefs::kVoiceSearchLocale, prefService);
272 274
273 _prefChangeRegistrar.Init(prefService); 275 _prefChangeRegistrar.Init(prefService);
274 _prefObserverBridge.reset(new PrefObserverBridge(self)); 276 _prefObserverBridge.reset(new PrefObserverBridge(self));
275 // Register to observe any changes on Perf backed values displayed by the 277 // Register to observe any changes on Perf backed values displayed by the
276 // screen. 278 // screen.
277 _prefObserverBridge->ObserveChangesForPreference(prefs::kVoiceSearchLocale, 279 _prefObserverBridge->ObserveChangesForPreference(prefs::kVoiceSearchLocale,
278 &_prefChangeRegistrar); 280 &_prefChangeRegistrar);
279 _prefObserverBridge->ObserveChangesForPreference( 281 _prefObserverBridge->ObserveChangesForPreference(
280 password_manager::prefs::kPasswordManagerSavingEnabled, 282 password_manager::prefs::kPasswordManagerSavingEnabled,
281 &_prefChangeRegistrar); 283 &_prefChangeRegistrar);
282 _prefObserverBridge->ObserveChangesForPreference( 284 _prefObserverBridge->ObserveChangesForPreference(
283 autofill::prefs::kAutofillEnabled, &_prefChangeRegistrar); 285 autofill::prefs::kAutofillEnabled, &_prefChangeRegistrar);
284 286
285 [self loadModel]; 287 [self loadModel];
286 } 288 }
287 return self; 289 return self;
288 } 290 }
289 291
290 - (void)dealloc { 292 - (void)dealloc {
291 [self stopBrowserStateServiceObservers]; 293 [self stopBrowserStateServiceObservers];
292 [super dealloc];
293 } 294 }
294 295
295 - (void)stopBrowserStateServiceObservers { 296 - (void)stopBrowserStateServiceObservers {
296 _syncObserverBridge.reset(); 297 _syncObserverBridge.reset();
297 _notificationBridge.reset(); 298 _notificationBridge.reset();
298 _identityServiceObserver.reset(); 299 _identityServiceObserver.reset();
299 [_showMemoryDebugToolsEnabled setObserver:nil]; 300 [_showMemoryDebugToolsEnabled setObserver:nil];
300 } 301 }
301 302
302 - (SigninInteractionController*)signinInteractionController { 303 - (SigninInteractionController*)signinInteractionController {
(...skipping 23 matching lines...) Expand all
326 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState); 327 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState);
327 if (!authService->IsAuthenticated()) { 328 if (!authService->IsAuthenticated()) {
328 if (!_hasRecordedSigninImpression) { 329 if (!_hasRecordedSigninImpression) {
329 // Once the Settings are open, this button impression will at most be 330 // Once the Settings are open, this button impression will at most be
330 // recorded once until they are closed. 331 // recorded once until they are closed.
331 base::RecordAction( 332 base::RecordAction(
332 base::UserMetricsAction("Signin_Impression_FromSettings")); 333 base::UserMetricsAction("Signin_Impression_FromSettings"));
333 _hasRecordedSigninImpression = YES; 334 _hasRecordedSigninImpression = YES;
334 } 335 }
335 if (experimental_flags::IsSigninPromoEnabled()) { 336 if (experimental_flags::IsSigninPromoEnabled()) {
336 _signinPromoViewMediator.reset([[SigninPromoViewMediator alloc] init]); 337 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] init];
337 _signinPromoViewMediator.get().consumer = self; 338 _signinPromoViewMediator.consumer = self;
338 } 339 }
339 [model addItem:[self signInTextItem] 340 [model addItem:[self signInTextItem]
340 toSectionWithIdentifier:SectionIdentifierSignIn]; 341 toSectionWithIdentifier:SectionIdentifierSignIn];
341 } else { 342 } else {
342 _signinPromoViewMediator.reset(nil); 343 _signinPromoViewMediator = nil;
343 [model addItem:[self accountCellItem] 344 [model addItem:[self accountCellItem]
344 toSectionWithIdentifier:SectionIdentifierSignIn]; 345 toSectionWithIdentifier:SectionIdentifierSignIn];
345 } 346 }
346 347
347 // Basics section 348 // Basics section
348 [model addSectionWithIdentifier:SectionIdentifierBasics]; 349 [model addSectionWithIdentifier:SectionIdentifierBasics];
349 CollectionViewTextItem* basicsHeader = [ 350 CollectionViewTextItem* basicsHeader =
350 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; 351 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
351 basicsHeader.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_GENERAL_TAB_LABEL); 352 basicsHeader.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_GENERAL_TAB_LABEL);
352 basicsHeader.textColor = [[MDCPalette greyPalette] tint500]; 353 basicsHeader.textColor = [[MDCPalette greyPalette] tint500];
353 [model setHeader:basicsHeader 354 [model setHeader:basicsHeader
354 forSectionWithIdentifier:SectionIdentifierBasics]; 355 forSectionWithIdentifier:SectionIdentifierBasics];
355 [model addItem:[self searchEngineDetailItem] 356 [model addItem:[self searchEngineDetailItem]
356 toSectionWithIdentifier:SectionIdentifierBasics]; 357 toSectionWithIdentifier:SectionIdentifierBasics];
357 [model addItem:[self savePasswordsDetailItem] 358 [model addItem:[self savePasswordsDetailItem]
358 toSectionWithIdentifier:SectionIdentifierBasics]; 359 toSectionWithIdentifier:SectionIdentifierBasics];
359 [model addItem:[self autoFillDetailItem] 360 [model addItem:[self autoFillDetailItem]
360 toSectionWithIdentifier:SectionIdentifierBasics]; 361 toSectionWithIdentifier:SectionIdentifierBasics];
361 if (experimental_flags::IsNativeAppLauncherEnabled()) { 362 if (experimental_flags::IsNativeAppLauncherEnabled()) {
362 [model addItem:[self nativeAppsDetailItem] 363 [model addItem:[self nativeAppsDetailItem]
363 toSectionWithIdentifier:SectionIdentifierBasics]; 364 toSectionWithIdentifier:SectionIdentifierBasics];
364 } 365 }
365 366
366 // Advanced Section 367 // Advanced Section
367 [model addSectionWithIdentifier:SectionIdentifierAdvanced]; 368 [model addSectionWithIdentifier:SectionIdentifierAdvanced];
368 CollectionViewTextItem* advancedHeader = [ 369 CollectionViewTextItem* advancedHeader =
369 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; 370 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
370 advancedHeader.text = 371 advancedHeader.text =
371 l10n_util::GetNSString(IDS_IOS_OPTIONS_ADVANCED_TAB_LABEL); 372 l10n_util::GetNSString(IDS_IOS_OPTIONS_ADVANCED_TAB_LABEL);
372 advancedHeader.textColor = [[MDCPalette greyPalette] tint500]; 373 advancedHeader.textColor = [[MDCPalette greyPalette] tint500];
373 [model setHeader:advancedHeader 374 [model setHeader:advancedHeader
374 forSectionWithIdentifier:SectionIdentifierAdvanced]; 375 forSectionWithIdentifier:SectionIdentifierAdvanced];
375 [model addItem:[self voiceSearchDetailItem] 376 [model addItem:[self voiceSearchDetailItem]
376 toSectionWithIdentifier:SectionIdentifierAdvanced]; 377 toSectionWithIdentifier:SectionIdentifierAdvanced];
377 [model addItem:[self privacyDetailItem] 378 [model addItem:[self privacyDetailItem]
378 toSectionWithIdentifier:SectionIdentifierAdvanced]; 379 toSectionWithIdentifier:SectionIdentifierAdvanced];
379 [model addItem:[self contentSettingsDetailItem] 380 [model addItem:[self contentSettingsDetailItem]
380 toSectionWithIdentifier:SectionIdentifierAdvanced]; 381 toSectionWithIdentifier:SectionIdentifierAdvanced];
381 [model addItem:[self bandwidthManagementDetailItem] 382 [model addItem:[self bandwidthManagementDetailItem]
382 toSectionWithIdentifier:SectionIdentifierAdvanced]; 383 toSectionWithIdentifier:SectionIdentifierAdvanced];
383 384
384 // Info Section 385 // Info Section
385 [model addSectionWithIdentifier:SectionIdentifierInfo]; 386 [model addSectionWithIdentifier:SectionIdentifierInfo];
386 [model addItem:[self aboutChromeDetailItem] 387 [model addItem:[self aboutChromeDetailItem]
387 toSectionWithIdentifier:SectionIdentifierInfo]; 388 toSectionWithIdentifier:SectionIdentifierInfo];
388 389
389 // Debug Section 390 // Debug Section
390 if ([self hasDebugSection]) { 391 if ([self hasDebugSection]) {
391 [model addSectionWithIdentifier:SectionIdentifierDebug]; 392 [model addSectionWithIdentifier:SectionIdentifierDebug];
392 CollectionViewTextItem* debugHeader = [[[CollectionViewTextItem alloc] 393 CollectionViewTextItem* debugHeader =
393 initWithType:ItemTypeHeader] autorelease]; 394 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
394 debugHeader.text = @"Debug"; 395 debugHeader.text = @"Debug";
395 debugHeader.textColor = [[MDCPalette greyPalette] tint500]; 396 debugHeader.textColor = [[MDCPalette greyPalette] tint500];
396 [model setHeader:debugHeader 397 [model setHeader:debugHeader
397 forSectionWithIdentifier:SectionIdentifierDebug]; 398 forSectionWithIdentifier:SectionIdentifierDebug];
398 } 399 }
399 400
400 if (experimental_flags::IsMemoryDebuggingEnabled()) { 401 if (experimental_flags::IsMemoryDebuggingEnabled()) {
401 _showMemoryDebugToolsItem.reset([[self showMemoryDebugSwitchItem] retain]); 402 _showMemoryDebugToolsItem = [self showMemoryDebugSwitchItem];
402 [model addItem:_showMemoryDebugToolsItem 403 [model addItem:_showMemoryDebugToolsItem
403 toSectionWithIdentifier:SectionIdentifierDebug]; 404 toSectionWithIdentifier:SectionIdentifierDebug];
404 } 405 }
405 406
406 #if CHROMIUM_BUILD && !defined(NDEBUG) 407 #if CHROMIUM_BUILD && !defined(NDEBUG)
407 [model addItem:[self viewSourceSwitchItem] 408 [model addItem:[self viewSourceSwitchItem]
408 toSectionWithIdentifier:SectionIdentifierDebug]; 409 toSectionWithIdentifier:SectionIdentifierDebug];
409 [model addItem:[self logJavascriptConsoleSwitchItem] 410 [model addItem:[self logJavascriptConsoleSwitchItem]
410 toSectionWithIdentifier:SectionIdentifierDebug]; 411 toSectionWithIdentifier:SectionIdentifierDebug];
411 [model addItem:[self showAutofillTypePredictionsSwitchItem] 412 [model addItem:[self showAutofillTypePredictionsSwitchItem]
412 toSectionWithIdentifier:SectionIdentifierDebug]; 413 toSectionWithIdentifier:SectionIdentifierDebug];
413 [model addItem:[self materialCatalogDetailItem] 414 [model addItem:[self materialCatalogDetailItem]
414 toSectionWithIdentifier:SectionIdentifierDebug]; 415 toSectionWithIdentifier:SectionIdentifierDebug];
415 #endif // CHROMIUM_BUILD && !defined(NDEBUG) 416 #endif // CHROMIUM_BUILD && !defined(NDEBUG)
416 } 417 }
417 418
418 #pragma mark - Model Items 419 #pragma mark - Model Items
419 420
420 - (CollectionViewItem*)signInTextItem { 421 - (CollectionViewItem*)signInTextItem {
421 if (experimental_flags::IsSigninPromoEnabled()) { 422 if (experimental_flags::IsSigninPromoEnabled()) {
422 DCHECK(_signinPromoViewMediator.get()); 423 DCHECK(_signinPromoViewMediator);
423 SigninPromoItem* signinPromoItem = [ 424 SigninPromoItem* signinPromoItem =
424 [[SigninPromoItem alloc] initWithType:ItemTypeSigninPromo] autorelease]; 425 [[SigninPromoItem alloc] initWithType:ItemTypeSigninPromo];
425 signinPromoItem.configurator = 426 signinPromoItem.configurator =
426 [_signinPromoViewMediator createConfigurator]; 427 [_signinPromoViewMediator createConfigurator];
427 return signinPromoItem; 428 return signinPromoItem;
428 } 429 }
429 AccountSignInItem* signInTextItem = [[[AccountSignInItem alloc] 430 AccountSignInItem* signInTextItem =
430 initWithType:ItemTypeSignInButton] autorelease]; 431 [[AccountSignInItem alloc] initWithType:ItemTypeSignInButton];
431 signInTextItem.accessibilityIdentifier = kSettingsSignInCellId; 432 signInTextItem.accessibilityIdentifier = kSettingsSignInCellId;
432 UIImage* image = CircularImageFromImage(ios::GetChromeBrowserProvider() 433 UIImage* image = CircularImageFromImage(ios::GetChromeBrowserProvider()
433 ->GetSigninResourcesProvider() 434 ->GetSigninResourcesProvider()
434 ->GetDefaultAvatar(), 435 ->GetDefaultAvatar(),
435 kAccountProfilePhotoDimension); 436 kAccountProfilePhotoDimension);
436 signInTextItem.image = image; 437 signInTextItem.image = image;
437 return signInTextItem; 438 return signInTextItem;
438 } 439 }
439 440
440 - (CollectionViewItem*)accountCellItem { 441 - (CollectionViewItem*)accountCellItem {
441 CollectionViewAccountItem* identityAccountItem = 442 CollectionViewAccountItem* identityAccountItem =
442 [[[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount] 443 [[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount];
443 autorelease];
444 identityAccountItem.accessoryType = 444 identityAccountItem.accessoryType =
445 MDCCollectionViewCellAccessoryDisclosureIndicator; 445 MDCCollectionViewCellAccessoryDisclosureIndicator;
446 identityAccountItem.accessibilityIdentifier = kSettingsAccountCellId; 446 identityAccountItem.accessibilityIdentifier = kSettingsAccountCellId;
447 [self updateIdentityAccountItem:identityAccountItem]; 447 [self updateIdentityAccountItem:identityAccountItem];
448 return identityAccountItem; 448 return identityAccountItem;
449 } 449 }
450 450
451 - (CollectionViewItem*)searchEngineDetailItem { 451 - (CollectionViewItem*)searchEngineDetailItem {
452 NSString* defaultSearchEngineName = 452 NSString* defaultSearchEngineName =
453 base::SysUTF16ToNSString(GetDefaultSearchEngineName( 453 base::SysUTF16ToNSString(GetDefaultSearchEngineName(
454 ios::TemplateURLServiceFactory::GetForBrowserState( 454 ios::TemplateURLServiceFactory::GetForBrowserState(
455 _mainBrowserState))); 455 _mainBrowserState)));
456 456
457 _defaultSearchEngineItem.reset( 457 _defaultSearchEngineItem =
458 [[self detailItemWithType:ItemTypeSearchEngine 458 [self detailItemWithType:ItemTypeSearchEngine
459 text:l10n_util::GetNSString( 459 text:l10n_util::GetNSString(
460 IDS_IOS_SEARCH_ENGINE_SETTING_TITLE) 460 IDS_IOS_SEARCH_ENGINE_SETTING_TITLE)
461 detailText:defaultSearchEngineName] retain]); 461 detailText:defaultSearchEngineName];
462 _defaultSearchEngineItem.get().accessibilityIdentifier = 462 _defaultSearchEngineItem.accessibilityIdentifier =
463 kSettingsSearchEngineCellId; 463 kSettingsSearchEngineCellId;
464 return _defaultSearchEngineItem; 464 return _defaultSearchEngineItem;
465 } 465 }
466 466
467 - (CollectionViewItem*)savePasswordsDetailItem { 467 - (CollectionViewItem*)savePasswordsDetailItem {
468 BOOL savePasswordsEnabled = _mainBrowserState->GetPrefs()->GetBoolean( 468 BOOL savePasswordsEnabled = _mainBrowserState->GetPrefs()->GetBoolean(
469 password_manager::prefs::kPasswordManagerSavingEnabled); 469 password_manager::prefs::kPasswordManagerSavingEnabled);
470 NSString* passwordsDetail = savePasswordsEnabled 470 NSString* passwordsDetail = savePasswordsEnabled
471 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 471 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
472 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 472 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
473 473
474 _savePasswordsDetailItem.reset( 474 _savePasswordsDetailItem =
475 [[self detailItemWithType:ItemTypeSavedPasswords 475 [self detailItemWithType:ItemTypeSavedPasswords
476 text:l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS) 476 text:l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS)
477 detailText:passwordsDetail] retain]); 477 detailText:passwordsDetail];
478 478
479 return _savePasswordsDetailItem; 479 return _savePasswordsDetailItem;
480 } 480 }
481 481
482 - (CollectionViewItem*)autoFillDetailItem { 482 - (CollectionViewItem*)autoFillDetailItem {
483 BOOL autofillEnabled = _mainBrowserState->GetPrefs()->GetBoolean( 483 BOOL autofillEnabled = _mainBrowserState->GetPrefs()->GetBoolean(
484 autofill::prefs::kAutofillEnabled); 484 autofill::prefs::kAutofillEnabled);
485 NSString* autofillDetail = autofillEnabled 485 NSString* autofillDetail = autofillEnabled
486 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 486 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
487 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 487 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
488 _autoFillDetailItem.reset( 488 _autoFillDetailItem =
489 [[self detailItemWithType:ItemTypeAutofill 489 [self detailItemWithType:ItemTypeAutofill
490 text:l10n_util::GetNSString(IDS_IOS_AUTOFILL) 490 text:l10n_util::GetNSString(IDS_IOS_AUTOFILL)
491 detailText:autofillDetail] retain]); 491 detailText:autofillDetail];
492 492
493 return _autoFillDetailItem; 493 return _autoFillDetailItem;
494 } 494 }
495 495
496 - (CollectionViewItem*)nativeAppsDetailItem { 496 - (CollectionViewItem*)nativeAppsDetailItem {
497 return [self 497 return [self
498 detailItemWithType:ItemTypeNativeApps 498 detailItemWithType:ItemTypeNativeApps
499 text:l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SETTINGS) 499 text:l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SETTINGS)
500 detailText:nil]; 500 detailText:nil];
501 } 501 }
502 502
503 - (CollectionViewItem*)voiceSearchDetailItem { 503 - (CollectionViewItem*)voiceSearchDetailItem {
504 voice::SpeechInputLocaleConfig* localeConfig = 504 voice::SpeechInputLocaleConfig* localeConfig =
505 voice::SpeechInputLocaleConfig::GetInstance(); 505 voice::SpeechInputLocaleConfig::GetInstance();
506 voice::SpeechInputLocale locale = 506 voice::SpeechInputLocale locale =
507 _voiceLocaleCode.GetValue().length() 507 _voiceLocaleCode.GetValue().length()
508 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) 508 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue())
509 : localeConfig->GetDefaultLocale(); 509 : localeConfig->GetDefaultLocale();
510 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); 510 NSString* languageName = base::SysUTF16ToNSString(locale.display_name);
511 _voiceSearchDetailItem.reset( 511 _voiceSearchDetailItem =
512 [[self detailItemWithType:ItemTypeVoiceSearch 512 [self detailItemWithType:ItemTypeVoiceSearch
513 text:l10n_util::GetNSString( 513 text:l10n_util::GetNSString(
514 IDS_IOS_VOICE_SEARCH_SETTING_TITLE) 514 IDS_IOS_VOICE_SEARCH_SETTING_TITLE)
515 detailText:languageName] retain]); 515 detailText:languageName];
516 _voiceSearchDetailItem.get().accessibilityIdentifier = 516 _voiceSearchDetailItem.accessibilityIdentifier = kSettingsVoiceSearchCellId;
517 kSettingsVoiceSearchCellId;
518 return _voiceSearchDetailItem; 517 return _voiceSearchDetailItem;
519 } 518 }
520 519
521 - (CollectionViewItem*)privacyDetailItem { 520 - (CollectionViewItem*)privacyDetailItem {
522 return 521 return
523 [self detailItemWithType:ItemTypePrivacy 522 [self detailItemWithType:ItemTypePrivacy
524 text:l10n_util::GetNSString( 523 text:l10n_util::GetNSString(
525 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY) 524 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY)
526 detailText:nil]; 525 detailText:nil];
527 } 526 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 #endif // CHROMIUM_BUILD && !defined(NDEBUG) 582 #endif // CHROMIUM_BUILD && !defined(NDEBUG)
584 583
585 #pragma mark Item Updaters 584 #pragma mark Item Updaters
586 585
587 - (void)updateSearchCell { 586 - (void)updateSearchCell {
588 NSString* defaultSearchEngineName = 587 NSString* defaultSearchEngineName =
589 base::SysUTF16ToNSString(GetDefaultSearchEngineName( 588 base::SysUTF16ToNSString(GetDefaultSearchEngineName(
590 ios::TemplateURLServiceFactory::GetForBrowserState( 589 ios::TemplateURLServiceFactory::GetForBrowserState(
591 _mainBrowserState))); 590 _mainBrowserState)));
592 591
593 _defaultSearchEngineItem.get().detailText = defaultSearchEngineName; 592 _defaultSearchEngineItem.detailText = defaultSearchEngineName;
594 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]]; 593 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]];
595 } 594 }
596 595
597 #pragma mark Item Constructors 596 #pragma mark Item Constructors
598 597
599 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type 598 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type
600 text:(NSString*)text 599 text:(NSString*)text
601 detailText:(NSString*)detailText { 600 detailText:(NSString*)detailText {
602 CollectionViewDetailItem* detailItem = 601 CollectionViewDetailItem* detailItem =
603 [[[CollectionViewDetailItem alloc] initWithType:type] autorelease]; 602 [[CollectionViewDetailItem alloc] initWithType:type];
604 detailItem.text = text; 603 detailItem.text = text;
605 detailItem.detailText = detailText; 604 detailItem.detailText = detailText;
606 detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; 605 detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
607 detailItem.accessibilityTraits |= UIAccessibilityTraitButton; 606 detailItem.accessibilityTraits |= UIAccessibilityTraitButton;
608 607
609 return detailItem; 608 return detailItem;
610 } 609 }
611 610
612 - (CollectionViewSwitchItem*)switchItemWithType:(NSInteger)type 611 - (CollectionViewSwitchItem*)switchItemWithType:(NSInteger)type
613 title:(NSString*)title 612 title:(NSString*)title
614 withDefaultsKey:(NSString*)key { 613 withDefaultsKey:(NSString*)key {
615 CollectionViewSwitchItem* switchItem = 614 CollectionViewSwitchItem* switchItem =
616 [[[CollectionViewSwitchItem alloc] initWithType:type] autorelease]; 615 [[CollectionViewSwitchItem alloc] initWithType:type];
617 switchItem.text = title; 616 switchItem.text = title;
618 if (key) { 617 if (key) {
619 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 618 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
620 switchItem.on = [defaults boolForKey:key]; 619 switchItem.on = [defaults boolForKey:key];
621 } 620 }
622 621
623 return switchItem; 622 return switchItem;
624 } 623 }
625 624
626 #pragma mark - UICollectionViewDataSource 625 #pragma mark - UICollectionViewDataSource
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 id object = [self.collectionViewModel itemAtIndexPath:indexPath]; 730 id object = [self.collectionViewModel itemAtIndexPath:indexPath];
732 if ([object respondsToSelector:@selector(isEnabled)] && 731 if ([object respondsToSelector:@selector(isEnabled)] &&
733 ![object performSelector:@selector(isEnabled)]) { 732 ![object performSelector:@selector(isEnabled)]) {
734 // Don't perform any action if the cell isn't enabled. 733 // Don't perform any action if the cell isn't enabled.
735 return; 734 return;
736 } 735 }
737 736
738 NSInteger itemType = 737 NSInteger itemType =
739 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 738 [self.collectionViewModel itemTypeForIndexPath:indexPath];
740 739
741 base::scoped_nsobject<UIViewController> controller; 740 UIViewController* controller;
742 741
743 switch (itemType) { 742 switch (itemType) {
744 case ItemTypeSignInButton: 743 case ItemTypeSignInButton:
745 [self showSignInWithIdentity:nil]; 744 [self showSignInWithIdentity:nil];
746 break; 745 break;
747 case ItemTypeAccount: 746 case ItemTypeAccount:
748 controller.reset([[AccountsCollectionViewController alloc] 747 controller = [[AccountsCollectionViewController alloc]
749 initWithBrowserState:_mainBrowserState 748 initWithBrowserState:_mainBrowserState
750 closeSettingsOnAddAccount:NO]); 749 closeSettingsOnAddAccount:NO];
751 break; 750 break;
752 case ItemTypeSearchEngine: 751 case ItemTypeSearchEngine:
753 controller.reset([[SearchEngineSettingsCollectionViewController alloc] 752 controller = [[SearchEngineSettingsCollectionViewController alloc]
754 initWithBrowserState:_mainBrowserState]); 753 initWithBrowserState:_mainBrowserState];
755 break; 754 break;
756 case ItemTypeSavedPasswords: { 755 case ItemTypeSavedPasswords: {
757 controller.reset([[SavePasswordsCollectionViewController alloc] 756 controller = [[SavePasswordsCollectionViewController alloc]
758 initWithBrowserState:_mainBrowserState]); 757 initWithBrowserState:_mainBrowserState];
759 break; 758 break;
760 } 759 }
761 case ItemTypeAutofill: 760 case ItemTypeAutofill:
762 controller.reset([[AutofillCollectionViewController alloc] 761 controller = [[AutofillCollectionViewController alloc]
763 initWithBrowserState:_mainBrowserState]); 762 initWithBrowserState:_mainBrowserState];
764 break; 763 break;
765 case ItemTypeNativeApps: 764 case ItemTypeNativeApps:
766 controller.reset([[NativeAppsCollectionViewController alloc] 765 controller = [[NativeAppsCollectionViewController alloc]
767 initWithURLRequestContextGetter:_currentBrowserState 766 initWithURLRequestContextGetter:_currentBrowserState
768 ->GetRequestContext()]); 767 ->GetRequestContext()];
769 break; 768 break;
770 case ItemTypeVoiceSearch: 769 case ItemTypeVoiceSearch:
771 controller.reset([[VoicesearchCollectionViewController alloc] 770 controller = [[VoicesearchCollectionViewController alloc]
772 initWithPrefs:_mainBrowserState->GetPrefs()]); 771 initWithPrefs:_mainBrowserState->GetPrefs()];
773 break; 772 break;
774 case ItemTypePrivacy: 773 case ItemTypePrivacy:
775 controller.reset([[PrivacyCollectionViewController alloc] 774 controller = [[PrivacyCollectionViewController alloc]
776 initWithBrowserState:_mainBrowserState]); 775 initWithBrowserState:_mainBrowserState];
777 break; 776 break;
778 case ItemTypeContentSettings: 777 case ItemTypeContentSettings:
779 controller.reset([[ContentSettingsCollectionViewController alloc] 778 controller = [[ContentSettingsCollectionViewController alloc]
780 initWithBrowserState:_mainBrowserState]); 779 initWithBrowserState:_mainBrowserState];
781 break; 780 break;
782 case ItemTypeBandwidth: 781 case ItemTypeBandwidth:
783 controller.reset([[BandwidthManagementCollectionViewController alloc] 782 controller = [[BandwidthManagementCollectionViewController alloc]
784 initWithBrowserState:_mainBrowserState]); 783 initWithBrowserState:_mainBrowserState];
785 break; 784 break;
786 case ItemTypeAboutChrome: 785 case ItemTypeAboutChrome:
787 controller.reset([[AboutChromeCollectionViewController alloc] init]); 786 controller = [[AboutChromeCollectionViewController alloc] init];
788 break; 787 break;
789 case ItemTypeMemoryDebugging: 788 case ItemTypeMemoryDebugging:
790 case ItemTypeViewSource: 789 case ItemTypeViewSource:
791 case ItemTypeLogJavascript: 790 case ItemTypeLogJavascript:
792 case ItemTypeShowAutofillTypePredictions: 791 case ItemTypeShowAutofillTypePredictions:
793 // Taps on these don't do anything. They have a switch as accessory view 792 // Taps on these don't do anything. They have a switch as accessory view
794 // and only the switch is tappable. 793 // and only the switch is tappable.
795 break; 794 break;
796 case ItemTypeCellCatalog: 795 case ItemTypeCellCatalog:
797 controller.reset([[MaterialCellCatalogViewController alloc] init]); 796 controller = [[MaterialCellCatalogViewController alloc] init];
798 break; 797 break;
799 default: 798 default:
800 break; 799 break;
801 } 800 }
802 801
803 if (controller) { 802 if (controller) {
804 [self.navigationController pushViewController:controller animated:YES]; 803 [self.navigationController pushViewController:controller animated:YES];
805 } 804 }
806 } 805 }
807 806
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 } 925 }
927 return NO; 926 return NO;
928 #endif // CHROMIUM_BUILD && !defined(NDEBUG) 927 #endif // CHROMIUM_BUILD && !defined(NDEBUG)
929 } 928 }
930 929
931 // Updates the identity cell. 930 // Updates the identity cell.
932 - (void)updateIdentityAccountItem: 931 - (void)updateIdentityAccountItem:
933 (CollectionViewAccountItem*)identityAccountItem { 932 (CollectionViewAccountItem*)identityAccountItem {
934 AuthenticationService* authService = 933 AuthenticationService* authService =
935 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState); 934 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState);
936 _identity.reset([authService->GetAuthenticatedIdentity() retain]); 935 _identity = authService->GetAuthenticatedIdentity();
937 if (!_identity) { 936 if (!_identity) {
938 // This could occur during the sign out process. Just ignore as the account 937 // This could occur during the sign out process. Just ignore as the account
939 // cell will be replaced by the "Sign in" button. 938 // cell will be replaced by the "Sign in" button.
940 return; 939 return;
941 } 940 }
942 identityAccountItem.image = [self userAccountImage]; 941 identityAccountItem.image = [self userAccountImage];
943 identityAccountItem.text = [_identity userFullName]; 942 identityAccountItem.text = [_identity userFullName];
944 943
945 SyncSetupService* syncSetupService = 944 SyncSetupService* syncSetupService =
946 SyncSetupServiceFactory::GetForBrowserState(_mainBrowserState); 945 SyncSetupServiceFactory::GetForBrowserState(_mainBrowserState);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 [self updateIdentityAccountItem:identityAccountItem]; 982 [self updateIdentityAccountItem:identityAccountItem];
984 [self reconfigureCellsForItems:@[ identityAccountItem ]]; 983 [self reconfigureCellsForItems:@[ identityAccountItem ]];
985 } 984 }
986 } 985 }
987 986
988 #pragma mark Sign in 987 #pragma mark Sign in
989 988
990 - (void)showSignInWithIdentity:(ChromeIdentity*)identity { 989 - (void)showSignInWithIdentity:(ChromeIdentity*)identity {
991 base::RecordAction(base::UserMetricsAction("Signin_Signin_FromSettings")); 990 base::RecordAction(base::UserMetricsAction("Signin_Signin_FromSettings"));
992 DCHECK(!_signinInteractionController); 991 DCHECK(!_signinInteractionController);
993 _signinInteractionController.reset([[SigninInteractionController alloc] 992 _signinInteractionController = [[SigninInteractionController alloc]
994 initWithBrowserState:_mainBrowserState 993 initWithBrowserState:_mainBrowserState
995 presentingViewController:self.navigationController 994 presentingViewController:self.navigationController
996 isPresentedOnSettings:YES 995 isPresentedOnSettings:YES
997 accessPoint:signin_metrics::AccessPoint:: 996 accessPoint:signin_metrics::AccessPoint::
998 ACCESS_POINT_SETTINGS]); 997 ACCESS_POINT_SETTINGS];
999 998
1000 base::WeakNSObject<SettingsCollectionViewController> weakSelf(self); 999 __weak SettingsCollectionViewController* weakSelf = self;
1001 [_signinInteractionController 1000 [_signinInteractionController
1002 signInWithViewController:self 1001 signInWithViewController:self
1003 identity:identity 1002 identity:identity
1004 completion:^(BOOL success) { 1003 completion:^(BOOL success) {
1005 [weakSelf didFinishSignin:success]; 1004 [weakSelf didFinishSignin:success];
1006 }]; 1005 }];
1007 } 1006 }
1008 1007
1009 - (void)didFinishSignin:(BOOL)signedIn { 1008 - (void)didFinishSignin:(BOOL)signedIn {
1010 _signinInteractionController.reset(); 1009 _signinInteractionController = nil;
1011 } 1010 }
1012 1011
1013 - (void)signinPromoPrimaryAction:(id)unused { 1012 - (void)signinPromoPrimaryAction:(id)unused {
1014 ChromeIdentity* identity = _signinPromoViewMediator.get().defaultIdentity; 1013 ChromeIdentity* identity = _signinPromoViewMediator.defaultIdentity;
1015 if (identity) { 1014 if (identity) {
1016 base::RecordAction( 1015 base::RecordAction(
1017 base::UserMetricsAction("Signin_SigninWithDefault_FromSettings")); 1016 base::UserMetricsAction("Signin_SigninWithDefault_FromSettings"));
1018 } else { 1017 } else {
1019 base::RecordAction( 1018 base::RecordAction(
1020 base::UserMetricsAction("Signin_SigninNewAccount_FromSettings")); 1019 base::UserMetricsAction("Signin_SigninNewAccount_FromSettings"));
1021 } 1020 }
1022 [self showSignInWithIdentity:identity]; 1021 [self showSignInWithIdentity:identity];
1023 } 1022 }
1024 1023
1025 - (void)signinPromoSecondaryAction:(id)unused { 1024 - (void)signinPromoSecondaryAction:(id)unused {
1026 DCHECK(_signinPromoViewMediator.get().defaultIdentity); 1025 DCHECK(_signinPromoViewMediator.defaultIdentity);
1027 base::RecordAction( 1026 base::RecordAction(
1028 base::UserMetricsAction("Signin_SigninNotDefault_FromSettings")); 1027 base::UserMetricsAction("Signin_SigninNotDefault_FromSettings"));
1029 [self showSignInWithIdentity:nil]; 1028 [self showSignInWithIdentity:nil];
1030 } 1029 }
1031 1030
1032 #pragma mark NotificationBridgeDelegate 1031 #pragma mark NotificationBridgeDelegate
1033 1032
1034 - (void)onSignInStateChanged { 1033 - (void)onSignInStateChanged {
1035 // Sign in state changes are rare. Just reload the entire collection when this 1034 // Sign in state changes are rare. Just reload the entire collection when this
1036 // happens. 1035 // happens.
(...skipping 26 matching lines...) Expand all
1063 ->GetDefaultAvatar(); 1062 ->GetDefaultAvatar();
1064 // No cached image, trigger a fetch, which will notify all observers 1063 // No cached image, trigger a fetch, which will notify all observers
1065 // (including the corresponding AccountViewBase). 1064 // (including the corresponding AccountViewBase).
1066 ios::GetChromeBrowserProvider() 1065 ios::GetChromeBrowserProvider()
1067 ->GetChromeIdentityService() 1066 ->GetChromeIdentityService()
1068 ->GetAvatarForIdentity(_identity, ^(UIImage*){ 1067 ->GetAvatarForIdentity(_identity, ^(UIImage*){
1069 }); 1068 });
1070 } 1069 }
1071 1070
1072 // If the currently used image has already been resized, use it. 1071 // If the currently used image has already been resized, use it.
1073 if (_resizedImage && _oldImage.get() == image) 1072 if (_resizedImage && _oldImage == image)
1074 return _resizedImage; 1073 return _resizedImage;
1075 1074
1076 _oldImage.reset(image); 1075 _oldImage = image;
1077 1076
1078 // Resize the profile image. 1077 // Resize the profile image.
1079 CGFloat dimension = kAccountProfilePhotoDimension; 1078 CGFloat dimension = kAccountProfilePhotoDimension;
1080 if (image.size.width != dimension || image.size.height != dimension) { 1079 if (image.size.width != dimension || image.size.height != dimension) {
1081 image = ResizeImage(image, CGSizeMake(dimension, dimension), 1080 image = ResizeImage(image, CGSizeMake(dimension, dimension),
1082 ProjectionMode::kAspectFit); 1081 ProjectionMode::kAspectFit);
1083 } 1082 }
1084 _resizedImage.reset([image retain]); 1083 _resizedImage = image;
1085 return _resizedImage; 1084 return _resizedImage;
1086 } 1085 }
1087 1086
1088 #pragma mark ChromeIdentityServiceObserver 1087 #pragma mark ChromeIdentityServiceObserver
1089 1088
1090 - (void)onProfileUpdate:(ChromeIdentity*)identity { 1089 - (void)onProfileUpdate:(ChromeIdentity*)identity {
1091 if (identity == _identity) { 1090 if (identity == _identity) {
1092 [self reloadAccountCell]; 1091 [self reloadAccountCell];
1093 } 1092 }
1094 } 1093 }
1095 1094
1096 - (void)onChromeIdentityServiceWillBeDestroyed { 1095 - (void)onChromeIdentityServiceWillBeDestroyed {
1097 _identityServiceObserver.reset(); 1096 _identityServiceObserver.reset();
1098 } 1097 }
1099 1098
1100 #pragma mark - BooleanObserver 1099 #pragma mark - BooleanObserver
1101 1100
1102 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { 1101 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
1103 DCHECK_EQ(observableBoolean, _showMemoryDebugToolsEnabled.get()); 1102 DCHECK_EQ(observableBoolean, _showMemoryDebugToolsEnabled);
1104 // Update the Item. 1103 // Update the Item.
1105 _showMemoryDebugToolsItem.get().on = [_showMemoryDebugToolsEnabled value]; 1104 _showMemoryDebugToolsItem.on = [_showMemoryDebugToolsEnabled value];
1106 1105
1107 // Update the Cell. 1106 // Update the Cell.
1108 [self reconfigureCellsForItems:@[ _showMemoryDebugToolsItem ]]; 1107 [self reconfigureCellsForItems:@[ _showMemoryDebugToolsItem ]];
1109 } 1108 }
1110 1109
1111 #pragma mark - PrefObserverDelegate 1110 #pragma mark - PrefObserverDelegate
1112 1111
1113 - (void)onPreferenceChanged:(const std::string&)preferenceName { 1112 - (void)onPreferenceChanged:(const std::string&)preferenceName {
1114 if (preferenceName == prefs::kVoiceSearchLocale) { 1113 if (preferenceName == prefs::kVoiceSearchLocale) {
1115 voice::SpeechInputLocaleConfig* localeConfig = 1114 voice::SpeechInputLocaleConfig* localeConfig =
1116 voice::SpeechInputLocaleConfig::GetInstance(); 1115 voice::SpeechInputLocaleConfig::GetInstance();
1117 voice::SpeechInputLocale locale = 1116 voice::SpeechInputLocale locale =
1118 _voiceLocaleCode.GetValue().length() 1117 _voiceLocaleCode.GetValue().length()
1119 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) 1118 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue())
1120 : localeConfig->GetDefaultLocale(); 1119 : localeConfig->GetDefaultLocale();
1121 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); 1120 NSString* languageName = base::SysUTF16ToNSString(locale.display_name);
1122 _voiceSearchDetailItem.get().detailText = languageName; 1121 _voiceSearchDetailItem.detailText = languageName;
1123 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ]]; 1122 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ]];
1124 } 1123 }
1125 1124
1126 if (preferenceName == 1125 if (preferenceName ==
1127 password_manager::prefs::kPasswordManagerSavingEnabled) { 1126 password_manager::prefs::kPasswordManagerSavingEnabled) {
1128 BOOL savePasswordsEnabled = 1127 BOOL savePasswordsEnabled =
1129 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); 1128 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName);
1130 NSString* passwordsDetail = 1129 NSString* passwordsDetail =
1131 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 1130 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
1132 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 1131 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
1133 1132
1134 _savePasswordsDetailItem.get().detailText = passwordsDetail; 1133 _savePasswordsDetailItem.detailText = passwordsDetail;
1135 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ]]; 1134 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ]];
1136 } 1135 }
1137 1136
1138 if (preferenceName == autofill::prefs::kAutofillEnabled) { 1137 if (preferenceName == autofill::prefs::kAutofillEnabled) {
1139 BOOL autofillEnabled = 1138 BOOL autofillEnabled =
1140 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); 1139 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName);
1141 NSString* autofillDetail = 1140 NSString* autofillDetail =
1142 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 1141 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
1143 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 1142 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
1144 _autoFillDetailItem.get().detailText = autofillDetail; 1143 _autoFillDetailItem.detailText = autofillDetail;
1145 [self reconfigureCellsForItems:@[ _autoFillDetailItem ]]; 1144 [self reconfigureCellsForItems:@[ _autoFillDetailItem ]];
1146 } 1145 }
1147 } 1146 }
1148 1147
1149 #pragma mark - SigninPromoViewConsumer 1148 #pragma mark - SigninPromoViewConsumer
1150 1149
1151 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity 1150 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity
1152 configurator:(SigninPromoViewConfigurator*) 1151 configurator:(SigninPromoViewConfigurator*)
1153 configurator { 1152 configurator {
1154 if (![self.collectionViewModel hasItemForItemType:ItemTypeSigninPromo 1153 if (![self.collectionViewModel hasItemForItemType:ItemTypeSigninPromo
1155 sectionIdentifier:SectionIdentifierSignIn]) { 1154 sectionIdentifier:SectionIdentifierSignIn]) {
1156 return; 1155 return;
1157 } 1156 }
1158 NSIndexPath* signinPromoCellIndexPath = 1157 NSIndexPath* signinPromoCellIndexPath =
1159 [self.collectionViewModel indexPathForItemType:ItemTypeSigninPromo 1158 [self.collectionViewModel indexPathForItemType:ItemTypeSigninPromo
1160 sectionIdentifier:SectionIdentifierSignIn]; 1159 sectionIdentifier:SectionIdentifierSignIn];
1161 DCHECK(signinPromoCellIndexPath.item != NSNotFound); 1160 DCHECK(signinPromoCellIndexPath.item != NSNotFound);
1162 SigninPromoItem* signinPromoItem = base::mac::ObjCCast<SigninPromoItem>( 1161 SigninPromoItem* signinPromoItem = base::mac::ObjCCast<SigninPromoItem>(
1163 [self.collectionViewModel itemAtIndexPath:signinPromoCellIndexPath]); 1162 [self.collectionViewModel itemAtIndexPath:signinPromoCellIndexPath]);
1164 if (signinPromoItem) { 1163 if (signinPromoItem) {
1165 signinPromoItem.configurator = configurator; 1164 signinPromoItem.configurator = configurator;
1166 [self reconfigureCellsForItems:@[ signinPromoItem ]]; 1165 [self reconfigureCellsForItems:@[ signinPromoItem ]];
1167 if (newIdentity) 1166 if (newIdentity)
1168 [self.collectionViewLayout invalidateLayout]; 1167 [self.collectionViewLayout invalidateLayout];
1169 } 1168 }
1170 } 1169 }
1171 1170
1172 @end 1171 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698