Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_NOTIFICATIONS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_NOTIFICATIONS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_NOTIFICATIONS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_NOTIFICATIONS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 | 16 |
| 17 class Profile; | 17 class Profile; |
| 18 | 18 |
| 19 class FileBrowserNotifications | 19 class FileBrowserNotifications |
| 20 : public base::SupportsWeakPtr<FileBrowserNotifications> { | 20 : public base::SupportsWeakPtr<FileBrowserNotifications> { |
| 21 public: | 21 public: |
| 22 // If changing the enum, please also update kNotificationTypes in .cc file. | |
| 22 enum NotificationType { | 23 enum NotificationType { |
| 23 DEVICE, | 24 DEVICE, |
| 24 DEVICE_FAIL, | 25 DEVICE_FAIL, |
| 25 DEVICE_HARD_UNPLUG, | 26 DEVICE_HARD_UNPLUG, |
| 27 DEVICE_EXTERNAL_STORAGE_DISABLED, | |
| 26 FORMAT_SUCCESS, | 28 FORMAT_SUCCESS, |
| 27 FORMAT_FAIL, | 29 FORMAT_FAIL, |
| 28 FORMAT_START, | 30 FORMAT_START, |
| 29 FORMAT_START_FAIL, | 31 FORMAT_START_FAIL, |
| 30 GDATA_SYNC, | |
| 31 GDATA_SYNC_SUCCESS, | |
| 32 GDATA_SYNC_FAIL, | |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 explicit FileBrowserNotifications(Profile* profile); | 34 explicit FileBrowserNotifications(Profile* profile); |
| 36 virtual ~FileBrowserNotifications(); | 35 virtual ~FileBrowserNotifications(); |
| 37 | 36 |
| 38 void RegisterDevice(const std::string& path); | 37 // Registers the removable device whose mount events will be handled in |
| 39 void UnregisterDevice(const std::string& path); | 38 // |ManageNotificationsOnMountComplete|. |
| 39 void RegisterDevice(const std::string& system_path); | |
|
stevenjb
2012/11/27 01:20:08
nit: blank line
| |
| 40 // Unregisters the removable device whose mount events will be handled in | |
| 41 // |ManageNotificationsOnMountComplete|. | |
| 42 void UnregisterDevice(const std::string& system_path); | |
| 40 | 43 |
| 41 void ManageNotificationsOnMountCompleted(const std::string& system_path, | 44 void ManageNotificationsOnMountCompleted(const std::string& system_path, |
| 42 const std::string& label, | 45 const std::string& label, |
| 43 bool is_parent, | 46 bool is_parent, |
| 44 bool success, | 47 bool success, |
| 45 bool is_unsupported); | 48 bool is_unsupported); |
| 46 | 49 |
| 47 void ManageNotificationOnGDataSyncProgress(int count); | 50 void ManageNotificationOnGDataSyncProgress(int count); |
| 48 void ManageNotificationOnGDataSyncFinish(bool success); | 51 void ManageNotificationOnGDataSyncFinish(bool success); |
| 49 | 52 |
| 50 // Retreives message body based on |type|. | 53 // Primary method for showing a notification. |
| 51 void ShowNotification(NotificationType type, const std::string& path); | 54 void ShowNotification(NotificationType type, const std::string& path); |
| 52 // Primary method for showing a notification. Virtual for mock in unittest. | |
| 53 virtual void ShowNotificationWithMessage(NotificationType type, | |
| 54 const std::string& path, | |
| 55 const string16& message); | |
| 56 void ShowNotificationDelayed(NotificationType type, | 55 void ShowNotificationDelayed(NotificationType type, |
| 57 const std::string& path, | 56 const std::string& path, |
| 58 base::TimeDelta delay); | 57 base::TimeDelta delay); |
| 59 | 58 |
| 60 // Primary method for hiding a notification. Virtual for mock in unittest. | 59 // Primary method for hiding a notification. Virtual for mock in unittest. |
| 61 virtual void HideNotification(NotificationType type, const std::string& path); | 60 virtual void HideNotification(NotificationType type, const std::string& path); |
| 62 void HideNotificationDelayed(NotificationType type, | 61 void HideNotificationDelayed(NotificationType type, |
| 63 const std::string& path, | 62 const std::string& path, |
| 64 base::TimeDelta delay); | 63 base::TimeDelta delay); |
| 65 | 64 |
| 66 size_t GetNotificationCountForTest() const { | 65 size_t GetNotificationCountForTest() const { |
| 67 return notification_map_.size(); | 66 return notification_map_.size(); |
| 68 } | 67 } |
| 68 | |
| 69 bool HasNotificationForTest(const std::string& id) const { | 69 bool HasNotificationForTest(const std::string& id) const { |
| 70 return notification_map_.find(id) != notification_map_.end(); | 70 return notification_map_.find(id) != notification_map_.end(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 string16 GetNotificationMessageForTest(const std::string& id) const; | |
| 74 | |
| 73 private: | 75 private: |
| 74 class NotificationMessage; | 76 class NotificationMessage; |
| 75 struct MountRequestsInfo; | 77 struct MountRequestsInfo; |
| 76 | 78 |
| 77 typedef std::map<std::string, MountRequestsInfo> MountRequestsMap; | 79 typedef std::map<std::string, MountRequestsInfo> MountRequestsMap; |
| 78 typedef std::map<std::string, NotificationMessage*> NotificationMap; | 80 typedef std::map<std::string, NotificationMessage*> NotificationMap; |
| 79 | 81 |
| 80 std::string CreateNotificationId(NotificationType type, | 82 // Virtual for mock in unittest. |
| 81 const std::string& path); | 83 virtual void ShowNotificationWithMessage(NotificationType type, |
| 84 const std::string& path, | |
| 85 const string16& message); | |
| 82 void ShowNotificationById(NotificationType type, | 86 void ShowNotificationById(NotificationType type, |
| 83 const std::string& notification_id, | 87 const std::string& notification_id, |
| 84 const string16& message); | 88 const string16& message); |
| 85 void HideNotificationById(const std::string& notification_id); | 89 void HideNotificationById(const std::string& notification_id); |
| 86 void RemoveNotificationById(const std::string& notification_id); | 90 void RemoveNotificationById(const std::string& notification_id); |
| 87 | 91 |
| 88 NotificationMap notification_map_; | 92 NotificationMap notification_map_; |
| 89 std::set<std::string> hidden_notifications_; | 93 std::set<std::string> hidden_notifications_; |
| 90 MountRequestsMap mount_requests_; | 94 MountRequestsMap mount_requests_; |
| 91 Profile* profile_; | 95 Profile* profile_; |
| 92 | 96 |
| 93 DISALLOW_COPY_AND_ASSIGN(FileBrowserNotifications); | 97 DISALLOW_COPY_AND_ASSIGN(FileBrowserNotifications); |
| 94 }; | 98 }; |
| 95 | 99 |
| 96 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_NOTIFICATIONS_H_ | 100 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_NOTIFICATIONS_H_ |
| OLD | NEW |