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; | 20 using namespace sync_ui_util; |
21 | 21 |
22 SyncGlobalError::SyncGlobalError(ProfileSyncService* service) | 22 SyncGlobalError::SyncGlobalError(ProfileSyncService* service) |
23 : has_error_(false), | 23 : service_(service) { |
24 service_(service) { | |
25 OnStateChanged(); | 24 OnStateChanged(); |
26 } | 25 } |
27 | 26 |
28 SyncGlobalError::~SyncGlobalError() { | 27 SyncGlobalError::~SyncGlobalError() { |
29 } | 28 } |
30 | 29 |
31 bool SyncGlobalError::HasBadge() { | 30 bool SyncGlobalError::HasBadge() { |
32 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 31 return !menu_label_.empty(); |
33 SYNC_ERROR; | |
34 } | 32 } |
35 | 33 |
36 bool SyncGlobalError::HasMenuItem() { | 34 bool SyncGlobalError::HasMenuItem() { |
37 // When we're on Chrome OS we need to add a separate menu item to the wrench | 35 // 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 | 36 // 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. | 37 // "Sign in to Chrome..." menu item to show the error. |
40 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
41 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 39 return !menu_label_.empty(); |
42 SYNC_ERROR; | |
43 #else | 40 #else |
44 return false; | 41 return false; |
45 #endif | 42 #endif |
46 } | 43 } |
47 | 44 |
48 int SyncGlobalError::MenuItemCommandID() { | 45 int SyncGlobalError::MenuItemCommandID() { |
49 return IDC_SHOW_SYNC_ERROR; | 46 return IDC_SHOW_SYNC_ERROR; |
50 } | 47 } |
51 | 48 |
52 string16 SyncGlobalError::MenuItemLabel() { | 49 string16 SyncGlobalError::MenuItemLabel() { |
53 string16 label; | 50 return menu_label_; |
54 GetStatusLabelsForSyncGlobalError(service_, &label, NULL, NULL); | |
55 return label; | |
56 } | 51 } |
57 | 52 |
58 void SyncGlobalError::ExecuteMenuItem(Browser* browser) { | 53 void SyncGlobalError::ExecuteMenuItem(Browser* browser) { |
59 service_->ShowErrorUI(); | 54 service_->ShowErrorUI(); |
60 } | 55 } |
61 | 56 |
62 bool SyncGlobalError::HasBubbleView() { | 57 bool SyncGlobalError::HasBubbleView() { |
63 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 58 return !bubble_message_.empty() && !bubble_accept_label_.empty(); |
64 SYNC_ERROR; | |
65 } | 59 } |
66 | 60 |
67 string16 SyncGlobalError::GetBubbleViewTitle() { | 61 string16 SyncGlobalError::GetBubbleViewTitle() { |
68 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE); | 62 return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE); |
69 } | 63 } |
70 | 64 |
71 string16 SyncGlobalError::GetBubbleViewMessage() { | 65 string16 SyncGlobalError::GetBubbleViewMessage() { |
72 string16 label; | 66 return bubble_message_; |
73 GetStatusLabelsForSyncGlobalError(service_, NULL, &label, NULL); | |
74 return label; | |
75 } | 67 } |
76 | 68 |
77 string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() { | 69 string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() { |
78 string16 label; | 70 return bubble_accept_label_; |
79 GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, &label); | |
80 return label; | |
81 } | 71 } |
82 | 72 |
83 string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() { | 73 string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() { |
84 return string16(); | 74 return string16(); |
85 } | 75 } |
86 | 76 |
87 void SyncGlobalError::BubbleViewDidClose() { | 77 void SyncGlobalError::BubbleViewDidClose() { |
88 } | 78 } |
89 | 79 |
90 void SyncGlobalError::BubbleViewAcceptButtonPressed() { | 80 void SyncGlobalError::BubbleViewAcceptButtonPressed() { |
91 service_->ShowErrorUI(); | 81 service_->ShowErrorUI(); |
92 } | 82 } |
93 | 83 |
94 void SyncGlobalError::BubbleViewCancelButtonPressed() { | 84 void SyncGlobalError::BubbleViewCancelButtonPressed() { |
95 NOTREACHED(); | 85 NOTREACHED(); |
96 } | 86 } |
97 | 87 |
98 void SyncGlobalError::OnStateChanged() { | 88 void SyncGlobalError::OnStateChanged() { |
99 bool new_has_error = GetStatusLabelsForSyncGlobalError( | 89 string16 menu_label; |
100 service_, NULL, NULL, NULL) == SYNC_ERROR; | 90 string16 bubble_message; |
101 if (new_has_error != has_error_) { | 91 string16 bubble_accept_label; |
102 has_error_ = new_has_error; | 92 GetStatusLabelsForSyncGlobalError(service_, &menu_label, &bubble_message, |
93 &bubble_accept_label); | |
94 | |
95 // All the labels should be empty or all of them non-empty. | |
96 DCHECK((menu_label.empty() && bubble_message.empty() && | |
97 bubble_accept_label.empty()) || | |
Andrew T Wilson (Slow)
2011/10/17 04:08:55
I think the logic in the DCHECK is off? Did you te
sail
2011/10/17 15:21:22
Oops. Fixed.
I'm testing in Release mode so maybe
| |
98 (menu_label.empty() && bubble_message.empty() && | |
99 bubble_accept_label.empty())); | |
100 | |
101 if (menu_label != menu_label_ || bubble_message != bubble_message_ || | |
102 bubble_accept_label != bubble_accept_label_) { | |
103 menu_label_ = menu_label; | |
104 bubble_message_ = bubble_message; | |
105 bubble_accept_label_ = bubble_accept_label; | |
103 GlobalErrorServiceFactory::GetForProfile( | 106 GlobalErrorServiceFactory::GetForProfile( |
104 service_->profile())->NotifyErrorsChanged(this); | 107 service_->profile())->NotifyErrorsChanged(this); |
105 } | 108 } |
106 } | 109 } |
107 | 110 |
108 bool SyncGlobalError::HasCustomizedSyncMenuItem() { | 111 bool SyncGlobalError::HasCustomizedSyncMenuItem() { |
109 return GetStatusLabelsForSyncGlobalError(service_, NULL, NULL, NULL) == | 112 return !menu_label_.empty(); |
110 SYNC_ERROR; | |
111 } | 113 } |
OLD | NEW |