From 1569dfa2e8682a0311b8b5bb5364408b4185fce7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Jul 2015 18:24:40 +0800 Subject: [PATCH] Remove manual lifetime check for Tray --- atom/browser/api/atom_api_tray.cc | 28 ++++------------------------ atom/browser/api/atom_api_tray.h | 5 +++-- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/atom/browser/api/atom_api_tray.cc b/atom/browser/api/atom_api_tray.cc index 2672f6f67ae5..f3dd57b738e7 100644 --- a/atom/browser/api/atom_api_tray.cc +++ b/atom/browser/api/atom_api_tray.cc @@ -60,45 +60,36 @@ void Tray::OnBalloonClosed() { Emit("balloon-closed"); } +bool Tray::IsDestroyed() const { + return !tray_icon_; +} + void Tray::Destroy() { tray_icon_.reset(); } void Tray::SetImage(mate::Arguments* args, const gfx::Image& image) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetImage(image); } void Tray::SetPressedImage(mate::Arguments* args, const gfx::Image& image) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetPressedImage(image); } void Tray::SetToolTip(mate::Arguments* args, const std::string& tool_tip) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetToolTip(tool_tip); } void Tray::SetTitle(mate::Arguments* args, const std::string& title) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetTitle(title); } void Tray::SetHighlightMode(mate::Arguments* args, bool highlight) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetHighlightMode(highlight); } void Tray::DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options) { - if (!CheckTrayLife(args)) - return; - gfx::Image icon; options.Get("icon", &icon); base::string16 title, content; @@ -112,20 +103,9 @@ void Tray::DisplayBalloon(mate::Arguments* args, } void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetContextMenu(menu->model()); } -bool Tray::CheckTrayLife(mate::Arguments* args) { - if (!tray_icon_) { - args->ThrowError("Tray is already destroyed"); - return false; - } else { - return true; - } -} - // static void Tray::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { diff --git a/atom/browser/api/atom_api_tray.h b/atom/browser/api/atom_api_tray.h index 6bbbe6d2d90c..1a4a498d16b9 100644 --- a/atom/browser/api/atom_api_tray.h +++ b/atom/browser/api/atom_api_tray.h @@ -47,6 +47,9 @@ class Tray : public mate::EventEmitter, void OnBalloonClicked() override; void OnBalloonClosed() override; + // mate::Wrappable: + bool IsDestroyed() const override; + void Destroy(); void SetImage(mate::Arguments* args, const gfx::Image& image); void SetPressedImage(mate::Arguments* args, const gfx::Image& image); @@ -57,8 +60,6 @@ class Tray : public mate::EventEmitter, void SetContextMenu(mate::Arguments* args, Menu* menu); private: - bool CheckTrayLife(mate::Arguments* args); - scoped_ptr tray_icon_; DISALLOW_COPY_AND_ASSIGN(Tray);