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

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

Issue 2610403003: [iOS] Correctly reload Sync Encryption settings screen on sync changes. (Closed)
Patch Set: Use MakeUnique with std::unique_ptr Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/sync_encryption_collection_view_controll er.h" 5 #import "ios/chrome/browser/ui/settings/sync_encryption_collection_view_controll er.h"
6 6
7 #import "base/ios/weak_nsobject.h" 7 #import "base/ios/weak_nsobject.h"
8 #import "base/mac/scoped_nsobject.h" 8 #import "base/mac/scoped_nsobject.h"
9 #include "base/memory/ptr_util.h"
9 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
10 #include "components/browser_sync/profile_sync_service.h" 11 #include "components/browser_sync/profile_sync_service.h"
11 #include "components/google/core/browser/google_util.h" 12 #include "components/google/core/browser/google_util.h"
12 #include "components/strings/grit/components_strings.h" 13 #include "components/strings/grit/components_strings.h"
13 #include "components/sync/base/sync_prefs.h" 14 #include "components/sync/base/sync_prefs.h"
14 #include "ios/chrome/browser/application_context.h" 15 #include "ios/chrome/browser/application_context.h"
15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 16 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
16 #include "ios/chrome/browser/chrome_url_constants.h" 17 #include "ios/chrome/browser/chrome_url_constants.h"
17 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" 18 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
19 #import "ios/chrome/browser/sync/sync_observer_bridge.h"
18 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 20 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" 21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h"
20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
22 #import "ios/chrome/browser/ui/settings/cells/encryption_item.h" 24 #import "ios/chrome/browser/ui/settings/cells/encryption_item.h"
23 #import "ios/chrome/browser/ui/settings/settings_utils.h" 25 #import "ios/chrome/browser/ui/settings/settings_utils.h"
24 #import "ios/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c ontroller.h" 26 #import "ios/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c ontroller.h"
25 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi ew_controller.h" 27 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi ew_controller.h"
26 #include "ios/chrome/grit/ios_strings.h" 28 #include "ios/chrome/grit/ios_strings.h"
27 #include "ui/base/l10n/l10n_util_mac.h" 29 #include "ui/base/l10n/l10n_util_mac.h"
28 #include "url/gurl.h" 30 #include "url/gurl.h"
29 31
30 namespace { 32 namespace {
31 33
32 typedef NS_ENUM(NSInteger, SectionIdentifier) { 34 typedef NS_ENUM(NSInteger, SectionIdentifier) {
33 SectionIdentifierEncryption = kSectionIdentifierEnumZero, 35 SectionIdentifierEncryption = kSectionIdentifierEnumZero,
34 SectionIdentifierFooter, 36 SectionIdentifierFooter,
35 }; 37 };
36 38
37 typedef NS_ENUM(NSInteger, ItemType) { 39 typedef NS_ENUM(NSInteger, ItemType) {
38 ItemTypeAccount = kItemTypeEnumZero, 40 ItemTypeAccount = kItemTypeEnumZero,
39 ItemTypePassphrase, 41 ItemTypePassphrase,
40 ItemTypeFooter, 42 ItemTypeFooter,
41 }; 43 };
42 44
43 } // namespace 45 } // namespace
44 46
45 @interface SyncEncryptionCollectionViewController () { 47 @interface SyncEncryptionCollectionViewController ()<SyncObserverModelBridge> {
46 ios::ChromeBrowserState* _browserState; 48 ios::ChromeBrowserState* _browserState;
49 std::unique_ptr<SyncObserverBridge> _syncObserver;
50 BOOL _isUsingSecondaryPassphrase;
47 } 51 }
48 // Returns an account item. 52 // Returns an account item.
49 - (CollectionViewItem*)accountItem; 53 - (CollectionViewItem*)accountItem;
50 54
51 // Returns a passphrase item. 55 // Returns a passphrase item.
52 - (CollectionViewItem*)passphraseItem; 56 - (CollectionViewItem*)passphraseItem;
53 57
54 // Returns a footer item with a link. 58 // Returns a footer item with a link.
55 - (CollectionViewItem*)footerItem; 59 - (CollectionViewItem*)footerItem;
56 @end 60 @end
57 61
58 @implementation SyncEncryptionCollectionViewController 62 @implementation SyncEncryptionCollectionViewController
59 63
60 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { 64 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
61 DCHECK(browserState); 65 DCHECK(browserState);
62 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; 66 self = [super initWithStyle:CollectionViewControllerStyleAppBar];
63 if (self) { 67 if (self) {
64 self.title = l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE); 68 self.title = l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE);
65 _browserState = browserState; 69 _browserState = browserState;
70 browser_sync::ProfileSyncService* syncService =
71 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
72 _isUsingSecondaryPassphrase = syncService->IsEngineInitialized() &&
73 syncService->IsUsingSecondaryPassphrase();
74 _syncObserver = base::MakeUnique<SyncObserverBridge>(self, syncService);
66 [self loadModel]; 75 [self loadModel];
67 } 76 }
68 return self; 77 return self;
69 } 78 }
70 79
71 #pragma mark - SettingsRootCollectionViewController 80 #pragma mark - SettingsRootCollectionViewController
72 81
73 - (void)loadModel { 82 - (void)loadModel {
74 [super loadModel]; 83 [super loadModel];
75 CollectionViewModel* model = self.collectionViewModel; 84 CollectionViewModel* model = self.collectionViewModel;
76 85
77 [model addSectionWithIdentifier:SectionIdentifierEncryption]; 86 [model addSectionWithIdentifier:SectionIdentifierEncryption];
78 [model addItem:[self accountItem] 87 [model addItem:[self accountItem]
79 toSectionWithIdentifier:SectionIdentifierEncryption]; 88 toSectionWithIdentifier:SectionIdentifierEncryption];
80 [model addItem:[self passphraseItem] 89 [model addItem:[self passphraseItem]
81 toSectionWithIdentifier:SectionIdentifierEncryption]; 90 toSectionWithIdentifier:SectionIdentifierEncryption];
82 91
83 browser_sync::ProfileSyncService* service = 92 if (_isUsingSecondaryPassphrase) {
84 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
85 if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) {
86 [model addSectionWithIdentifier:SectionIdentifierFooter]; 93 [model addSectionWithIdentifier:SectionIdentifierFooter];
87 [model addItem:[self footerItem] 94 [model addItem:[self footerItem]
88 toSectionWithIdentifier:SectionIdentifierFooter]; 95 toSectionWithIdentifier:SectionIdentifierFooter];
89 } 96 }
90 } 97 }
91 98
92 #pragma mark - Items 99 #pragma mark - Items
93 100
94 - (CollectionViewItem*)accountItem { 101 - (CollectionViewItem*)accountItem {
95 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); 102 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag());
96 BOOL checkedAndEnabled = YES;
97 browser_sync::ProfileSyncService* service =
98 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
99 if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) {
100 checkedAndEnabled = NO;
101 }
102 NSString* text = l10n_util::GetNSString(IDS_SYNC_BASIC_ENCRYPTION_DATA); 103 NSString* text = l10n_util::GetNSString(IDS_SYNC_BASIC_ENCRYPTION_DATA);
103 return [self itemWithType:ItemTypeAccount 104 return [self itemWithType:ItemTypeAccount
104 text:text 105 text:text
105 checked:checkedAndEnabled 106 checked:!_isUsingSecondaryPassphrase
106 enabled:checkedAndEnabled]; 107 enabled:!_isUsingSecondaryPassphrase];
107 } 108 }
108 109
109 - (CollectionViewItem*)passphraseItem { 110 - (CollectionViewItem*)passphraseItem {
110 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); 111 DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag());
111 BOOL checked = NO;
112 BOOL enabled = NO;
113 browser_sync::ProfileSyncService* service =
114 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
115 if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) {
116 checked = YES;
117 } else {
118 enabled = YES;
119 }
120 NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA); 112 NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA);
121 return [self itemWithType:ItemTypePassphrase 113 return [self itemWithType:ItemTypePassphrase
122 text:text 114 text:text
123 checked:checked 115 checked:_isUsingSecondaryPassphrase
124 enabled:enabled]; 116 enabled:!_isUsingSecondaryPassphrase];
125 } 117 }
126 118
127 - (CollectionViewItem*)footerItem { 119 - (CollectionViewItem*)footerItem {
128 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc] 120 CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc]
129 initWithType:ItemTypeFooter] autorelease]; 121 initWithType:ItemTypeFooter] autorelease];
130 footerItem.text = 122 footerItem.text =
131 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_HINT); 123 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_HINT);
132 footerItem.linkURL = google_util::AppendGoogleLocaleParam( 124 footerItem.linkURL = google_util::AppendGoogleLocaleParam(
133 GURL(kSyncGoogleDashboardURL), 125 GURL(kSyncGoogleDashboardURL),
134 GetApplicationContext()->GetApplicationLocale()); 126 GetApplicationContext()->GetApplicationLocale());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 198 }
207 break; 199 break;
208 } 200 }
209 case ItemTypeAccount: 201 case ItemTypeAccount:
210 case ItemTypeFooter: 202 case ItemTypeFooter:
211 default: 203 default:
212 break; 204 break;
213 } 205 }
214 } 206 }
215 207
208 #pragma mark SyncObserverModelBridge
209
210 - (void)onSyncStateChanged {
211 browser_sync::ProfileSyncService* service =
212 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
213 BOOL isNowUsingSecondaryPassphrase =
214 service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase();
215 if (_isUsingSecondaryPassphrase != isNowUsingSecondaryPassphrase) {
216 _isUsingSecondaryPassphrase = isNowUsingSecondaryPassphrase;
217 [self reloadData];
218 }
219 }
220
216 #pragma mark - Private methods 221 #pragma mark - Private methods
217 222
218 - (CollectionViewItem*)itemWithType:(NSInteger)type 223 - (CollectionViewItem*)itemWithType:(NSInteger)type
219 text:(NSString*)text 224 text:(NSString*)text
220 checked:(BOOL)checked 225 checked:(BOOL)checked
221 enabled:(BOOL)enabled { 226 enabled:(BOOL)enabled {
222 EncryptionItem* item = 227 EncryptionItem* item =
223 [[[EncryptionItem alloc] initWithType:type] autorelease]; 228 [[[EncryptionItem alloc] initWithType:type] autorelease];
224 item.text = text; 229 item.text = text;
225 item.accessoryType = checked ? MDCCollectionViewCellAccessoryCheckmark 230 item.accessoryType = checked ? MDCCollectionViewCellAccessoryCheckmark
226 : MDCCollectionViewCellAccessoryNone; 231 : MDCCollectionViewCellAccessoryNone;
227 item.enabled = enabled; 232 item.enabled = enabled;
228 return item; 233 return item;
229 } 234 }
230 235
231 @end 236 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698