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

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

Issue 2772783004: [Sync] Don't display passphrase notification if user dismissed previous one (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_error_notifier_ash.h" 5 #include "chrome/browser/sync/sync_error_notifier_ash.h"
6 6
7 #include "ash/common/system/system_notifier.h" 7 #include "ash/common/system/system_notifier.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return; 91 return;
92 } 92 }
93 93
94 chrome::ShowSettingsSubPageForProfile(profile_, chrome::kSyncSetupSubPage); 94 chrome::ShowSettingsSubPageForProfile(profile_, chrome::kSyncSetupSubPage);
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 SyncErrorNotifier::SyncErrorNotifier(syncer::SyncErrorController* controller, 99 SyncErrorNotifier::SyncErrorNotifier(syncer::SyncErrorController* controller,
100 Profile* profile) 100 Profile* profile)
101 : error_controller_(controller), profile_(profile) { 101 : error_controller_(controller),
102 profile_(profile),
103 notification_displayed_(false) {
102 // Create a unique notification ID for this profile. 104 // Create a unique notification ID for this profile.
103 notification_id_ = 105 notification_id_ =
104 kProfileSyncNotificationId + profile_->GetProfileUserName(); 106 kProfileSyncNotificationId + profile_->GetProfileUserName();
105 107
106 error_controller_->AddObserver(this); 108 error_controller_->AddObserver(this);
107 OnErrorChanged(); 109 OnErrorChanged();
108 } 110 }
109 111
110 SyncErrorNotifier::~SyncErrorNotifier() { 112 SyncErrorNotifier::~SyncErrorNotifier() {
111 DCHECK(!error_controller_) 113 DCHECK(!error_controller_)
112 << "SyncErrorNotifier::Shutdown() was not called"; 114 << "SyncErrorNotifier::Shutdown() was not called";
113 } 115 }
114 116
115 void SyncErrorNotifier::Shutdown() { 117 void SyncErrorNotifier::Shutdown() {
116 error_controller_->RemoveObserver(this); 118 error_controller_->RemoveObserver(this);
117 error_controller_ = nullptr; 119 error_controller_ = nullptr;
118 } 120 }
119 121
120 void SyncErrorNotifier::OnErrorChanged() { 122 void SyncErrorNotifier::OnErrorChanged() {
121 NotificationUIManager* notification_ui_manager = 123 NotificationUIManager* notification_ui_manager =
122 g_browser_process->notification_ui_manager(); 124 g_browser_process->notification_ui_manager();
123 125
124 // notification_ui_manager() may return null when shutting down. 126 // notification_ui_manager() may return null when shutting down.
125 if (!notification_ui_manager) 127 if (!notification_ui_manager)
126 return; 128 return;
127 129
130 if (error_controller_->HasError() == notification_displayed_)
131 return;
132
128 if (!error_controller_->HasError()) { 133 if (!error_controller_->HasError()) {
134 notification_displayed_ = false;
129 g_browser_process->notification_ui_manager()->CancelById( 135 g_browser_process->notification_ui_manager()->CancelById(
130 notification_id_, NotificationUIManager::GetProfileID(profile_)); 136 notification_id_, NotificationUIManager::GetProfileID(profile_));
131 return; 137 return;
132 } 138 }
133 139
134 #if defined(OS_CHROMEOS) 140 #if defined(OS_CHROMEOS)
135 if (user_manager::UserManager::IsInitialized()) { 141 if (user_manager::UserManager::IsInitialized()) {
136 chromeos::UserFlow* user_flow = 142 chromeos::UserFlow* user_flow =
137 chromeos::ChromeUserManager::Get()->GetCurrentUserFlow(); 143 chromeos::ChromeUserManager::Get()->GetCurrentUserFlow();
138 144
139 // Check whether Chrome OS user flow allows launching browser. 145 // Check whether Chrome OS user flow allows launching browser.
140 // Example: Supervised user creation flow which handles token invalidation 146 // Example: Supervised user creation flow which handles token invalidation
141 // itself and notifications should be suppressed. http://crbug.com/359045 147 // itself and notifications should be suppressed. http://crbug.com/359045
142 if (!user_flow->ShouldLaunchBrowser()) 148 if (!user_flow->ShouldLaunchBrowser())
143 return; 149 return;
144 } 150 }
145 #endif 151 #endif
146 152
147 // Keep the existing notification if there is one. 153 // Error state just got triggered. There shouldn't be previous notification.
148 if (notification_ui_manager->FindById( 154 // Let's display one.
149 notification_id_, NotificationUIManager::GetProfileID(profile_))) 155 DCHECK(!notification_displayed_ && error_controller_->HasError());
150 return; 156 DCHECK(notification_ui_manager->FindById(
157 notification_id_, NotificationUIManager::GetProfileID(profile_)) ==
158 nullptr);
151 159
152 // Add an accept button to launch the sync setup settings subpage. 160 // Add an accept button to launch the sync setup settings subpage.
153 message_center::RichNotificationData data; 161 message_center::RichNotificationData data;
154 data.buttons.push_back(message_center::ButtonInfo( 162 data.buttons.push_back(message_center::ButtonInfo(
155 l10n_util::GetStringUTF16(IDS_SYNC_NOTIFICATION_ACCEPT))); 163 l10n_util::GetStringUTF16(IDS_SYNC_NOTIFICATION_ACCEPT)));
156 164
157 // Set the delegate for the notification's sync setup button. 165 // Set the delegate for the notification's sync setup button.
158 SyncNotificationDelegate* delegate = 166 SyncNotificationDelegate* delegate =
159 new SyncNotificationDelegate(notification_id_, profile_); 167 new SyncNotificationDelegate(notification_id_, profile_);
160 168
161 message_center::NotifierId notifier_id( 169 message_center::NotifierId notifier_id(
162 message_center::NotifierId::SYSTEM_COMPONENT, 170 message_center::NotifierId::SYSTEM_COMPONENT,
163 kProfileSyncNotificationId); 171 kProfileSyncNotificationId);
164 172
165 // Set |profile_id| for multi-user notification blocker. 173 // Set |profile_id| for multi-user notification blocker.
166 notifier_id.profile_id = 174 notifier_id.profile_id =
167 multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail(); 175 multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail();
168 176
169 // Add a new notification. 177 // Add a new notification.
170 Notification notification( 178 Notification notification(
171 message_center::NOTIFICATION_TYPE_SIMPLE, 179 message_center::NOTIFICATION_TYPE_SIMPLE,
172 l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE), 180 l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE),
173 l10n_util::GetStringUTF16(IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE), 181 l10n_util::GetStringUTF16(IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE),
174 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 182 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
175 IDR_NOTIFICATION_ALERT), 183 IDR_NOTIFICATION_ALERT),
176 notifier_id, 184 notifier_id,
177 base::string16(), // display_source 185 base::string16(), // display_source
178 GURL(notification_id_), notification_id_, data, delegate); 186 GURL(notification_id_), notification_id_, data, delegate);
179 notification_ui_manager->Add(notification, profile_); 187 notification_ui_manager->Add(notification, profile_);
188 notification_displayed_ = true;
180 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698