From 5fa2831756b705f9121498a56786c2e165965cc2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 31 May 2017 16:17:29 +0900 Subject: [PATCH] Coding style fixes --- atom/browser/api/atom_api_notification.cc | 35 +++++++++------------ atom/browser/api/atom_api_notification.h | 4 +-- brightray/browser/mac/cocoa_notification.h | 2 +- brightray/browser/mac/cocoa_notification.mm | 2 +- brightray/browser/notification.cc | 4 --- brightray/browser/notification.h | 7 ++--- brightray/browser/notification_delegate.h | 2 +- 7 files changed, 23 insertions(+), 33 deletions(-) diff --git a/atom/browser/api/atom_api_notification.cc b/atom/browser/api/atom_api_notification.cc index 58b3847e472..791d574774c 100644 --- a/atom/browser/api/atom_api_notification.cc +++ b/atom/browser/api/atom_api_notification.cc @@ -4,24 +4,16 @@ #include "atom/browser/api/atom_api_notification.h" -#include -#include - #include "atom/browser/api/atom_api_menu.h" #include "atom/browser/browser.h" -#include "atom/common/api/atom_api_native_image.h" #include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/node_includes.h" #include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_task_runner_handle.h" #include "brightray/browser/browser_client.h" #include "native_mate/constructor.h" #include "native_mate/dictionary.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/image/image.h" #include "url/gurl.h" namespace atom { @@ -33,6 +25,8 @@ Notification::Notification(v8::Isolate* isolate, mate::Arguments* args) { InitWith(isolate, wrapper); + presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter(); + mate::Dictionary opts; if (args->GetNext(&opts)) { opts.Get("title", &title_); @@ -45,11 +39,11 @@ Notification::Notification(v8::Isolate* isolate, opts.Get("replyPlaceholder", &reply_placeholder_); opts.Get("hasReply", &has_reply_); } - OnInitialProps(); } Notification::~Notification() { - notification_->set_delegate(nullptr); + if (notification_) + notification_->set_delegate(nullptr); } // static @@ -65,15 +59,19 @@ mate::WrappableBase* Notification::New(mate::Arguments* args) { base::string16 Notification::GetTitle() { return title_; } + base::string16 Notification::GetBody() { return body_; } + bool Notification::GetSilent() { return silent_; } + base::string16 Notification::GetReplyPlaceholder() { return reply_placeholder_; } + bool Notification::GetHasReply() { return has_reply_; } @@ -82,15 +80,19 @@ bool Notification::GetHasReply() { void Notification::SetTitle(const base::string16& new_title) { title_ = new_title; } + void Notification::SetBody(const base::string16& new_body) { body_ = new_body; } + void Notification::SetSilent(bool new_silent) { silent_ = new_silent; } + void Notification::SetReplyPlaceholder(const base::string16& new_placeholder) { reply_placeholder_ = new_placeholder; } + void Notification::SetHasReply(bool new_has_reply) { has_reply_ = new_has_reply; } @@ -99,7 +101,7 @@ void Notification::NotificationClick() { Emit("click"); } -void Notification::NotificationReplied(const std::string reply) { +void Notification::NotificationReplied(const std::string& reply) { Emit("reply", reply); } @@ -111,7 +113,8 @@ void Notification::NotificationDestroyed() { Emit("close"); } -void Notification::NotificationClosed() {} +void Notification::NotificationClosed() { +} // Showing notifications void Notification::Show() { @@ -124,14 +127,6 @@ void Notification::Show() { } } -bool initialized_ = false; -void Notification::OnInitialProps() { - if (!initialized_) { - presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter(); - initialized_ = true; - } -} - bool Notification::IsSupported() { return !!brightray::BrowserClient::Get()->GetNotificationPresenter(); } diff --git a/atom/browser/api/atom_api_notification.h b/atom/browser/api/atom_api_notification.h index 1b6a4fedbbb..9e1c47eeb74 100644 --- a/atom/browser/api/atom_api_notification.h +++ b/atom/browser/api/atom_api_notification.h @@ -32,7 +32,7 @@ class Notification : public mate::TrackableObject, // NotificationDelegate: void NotificationClick() override; - void NotificationReplied(const std::string reply) override; + void NotificationReplied(const std::string& reply) override; void NotificationDisplayed() override; void NotificationDestroyed() override; void NotificationClosed() override; @@ -43,7 +43,6 @@ class Notification : public mate::TrackableObject, mate::Arguments* args); ~Notification() override; - void OnInitialProps(); void Show(); // Prop Getters @@ -69,6 +68,7 @@ class Notification : public mate::TrackableObject, bool silent_ = false; base::string16 reply_placeholder_; bool has_reply_ = false; + brightray::NotificationPresenter* presenter_; base::WeakPtr notification_; diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index a6411d924fa..4e043dd7d8f 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -32,7 +32,7 @@ class CocoaNotification : public Notification { void Dismiss() override; void NotificationDisplayed(); - void NotificationReplied(const std::string reply); + void NotificationReplied(const std::string& reply); NSUserNotification* notification() const { return notification_; } diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 40ac97c66af..5a16d40d1a7 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -69,7 +69,7 @@ void CocoaNotification::NotificationDisplayed() { delegate()->NotificationDisplayed(); } -void CocoaNotification::NotificationReplied(const std::string reply) { +void CocoaNotification::NotificationReplied(const std::string& reply) { if (delegate()) delegate()->NotificationReplied(reply); } diff --git a/brightray/browser/notification.cc b/brightray/browser/notification.cc index 4976a91c03f..2db8e5ce4fb 100644 --- a/brightray/browser/notification.cc +++ b/brightray/browser/notification.cc @@ -21,10 +21,6 @@ Notification::~Notification() { delegate()->NotificationDestroyed(); } -void Notification::set_delegate(NotificationDelegate* delegate) { - delegate_ = delegate; -} - void Notification::NotificationClicked() { if (delegate()) delegate()->NotificationClick(); diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 054adb5bea3..f5e00a23a9b 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -20,6 +20,8 @@ class NotificationPresenter; class Notification { public: + virtual ~Notification(); + // Shows the notification. virtual void Show(const base::string16& title, const base::string16& msg, @@ -45,6 +47,7 @@ class Notification { return weak_factory_.GetWeakPtr(); } + void set_delegate(NotificationDelegate* delegate) { delegate_ = delegate; } NotificationDelegate* delegate() const { return delegate_; } NotificationPresenter* presenter() const { return presenter_; } @@ -52,10 +55,6 @@ class Notification { Notification(NotificationDelegate* delegate, NotificationPresenter* presenter); - public: - virtual ~Notification(); - void set_delegate(NotificationDelegate* delegate); - private: NotificationDelegate* delegate_; NotificationPresenter* presenter_; diff --git a/brightray/browser/notification_delegate.h b/brightray/browser/notification_delegate.h index 16eda723a5b..8493fdc3a5a 100644 --- a/brightray/browser/notification_delegate.h +++ b/brightray/browser/notification_delegate.h @@ -20,7 +20,7 @@ class NotificationDelegate : public content::DesktopNotificationDelegate { virtual void NotificationFailed() {} // Notification was replied to - virtual void NotificationReplied(const std::string reply) {} + virtual void NotificationReplied(const std::string& reply) {} }; } // namespace brightray