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

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: rebase 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
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 [model addItem:[self nativeAppsDetailItem] 362 [model addItem:[self nativeAppsDetailItem]
362 toSectionWithIdentifier:SectionIdentifierBasics]; 363 toSectionWithIdentifier:SectionIdentifierBasics];
363 364
364 // Advanced Section 365 // Advanced Section
365 [model addSectionWithIdentifier:SectionIdentifierAdvanced]; 366 [model addSectionWithIdentifier:SectionIdentifierAdvanced];
366 CollectionViewTextItem* advancedHeader = [ 367 CollectionViewTextItem* advancedHeader =
367 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; 368 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
368 advancedHeader.text = 369 advancedHeader.text =
369 l10n_util::GetNSString(IDS_IOS_OPTIONS_ADVANCED_TAB_LABEL); 370 l10n_util::GetNSString(IDS_IOS_OPTIONS_ADVANCED_TAB_LABEL);
370 advancedHeader.textColor = [[MDCPalette greyPalette] tint500]; 371 advancedHeader.textColor = [[MDCPalette greyPalette] tint500];
371 [model setHeader:advancedHeader 372 [model setHeader:advancedHeader
372 forSectionWithIdentifier:SectionIdentifierAdvanced]; 373 forSectionWithIdentifier:SectionIdentifierAdvanced];
373 [model addItem:[self voiceSearchDetailItem] 374 [model addItem:[self voiceSearchDetailItem]
374 toSectionWithIdentifier:SectionIdentifierAdvanced]; 375 toSectionWithIdentifier:SectionIdentifierAdvanced];
375 [model addItem:[self privacyDetailItem] 376 [model addItem:[self privacyDetailItem]
376 toSectionWithIdentifier:SectionIdentifierAdvanced]; 377 toSectionWithIdentifier:SectionIdentifierAdvanced];
377 [model addItem:[self contentSettingsDetailItem] 378 [model addItem:[self contentSettingsDetailItem]
378 toSectionWithIdentifier:SectionIdentifierAdvanced]; 379 toSectionWithIdentifier:SectionIdentifierAdvanced];
379 [model addItem:[self bandwidthManagementDetailItem] 380 [model addItem:[self bandwidthManagementDetailItem]
380 toSectionWithIdentifier:SectionIdentifierAdvanced]; 381 toSectionWithIdentifier:SectionIdentifierAdvanced];
381 382
382 // Info Section 383 // Info Section
383 [model addSectionWithIdentifier:SectionIdentifierInfo]; 384 [model addSectionWithIdentifier:SectionIdentifierInfo];
384 [model addItem:[self aboutChromeDetailItem] 385 [model addItem:[self aboutChromeDetailItem]
385 toSectionWithIdentifier:SectionIdentifierInfo]; 386 toSectionWithIdentifier:SectionIdentifierInfo];
386 387
387 // Debug Section 388 // Debug Section
388 if ([self hasDebugSection]) { 389 if ([self hasDebugSection]) {
389 [model addSectionWithIdentifier:SectionIdentifierDebug]; 390 [model addSectionWithIdentifier:SectionIdentifierDebug];
390 CollectionViewTextItem* debugHeader = [[[CollectionViewTextItem alloc] 391 CollectionViewTextItem* debugHeader =
391 initWithType:ItemTypeHeader] autorelease]; 392 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
392 debugHeader.text = @"Debug"; 393 debugHeader.text = @"Debug";
393 debugHeader.textColor = [[MDCPalette greyPalette] tint500]; 394 debugHeader.textColor = [[MDCPalette greyPalette] tint500];
394 [model setHeader:debugHeader 395 [model setHeader:debugHeader
395 forSectionWithIdentifier:SectionIdentifierDebug]; 396 forSectionWithIdentifier:SectionIdentifierDebug];
396 } 397 }
397 398
398 if (experimental_flags::IsMemoryDebuggingEnabled()) { 399 if (experimental_flags::IsMemoryDebuggingEnabled()) {
399 _showMemoryDebugToolsItem.reset([[self showMemoryDebugSwitchItem] retain]); 400 _showMemoryDebugToolsItem = [self showMemoryDebugSwitchItem];
400 [model addItem:_showMemoryDebugToolsItem 401 [model addItem:_showMemoryDebugToolsItem
401 toSectionWithIdentifier:SectionIdentifierDebug]; 402 toSectionWithIdentifier:SectionIdentifierDebug];
402 } 403 }
403 404
404 #if CHROMIUM_BUILD && !defined(NDEBUG) 405 #if CHROMIUM_BUILD && !defined(NDEBUG)
405 [model addItem:[self viewSourceSwitchItem] 406 [model addItem:[self viewSourceSwitchItem]
406 toSectionWithIdentifier:SectionIdentifierDebug]; 407 toSectionWithIdentifier:SectionIdentifierDebug];
407 [model addItem:[self logJavascriptConsoleSwitchItem] 408 [model addItem:[self logJavascriptConsoleSwitchItem]
408 toSectionWithIdentifier:SectionIdentifierDebug]; 409 toSectionWithIdentifier:SectionIdentifierDebug];
409 [model addItem:[self showAutofillTypePredictionsSwitchItem] 410 [model addItem:[self showAutofillTypePredictionsSwitchItem]
410 toSectionWithIdentifier:SectionIdentifierDebug]; 411 toSectionWithIdentifier:SectionIdentifierDebug];
411 [model addItem:[self materialCatalogDetailItem] 412 [model addItem:[self materialCatalogDetailItem]
412 toSectionWithIdentifier:SectionIdentifierDebug]; 413 toSectionWithIdentifier:SectionIdentifierDebug];
413 #endif // CHROMIUM_BUILD && !defined(NDEBUG) 414 #endif // CHROMIUM_BUILD && !defined(NDEBUG)
414 } 415 }
415 416
416 #pragma mark - Model Items 417 #pragma mark - Model Items
417 418
418 - (CollectionViewItem*)signInTextItem { 419 - (CollectionViewItem*)signInTextItem {
419 if (experimental_flags::IsSigninPromoEnabled()) { 420 if (experimental_flags::IsSigninPromoEnabled()) {
420 DCHECK(_signinPromoViewMediator.get()); 421 DCHECK(_signinPromoViewMediator);
421 SigninPromoItem* signinPromoItem = [ 422 SigninPromoItem* signinPromoItem =
422 [[SigninPromoItem alloc] initWithType:ItemTypeSigninPromo] autorelease]; 423 [[SigninPromoItem alloc] initWithType:ItemTypeSigninPromo];
423 signinPromoItem.configurator = 424 signinPromoItem.configurator =
424 [_signinPromoViewMediator createConfigurator]; 425 [_signinPromoViewMediator createConfigurator];
425 return signinPromoItem; 426 return signinPromoItem;
426 } 427 }
427 AccountSignInItem* signInTextItem = [[[AccountSignInItem alloc] 428 AccountSignInItem* signInTextItem =
428 initWithType:ItemTypeSignInButton] autorelease]; 429 [[AccountSignInItem alloc] initWithType:ItemTypeSignInButton];
429 signInTextItem.accessibilityIdentifier = kSettingsSignInCellId; 430 signInTextItem.accessibilityIdentifier = kSettingsSignInCellId;
430 UIImage* image = CircularImageFromImage(ios::GetChromeBrowserProvider() 431 UIImage* image = CircularImageFromImage(ios::GetChromeBrowserProvider()
431 ->GetSigninResourcesProvider() 432 ->GetSigninResourcesProvider()
432 ->GetDefaultAvatar(), 433 ->GetDefaultAvatar(),
433 kAccountProfilePhotoDimension); 434 kAccountProfilePhotoDimension);
434 signInTextItem.image = image; 435 signInTextItem.image = image;
435 return signInTextItem; 436 return signInTextItem;
436 } 437 }
437 438
438 - (CollectionViewItem*)accountCellItem { 439 - (CollectionViewItem*)accountCellItem {
439 CollectionViewAccountItem* identityAccountItem = 440 CollectionViewAccountItem* identityAccountItem =
440 [[[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount] 441 [[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount];
441 autorelease];
442 identityAccountItem.accessoryType = 442 identityAccountItem.accessoryType =
443 MDCCollectionViewCellAccessoryDisclosureIndicator; 443 MDCCollectionViewCellAccessoryDisclosureIndicator;
444 identityAccountItem.accessibilityIdentifier = kSettingsAccountCellId; 444 identityAccountItem.accessibilityIdentifier = kSettingsAccountCellId;
445 [self updateIdentityAccountItem:identityAccountItem]; 445 [self updateIdentityAccountItem:identityAccountItem];
446 return identityAccountItem; 446 return identityAccountItem;
447 } 447 }
448 448
449 - (CollectionViewItem*)searchEngineDetailItem { 449 - (CollectionViewItem*)searchEngineDetailItem {
450 NSString* defaultSearchEngineName = 450 NSString* defaultSearchEngineName =
451 base::SysUTF16ToNSString(GetDefaultSearchEngineName( 451 base::SysUTF16ToNSString(GetDefaultSearchEngineName(
452 ios::TemplateURLServiceFactory::GetForBrowserState( 452 ios::TemplateURLServiceFactory::GetForBrowserState(
453 _mainBrowserState))); 453 _mainBrowserState)));
454 454
455 _defaultSearchEngineItem.reset( 455 _defaultSearchEngineItem =
456 [[self detailItemWithType:ItemTypeSearchEngine 456 [self detailItemWithType:ItemTypeSearchEngine
457 text:l10n_util::GetNSString( 457 text:l10n_util::GetNSString(
458 IDS_IOS_SEARCH_ENGINE_SETTING_TITLE) 458 IDS_IOS_SEARCH_ENGINE_SETTING_TITLE)
459 detailText:defaultSearchEngineName] retain]); 459 detailText:defaultSearchEngineName];
460 _defaultSearchEngineItem.get().accessibilityIdentifier = 460 _defaultSearchEngineItem.accessibilityIdentifier =
461 kSettingsSearchEngineCellId; 461 kSettingsSearchEngineCellId;
462 return _defaultSearchEngineItem; 462 return _defaultSearchEngineItem;
463 } 463 }
464 464
465 - (CollectionViewItem*)savePasswordsDetailItem { 465 - (CollectionViewItem*)savePasswordsDetailItem {
466 BOOL savePasswordsEnabled = _mainBrowserState->GetPrefs()->GetBoolean( 466 BOOL savePasswordsEnabled = _mainBrowserState->GetPrefs()->GetBoolean(
467 password_manager::prefs::kPasswordManagerSavingEnabled); 467 password_manager::prefs::kPasswordManagerSavingEnabled);
468 NSString* passwordsDetail = savePasswordsEnabled 468 NSString* passwordsDetail = savePasswordsEnabled
469 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 469 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
470 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 470 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
471 471
472 _savePasswordsDetailItem.reset( 472 _savePasswordsDetailItem =
473 [[self detailItemWithType:ItemTypeSavedPasswords 473 [self detailItemWithType:ItemTypeSavedPasswords
474 text:l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS) 474 text:l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS)
475 detailText:passwordsDetail] retain]); 475 detailText:passwordsDetail];
476 476
477 return _savePasswordsDetailItem; 477 return _savePasswordsDetailItem;
478 } 478 }
479 479
480 - (CollectionViewItem*)autoFillDetailItem { 480 - (CollectionViewItem*)autoFillDetailItem {
481 BOOL autofillEnabled = _mainBrowserState->GetPrefs()->GetBoolean( 481 BOOL autofillEnabled = _mainBrowserState->GetPrefs()->GetBoolean(
482 autofill::prefs::kAutofillEnabled); 482 autofill::prefs::kAutofillEnabled);
483 NSString* autofillDetail = autofillEnabled 483 NSString* autofillDetail = autofillEnabled
484 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 484 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
485 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 485 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
486 _autoFillDetailItem.reset( 486 _autoFillDetailItem =
487 [[self detailItemWithType:ItemTypeAutofill 487 [self detailItemWithType:ItemTypeAutofill
488 text:l10n_util::GetNSString(IDS_IOS_AUTOFILL) 488 text:l10n_util::GetNSString(IDS_IOS_AUTOFILL)
489 detailText:autofillDetail] retain]); 489 detailText:autofillDetail];
490 490
491 return _autoFillDetailItem; 491 return _autoFillDetailItem;
492 } 492 }
493 493
494 - (CollectionViewItem*)nativeAppsDetailItem { 494 - (CollectionViewItem*)nativeAppsDetailItem {
495 return [self 495 return [self
496 detailItemWithType:ItemTypeNativeApps 496 detailItemWithType:ItemTypeNativeApps
497 text:l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SETTINGS) 497 text:l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SETTINGS)
498 detailText:nil]; 498 detailText:nil];
499 } 499 }
500 500
501 - (CollectionViewItem*)voiceSearchDetailItem { 501 - (CollectionViewItem*)voiceSearchDetailItem {
502 voice::SpeechInputLocaleConfig* localeConfig = 502 voice::SpeechInputLocaleConfig* localeConfig =
503 voice::SpeechInputLocaleConfig::GetInstance(); 503 voice::SpeechInputLocaleConfig::GetInstance();
504 voice::SpeechInputLocale locale = 504 voice::SpeechInputLocale locale =
505 _voiceLocaleCode.GetValue().length() 505 _voiceLocaleCode.GetValue().length()
506 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) 506 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue())
507 : localeConfig->GetDefaultLocale(); 507 : localeConfig->GetDefaultLocale();
508 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); 508 NSString* languageName = base::SysUTF16ToNSString(locale.display_name);
509 _voiceSearchDetailItem.reset( 509 _voiceSearchDetailItem =
510 [[self detailItemWithType:ItemTypeVoiceSearch 510 [self detailItemWithType:ItemTypeVoiceSearch
511 text:l10n_util::GetNSString( 511 text:l10n_util::GetNSString(
512 IDS_IOS_VOICE_SEARCH_SETTING_TITLE) 512 IDS_IOS_VOICE_SEARCH_SETTING_TITLE)
513 detailText:languageName] retain]); 513 detailText:languageName];
514 _voiceSearchDetailItem.get().accessibilityIdentifier = 514 _voiceSearchDetailItem.accessibilityIdentifier = kSettingsVoiceSearchCellId;
515 kSettingsVoiceSearchCellId;
516 return _voiceSearchDetailItem; 515 return _voiceSearchDetailItem;
517 } 516 }
518 517
519 - (CollectionViewItem*)privacyDetailItem { 518 - (CollectionViewItem*)privacyDetailItem {
520 return 519 return
521 [self detailItemWithType:ItemTypePrivacy 520 [self detailItemWithType:ItemTypePrivacy
522 text:l10n_util::GetNSString( 521 text:l10n_util::GetNSString(
523 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY) 522 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY)
524 detailText:nil]; 523 detailText:nil];
525 } 524 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 #endif // CHROMIUM_BUILD && !defined(NDEBUG) 580 #endif // CHROMIUM_BUILD && !defined(NDEBUG)
582 581
583 #pragma mark Item Updaters 582 #pragma mark Item Updaters
584 583
585 - (void)updateSearchCell { 584 - (void)updateSearchCell {
586 NSString* defaultSearchEngineName = 585 NSString* defaultSearchEngineName =
587 base::SysUTF16ToNSString(GetDefaultSearchEngineName( 586 base::SysUTF16ToNSString(GetDefaultSearchEngineName(
588 ios::TemplateURLServiceFactory::GetForBrowserState( 587 ios::TemplateURLServiceFactory::GetForBrowserState(
589 _mainBrowserState))); 588 _mainBrowserState)));
590 589
591 _defaultSearchEngineItem.get().detailText = defaultSearchEngineName; 590 _defaultSearchEngineItem.detailText = defaultSearchEngineName;
592 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ] 591 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]
593 inSectionWithIdentifier:SectionIdentifierBasics]; 592 inSectionWithIdentifier:SectionIdentifierBasics];
594 } 593 }
595 594
596 #pragma mark Item Constructors 595 #pragma mark Item Constructors
597 596
598 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type 597 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type
599 text:(NSString*)text 598 text:(NSString*)text
600 detailText:(NSString*)detailText { 599 detailText:(NSString*)detailText {
601 CollectionViewDetailItem* detailItem = 600 CollectionViewDetailItem* detailItem =
602 [[[CollectionViewDetailItem alloc] initWithType:type] autorelease]; 601 [[CollectionViewDetailItem alloc] initWithType:type];
603 detailItem.text = text; 602 detailItem.text = text;
604 detailItem.detailText = detailText; 603 detailItem.detailText = detailText;
605 detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; 604 detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
606 detailItem.accessibilityTraits |= UIAccessibilityTraitButton; 605 detailItem.accessibilityTraits |= UIAccessibilityTraitButton;
607 606
608 return detailItem; 607 return detailItem;
609 } 608 }
610 609
611 - (CollectionViewSwitchItem*)switchItemWithType:(NSInteger)type 610 - (CollectionViewSwitchItem*)switchItemWithType:(NSInteger)type
612 title:(NSString*)title 611 title:(NSString*)title
613 withDefaultsKey:(NSString*)key { 612 withDefaultsKey:(NSString*)key {
614 CollectionViewSwitchItem* switchItem = 613 CollectionViewSwitchItem* switchItem =
615 [[[CollectionViewSwitchItem alloc] initWithType:type] autorelease]; 614 [[CollectionViewSwitchItem alloc] initWithType:type];
616 switchItem.text = title; 615 switchItem.text = title;
617 if (key) { 616 if (key) {
618 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 617 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
619 switchItem.on = [defaults boolForKey:key]; 618 switchItem.on = [defaults boolForKey:key];
620 } 619 }
621 620
622 return switchItem; 621 return switchItem;
623 } 622 }
624 623
625 #pragma mark - UICollectionViewDataSource 624 #pragma mark - UICollectionViewDataSource
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 id object = [self.collectionViewModel itemAtIndexPath:indexPath]; 729 id object = [self.collectionViewModel itemAtIndexPath:indexPath];
731 if ([object respondsToSelector:@selector(isEnabled)] && 730 if ([object respondsToSelector:@selector(isEnabled)] &&
732 ![object performSelector:@selector(isEnabled)]) { 731 ![object performSelector:@selector(isEnabled)]) {
733 // Don't perform any action if the cell isn't enabled. 732 // Don't perform any action if the cell isn't enabled.
734 return; 733 return;
735 } 734 }
736 735
737 NSInteger itemType = 736 NSInteger itemType =
738 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 737 [self.collectionViewModel itemTypeForIndexPath:indexPath];
739 738
740 base::scoped_nsobject<UIViewController> controller; 739 UIViewController* controller;
741 740
742 switch (itemType) { 741 switch (itemType) {
743 case ItemTypeSignInButton: 742 case ItemTypeSignInButton:
744 [self showSignInWithIdentity:nil]; 743 [self showSignInWithIdentity:nil];
745 break; 744 break;
746 case ItemTypeAccount: 745 case ItemTypeAccount:
747 controller.reset([[AccountsCollectionViewController alloc] 746 controller = [[AccountsCollectionViewController alloc]
748 initWithBrowserState:_mainBrowserState 747 initWithBrowserState:_mainBrowserState
749 closeSettingsOnAddAccount:NO]); 748 closeSettingsOnAddAccount:NO];
750 break; 749 break;
751 case ItemTypeSearchEngine: 750 case ItemTypeSearchEngine:
752 controller.reset([[SearchEngineSettingsCollectionViewController alloc] 751 controller = [[SearchEngineSettingsCollectionViewController alloc]
753 initWithBrowserState:_mainBrowserState]); 752 initWithBrowserState:_mainBrowserState];
754 break; 753 break;
755 case ItemTypeSavedPasswords: { 754 case ItemTypeSavedPasswords: {
756 controller.reset([[SavePasswordsCollectionViewController alloc] 755 controller = [[SavePasswordsCollectionViewController alloc]
757 initWithBrowserState:_mainBrowserState]); 756 initWithBrowserState:_mainBrowserState];
758 break; 757 break;
759 } 758 }
760 case ItemTypeAutofill: 759 case ItemTypeAutofill:
761 controller.reset([[AutofillCollectionViewController alloc] 760 controller = [[AutofillCollectionViewController alloc]
762 initWithBrowserState:_mainBrowserState]); 761 initWithBrowserState:_mainBrowserState];
763 break; 762 break;
764 case ItemTypeNativeApps: 763 case ItemTypeNativeApps:
765 controller.reset([[NativeAppsCollectionViewController alloc] 764 controller = [[NativeAppsCollectionViewController alloc]
766 initWithURLRequestContextGetter:_currentBrowserState 765 initWithURLRequestContextGetter:_currentBrowserState
767 ->GetRequestContext()]); 766 ->GetRequestContext()];
768 break; 767 break;
769 case ItemTypeVoiceSearch: 768 case ItemTypeVoiceSearch:
770 controller.reset([[VoicesearchCollectionViewController alloc] 769 controller = [[VoicesearchCollectionViewController alloc]
771 initWithPrefs:_mainBrowserState->GetPrefs()]); 770 initWithPrefs:_mainBrowserState->GetPrefs()];
772 break; 771 break;
773 case ItemTypePrivacy: 772 case ItemTypePrivacy:
774 controller.reset([[PrivacyCollectionViewController alloc] 773 controller = [[PrivacyCollectionViewController alloc]
775 initWithBrowserState:_mainBrowserState]); 774 initWithBrowserState:_mainBrowserState];
776 break; 775 break;
777 case ItemTypeContentSettings: 776 case ItemTypeContentSettings:
778 controller.reset([[ContentSettingsCollectionViewController alloc] 777 controller = [[ContentSettingsCollectionViewController alloc]
779 initWithBrowserState:_mainBrowserState]); 778 initWithBrowserState:_mainBrowserState];
780 break; 779 break;
781 case ItemTypeBandwidth: 780 case ItemTypeBandwidth:
782 controller.reset([[BandwidthManagementCollectionViewController alloc] 781 controller = [[BandwidthManagementCollectionViewController alloc]
783 initWithBrowserState:_mainBrowserState]); 782 initWithBrowserState:_mainBrowserState];
784 break; 783 break;
785 case ItemTypeAboutChrome: 784 case ItemTypeAboutChrome:
786 controller.reset([[AboutChromeCollectionViewController alloc] init]); 785 controller = [[AboutChromeCollectionViewController alloc] init];
787 break; 786 break;
788 case ItemTypeMemoryDebugging: 787 case ItemTypeMemoryDebugging:
789 case ItemTypeViewSource: 788 case ItemTypeViewSource:
790 case ItemTypeLogJavascript: 789 case ItemTypeLogJavascript:
791 case ItemTypeShowAutofillTypePredictions: 790 case ItemTypeShowAutofillTypePredictions:
792 // Taps on these don't do anything. They have a switch as accessory view 791 // Taps on these don't do anything. They have a switch as accessory view
793 // and only the switch is tappable. 792 // and only the switch is tappable.
794 break; 793 break;
795 case ItemTypeCellCatalog: 794 case ItemTypeCellCatalog:
796 controller.reset([[MaterialCellCatalogViewController alloc] init]); 795 controller = [[MaterialCellCatalogViewController alloc] init];
797 break; 796 break;
798 default: 797 default:
799 break; 798 break;
800 } 799 }
801 800
802 if (controller) { 801 if (controller) {
803 [self.navigationController pushViewController:controller animated:YES]; 802 [self.navigationController pushViewController:controller animated:YES];
804 } 803 }
805 } 804 }
806 805
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 } 924 }
926 return NO; 925 return NO;
927 #endif // CHROMIUM_BUILD && !defined(NDEBUG) 926 #endif // CHROMIUM_BUILD && !defined(NDEBUG)
928 } 927 }
929 928
930 // Updates the identity cell. 929 // Updates the identity cell.
931 - (void)updateIdentityAccountItem: 930 - (void)updateIdentityAccountItem:
932 (CollectionViewAccountItem*)identityAccountItem { 931 (CollectionViewAccountItem*)identityAccountItem {
933 AuthenticationService* authService = 932 AuthenticationService* authService =
934 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState); 933 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState);
935 _identity.reset([authService->GetAuthenticatedIdentity() retain]); 934 _identity = authService->GetAuthenticatedIdentity();
936 if (!_identity) { 935 if (!_identity) {
937 // This could occur during the sign out process. Just ignore as the account 936 // This could occur during the sign out process. Just ignore as the account
938 // cell will be replaced by the "Sign in" button. 937 // cell will be replaced by the "Sign in" button.
939 return; 938 return;
940 } 939 }
941 identityAccountItem.image = [self userAccountImage]; 940 identityAccountItem.image = [self userAccountImage];
942 identityAccountItem.text = [_identity userFullName]; 941 identityAccountItem.text = [_identity userFullName];
943 942
944 SyncSetupService* syncSetupService = 943 SyncSetupService* syncSetupService =
945 SyncSetupServiceFactory::GetForBrowserState(_mainBrowserState); 944 SyncSetupServiceFactory::GetForBrowserState(_mainBrowserState);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 [self reconfigureCellsForItems:@[ identityAccountItem ] 982 [self reconfigureCellsForItems:@[ identityAccountItem ]
984 inSectionWithIdentifier:SectionIdentifierSignIn]; 983 inSectionWithIdentifier:SectionIdentifierSignIn];
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 signInAccessPoint:signin_metrics::AccessPoint:: 996 signInAccessPoint: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 [self showSignInWithIdentity:_signinPromoViewMediator.get().defaultIdentity]; 1013 [self showSignInWithIdentity:_signinPromoViewMediator.defaultIdentity];
1015 } 1014 }
1016 1015
1017 - (void)signinPromoSecondaryAction:(id)unused { 1016 - (void)signinPromoSecondaryAction:(id)unused {
1018 DCHECK(_signinPromoViewMediator.get().defaultIdentity); 1017 DCHECK(_signinPromoViewMediator.defaultIdentity);
1019 [self showSignInWithIdentity:nil]; 1018 [self showSignInWithIdentity:nil];
1020 } 1019 }
1021 1020
1022 #pragma mark NotificationBridgeDelegate 1021 #pragma mark NotificationBridgeDelegate
1023 1022
1024 - (void)onSignInStateChanged { 1023 - (void)onSignInStateChanged {
1025 // Sign in state changes are rare. Just reload the entire collection when this 1024 // Sign in state changes are rare. Just reload the entire collection when this
1026 // happens. 1025 // happens.
1027 [self reloadData]; 1026 [self reloadData];
1028 } 1027 }
(...skipping 24 matching lines...) Expand all
1053 ->GetDefaultAvatar(); 1052 ->GetDefaultAvatar();
1054 // No cached image, trigger a fetch, which will notify all observers 1053 // No cached image, trigger a fetch, which will notify all observers
1055 // (including the corresponding AccountViewBase). 1054 // (including the corresponding AccountViewBase).
1056 ios::GetChromeBrowserProvider() 1055 ios::GetChromeBrowserProvider()
1057 ->GetChromeIdentityService() 1056 ->GetChromeIdentityService()
1058 ->GetAvatarForIdentity(_identity, ^(UIImage*){ 1057 ->GetAvatarForIdentity(_identity, ^(UIImage*){
1059 }); 1058 });
1060 } 1059 }
1061 1060
1062 // If the currently used image has already been resized, use it. 1061 // If the currently used image has already been resized, use it.
1063 if (_resizedImage && _oldImage.get() == image) 1062 if (_resizedImage && _oldImage == image)
1064 return _resizedImage; 1063 return _resizedImage;
1065 1064
1066 _oldImage.reset(image); 1065 _oldImage = image;
1067 1066
1068 // Resize the profile image. 1067 // Resize the profile image.
1069 CGFloat dimension = kAccountProfilePhotoDimension; 1068 CGFloat dimension = kAccountProfilePhotoDimension;
1070 if (image.size.width != dimension || image.size.height != dimension) { 1069 if (image.size.width != dimension || image.size.height != dimension) {
1071 image = ResizeImage(image, CGSizeMake(dimension, dimension), 1070 image = ResizeImage(image, CGSizeMake(dimension, dimension),
1072 ProjectionMode::kAspectFit); 1071 ProjectionMode::kAspectFit);
1073 } 1072 }
1074 _resizedImage.reset([image retain]); 1073 _resizedImage = image;
1075 return _resizedImage; 1074 return _resizedImage;
1076 } 1075 }
1077 1076
1078 #pragma mark ChromeIdentityServiceObserver 1077 #pragma mark ChromeIdentityServiceObserver
1079 1078
1080 - (void)onProfileUpdate:(ChromeIdentity*)identity { 1079 - (void)onProfileUpdate:(ChromeIdentity*)identity {
1081 if (identity == _identity) { 1080 if (identity == _identity) {
1082 [self reloadAccountCell]; 1081 [self reloadAccountCell];
1083 } 1082 }
1084 } 1083 }
1085 1084
1086 - (void)onChromeIdentityServiceWillBeDestroyed { 1085 - (void)onChromeIdentityServiceWillBeDestroyed {
1087 _identityServiceObserver.reset(); 1086 _identityServiceObserver.reset();
1088 } 1087 }
1089 1088
1090 #pragma mark - BooleanObserver 1089 #pragma mark - BooleanObserver
1091 1090
1092 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { 1091 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
1093 DCHECK_EQ(observableBoolean, _showMemoryDebugToolsEnabled.get()); 1092 DCHECK_EQ(observableBoolean, _showMemoryDebugToolsEnabled);
1094 // Update the Item. 1093 // Update the Item.
1095 _showMemoryDebugToolsItem.get().on = [_showMemoryDebugToolsEnabled value]; 1094 _showMemoryDebugToolsItem.on = [_showMemoryDebugToolsEnabled value];
1096 1095
1097 // Update the Cell. 1096 // Update the Cell.
1098 [self reconfigureCellsForItems:@[ _showMemoryDebugToolsItem ] 1097 [self reconfigureCellsForItems:@[ _showMemoryDebugToolsItem ]
1099 inSectionWithIdentifier:SectionIdentifierDebug]; 1098 inSectionWithIdentifier:SectionIdentifierDebug];
1100 } 1099 }
1101 1100
1102 #pragma mark - PrefObserverDelegate 1101 #pragma mark - PrefObserverDelegate
1103 1102
1104 - (void)onPreferenceChanged:(const std::string&)preferenceName { 1103 - (void)onPreferenceChanged:(const std::string&)preferenceName {
1105 if (preferenceName == prefs::kVoiceSearchLocale) { 1104 if (preferenceName == prefs::kVoiceSearchLocale) {
1106 voice::SpeechInputLocaleConfig* localeConfig = 1105 voice::SpeechInputLocaleConfig* localeConfig =
1107 voice::SpeechInputLocaleConfig::GetInstance(); 1106 voice::SpeechInputLocaleConfig::GetInstance();
1108 voice::SpeechInputLocale locale = 1107 voice::SpeechInputLocale locale =
1109 _voiceLocaleCode.GetValue().length() 1108 _voiceLocaleCode.GetValue().length()
1110 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) 1109 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue())
1111 : localeConfig->GetDefaultLocale(); 1110 : localeConfig->GetDefaultLocale();
1112 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); 1111 NSString* languageName = base::SysUTF16ToNSString(locale.display_name);
1113 _voiceSearchDetailItem.get().detailText = languageName; 1112 _voiceSearchDetailItem.detailText = languageName;
1114 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ] 1113 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ]
1115 inSectionWithIdentifier:SectionIdentifierAdvanced]; 1114 inSectionWithIdentifier:SectionIdentifierAdvanced];
1116 } 1115 }
1117 1116
1118 if (preferenceName == 1117 if (preferenceName ==
1119 password_manager::prefs::kPasswordManagerSavingEnabled) { 1118 password_manager::prefs::kPasswordManagerSavingEnabled) {
1120 BOOL savePasswordsEnabled = 1119 BOOL savePasswordsEnabled =
1121 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); 1120 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName);
1122 NSString* passwordsDetail = 1121 NSString* passwordsDetail =
1123 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 1122 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
1124 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 1123 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
1125 1124
1126 _savePasswordsDetailItem.get().detailText = passwordsDetail; 1125 _savePasswordsDetailItem.detailText = passwordsDetail;
1127 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ] 1126 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ]
1128 inSectionWithIdentifier:SectionIdentifierBasics]; 1127 inSectionWithIdentifier:SectionIdentifierBasics];
1129 } 1128 }
1130 1129
1131 if (preferenceName == autofill::prefs::kAutofillEnabled) { 1130 if (preferenceName == autofill::prefs::kAutofillEnabled) {
1132 BOOL autofillEnabled = 1131 BOOL autofillEnabled =
1133 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); 1132 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName);
1134 NSString* autofillDetail = 1133 NSString* autofillDetail =
1135 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 1134 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
1136 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 1135 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
1137 _autoFillDetailItem.get().detailText = autofillDetail; 1136 _autoFillDetailItem.detailText = autofillDetail;
1138 [self reconfigureCellsForItems:@[ _autoFillDetailItem ] 1137 [self reconfigureCellsForItems:@[ _autoFillDetailItem ]
1139 inSectionWithIdentifier:SectionIdentifierBasics]; 1138 inSectionWithIdentifier:SectionIdentifierBasics];
1140 } 1139 }
1141 } 1140 }
1142 1141
1143 #pragma mark - SigninPromoViewConsumer 1142 #pragma mark - SigninPromoViewConsumer
1144 1143
1145 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity 1144 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity
1146 configurator:(SigninPromoViewConfigurator*) 1145 configurator:(SigninPromoViewConfigurator*)
1147 configurator { 1146 configurator {
(...skipping 10 matching lines...) Expand all
1158 if (signinPromoItem) { 1157 if (signinPromoItem) {
1159 signinPromoItem.configurator = configurator; 1158 signinPromoItem.configurator = configurator;
1160 [self reconfigureCellsForItems:@[ signinPromoItem ] 1159 [self reconfigureCellsForItems:@[ signinPromoItem ]
1161 inSectionWithIdentifier:SectionIdentifierSignIn]; 1160 inSectionWithIdentifier:SectionIdentifierSignIn];
1162 if (newIdentity) 1161 if (newIdentity)
1163 [self.collectionViewLayout invalidateLayout]; 1162 [self.collectionViewLayout invalidateLayout];
1164 } 1163 }
1165 } 1164 }
1166 1165
1167 @end 1166 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698