Refactor the notification code
This commit is contained in:
parent
b4664ce897
commit
41084883cf
9 changed files with 281 additions and 191 deletions
48
brightray/browser/mac/notification_presenter_mac.mm
Normal file
48
brightray/browser/mac/notification_presenter_mac.mm
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#import "browser/mac/notification_presenter_mac.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "browser/mac/cocoa_notification.h"
|
||||
#include "content/public/common/platform_notification_data.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
void RemoveNotification(base::WeakPtr<CocoaNotification> notification) {
|
||||
if (notification)
|
||||
notification->DismissNotification();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NotificationPresenter* NotificationPresenter::Create() {
|
||||
return new NotificationPresenterMac;
|
||||
}
|
||||
|
||||
NotificationPresenterMac::NotificationPresenterMac() {
|
||||
}
|
||||
|
||||
NotificationPresenterMac::~NotificationPresenterMac() {
|
||||
}
|
||||
|
||||
void NotificationPresenterMac::ShowNotification(
|
||||
const content::PlatformNotificationData& data,
|
||||
const SkBitmap& icon,
|
||||
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
||||
base::Closure* cancel_callback) {
|
||||
// This class manages itself.
|
||||
auto notification = new CocoaNotification(delegate.Pass());
|
||||
notification->ShowNotification(data.title, data.body, icon);
|
||||
|
||||
if (cancel_callback) {
|
||||
*cancel_callback = base::Bind(
|
||||
&RemoveNotification, notification->GetWeakPtr());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace brightray
|
Loading…
Add table
Add a link
Reference in a new issue