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_global_error.h" | 5 #include "chrome/browser/sync/sync_global_error.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/sync/profile_sync_service.h" | 8 #include "chrome/browser/sync/profile_sync_service.h" |
9 #include "chrome/browser/sync/profile_sync_service_observer.h" | 9 #include "chrome/browser/sync/profile_sync_service_observer.h" |
10 #include "chrome/browser/sync/sync_ui_util.h" | 10 #include "chrome/browser/sync/sync_ui_util.h" |
11 #include "chrome/browser/ui/global_error_service.h" | 11 #include "chrome/browser/ui/global_error_service.h" |
12 #include "chrome/browser/ui/global_error_service_factory.h" | 12 #include "chrome/browser/ui/global_error_service_factory.h" |
13 #include "chrome/common/net/gaia/google_service_auth_error.h" | 13 #include "chrome/common/net/gaia/google_service_auth_error.h" |
14 #include "grit/chromium_strings.h" | 14 #include "grit/chromium_strings.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 | 17 |
18 typedef GoogleServiceAuthError AuthError; | 18 typedef GoogleServiceAuthError AuthError; |
19 | 19 |
20 using namespace sync_ui_util; | |
21 | |
22 SyncGlobalError::SyncGlobalError(ProfileSyncService* service) | 20 SyncGlobalError::SyncGlobalError(ProfileSyncService* service) |
23 : has_error_(false), | 21 : service_(service) { |
24 service_(service) { | |
25 OnStateChanged(); | 22 OnStateChanged(); |
26 } | 23 } |
27 | 24 |
28 SyncGlobalError::~SyncGlobalError() { | 25 SyncGlobalError::~SyncGlobalError() { |
29 } | 26 } |
30 | 27 |
31 bool SyncGlobalError::HasBadge() { | 28 bool SyncGlobalError::HasBadge() { |
32 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 29 return !menu_label_.empty(); |
33 SYNC_ERROR; | |
34 } | 30 } |
35 | 31 |
36 bool SyncGlobalError::HasMenuItem() { | 32 bool SyncGlobalError::HasMenuItem() { |
37 // When we're on Chrome OS we need to add a separate menu item to the wrench | 33 // When we're on Chrome OS we need to add a separate menu item to the wrench |
38 // menu to the show the error. On other platforms we can just reuse the | 34 // menu to the show the error. On other platforms we can just reuse the |
39 // "Sign in to Chrome..." menu item to show the error. | 35 // "Sign in to Chrome..." menu item to show the error. |
40 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
41 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 37 return !menu_label_.empty(); |
42 SYNC_ERROR; | |
43 #else | 38 #else |
44 return false; | 39 return false; |
45 #endif | 40 #endif |
46 } | 41 } |
47 | 42 |
48 int SyncGlobalError::MenuItemCommandID() { | 43 int SyncGlobalError::MenuItemCommandID() { |
49 return IDC_SHOW_SYNC_ERROR; | 44 return IDC_SHOW_SYNC_ERROR; |
50 } | 45 } |
51 | 46 |
52 string16 SyncGlobalError::MenuItemLabel() { | 47 string16 SyncGlobalError::MenuItemLabel() { |
53 string16 label; | 48 return menu_label_; |
54 GetStatusLabelsForSyncGlobalError(service_, &label, NULL, NULL); | |
55 return label; | |
56 } | 49 } |
57 | 50 |
58 void SyncGlobalError::ExecuteMenuItem(Browser* browser) { | 51 void SyncGlobalError::ExecuteMenuItem(Browser* browser) { |
59 service_->ShowErrorUI(); | 52 service_->ShowErrorUI(); |
60 } | 53 } |
61 | 54 |
62 bool SyncGlobalError::HasBubbleView() { | 55 bool SyncGlobalError::HasBubbleView() { |
63 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 56 return !bubble_message_.empty() && !bubble_accept_label_.empty(); |
64 SYNC_ERROR; | |
65 } | 57 } |
66 | 58 |
67 string16 SyncGlobalError::GetBubbleViewTitle() { | 59 string16 SyncGlobalError::GetBubbleViewTitle() { |
68 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE); | 60 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE); |
69 } | 61 } |
70 | 62 |
71 string16 SyncGlobalError::GetBubbleViewMessage() { | 63 string16 SyncGlobalError::GetBubbleViewMessage() { |
72 string16 label; | 64 return bubble_message_; |
73 GetStatusLabelsForSyncGlobalError(service_, NULL, &label, NULL); | |
74 return label; | |
75 } | 65 } |
76 | 66 |
77 string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() { | 67 string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() { |
78 string16 label; | 68 return bubble_accept_label_; |
79 GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, &label); | |
80 return label; | |
81 } | 69 } |
82 | 70 |
83 string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() { | 71 string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() { |
84 return string16(); | 72 return string16(); |
85 } | 73 } |
86 | 74 |
87 void SyncGlobalError::BubbleViewDidClose() { | 75 void SyncGlobalError::BubbleViewDidClose() { |
88 } | 76 } |
89 | 77 |
90 void SyncGlobalError::BubbleViewAcceptButtonPressed() { | 78 void SyncGlobalError::BubbleViewAcceptButtonPressed() { |
91 service_->ShowErrorUI(); | 79 service_->ShowErrorUI(); |
92 } | 80 } |
93 | 81 |
94 void SyncGlobalError::BubbleViewCancelButtonPressed() { | 82 void SyncGlobalError::BubbleViewCancelButtonPressed() { |
95 NOTREACHED(); | 83 NOTREACHED(); |
96 } | 84 } |
97 | 85 |
98 void SyncGlobalError::OnStateChanged() { | 86 void SyncGlobalError::OnStateChanged() { |
99 bool new_has_error = GetStatusLabelsForSyncGlobalError( | 87 string16 menu_label; |
100 service_, NULL, NULL, NULL) == SYNC_ERROR; | 88 string16 bubble_message; |
101 if (new_has_error != has_error_) { | 89 string16 bubble_accept_label; |
102 has_error_ = new_has_error; | 90 sync_ui_util::GetStatusLabelsForSyncGlobalError( |
103 GlobalErrorServiceFactory::GetForProfile( | 91 service_, &menu_label, &bubble_message, &bubble_accept_label); |
104 service_->profile())->NotifyErrorsChanged(this); | 92 |
| 93 // All the labels should be empty or all of them non-empty. |
| 94 DCHECK((menu_label.empty() && bubble_message.empty() && |
| 95 bubble_accept_label.empty()) || |
| 96 (!menu_label.empty() && !bubble_message.empty() && |
| 97 !bubble_accept_label.empty())); |
| 98 |
| 99 if (menu_label != menu_label_ || bubble_message != bubble_message_ || |
| 100 bubble_accept_label != bubble_accept_label_) { |
| 101 menu_label_ = menu_label; |
| 102 bubble_message_ = bubble_message; |
| 103 bubble_accept_label_ = bubble_accept_label; |
| 104 |
| 105 // Profile can be NULL during tests. |
| 106 Profile* profile = service_->profile(); |
| 107 if (profile) { |
| 108 GlobalErrorServiceFactory::GetForProfile( |
| 109 profile)->NotifyErrorsChanged(this); |
| 110 } |
105 } | 111 } |
106 } | 112 } |
107 | 113 |
108 bool SyncGlobalError::HasCustomizedSyncMenuItem() { | 114 bool SyncGlobalError::HasCustomizedSyncMenuItem() { |
109 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 115 return !menu_label_.empty(); |
110 SYNC_ERROR; | |
111 } | 116 } |
OLD | NEW |