OLD | NEW |
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/chromeos/extensions/file_browser_notifications.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 class Delegate : public NotificationDelegate { | 100 class Delegate : public NotificationDelegate { |
101 public: | 101 public: |
102 Delegate(const base::WeakPtr<FileBrowserNotifications>& host, | 102 Delegate(const base::WeakPtr<FileBrowserNotifications>& host, |
103 const std::string& id) | 103 const std::string& id) |
104 : host_(host), | 104 : host_(host), |
105 id_(id) {} | 105 id_(id) {} |
106 virtual void Display() OVERRIDE {} | 106 virtual void Display() OVERRIDE {} |
107 virtual void Error() OVERRIDE {} | 107 virtual void Error() OVERRIDE {} |
108 virtual void Close(bool by_user) OVERRIDE { | 108 virtual void Close(bool by_user) OVERRIDE { |
109 if (host_) | 109 if (host_) |
110 host_->HideNotificationById(id_); | 110 host_->RemoveNotificationById(id_); |
111 } | 111 } |
112 virtual void Click() OVERRIDE { | 112 virtual void Click() OVERRIDE { |
113 // TODO(tbarzic): Show more info page once we have one. | 113 // TODO(tbarzic): Show more info page once we have one. |
114 } | 114 } |
115 virtual std::string id() const OVERRIDE { return id_; } | 115 virtual std::string id() const OVERRIDE { return id_; } |
116 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { | 116 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { |
117 return NULL; | 117 return NULL; |
118 } | 118 } |
119 | 119 |
120 private: | 120 private: |
(...skipping 12 matching lines...) Expand all Loading... |
133 const string16& message) | 133 const string16& message) |
134 : profile_(profile), | 134 : profile_(profile), |
135 type_(type), | 135 type_(type), |
136 notification_id_(notification_id), | 136 notification_id_(notification_id), |
137 message_(message) { | 137 message_(message) { |
138 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 138 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
139 ash::switches::kAshNotifyDisabled)) { | 139 ash::switches::kAshNotifyDisabled)) { |
140 const gfx::ImageSkia& icon = | 140 const gfx::ImageSkia& icon = |
141 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 141 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
142 IDR_FILES_APP_ICON); | 142 IDR_FILES_APP_ICON); |
| 143 string16 replace_id = UTF8ToUTF16(notification_id_); |
143 notification_id_ = DesktopNotificationService::AddIconNotification( | 144 notification_id_ = DesktopNotificationService::AddIconNotification( |
144 GURL(), GetTitle(type_), message, icon, | 145 GURL(), GetTitle(type_), message, icon, replace_id, |
145 new Delegate(host->AsWeakPtr(), notification_id_), profile_); | 146 new Delegate(host->AsWeakPtr(), notification_id_), profile_); |
146 } else { | 147 } else { |
147 system_notification_.reset( | 148 system_notification_.reset( |
148 new chromeos::SystemNotification(profile_, | 149 new chromeos::SystemNotification(profile_, |
149 notification_id_, | 150 notification_id_, |
150 GetIconId(type_), | 151 GetIconId(type_), |
151 GetTitle(type_))); | 152 GetTitle(type_))); |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 hidden_notifications_.end()) { | 382 hidden_notifications_.end()) { |
382 // Notification was hidden after a delayed show was requested. | 383 // Notification was hidden after a delayed show was requested. |
383 hidden_notifications_.erase(notification_id); | 384 hidden_notifications_.erase(notification_id); |
384 return; | 385 return; |
385 } | 386 } |
386 NotificationMessage* notification = | 387 NotificationMessage* notification = |
387 GetNotification(type, notification_id, message); | 388 GetNotification(type, notification_id, message); |
388 notification->Show(); | 389 notification->Show(); |
389 } | 390 } |
390 | 391 |
391 void FileBrowserNotifications::HideNotificationById(const std::string& id) { | 392 void FileBrowserNotifications::HideNotificationById( |
392 NotificationMap::iterator it = notification_map_.find(id); | 393 const std::string& notification_id) { |
| 394 NotificationMap::iterator it = notification_map_.find(notification_id); |
393 if (it != notification_map_.end()) { | 395 if (it != notification_map_.end()) { |
394 delete it->second; | 396 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
395 notification_map_.erase(it); | 397 ash::switches::kAshNotifyDisabled)) { |
| 398 // Will trigger Delegate::Close which will call RemoveNotificationById. |
| 399 DesktopNotificationService::RemoveNotification(notification_id); |
| 400 } else { |
| 401 NotificationMessage* notification = it->second; |
| 402 notification_map_.erase(it); |
| 403 delete notification; |
| 404 } |
396 } else { | 405 } else { |
397 // Mark as hidden so it does not get shown from a delayed task. | 406 // Mark as hidden so it does not get shown from a delayed task. |
398 hidden_notifications_.insert(id); | 407 hidden_notifications_.insert(notification_id); |
399 } | 408 } |
400 } | 409 } |
| 410 |
| 411 void FileBrowserNotifications::RemoveNotificationById( |
| 412 const std::string& notification_id) { |
| 413 NotificationMap::iterator it = notification_map_.find(notification_id); |
| 414 if (it != notification_map_.end()) { |
| 415 NotificationMessage* notification = it->second; |
| 416 notification_map_.erase(it); |
| 417 delete notification; |
| 418 } |
| 419 } |
OLD | NEW |