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

Side by Side Diff: chrome/browser/sync/sync_global_error.cc

Issue 7906013: Show bubble and wrench menu item for sync error (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/sync_global_error.h"
6
7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/profile_sync_service_observer.h"
9 #include "chrome/common/net/gaia/google_service_auth_error.h"
10 #include "grit/chromium_strings.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 typedef GoogleServiceAuthError AuthError;
15
16 SyncGlobalError::SyncGlobalError(ProfileSyncService* service)
17 : error_type_(ERROR_TYPE_NONE),
18 service_(service) {
19 OnStateChanged();
20 }
21
22 SyncGlobalError::~SyncGlobalError() {
23 }
24
25 bool SyncGlobalError::HasBadge() {
26 #if defined(OS_CHROMEOS)
27 // TODO(sail): Due to http://crbug.com/96608 we don't have a wrench menu
28 // item on ChromeOS thus we don't badge the wrench menu either.
29 return false;
30 #else
31 return error_type_ != ERROR_TYPE_NONE;
32 #endif
33 }
34
35 bool SyncGlobalError::HasMenuItem() {
36 // TODO(sail): Once http://crbug.com/96608 is fixed this should return
37 // true for ChromeOS.
38 return false;
39 }
40
41 int SyncGlobalError::MenuItemCommandID() {
42 NOTREACHED();
43 return 0;
44 }
45
46 string16 SyncGlobalError::MenuItemLabel() {
47 switch (error_type_) {
48 case ERROR_TYPE_PASSPHRASE:
49 return l10n_util::GetStringUTF16(
50 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM);
51 default:
52 return l10n_util::GetStringUTF16(
53 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM);
54 }
55 }
56
57 void SyncGlobalError::ExecuteMenuItem(Browser* browser) {
58 service_->ShowErrorUI();
59 }
60
61 bool SyncGlobalError::HasBubbleView() {
62 return error_type_ != ERROR_TYPE_NONE;
63 }
64
65 string16 SyncGlobalError::GetBubbleViewTitle() {
66 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE);
67 }
68
69 string16 SyncGlobalError::GetBubbleViewMessage() {
70 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
71 switch (error_type_) {
72 case ERROR_TYPE_PASSPHRASE:
73 return l10n_util::GetStringFUTF16(
74 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name);
75 case ERROR_TYPE_SIGN_IN:
76 return l10n_util::GetStringFUTF16(
77 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name);
78 case ERROR_TYPE_UNAVAILABLE:
79 return l10n_util::GetStringFUTF16(
80 IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_MESSAGE, product_name);
81 case ERROR_TYPE_OTHER:
82 return l10n_util::GetStringFUTF16(
83 IDS_SYNC_OTHER_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name);
84 default:
85 NOTREACHED();
86 return string16();
87 }
88 }
89
90 string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() {
91 switch (error_type_) {
92 case ERROR_TYPE_PASSPHRASE:
93 return l10n_util::GetStringUTF16(
94 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT);
95 case ERROR_TYPE_SIGN_IN:
96 case ERROR_TYPE_OTHER:
97 return l10n_util::GetStringUTF16(
98 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT);
99 case ERROR_TYPE_UNAVAILABLE:
100 return l10n_util::GetStringUTF16(
101 IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_ACCEPT);
102 default:
103 NOTREACHED();
104 return string16();
105 }
106 }
107
108 string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() {
109 return string16();
110 }
111
112 void SyncGlobalError::BubbleViewDidClose() {
113 }
114
115 void SyncGlobalError::BubbleViewAcceptButtonPressed() {
116 service_->ShowErrorUI();
117 }
118
119 void SyncGlobalError::BubbleViewCancelButtonPressed() {
120 NOTREACHED();
121 }
122
123 void SyncGlobalError::OnStateChanged() {
124 error_type_ = GetUpdatedErrorType();
125 }
126
127 bool SyncGlobalError::HasCustomizedSyncMenuItem() {
128 return error_type_ != ERROR_TYPE_NONE;
129 }
130
131
sky 2011/09/15 19:52:07 nit: remove this line.
sail 2011/09/15 20:22:52 Done.
132 SyncGlobalError::ErrorType SyncGlobalError::GetUpdatedErrorType() {
133 return ERROR_TYPE_PASSPHRASE;
134
135 // If the user hasn't completed sync setup then we don't worry about errors.
136 if (!service_->HasSyncSetupCompleted())
137 return ERROR_TYPE_NONE;
138
139 const AuthError& auth_error = service_->GetAuthError();
140 switch (auth_error.state()) {
141 case AuthError::NONE:
142 case AuthError::CONNECTION_FAILED:
143 break;
144 case AuthError::INVALID_GAIA_CREDENTIALS:
145 case AuthError::ACCOUNT_DELETED:
146 case AuthError::ACCOUNT_DISABLED:
147 // If no user name is entered then the error should be handled in the
148 // setup UI.
149 if (service_->GetAuthenticatedUsername().empty())
150 break;
151 else
152 return ERROR_TYPE_SIGN_IN;
153 case AuthError::SERVICE_UNAVAILABLE:
154 return ERROR_TYPE_UNAVAILABLE;
155 default:
156 return ERROR_TYPE_OTHER;
157 }
158
159 if (service_->IsPassphraseRequired() &&
160 service_->IsPassphraseRequiredForDecryption())
161 return ERROR_TYPE_PASSPHRASE;
162
163 return ERROR_TYPE_NONE;
164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698