OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( | 124 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( |
125 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); | 125 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); |
126 } | 126 } |
127 break; | 127 break; |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 // Returns the message that should be displayed when the user is authenticated | 131 // Returns the message that should be displayed when the user is authenticated |
132 // and can connect to the sync server. If the user hasn't yet authenticated, an | 132 // and can connect to the sync server. If the user hasn't yet authenticated, an |
133 // empty string is returned. | 133 // empty string is returned. |
134 string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { | 134 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
135 bool html_links) { | |
akalin
2011/10/28 19:10:22
indent with (
jimblackler
2011/11/01 16:15:30
Done.
jimblackler
2011/11/01 16:15:30
Done.
| |
135 string16 label; | 136 string16 label; |
136 string16 user_name(service->GetAuthenticatedUsername()); | 137 string16 user_name(service->GetAuthenticatedUsername()); |
137 if (user_name.empty()) | 138 if (user_name.empty()) |
138 return label; | 139 return label; |
139 | 140 |
140 return l10n_util::GetStringFUTF16( | 141 // Message may also carry additional advice with an HTML link, if acceptable. |
141 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | 142 if (html_links) { |
142 user_name, | 143 return l10n_util::GetStringFUTF16( |
143 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | 144 IDS_SYNC_ACCOUNT_SYNCING_TO_USER_WITH_MANAGE_LINK, |
145 user_name, | |
146 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | |
147 } else { | |
148 return l10n_util::GetStringFUTF16( | |
149 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | |
150 user_name); | |
151 } | |
144 } | 152 } |
145 | 153 |
146 void GetStatusForActionableError( | 154 void GetStatusForActionableError( |
147 const browser_sync::SyncProtocolError& error, | 155 const browser_sync::SyncProtocolError& error, |
148 string16* status_label) { | 156 string16* status_label) { |
149 DCHECK(status_label); | 157 DCHECK(status_label); |
150 switch (error.action) { | 158 switch (error.action) { |
151 case browser_sync::STOP_AND_RESTART_SYNC: | 159 case browser_sync::STOP_AND_RESTART_SYNC: |
152 status_label->assign( | 160 status_label->assign( |
153 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); | 161 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); |
(...skipping 14 matching lines...) Expand all Loading... | |
168 default: | 176 default: |
169 NOTREACHED(); | 177 NOTREACHED(); |
170 } | 178 } |
171 } | 179 } |
172 | 180 |
173 // TODO(akalin): Write unit tests for these three functions below. | 181 // TODO(akalin): Write unit tests for these three functions below. |
174 | 182 |
175 // status_label and link_label must either be both NULL or both non-NULL. | 183 // status_label and link_label must either be both NULL or both non-NULL. |
176 MessageType GetStatusInfo(ProfileSyncService* service, | 184 MessageType GetStatusInfo(ProfileSyncService* service, |
177 string16* status_label, | 185 string16* status_label, |
178 string16* link_label) { | 186 string16* link_label, |
187 bool html_links) { | |
179 DCHECK_EQ(status_label == NULL, link_label == NULL); | 188 DCHECK_EQ(status_label == NULL, link_label == NULL); |
180 | 189 |
181 MessageType result_type(SYNCED); | 190 MessageType result_type(SYNCED); |
182 | 191 |
183 if (!service) { | 192 if (!service) { |
184 return PRE_SYNCED; | 193 return PRE_SYNCED; |
185 } | 194 } |
186 | 195 |
187 if (service->HasSyncSetupCompleted()) { | 196 if (service->HasSyncSetupCompleted()) { |
188 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); | 197 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 | 238 |
230 // Now finally passphrase error. | 239 // Now finally passphrase error. |
231 if (service->IsPassphraseRequired()) { | 240 if (service->IsPassphraseRequired()) { |
232 if (service->IsPassphraseRequiredForDecryption()) { | 241 if (service->IsPassphraseRequiredForDecryption()) { |
233 // TODO(lipalani) : Ask tim if this is still needed. | 242 // TODO(lipalani) : Ask tim if this is still needed. |
234 // NOT first machine. | 243 // NOT first machine. |
235 // Show a link ("needs attention"), but still indicate the | 244 // Show a link ("needs attention"), but still indicate the |
236 // current synced status. Return SYNC_PROMO so that | 245 // current synced status. Return SYNC_PROMO so that |
237 // the configure link will still be shown. | 246 // the configure link will still be shown. |
238 if (status_label && link_label) { | 247 if (status_label && link_label) { |
239 status_label->assign(GetSyncedStateStatusLabel(service)); | 248 status_label->assign(GetSyncedStateStatusLabel(service, html_links)); |
240 link_label->assign( | 249 link_label->assign( |
241 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); | 250 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); |
242 } | 251 } |
243 return SYNC_PROMO; | 252 return SYNC_PROMO; |
244 } | 253 } |
245 } | 254 } |
246 | 255 |
247 // There is no error. Display "Last synced..." message. | 256 // There is no error. Display "Last synced..." message. |
248 if (status_label) | 257 if (status_label) |
249 status_label->assign(GetSyncedStateStatusLabel(service)); | 258 status_label->assign(GetSyncedStateStatusLabel(service, html_links)); |
250 return SYNCED; | 259 return SYNCED; |
251 } else { | 260 } else { |
252 // Either show auth error information with a link to re-login, auth in prog, | 261 // Either show auth error information with a link to re-login, auth in prog, |
253 // or provide a link to continue with setup. | 262 // or provide a link to continue with setup. |
254 result_type = PRE_SYNCED; | 263 result_type = PRE_SYNCED; |
255 if (service->SetupInProgress()) { | 264 if (service->SetupInProgress()) { |
256 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); | 265 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
257 const AuthError& auth_error = service->GetAuthError(); | 266 const AuthError& auth_error = service->GetAuthError(); |
258 if (status_label) { | 267 if (status_label) { |
259 status_label->assign( | 268 status_label->assign( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 if (status_label && link_label) { | 330 if (status_label && link_label) { |
322 status_label->assign(string16()); | 331 status_label->assign(string16()); |
323 link_label->assign( | 332 link_label->assign( |
324 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); | 333 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); |
325 } | 334 } |
326 return SYNC_ERROR; | 335 return SYNC_ERROR; |
327 } | 336 } |
328 } | 337 } |
329 | 338 |
330 // Fallback to default. | 339 // Fallback to default. |
331 return GetStatusInfo(service, status_label, link_label); | 340 return GetStatusInfo(service, status_label, link_label, true); |
332 } | 341 } |
333 | 342 |
334 } // namespace | 343 } // namespace |
335 | 344 |
336 MessageType GetStatusLabels(ProfileSyncService* service, | 345 MessageType GetStatusLabels(ProfileSyncService* service, |
337 string16* status_label, | 346 string16* status_label, |
338 string16* link_label) { | 347 string16* link_label, |
348 bool html_links) { | |
339 DCHECK(status_label); | 349 DCHECK(status_label); |
340 DCHECK(link_label); | 350 DCHECK(link_label); |
341 return sync_ui_util::GetStatusInfo(service, status_label, link_label); | 351 return sync_ui_util::GetStatusInfo(service, status_label, link_label, |
352 html_links); | |
akalin
2011/10/28 19:10:22
indent with (
jimblackler
2011/11/01 16:15:30
Done.
| |
342 } | 353 } |
343 | 354 |
344 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, | 355 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, |
345 string16* status_label, | 356 string16* status_label, |
346 string16* link_label) { | 357 string16* link_label) { |
347 DCHECK(status_label); | 358 DCHECK(status_label); |
348 DCHECK(link_label); | 359 DCHECK(link_label); |
349 return sync_ui_util::GetStatusInfoForNewTabPage( | 360 return sync_ui_util::GetStatusInfoForNewTabPage( |
350 service, status_label, link_label); | 361 service, status_label, link_label); |
351 } | 362 } |
(...skipping 30 matching lines...) Expand all Loading... | |
382 return; | 393 return; |
383 | 394 |
384 const AuthError& auth_error = service->GetAuthError(); | 395 const AuthError& auth_error = service->GetAuthError(); |
385 if (auth_error.state() != AuthError::NONE) { | 396 if (auth_error.state() != AuthError::NONE) { |
386 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, | 397 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, |
387 menu_label, bubble_message, bubble_accept_label); | 398 menu_label, bubble_message, bubble_accept_label); |
388 } | 399 } |
389 } | 400 } |
390 | 401 |
391 MessageType GetStatus(ProfileSyncService* service) { | 402 MessageType GetStatus(ProfileSyncService* service) { |
392 return sync_ui_util::GetStatusInfo(service, NULL, NULL); | 403 return sync_ui_util::GetStatusInfo(service, NULL, NULL, true); |
393 } | 404 } |
394 | 405 |
395 string16 GetSyncMenuLabel(ProfileSyncService* service) { | 406 string16 GetSyncMenuLabel(ProfileSyncService* service) { |
396 MessageType type = GetStatus(service); | 407 MessageType type = GetStatus(service); |
397 | 408 |
398 if (type == sync_ui_util::SYNCED) | 409 if (type == sync_ui_util::SYNCED) |
399 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); | 410 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); |
400 else if (type == sync_ui_util::SYNC_ERROR) | 411 else if (type == sync_ui_util::SYNC_ERROR) |
401 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | 412 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); |
402 else | 413 else |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 DictionaryValue* val = new DictionaryValue; | 668 DictionaryValue* val = new DictionaryValue; |
658 val->SetString("model_type", ModelTypeToString(it->first)); | 669 val->SetString("model_type", ModelTypeToString(it->first)); |
659 val->SetString("group", ModelSafeGroupToString(it->second)); | 670 val->SetString("group", ModelSafeGroupToString(it->second)); |
660 routing_info->Append(val); | 671 routing_info->Append(val); |
661 } | 672 } |
662 } | 673 } |
663 } | 674 } |
664 } | 675 } |
665 | 676 |
666 } // namespace sync_ui_util | 677 } // namespace sync_ui_util |
OLD | NEW |