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

Side by Side Diff: ios/chrome/browser/ui/sync/sync_util.mm

Issue 2587023002: Upstream Chrome on iOS source code [8/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/sync/sync_util.h ('k') | ios/chrome/browser/ui/tab/README.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/sync/sync_util.h"
6
7 #include "base/metrics/histogram.h"
8 #include "components/infobars/core/infobar_manager.h"
9 #include "components/strings/grit/components_strings.h"
10 #import "ios/chrome/browser/browser_state/chrome_browser_state.h"
11 #include "ios/chrome/browser/sync/sync_setup_service.h"
12 #include "ios/chrome/browser/sync/sync_setup_service_factory.h"
13 #import "ios/chrome/browser/tabs/tab.h"
14 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
16 #import "ios/chrome/browser/ui/commands/show_signin_command.h"
17 #include "ios/chrome/browser/ui/sync/sync_error_infobar_delegate.h"
18 #include "ios/chrome/grit/ios_chromium_strings.h"
19 #include "ios/chrome/grit/ios_strings.h"
20 #include "ui/base/l10n/l10n_util.h"
21
22 namespace {
23 // Enumerated constants for logging when a sign-in error infobar was shown
24 // to the user. This was added for crbug/265352 to quantify how often this
25 // bug shows up in the wild. The logged histogram count should be interpreted
26 // as a ratio of the number of active sync users.
27 enum {
28 SYNC_SIGN_IN_NEEDS_UPDATE = 1,
29 SYNC_SERVICE_UNAVAILABLE,
30 SYNC_NEEDS_PASSPHRASE,
31 SYNC_UNRECOVERABLE_ERROR,
32 SYNC_ERROR_COUNT
33 };
34
35 } // namespace
36
37 namespace ios_internal {
38 namespace sync {
39
40 NSString* GetSyncErrorDescriptionForBrowserState(
41 ios::ChromeBrowserState* browserState) {
42 SyncSetupService* syncSetupService =
43 SyncSetupServiceFactory::GetForBrowserState(browserState);
44 DCHECK(syncSetupService);
45 SyncSetupService::SyncServiceState syncState =
46 syncSetupService->GetSyncServiceState();
47 switch (syncState) {
48 case SyncSetupService::kNoSyncServiceError:
49 return nil;
50 case SyncSetupService::kSyncServiceSignInNeedsUpdate:
51 return l10n_util::GetNSString(IDS_IOS_SYNC_LOGIN_INFO_OUT_OF_DATE);
52 case SyncSetupService::kSyncServiceNeedsPassphrase:
53 return l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_DESCRIPTION);
54 case SyncSetupService::kSyncServiceServiceUnavailable:
55 case SyncSetupService::kSyncServiceCouldNotConnect:
56 case SyncSetupService::kSyncServiceUnrecoverableError:
57 return l10n_util::GetNSString(IDS_IOS_SYNC_STATUS_UNRECOVERABLE_ERROR);
58 }
59 }
60
61 NSString* GetSyncErrorMessageForBrowserState(
62 ios::ChromeBrowserState* browserState) {
63 SyncSetupService* syncSetupService =
64 SyncSetupServiceFactory::GetForBrowserState(browserState);
65 DCHECK(syncSetupService);
66 SyncSetupService::SyncServiceState syncState =
67 syncSetupService->GetSyncServiceState();
68 switch (syncState) {
69 case SyncSetupService::kNoSyncServiceError:
70 return nil;
71 case SyncSetupService::kSyncServiceSignInNeedsUpdate:
72 return l10n_util::GetNSString(IDS_IOS_SYNC_ERROR_INFO_OUT_OF_DATE);
73 case SyncSetupService::kSyncServiceNeedsPassphrase:
74 return l10n_util::GetNSString(IDS_IOS_SYNC_CONFIGURE_ENCRYPTION);
75 case SyncSetupService::kSyncServiceServiceUnavailable:
76 return l10n_util::GetNSString(IDS_SYNC_SERVICE_UNAVAILABLE);
77 case SyncSetupService::kSyncServiceCouldNotConnect:
78 return l10n_util::GetNSString(IDS_IOS_SYNC_ERROR_COULD_NOT_CONNECT);
79 case SyncSetupService::kSyncServiceUnrecoverableError:
80 return l10n_util::GetNSString(IDS_IOS_SYNC_ERROR_UNRECOVERABLE);
81 }
82 }
83
84 NSString* GetSyncErrorButtonTitleForBrowserState(
85 ios::ChromeBrowserState* browserState) {
86 SyncSetupService* syncSetupService =
87 SyncSetupServiceFactory::GetForBrowserState(browserState);
88 DCHECK(syncSetupService);
89 SyncSetupService::SyncServiceState syncState =
90 syncSetupService->GetSyncServiceState();
91 switch (syncState) {
92 case SyncSetupService::kSyncServiceSignInNeedsUpdate:
93 return l10n_util::GetNSString(IDS_IOS_SYNC_UPDATE_CREDENTIALS);
94 case SyncSetupService::kSyncServiceNeedsPassphrase:
95 return l10n_util::GetNSString(IDS_IOS_SYNC_ENTER_PASSPHRASE);
96 case SyncSetupService::kSyncServiceUnrecoverableError:
97 return l10n_util::GetNSString(IDS_IOS_SYNC_SIGN_IN_AGAIN);
98 default:
99 return nil;
100 }
101 }
102
103 GenericChromeCommand* GetSyncCommandForBrowserState(
104 ios::ChromeBrowserState* browserState) {
105 SyncSetupService* syncSetupService =
106 SyncSetupServiceFactory::GetForBrowserState(browserState);
107 DCHECK(syncSetupService);
108 SyncSetupService::SyncServiceState syncState =
109 syncSetupService->GetSyncServiceState();
110 switch (syncState) {
111 case SyncSetupService::kSyncServiceSignInNeedsUpdate:
112 return [[[ShowSigninCommand alloc]
113 initWithOperation:AUTHENTICATION_OPERATION_REAUTHENTICATE
114 signInAccessPoint:signin_metrics::AccessPoint::ACCESS_POINT_UNKNOWN]
115 autorelease];
116 case SyncSetupService::kSyncServiceNeedsPassphrase:
117 return [[[GenericChromeCommand alloc]
118 initWithTag:IDC_SHOW_SYNC_PASSPHRASE_SETTINGS] autorelease];
119 case SyncSetupService::kSyncServiceCouldNotConnect:
120 case SyncSetupService::kSyncServiceServiceUnavailable:
121 case SyncSetupService::kSyncServiceUnrecoverableError:
122 case SyncSetupService::kNoSyncServiceError:
123 return [[[GenericChromeCommand alloc] initWithTag:IDC_SHOW_SYNC_SETTINGS]
124 autorelease];
125 }
126 }
127
128 bool displaySyncErrors(ios::ChromeBrowserState* browser_state, Tab* tab) {
129 // Avoid displaying sync errors on incognito tabs.
130 if (browser_state->IsOffTheRecord())
131 return false;
132
133 SyncSetupService* syncSetupService =
134 SyncSetupServiceFactory::GetForBrowserState(browser_state);
135 if (!syncSetupService)
136 return false;
137 SyncSetupService::SyncServiceState errorState =
138 syncSetupService->GetSyncServiceState();
139 if (IsTransientSyncError(errorState))
140 return false;
141
142 // Logs when an infobar is shown to user. See crbug/265352.
143 int loggedErrorState = 0;
144 switch (errorState) {
145 case SyncSetupService::kNoSyncServiceError:
146 case SyncSetupService::kSyncServiceCouldNotConnect:
147 case SyncSetupService::kSyncServiceServiceUnavailable:
148 NOTREACHED();
149 break;
150 case SyncSetupService::kSyncServiceSignInNeedsUpdate:
151 loggedErrorState = SYNC_SIGN_IN_NEEDS_UPDATE;
152 break;
153 case SyncSetupService::kSyncServiceNeedsPassphrase:
154 loggedErrorState = SYNC_NEEDS_PASSPHRASE;
155 break;
156 case SyncSetupService::kSyncServiceUnrecoverableError:
157 loggedErrorState = SYNC_UNRECOVERABLE_ERROR;
158 break;
159 }
160 UMA_HISTOGRAM_ENUMERATION("Sync.SyncErrorInfobarDisplayed", loggedErrorState,
161 SYNC_ERROR_COUNT);
162
163 DCHECK(tab);
164 DCHECK([tab infoBarManager]);
165 return SyncErrorInfoBarDelegate::Create([tab infoBarManager], browser_state);
166 }
167
168 bool IsTransientSyncError(SyncSetupService::SyncServiceState errorState) {
169 switch (errorState) {
170 case SyncSetupService::kNoSyncServiceError:
171 case SyncSetupService::kSyncServiceCouldNotConnect:
172 case SyncSetupService::kSyncServiceServiceUnavailable:
173 return true;
174 case SyncSetupService::kSyncServiceSignInNeedsUpdate:
175 case SyncSetupService::kSyncServiceNeedsPassphrase:
176 case SyncSetupService::kSyncServiceUnrecoverableError:
177 return false;
178 }
179 }
180
181 } // namespace sync
182 } // namespace ios_internal
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/sync/sync_util.h ('k') | ios/chrome/browser/ui/tab/README.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698