OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/sync/sync_ui_util.h" | 5 #include "chrome/browser/sync/sync_ui_util.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/signin/signin_global_error.h" | 14 #include "chrome/browser/signin/signin_global_error.h" |
15 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager_base.h" |
16 #include "chrome/browser/signin/signin_ui_util.h" | 16 #include "chrome/browser/signin/signin_ui_util.h" |
17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 21 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
(...skipping 12 matching lines...) Expand all Loading... |
38 typedef GoogleServiceAuthError AuthError; | 38 typedef GoogleServiceAuthError AuthError; |
39 | 39 |
40 namespace sync_ui_util { | 40 namespace sync_ui_util { |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 // Returns the message that should be displayed when the user is authenticated | 44 // Returns the message that should be displayed when the user is authenticated |
45 // and can connect to the sync server. If the user hasn't yet authenticated, an | 45 // and can connect to the sync server. If the user hasn't yet authenticated, an |
46 // empty string is returned. | 46 // empty string is returned. |
47 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, | 47 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
48 const SigninManager& signin, | 48 const SigninManagerBase& signin, |
49 StatusLabelStyle style) { | 49 StatusLabelStyle style) { |
50 string16 user_name = UTF8ToUTF16(signin.GetAuthenticatedUsername()); | 50 string16 user_name = UTF8ToUTF16(signin.GetAuthenticatedUsername()); |
51 | 51 |
52 if (!user_name.empty()) { | 52 if (!user_name.empty()) { |
53 if (!service || service->IsManaged()) { | 53 if (!service || service->IsManaged()) { |
54 // User is signed in, but sync is disabled. | 54 // User is signed in, but sync is disabled. |
55 return l10n_util::GetStringFUTF16(IDS_SIGNED_IN_WITH_SYNC_DISABLED, | 55 return l10n_util::GetStringFUTF16(IDS_SIGNED_IN_WITH_SYNC_DISABLED, |
56 user_name); | 56 user_name); |
57 } else if (service->IsStartSuppressed()) { | 57 } else if (service->IsStartSuppressed()) { |
58 return l10n_util::GetStringFUTF16(IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED, | 58 return l10n_util::GetStringFUTF16(IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 break; | 108 break; |
109 default: | 109 default: |
110 NOTREACHED(); | 110 NOTREACHED(); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 // TODO(akalin): Write unit tests for these three functions below. | 114 // TODO(akalin): Write unit tests for these three functions below. |
115 | 115 |
116 // status_label and link_label must either be both NULL or both non-NULL. | 116 // status_label and link_label must either be both NULL or both non-NULL. |
117 MessageType GetStatusInfo(ProfileSyncService* service, | 117 MessageType GetStatusInfo(ProfileSyncService* service, |
118 const SigninManager& signin, | 118 const SigninManagerBase& signin, |
119 StatusLabelStyle style, | 119 StatusLabelStyle style, |
120 string16* status_label, | 120 string16* status_label, |
121 string16* link_label) { | 121 string16* link_label) { |
122 DCHECK_EQ(status_label == NULL, link_label == NULL); | 122 DCHECK_EQ(status_label == NULL, link_label == NULL); |
123 | 123 |
124 MessageType result_type(SYNCED); | 124 MessageType result_type(SYNCED); |
125 | 125 |
126 if (signin.GetAuthenticatedUsername().empty()) | 126 if (signin.GetAuthenticatedUsername().empty()) |
127 return PRE_SYNCED; | 127 return PRE_SYNCED; |
128 | 128 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); | 246 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); |
247 } | 247 } |
248 } | 248 } |
249 } | 249 } |
250 return result_type; | 250 return result_type; |
251 } | 251 } |
252 | 252 |
253 // Returns the status info for use on the new tab page, where we want slightly | 253 // Returns the status info for use on the new tab page, where we want slightly |
254 // different information than in the settings panel. | 254 // different information than in the settings panel. |
255 MessageType GetStatusInfoForNewTabPage(ProfileSyncService* service, | 255 MessageType GetStatusInfoForNewTabPage(ProfileSyncService* service, |
256 const SigninManager& signin, | 256 const SigninManagerBase& signin, |
257 string16* status_label, | 257 string16* status_label, |
258 string16* link_label) { | 258 string16* link_label) { |
259 DCHECK(status_label); | 259 DCHECK(status_label); |
260 DCHECK(link_label); | 260 DCHECK(link_label); |
261 | 261 |
262 if (service->HasSyncSetupCompleted() && | 262 if (service->HasSyncSetupCompleted() && |
263 service->IsPassphraseRequired()) { | 263 service->IsPassphraseRequired()) { |
264 if (service->passphrase_required_reason() == syncer::REASON_ENCRYPTION) { | 264 if (service->passphrase_required_reason() == syncer::REASON_ENCRYPTION) { |
265 // First machine migrating to passwords. Show as a promotion. | 265 // First machine migrating to passwords. Show as a promotion. |
266 if (status_label && link_label) { | 266 if (status_label && link_label) { |
(...skipping 17 matching lines...) Expand all Loading... |
284 } | 284 } |
285 } | 285 } |
286 | 286 |
287 // Fallback to default. | 287 // Fallback to default. |
288 return GetStatusInfo(service, signin, WITH_HTML, status_label, link_label); | 288 return GetStatusInfo(service, signin, WITH_HTML, status_label, link_label); |
289 } | 289 } |
290 | 290 |
291 } // namespace | 291 } // namespace |
292 | 292 |
293 MessageType GetStatusLabels(ProfileSyncService* service, | 293 MessageType GetStatusLabels(ProfileSyncService* service, |
294 const SigninManager& signin, | 294 const SigninManagerBase& signin, |
295 StatusLabelStyle style, | 295 StatusLabelStyle style, |
296 string16* status_label, | 296 string16* status_label, |
297 string16* link_label) { | 297 string16* link_label) { |
298 DCHECK(status_label); | 298 DCHECK(status_label); |
299 DCHECK(link_label); | 299 DCHECK(link_label); |
300 return sync_ui_util::GetStatusInfo( | 300 return sync_ui_util::GetStatusInfo( |
301 service, signin, style, status_label, link_label); | 301 service, signin, style, status_label, link_label); |
302 } | 302 } |
303 | 303 |
304 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, | 304 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, |
305 const SigninManager& signin, | 305 const SigninManagerBase& signin, |
306 string16* status_label, | 306 string16* status_label, |
307 string16* link_label) { | 307 string16* link_label) { |
308 DCHECK(status_label); | 308 DCHECK(status_label); |
309 DCHECK(link_label); | 309 DCHECK(link_label); |
310 return sync_ui_util::GetStatusInfoForNewTabPage( | 310 return sync_ui_util::GetStatusInfoForNewTabPage( |
311 service, signin, status_label, link_label); | 311 service, signin, status_label, link_label); |
312 } | 312 } |
313 | 313 |
314 void GetStatusLabelsForSyncGlobalError(ProfileSyncService* service, | 314 void GetStatusLabelsForSyncGlobalError(ProfileSyncService* service, |
315 const SigninManager& signin, | 315 const SigninManagerBase& signin, |
316 string16* menu_label, | 316 string16* menu_label, |
317 string16* bubble_message, | 317 string16* bubble_message, |
318 string16* bubble_accept_label) { | 318 string16* bubble_accept_label) { |
319 DCHECK(menu_label); | 319 DCHECK(menu_label); |
320 DCHECK(bubble_message); | 320 DCHECK(bubble_message); |
321 DCHECK(bubble_accept_label); | 321 DCHECK(bubble_accept_label); |
322 *menu_label = string16(); | 322 *menu_label = string16(); |
323 *bubble_message = string16(); | 323 *bubble_message = string16(); |
324 *bubble_accept_label = string16(); | 324 *bubble_accept_label = string16(); |
325 | 325 |
(...skipping 10 matching lines...) Expand all Loading... |
336 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 336 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
337 *bubble_message = l10n_util::GetStringFUTF16( | 337 *bubble_message = l10n_util::GetStringFUTF16( |
338 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); | 338 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); |
339 *bubble_accept_label = l10n_util::GetStringUTF16( | 339 *bubble_accept_label = l10n_util::GetStringUTF16( |
340 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); | 340 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); |
341 return; | 341 return; |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 MessageType GetStatus( | 345 MessageType GetStatus( |
346 ProfileSyncService* service, const SigninManager& signin) { | 346 ProfileSyncService* service, const SigninManagerBase& signin) { |
347 return sync_ui_util::GetStatusInfo(service, signin, WITH_HTML, NULL, NULL); | 347 return sync_ui_util::GetStatusInfo(service, signin, WITH_HTML, NULL, NULL); |
348 } | 348 } |
349 | 349 |
350 string16 ConstructTime(int64 time_in_int) { | 350 string16 ConstructTime(int64 time_in_int) { |
351 base::Time time = base::Time::FromInternalValue(time_in_int); | 351 base::Time time = base::Time::FromInternalValue(time_in_int); |
352 | 352 |
353 // If time is null the format function returns a time in 1969. | 353 // If time is null the format function returns a time in 1969. |
354 if (time.is_null()) | 354 if (time.is_null()) |
355 return string16(); | 355 return string16(); |
356 return base::TimeFormatFriendlyDateAndTime(time); | 356 return base::TimeFormatFriendlyDateAndTime(time); |
357 } | 357 } |
358 | 358 |
359 } // namespace sync_ui_util | 359 } // namespace sync_ui_util |
OLD | NEW |