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

Side by Side Diff: chrome/browser/notifications/message_center_notification_manager.cc

Issue 23636010: Notifications: Add cross-platform UMA: ShowMessageCenter, ShowSettings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove spurious test code. Created 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/notifications/message_center_notification_manager.h" 5 #include "chrome/browser/notifications/message_center_notification_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #if defined(OS_WIN) 43 #if defined(OS_WIN)
44 first_run_idle_timeout_( 44 first_run_idle_timeout_(
45 base::TimeDelta::FromSeconds(kFirstRunIdleDelaySeconds)), 45 base::TimeDelta::FromSeconds(kFirstRunIdleDelaySeconds)),
46 weak_factory_(this), 46 weak_factory_(this),
47 #endif 47 #endif
48 settings_provider_(settings_provider.Pass()) { 48 settings_provider_(settings_provider.Pass()) {
49 #if defined(OS_WIN) 49 #if defined(OS_WIN)
50 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state); 50 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state);
51 #endif 51 #endif
52 52
53 message_center_->SetDelegate(this);
54 message_center_->AddObserver(this); 53 message_center_->AddObserver(this);
55 message_center_->SetNotifierSettingsProvider(settings_provider_.get()); 54 message_center_->SetNotifierSettingsProvider(settings_provider_.get());
56 55
57 #if defined(OS_WIN) || defined(OS_MACOSX) \ 56 #if defined(OS_WIN) || defined(OS_MACOSX) \
58 || (defined(USE_AURA) && !defined(USE_ASH)) 57 || (defined(USE_AURA) && !defined(USE_ASH))
59 // On Windows, Linux and Mac, the notification manager owns the tray icon and 58 // On Windows, Linux and Mac, the notification manager owns the tray icon and
60 // views.Other platforms have global ownership and Create will return NULL. 59 // views.Other platforms have global ownership and Create will return NULL.
61 tray_.reset(message_center::CreateMessageCenterTray()); 60 tray_.reset(message_center::CreateMessageCenterTray());
62 #endif 61 #endif
63 registrar_.Add(this, 62 registrar_.Add(this,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 message_center_notification.Pass()); 222 message_center_notification.Pass());
224 223
225 new_notification->StartDownloads(); 224 new_notification->StartDownloads();
226 return true; 225 return true;
227 } 226 }
228 } 227 }
229 return false; 228 return false;
230 } 229 }
231 230
232 //////////////////////////////////////////////////////////////////////////////// 231 ////////////////////////////////////////////////////////////////////////////////
233 // MessageCenter::Delegate
234
235 void MessageCenterNotificationManager::ShowSettings(
236 const std::string& notification_id) {
237 // The per-message-center Settings button passes an empty string.
238 if (notification_id.empty()) {
239 NOTIMPLEMENTED();
240 return;
241 }
242
243 ProfileNotification* profile_notification =
244 FindProfileNotification(notification_id);
245 if (!profile_notification)
246 return;
247
248 Browser* browser =
249 chrome::FindOrCreateTabbedBrowser(profile_notification->profile(),
250 chrome::HOST_DESKTOP_TYPE_NATIVE);
251 if (profile_notification->GetExtensionId().empty())
252 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
253 else
254 chrome::ShowExtensions(browser, std::string());
255 }
256
257 ////////////////////////////////////////////////////////////////////////////////
258 // MessageCenter::Observer 232 // MessageCenter::Observer
259 void MessageCenterNotificationManager::OnNotificationRemoved( 233 void MessageCenterNotificationManager::OnNotificationRemoved(
260 const std::string& notification_id, 234 const std::string& notification_id,
261 bool by_user) { 235 bool by_user) {
262 // Do not call FindProfileNotification(). Some tests create notifications 236 // Do not call FindProfileNotification(). Some tests create notifications
263 // directly to MessageCenter, but this method will be called for the removals 237 // directly to MessageCenter, but this method will be called for the removals
264 // of such notifications. 238 // of such notifications.
265 NotificationMap::const_iterator iter = 239 NotificationMap::const_iterator iter =
266 profile_notifications_.find(notification_id); 240 profile_notifications_.find(notification_id);
267 if (iter != profile_notifications_.end()) 241 if (iter != profile_notifications_.end())
268 RemoveProfileNotification(iter->second); 242 RemoveProfileNotification(iter->second);
269 243
270 #if defined(OS_WIN) 244 #if defined(OS_WIN)
271 CheckFirstRunTimer(); 245 CheckFirstRunTimer();
272 #endif 246 #endif
273 } 247 }
274 248
275 void MessageCenterNotificationManager::OnNotificationCenterClosed() { 249 void MessageCenterNotificationManager::OnCenterVisibilityChanged(
276 // When the center is open it halts all notifications, so we need to listen 250 message_center::Visibility visibility) {
277 // for events indicating it's been closed. 251 switch (visibility) {
278 CheckAndShowNotifications(); 252 case message_center::VISIBILITY_TRANSIENT:
253 // When the center is open it halts all notifications, so we need to
254 // listen for events indicating it's been closed.
255 CheckAndShowNotifications();
279 #if defined(OS_WIN) 256 #if defined(OS_WIN)
280 CheckFirstRunTimer(); 257 CheckFirstRunTimer();
281 #endif 258 #endif
259 break;
260 case message_center::VISIBILITY_MESSAGE_CENTER:
261 content::RecordAction(
262 content::UserMetricsAction("Notifications.ShowMessageCenter"));
263 break;
264 case message_center::VISIBILITY_SETTINGS:
265 content::RecordAction(
266 content::UserMetricsAction("Notifications.ShowSettings"));
267 break;
268 }
282 } 269 }
283 270
284 void MessageCenterNotificationManager::OnNotificationUpdated( 271 void MessageCenterNotificationManager::OnNotificationUpdated(
285 const std::string& notification_id) { 272 const std::string& notification_id) {
286 #if defined(OS_WIN) 273 #if defined(OS_WIN)
287 CheckFirstRunTimer(); 274 CheckFirstRunTimer();
288 #endif 275 #endif
289 } 276 }
290 277
291 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest( 278 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest(
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 500
514 MessageCenterNotificationManager::ProfileNotification* 501 MessageCenterNotificationManager::ProfileNotification*
515 MessageCenterNotificationManager::FindProfileNotification( 502 MessageCenterNotificationManager::FindProfileNotification(
516 const std::string& id) const { 503 const std::string& id) const {
517 NotificationMap::const_iterator iter = profile_notifications_.find(id); 504 NotificationMap::const_iterator iter = profile_notifications_.find(id);
518 if (iter == profile_notifications_.end()) 505 if (iter == profile_notifications_.end())
519 return NULL; 506 return NULL;
520 507
521 return (*iter).second; 508 return (*iter).second;
522 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698