Make Notification
factory function a member of NotificationPresenter
so that we can create different types of notifications based on runtime conditions.
This commit is contained in:
parent
0981807261
commit
e6a30388da
12 changed files with 22 additions and 26 deletions
brightray/browser
|
@ -55,12 +55,6 @@ void log_and_clear_error(GError* error, const char* context) {
|
|||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
Notification* Notification::Create(NotificationDelegate* delegate,
|
||||
NotificationPresenter* presenter) {
|
||||
return new LibnotifyNotification(delegate, presenter);
|
||||
}
|
||||
|
||||
// static
|
||||
bool LibnotifyNotification::Initialize() {
|
||||
if (!libnotify_loader_.Load("libnotify.so.4") && // most common one
|
||||
|
|
|
@ -22,4 +22,8 @@ NotificationPresenterLinux::NotificationPresenterLinux() {
|
|||
NotificationPresenterLinux::~NotificationPresenterLinux() {
|
||||
}
|
||||
|
||||
Notification* NotificationPresenterLinux::CreateNotificationObject(NotificationDelegate* delegate) {
|
||||
return new LibnotifyNotification(delegate, this);
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -16,6 +16,8 @@ class NotificationPresenterLinux : public NotificationPresenter {
|
|||
~NotificationPresenterLinux();
|
||||
|
||||
private:
|
||||
Notification* CreateNotificationObject(NotificationDelegate* delegate) override;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterLinux);
|
||||
};
|
||||
|
||||
|
|
|
@ -12,12 +12,6 @@
|
|||
|
||||
namespace brightray {
|
||||
|
||||
// static
|
||||
Notification* Notification::Create(NotificationDelegate* delegate,
|
||||
NotificationPresenter* presenter) {
|
||||
return new CocoaNotification(delegate, presenter);
|
||||
}
|
||||
|
||||
CocoaNotification::CocoaNotification(NotificationDelegate* delegate,
|
||||
NotificationPresenter* presenter)
|
||||
: Notification(delegate, presenter) {
|
||||
|
|
|
@ -22,6 +22,8 @@ class NotificationPresenterMac : public NotificationPresenter {
|
|||
~NotificationPresenterMac();
|
||||
|
||||
private:
|
||||
Notification* CreateNotificationObject(NotificationDelegate* delegate) override;
|
||||
|
||||
base::scoped_nsobject<NotificationCenterDelegate>
|
||||
notification_center_delegate_;
|
||||
|
||||
|
|
|
@ -35,4 +35,8 @@ NotificationPresenterMac::~NotificationPresenterMac() {
|
|||
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
|
||||
}
|
||||
|
||||
Notification* NotificationPresenterMac::CreateNotificationObject(NotificationDelegate* delegate) {
|
||||
return new CocoaNotification(delegate, this);
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -47,16 +47,10 @@ class Notification {
|
|||
protected:
|
||||
Notification(NotificationDelegate* delegate,
|
||||
NotificationPresenter* presenter);
|
||||
public:
|
||||
virtual ~Notification();
|
||||
|
||||
private:
|
||||
friend class NotificationPresenter;
|
||||
|
||||
// Can only be called by NotificationPresenter, the caller is responsible of
|
||||
// freeing the returned instance.
|
||||
static Notification* Create(NotificationDelegate* delegate,
|
||||
NotificationPresenter* presenter);
|
||||
|
||||
NotificationDelegate* delegate_;
|
||||
NotificationPresenter* presenter_;
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ NotificationPresenter::~NotificationPresenter() {
|
|||
|
||||
base::WeakPtr<Notification> NotificationPresenter::CreateNotification(
|
||||
NotificationDelegate* delegate) {
|
||||
Notification* notification = Notification::Create(delegate, this);
|
||||
Notification* notification = CreateNotificationObject(delegate);
|
||||
if (!notification) return {};
|
||||
notifications_.insert(notification);
|
||||
return notification->GetWeakPtr();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ class NotificationPresenter {
|
|||
|
||||
protected:
|
||||
NotificationPresenter();
|
||||
virtual Notification* CreateNotificationObject(NotificationDelegate* delegate) = 0;
|
||||
|
||||
private:
|
||||
friend class Notification;
|
||||
|
|
|
@ -66,4 +66,8 @@ base::string16 NotificationPresenterWin::SaveIconToFilesystem(
|
|||
return base::UTF8ToUTF16(origin.spec());
|
||||
}
|
||||
|
||||
Notification* NotificationPresenterWin::CreateNotificationObject(NotificationDelegate* delegate) {
|
||||
return new WindowsToastNotification(delegate, this);
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -42,6 +42,8 @@ class NotificationPresenterWin : public NotificationPresenter {
|
|||
base::string16 SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin);
|
||||
|
||||
private:
|
||||
Notification* CreateNotificationObject(NotificationDelegate* delegate) override;
|
||||
|
||||
base::ScopedTempDir temp_dir_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin);
|
||||
|
|
|
@ -42,12 +42,6 @@ bool GetAppUserModelId(ScopedHString* app_id) {
|
|||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
Notification* Notification::Create(NotificationDelegate* delegate,
|
||||
NotificationPresenter* presenter) {
|
||||
return new WindowsToastNotification(delegate, presenter);
|
||||
}
|
||||
|
||||
// static
|
||||
ComPtr<ABI::Windows::UI::Notifications::IToastNotificationManagerStatics>
|
||||
WindowsToastNotification::toast_manager_;
|
||||
|
|
Loading…
Add table
Reference in a new issue