| 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_manager/file_manager_notificat
ions.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" | 12 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service.h" | 13 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 14 #include "chrome/browser/notifications/notification_delegate.h" | 14 #include "chrome/browser/notifications/notification_delegate.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/webui/web_ui_util.h" | 22 #include "ui/webui/web_ui_util.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 struct NotificationTypeInfo { | 26 struct NotificationTypeInfo { |
| 27 FileBrowserNotifications::NotificationType type; | 27 FileManagerNotifications::NotificationType type; |
| 28 const char* notification_id_prefix; | 28 const char* notification_id_prefix; |
| 29 int icon_id; | 29 int icon_id; |
| 30 int title_id; | 30 int title_id; |
| 31 int message_id; | 31 int message_id; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Information about notification types. | 34 // Information about notification types. |
| 35 // The order of notification types in the array must match the order of types in | 35 // The order of notification types in the array must match the order of types in |
| 36 // NotificationType enum (i.e. the following MUST be satisfied: | 36 // NotificationType enum (i.e. the following MUST be satisfied: |
| 37 // kNotificationTypes[type].type == type). | 37 // kNotificationTypes[type].type == type). |
| 38 const NotificationTypeInfo kNotificationTypes[] = { | 38 const NotificationTypeInfo kNotificationTypes[] = { |
| 39 { | 39 { |
| 40 FileBrowserNotifications::DEVICE, // type | 40 FileManagerNotifications::DEVICE, // type |
| 41 "Device_", // notification_id_prefix | 41 "Device_", // notification_id_prefix |
| 42 IDR_FILES_APP_ICON, // icon_id | 42 IDR_FILES_APP_ICON, // icon_id |
| 43 IDS_REMOVABLE_DEVICE_DETECTION_TITLE, // title_id | 43 IDS_REMOVABLE_DEVICE_DETECTION_TITLE, // title_id |
| 44 IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE // message_id | 44 IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE // message_id |
| 45 }, | 45 }, |
| 46 { | 46 { |
| 47 FileBrowserNotifications::DEVICE_FAIL, // type | 47 FileManagerNotifications::DEVICE_FAIL, // type |
| 48 "DeviceFail_", // notification_id_prefix | 48 "DeviceFail_", // notification_id_prefix |
| 49 IDR_FILES_APP_ICON, // icon_id | 49 IDR_FILES_APP_ICON, // icon_id |
| 50 IDS_REMOVABLE_DEVICE_DETECTION_TITLE, // title_id | 50 IDS_REMOVABLE_DEVICE_DETECTION_TITLE, // title_id |
| 51 IDS_DEVICE_UNSUPPORTED_DEFAULT_MESSAGE // message_id | 51 IDS_DEVICE_UNSUPPORTED_DEFAULT_MESSAGE // message_id |
| 52 }, | 52 }, |
| 53 { | 53 { |
| 54 FileBrowserNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED, // type | 54 FileManagerNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED, // type |
| 55 "DeviceFail_", // nottification_id_prefix; same as for DEVICE_FAIL. | 55 "DeviceFail_", // nottification_id_prefix; same as for DEVICE_FAIL. |
| 56 IDR_FILES_APP_ICON, // icon_id | 56 IDR_FILES_APP_ICON, // icon_id |
| 57 IDS_REMOVABLE_DEVICE_DETECTION_TITLE, // title_id | 57 IDS_REMOVABLE_DEVICE_DETECTION_TITLE, // title_id |
| 58 IDS_EXTERNAL_STORAGE_DISABLED_MESSAGE // message_id | 58 IDS_EXTERNAL_STORAGE_DISABLED_MESSAGE // message_id |
| 59 }, | 59 }, |
| 60 { | 60 { |
| 61 FileBrowserNotifications::FORMAT_START, // type | 61 FileManagerNotifications::FORMAT_START, // type |
| 62 "FormatStart_", // notification_id_prefix | 62 "FormatStart_", // notification_id_prefix |
| 63 IDR_FILES_APP_ICON, // icon_id | 63 IDR_FILES_APP_ICON, // icon_id |
| 64 IDS_FORMATTING_OF_DEVICE_PENDING_TITLE, // title_id | 64 IDS_FORMATTING_OF_DEVICE_PENDING_TITLE, // title_id |
| 65 IDS_FORMATTING_OF_DEVICE_PENDING_MESSAGE // message_id | 65 IDS_FORMATTING_OF_DEVICE_PENDING_MESSAGE // message_id |
| 66 }, | 66 }, |
| 67 { | 67 { |
| 68 FileBrowserNotifications::FORMAT_START_FAIL, // type | 68 FileManagerNotifications::FORMAT_START_FAIL, // type |
| 69 "FormatComplete_", // notification_id_prefix | 69 "FormatComplete_", // notification_id_prefix |
| 70 IDR_FILES_APP_ICON, // icon_id | 70 IDR_FILES_APP_ICON, // icon_id |
| 71 IDS_FORMATTING_OF_DEVICE_FAILED_TITLE, // title_id | 71 IDS_FORMATTING_OF_DEVICE_FAILED_TITLE, // title_id |
| 72 IDS_FORMATTING_STARTED_FAILURE_MESSAGE // message_id | 72 IDS_FORMATTING_STARTED_FAILURE_MESSAGE // message_id |
| 73 }, | 73 }, |
| 74 { | 74 { |
| 75 FileBrowserNotifications::FORMAT_SUCCESS, // type | 75 FileManagerNotifications::FORMAT_SUCCESS, // type |
| 76 "FormatComplete_", // notification_id_prefix | 76 "FormatComplete_", // notification_id_prefix |
| 77 IDR_FILES_APP_ICON, // icon_id | 77 IDR_FILES_APP_ICON, // icon_id |
| 78 IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE, // title_id | 78 IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE, // title_id |
| 79 IDS_FORMATTING_FINISHED_SUCCESS_MESSAGE // message_id | 79 IDS_FORMATTING_FINISHED_SUCCESS_MESSAGE // message_id |
| 80 }, | 80 }, |
| 81 { | 81 { |
| 82 FileBrowserNotifications::FORMAT_FAIL, // type | 82 FileManagerNotifications::FORMAT_FAIL, // type |
| 83 "FormatComplete_", // notifications_id_prefix | 83 "FormatComplete_", // notifications_id_prefix |
| 84 IDR_FILES_APP_ICON, // icon_id | 84 IDR_FILES_APP_ICON, // icon_id |
| 85 IDS_FORMATTING_OF_DEVICE_FAILED_TITLE, // title_id | 85 IDS_FORMATTING_OF_DEVICE_FAILED_TITLE, // title_id |
| 86 IDS_FORMATTING_FINISHED_FAILURE_MESSAGE // message_id | 86 IDS_FORMATTING_FINISHED_FAILURE_MESSAGE // message_id |
| 87 }, | 87 }, |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 int GetIconId(FileBrowserNotifications::NotificationType type) { | 90 int GetIconId(FileManagerNotifications::NotificationType type) { |
| 91 DCHECK_GE(type, 0); | 91 DCHECK_GE(type, 0); |
| 92 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); | 92 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); |
| 93 DCHECK(kNotificationTypes[type].type == type); | 93 DCHECK(kNotificationTypes[type].type == type); |
| 94 | 94 |
| 95 return kNotificationTypes[type].icon_id; | 95 return kNotificationTypes[type].icon_id; |
| 96 } | 96 } |
| 97 | 97 |
| 98 string16 GetTitle(FileBrowserNotifications::NotificationType type) { | 98 string16 GetTitle(FileManagerNotifications::NotificationType type) { |
| 99 DCHECK_GE(type, 0); | 99 DCHECK_GE(type, 0); |
| 100 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); | 100 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); |
| 101 DCHECK(kNotificationTypes[type].type == type); | 101 DCHECK(kNotificationTypes[type].type == type); |
| 102 | 102 |
| 103 int id = kNotificationTypes[type].title_id; | 103 int id = kNotificationTypes[type].title_id; |
| 104 if (id < 0) | 104 if (id < 0) |
| 105 return string16(); | 105 return string16(); |
| 106 return l10n_util::GetStringUTF16(id); | 106 return l10n_util::GetStringUTF16(id); |
| 107 } | 107 } |
| 108 | 108 |
| 109 string16 GetMessage(FileBrowserNotifications::NotificationType type) { | 109 string16 GetMessage(FileManagerNotifications::NotificationType type) { |
| 110 DCHECK_GE(type, 0); | 110 DCHECK_GE(type, 0); |
| 111 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); | 111 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); |
| 112 DCHECK(kNotificationTypes[type].type == type); | 112 DCHECK(kNotificationTypes[type].type == type); |
| 113 | 113 |
| 114 int id = kNotificationTypes[type].message_id; | 114 int id = kNotificationTypes[type].message_id; |
| 115 if (id < 0) | 115 if (id < 0) |
| 116 return string16(); | 116 return string16(); |
| 117 return l10n_util::GetStringUTF16(id); | 117 return l10n_util::GetStringUTF16(id); |
| 118 } | 118 } |
| 119 | 119 |
| 120 std::string GetNotificationId(FileBrowserNotifications::NotificationType type, | 120 std::string GetNotificationId(FileManagerNotifications::NotificationType type, |
| 121 const std::string& path) { | 121 const std::string& path) { |
| 122 DCHECK_GE(type, 0); | 122 DCHECK_GE(type, 0); |
| 123 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); | 123 DCHECK_LT(static_cast<size_t>(type), arraysize(kNotificationTypes)); |
| 124 DCHECK(kNotificationTypes[type].type == type); | 124 DCHECK(kNotificationTypes[type].type == type); |
| 125 | 125 |
| 126 std::string id_prefix(kNotificationTypes[type].notification_id_prefix); | 126 std::string id_prefix(kNotificationTypes[type].notification_id_prefix); |
| 127 return id_prefix.append(path); | 127 return id_prefix.append(path); |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 // Manages file browser notifications. Generates a desktop notification on | 132 // Manages file browser notifications. Generates a desktop notification on |
| 133 // construction and removes it from the host when closed. Owned by the host. | 133 // construction and removes it from the host when closed. Owned by the host. |
| 134 class FileBrowserNotifications::NotificationMessage { | 134 class FileManagerNotifications::NotificationMessage { |
| 135 public: | 135 public: |
| 136 class Delegate : public NotificationDelegate { | 136 class Delegate : public NotificationDelegate { |
| 137 public: | 137 public: |
| 138 Delegate(const base::WeakPtr<FileBrowserNotifications>& host, | 138 Delegate(const base::WeakPtr<FileManagerNotifications>& host, |
| 139 const std::string& id) | 139 const std::string& id) |
| 140 : host_(host), | 140 : host_(host), |
| 141 id_(id) {} | 141 id_(id) {} |
| 142 virtual void Display() OVERRIDE {} | 142 virtual void Display() OVERRIDE {} |
| 143 virtual void Error() OVERRIDE {} | 143 virtual void Error() OVERRIDE {} |
| 144 virtual void Close(bool by_user) OVERRIDE { | 144 virtual void Close(bool by_user) OVERRIDE { |
| 145 if (host_) | 145 if (host_) |
| 146 host_->RemoveNotificationById(id_); | 146 host_->RemoveNotificationById(id_); |
| 147 } | 147 } |
| 148 virtual void Click() OVERRIDE { | 148 virtual void Click() OVERRIDE { |
| 149 // TODO(tbarzic): Show more info page once we have one. | 149 // TODO(tbarzic): Show more info page once we have one. |
| 150 } | 150 } |
| 151 virtual std::string id() const OVERRIDE { return id_; } | 151 virtual std::string id() const OVERRIDE { return id_; } |
| 152 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { | 152 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { |
| 153 return NULL; | 153 return NULL; |
| 154 } | 154 } |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 virtual ~Delegate() {} | 157 virtual ~Delegate() {} |
| 158 | 158 |
| 159 base::WeakPtr<FileBrowserNotifications> host_; | 159 base::WeakPtr<FileManagerNotifications> host_; |
| 160 std::string id_; | 160 std::string id_; |
| 161 | 161 |
| 162 DISALLOW_COPY_AND_ASSIGN(Delegate); | 162 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 NotificationMessage(FileBrowserNotifications* host, | 165 NotificationMessage(FileManagerNotifications* host, |
| 166 Profile* profile, | 166 Profile* profile, |
| 167 NotificationType type, | 167 NotificationType type, |
| 168 const std::string& notification_id, | 168 const std::string& notification_id, |
| 169 const string16& message) | 169 const string16& message) |
| 170 : message_(message) { | 170 : message_(message) { |
| 171 const gfx::Image& icon = | 171 const gfx::Image& icon = |
| 172 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 172 ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 173 GetIconId(type)); | 173 GetIconId(type)); |
| 174 // TODO(mukai): refactor here to invoke NotificationUIManager directly. | 174 // TODO(mukai): refactor here to invoke NotificationUIManager directly. |
| 175 const string16 replace_id = UTF8ToUTF16(notification_id); | 175 const string16 replace_id = UTF8ToUTF16(notification_id); |
| 176 DesktopNotificationService::AddIconNotification( | 176 DesktopNotificationService::AddIconNotification( |
| 177 file_manager_util::GetFileBrowserExtensionUrl(), GetTitle(type), | 177 file_manager_util::GetFileBrowserExtensionUrl(), GetTitle(type), |
| 178 message, icon, replace_id, | 178 message, icon, replace_id, |
| 179 new Delegate(host->AsWeakPtr(), notification_id), profile); | 179 new Delegate(host->AsWeakPtr(), notification_id), profile); |
| 180 } | 180 } |
| 181 | 181 |
| 182 ~NotificationMessage() {} | 182 ~NotificationMessage() {} |
| 183 | 183 |
| 184 // Used in test. | 184 // Used in test. |
| 185 string16 message() { return message_; } | 185 string16 message() { return message_; } |
| 186 | 186 |
| 187 private: | 187 private: |
| 188 string16 message_; | 188 string16 message_; |
| 189 | 189 |
| 190 DISALLOW_COPY_AND_ASSIGN(NotificationMessage); | 190 DISALLOW_COPY_AND_ASSIGN(NotificationMessage); |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 struct FileBrowserNotifications::MountRequestsInfo { | 193 struct FileManagerNotifications::MountRequestsInfo { |
| 194 bool mount_success_exists; | 194 bool mount_success_exists; |
| 195 bool fail_message_finalized; | 195 bool fail_message_finalized; |
| 196 bool fail_notification_shown; | 196 bool fail_notification_shown; |
| 197 bool non_parent_device_failed; | 197 bool non_parent_device_failed; |
| 198 bool device_notification_hidden; | 198 bool device_notification_hidden; |
| 199 | 199 |
| 200 MountRequestsInfo() : mount_success_exists(false), | 200 MountRequestsInfo() : mount_success_exists(false), |
| 201 fail_message_finalized(false), | 201 fail_message_finalized(false), |
| 202 fail_notification_shown(false), | 202 fail_notification_shown(false), |
| 203 non_parent_device_failed(false), | 203 non_parent_device_failed(false), |
| 204 device_notification_hidden(false) { | 204 device_notification_hidden(false) { |
| 205 } | 205 } |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 FileBrowserNotifications::FileBrowserNotifications(Profile* profile) | 208 FileManagerNotifications::FileManagerNotifications(Profile* profile) |
| 209 : profile_(profile) { | 209 : profile_(profile) { |
| 210 } | 210 } |
| 211 | 211 |
| 212 FileBrowserNotifications::~FileBrowserNotifications() { | 212 FileManagerNotifications::~FileManagerNotifications() { |
| 213 STLDeleteContainerPairSecondPointers(notification_map_.begin(), | 213 STLDeleteContainerPairSecondPointers(notification_map_.begin(), |
| 214 notification_map_.end()); | 214 notification_map_.end()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void FileBrowserNotifications::RegisterDevice(const std::string& path) { | 217 void FileManagerNotifications::RegisterDevice(const std::string& path) { |
| 218 mount_requests_.insert(MountRequestsMap::value_type(path, | 218 mount_requests_.insert(MountRequestsMap::value_type(path, |
| 219 MountRequestsInfo())); | 219 MountRequestsInfo())); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void FileBrowserNotifications::UnregisterDevice(const std::string& path) { | 222 void FileManagerNotifications::UnregisterDevice(const std::string& path) { |
| 223 mount_requests_.erase(path); | 223 mount_requests_.erase(path); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void FileBrowserNotifications::ManageNotificationsOnMountCompleted( | 226 void FileManagerNotifications::ManageNotificationsOnMountCompleted( |
| 227 const std::string& system_path, const std::string& label, bool is_parent, | 227 const std::string& system_path, const std::string& label, bool is_parent, |
| 228 bool success, bool is_unsupported) { | 228 bool success, bool is_unsupported) { |
| 229 MountRequestsMap::iterator it = mount_requests_.find(system_path); | 229 MountRequestsMap::iterator it = mount_requests_.find(system_path); |
| 230 if (it == mount_requests_.end()) | 230 if (it == mount_requests_.end()) |
| 231 return; | 231 return; |
| 232 | 232 |
| 233 // We have to hide device scanning notification if we haven't done it already. | 233 // We have to hide device scanning notification if we haven't done it already. |
| 234 if (!it->second.device_notification_hidden) { | 234 if (!it->second.device_notification_hidden) { |
| 235 HideNotification(DEVICE, system_path); | 235 HideNotification(DEVICE, system_path); |
| 236 it->second.device_notification_hidden = true; | 236 it->second.device_notification_hidden = true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 if (!label.empty()) { | 292 if (!label.empty()) { |
| 293 ShowNotificationWithMessage(DEVICE_FAIL, system_path, | 293 ShowNotificationWithMessage(DEVICE_FAIL, system_path, |
| 294 l10n_util::GetStringFUTF16(notification_message_id, | 294 l10n_util::GetStringFUTF16(notification_message_id, |
| 295 ASCIIToUTF16(label))); | 295 ASCIIToUTF16(label))); |
| 296 } else { | 296 } else { |
| 297 ShowNotificationWithMessage(DEVICE_FAIL, system_path, | 297 ShowNotificationWithMessage(DEVICE_FAIL, system_path, |
| 298 l10n_util::GetStringUTF16(notification_message_id)); | 298 l10n_util::GetStringUTF16(notification_message_id)); |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 | 301 |
| 302 void FileBrowserNotifications::ShowNotification(NotificationType type, | 302 void FileManagerNotifications::ShowNotification(NotificationType type, |
| 303 const std::string& path) { | 303 const std::string& path) { |
| 304 ShowNotificationWithMessage(type, path, GetMessage(type)); | 304 ShowNotificationWithMessage(type, path, GetMessage(type)); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void FileBrowserNotifications::ShowNotificationWithMessage( | 307 void FileManagerNotifications::ShowNotificationWithMessage( |
| 308 NotificationType type, | 308 NotificationType type, |
| 309 const std::string& path, | 309 const std::string& path, |
| 310 const string16& message) { | 310 const string16& message) { |
| 311 std::string notification_id = GetNotificationId(type, path); | 311 std::string notification_id = GetNotificationId(type, path); |
| 312 hidden_notifications_.erase(notification_id); | 312 hidden_notifications_.erase(notification_id); |
| 313 ShowNotificationById(type, notification_id, message); | 313 ShowNotificationById(type, notification_id, message); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void FileBrowserNotifications::ShowNotificationDelayed( | 316 void FileManagerNotifications::ShowNotificationDelayed( |
| 317 NotificationType type, | 317 NotificationType type, |
| 318 const std::string& path, | 318 const std::string& path, |
| 319 base::TimeDelta delay) { | 319 base::TimeDelta delay) { |
| 320 std::string notification_id = GetNotificationId(type, path); | 320 std::string notification_id = GetNotificationId(type, path); |
| 321 hidden_notifications_.erase(notification_id); | 321 hidden_notifications_.erase(notification_id); |
| 322 MessageLoop::current()->PostDelayedTask( | 322 MessageLoop::current()->PostDelayedTask( |
| 323 FROM_HERE, | 323 FROM_HERE, |
| 324 base::Bind(&FileBrowserNotifications::ShowNotificationById, AsWeakPtr(), | 324 base::Bind(&FileManagerNotifications::ShowNotificationById, AsWeakPtr(), |
| 325 type, notification_id, GetMessage(type)), | 325 type, notification_id, GetMessage(type)), |
| 326 delay); | 326 delay); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void FileBrowserNotifications::HideNotification(NotificationType type, | 329 void FileManagerNotifications::HideNotification(NotificationType type, |
| 330 const std::string& path) { | 330 const std::string& path) { |
| 331 std::string notification_id = GetNotificationId(type, path); | 331 std::string notification_id = GetNotificationId(type, path); |
| 332 HideNotificationById(notification_id); | 332 HideNotificationById(notification_id); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void FileBrowserNotifications::HideNotificationDelayed( | 335 void FileManagerNotifications::HideNotificationDelayed( |
| 336 NotificationType type, const std::string& path, base::TimeDelta delay) { | 336 NotificationType type, const std::string& path, base::TimeDelta delay) { |
| 337 MessageLoop::current()->PostDelayedTask( | 337 MessageLoop::current()->PostDelayedTask( |
| 338 FROM_HERE, | 338 FROM_HERE, |
| 339 base::Bind(&FileBrowserNotifications::HideNotification, AsWeakPtr(), | 339 base::Bind(&FileManagerNotifications::HideNotification, AsWeakPtr(), |
| 340 type, path), | 340 type, path), |
| 341 delay); | 341 delay); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void FileBrowserNotifications::ShowNotificationById( | 344 void FileManagerNotifications::ShowNotificationById( |
| 345 NotificationType type, | 345 NotificationType type, |
| 346 const std::string& notification_id, | 346 const std::string& notification_id, |
| 347 const string16& message) { | 347 const string16& message) { |
| 348 if (hidden_notifications_.find(notification_id) != | 348 if (hidden_notifications_.find(notification_id) != |
| 349 hidden_notifications_.end()) { | 349 hidden_notifications_.end()) { |
| 350 // Notification was hidden after a delayed show was requested. | 350 // Notification was hidden after a delayed show was requested. |
| 351 hidden_notifications_.erase(notification_id); | 351 hidden_notifications_.erase(notification_id); |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 if (notification_map_.find(notification_id) != notification_map_.end()) { | 354 if (notification_map_.find(notification_id) != notification_map_.end()) { |
| 355 // Remove any existing notification with |notification_id|. | 355 // Remove any existing notification with |notification_id|. |
| 356 // Will trigger Delegate::Close which will call RemoveNotificationById. | 356 // Will trigger Delegate::Close which will call RemoveNotificationById. |
| 357 DesktopNotificationService::RemoveNotification(notification_id); | 357 DesktopNotificationService::RemoveNotification(notification_id); |
| 358 DCHECK(notification_map_.find(notification_id) == notification_map_.end()); | 358 DCHECK(notification_map_.find(notification_id) == notification_map_.end()); |
| 359 } | 359 } |
| 360 // Create a new notification with |notification_id|. | 360 // Create a new notification with |notification_id|. |
| 361 NotificationMessage* new_message = | 361 NotificationMessage* new_message = |
| 362 new NotificationMessage(this, profile_, type, notification_id, message); | 362 new NotificationMessage(this, profile_, type, notification_id, message); |
| 363 notification_map_[notification_id] = new_message; | 363 notification_map_[notification_id] = new_message; |
| 364 } | 364 } |
| 365 | 365 |
| 366 void FileBrowserNotifications::HideNotificationById( | 366 void FileManagerNotifications::HideNotificationById( |
| 367 const std::string& notification_id) { | 367 const std::string& notification_id) { |
| 368 NotificationMap::iterator it = notification_map_.find(notification_id); | 368 NotificationMap::iterator it = notification_map_.find(notification_id); |
| 369 if (it != notification_map_.end()) { | 369 if (it != notification_map_.end()) { |
| 370 // Will trigger Delegate::Close which will call RemoveNotificationById. | 370 // Will trigger Delegate::Close which will call RemoveNotificationById. |
| 371 DesktopNotificationService::RemoveNotification(notification_id); | 371 DesktopNotificationService::RemoveNotification(notification_id); |
| 372 } else { | 372 } else { |
| 373 // Mark as hidden so it does not get shown from a delayed task. | 373 // Mark as hidden so it does not get shown from a delayed task. |
| 374 hidden_notifications_.insert(notification_id); | 374 hidden_notifications_.insert(notification_id); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 | 377 |
| 378 void FileBrowserNotifications::RemoveNotificationById( | 378 void FileManagerNotifications::RemoveNotificationById( |
| 379 const std::string& notification_id) { | 379 const std::string& notification_id) { |
| 380 NotificationMap::iterator it = notification_map_.find(notification_id); | 380 NotificationMap::iterator it = notification_map_.find(notification_id); |
| 381 if (it != notification_map_.end()) { | 381 if (it != notification_map_.end()) { |
| 382 NotificationMessage* notification = it->second; | 382 NotificationMessage* notification = it->second; |
| 383 notification_map_.erase(it); | 383 notification_map_.erase(it); |
| 384 delete notification; | 384 delete notification; |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 string16 FileBrowserNotifications::GetNotificationMessageForTest( | 388 string16 FileManagerNotifications::GetNotificationMessageForTest( |
| 389 const std::string& id) const { | 389 const std::string& id) const { |
| 390 NotificationMap::const_iterator it = notification_map_.find(id); | 390 NotificationMap::const_iterator it = notification_map_.find(id); |
| 391 if (it == notification_map_.end()) | 391 if (it == notification_map_.end()) |
| 392 return string16(); | 392 return string16(); |
| 393 return it->second->message(); | 393 return it->second->message(); |
| 394 } | 394 } |
| OLD | NEW |