1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_DESKTOP_NOTIFICATIONS_H_ 6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_DESKTOP_NOTIFICATIONS_H_ 7 8 #include <map> 9 #include <set> 10 #include <string> 11 12 #include "base/basictypes.h" 13 #include "base/memory/weak_ptr.h" 14 #include "base/strings/string16.h" 15 #include "base/time/time.h" 16 17 class Profile; 18 19 namespace file_manager { 20 21 // The class is used for showing desktop notifications about activities of 22 // Files.app, such as a new storage device getting detected. 23 // 24 // Note that updates for file transfers from/to Drive shown in the ash tray, 25 // hence not handled in this class. See ash/system/drive/tray_drive.h for 26 // details. 27 class DesktopNotifications 28 : public base::SupportsWeakPtr<DesktopNotifications> { 29 public: 30 // If changing the enum, please also update kNotificationTypes in .cc file. 31 enum NotificationType { 32 DEVICE, 33 DEVICE_FAIL, 34 DEVICE_EXTERNAL_STORAGE_DISABLED, 35 FORMAT_START, 36 FORMAT_START_FAIL, 37 FORMAT_SUCCESS, 38 FORMAT_FAIL, 39 }; 40 41 explicit DesktopNotifications(Profile* profile); 42 virtual ~DesktopNotifications(); 43 44 // Registers the removable device whose mount events will be handled in 45 // |ManageNotificationsOnMountComplete|. 46 void RegisterDevice(const std::string& system_path); 47 48 // Unregisters the removable device whose mount events will be handled in 49 // |ManageNotificationsOnMountComplete|. 50 void UnregisterDevice(const std::string& system_path); 51 52 void ManageNotificationsOnMountCompleted(const std::string& system_path, 53 const std::string& label, 54 bool is_parent, 55 bool success, 56 bool is_unsupported); 57 58 // Primary method for showing a notification. 59 void ShowNotification(NotificationType type, const std::string& path); 60 void ShowNotificationDelayed(NotificationType type, 61 const std::string& path, 62 base::TimeDelta delay); 63 64 // Primary method for hiding a notification. Virtual for mock in unittest. 65 virtual void HideNotification(NotificationType type, const std::string& path); 66 void HideNotificationDelayed(NotificationType type, 67 const std::string& path, 68 base::TimeDelta delay); 69 70 size_t GetNotificationCountForTest() const { 71 return notification_map_.size(); 72 } 73 74 bool HasNotificationForTest(const std::string& id) const { 75 return notification_map_.find(id) != notification_map_.end(); 76 } 77 78 base::string16 GetNotificationMessageForTest(const std::string& id) const; 79 80 private: 81 class NotificationMessage; 82 struct MountRequestsInfo; 83 84 typedef std::map<std::string, MountRequestsInfo> MountRequestsMap; 85 typedef std::map<std::string, NotificationMessage*> NotificationMap; 86 87 // Virtual for mock in unittest. 88 virtual void ShowNotificationWithMessage(NotificationType type, 89 const std::string& path, 90 const base::string16& message); 91 void ShowNotificationById(NotificationType type, 92 const std::string& notification_id, 93 const base::string16& message); 94 void HideNotificationById(const std::string& notification_id); 95 void RemoveNotificationById(const std::string& notification_id); 96 97 NotificationMap notification_map_; 98 std::set<std::string> hidden_notifications_; 99 MountRequestsMap mount_requests_; 100 Profile* profile_; 101 102 DISALLOW_COPY_AND_ASSIGN(DesktopNotifications); 103 }; 104 105 } // namespace file_manager 106 107 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_DESKTOP_NOTIFICATIONS_H_ 108