diff --git a/atom/browser/ui/win/taskbar_host.cc b/atom/browser/ui/win/taskbar_host.cc index e3ee3fcd47c6..1ffc567f7b00 100644 --- a/atom/browser/ui/win/taskbar_host.cc +++ b/atom/browser/ui/win/taskbar_host.cc @@ -4,12 +4,9 @@ #include "atom/browser/ui/win/taskbar_host.h" -#include - #include #include "base/stl_util.h" -#include "base/win/scoped_comptr.h" #include "base/win/scoped_gdi_object.h" #include "base/strings/utf_string_conversions.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -57,13 +54,8 @@ TaskbarHost::~TaskbarHost() { bool TaskbarHost::SetThumbarButtons( HWND window, const std::vector& buttons) { - base::win::ScopedComPtr taskbar; - if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList, - nullptr, - CLSCTX_INPROC_SERVER)) || - FAILED(taskbar->HrInit())) { + if (!InitailizeTaskbar()) return false; - } callback_map_.clear(); @@ -115,30 +107,26 @@ bool TaskbarHost::SetThumbarButtons( // Finally add them to taskbar. HRESULT r; if (thumbar_buttons_added_) - r = taskbar->ThumbBarUpdateButtons(window, kMaxButtonsCount, thumb_buttons); + r = taskbar_->ThumbBarUpdateButtons(window, kMaxButtonsCount, + thumb_buttons); else - r = taskbar->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons); + r = taskbar_->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons); thumbar_buttons_added_ = true; return SUCCEEDED(r); } bool TaskbarHost::SetProgressBar(HWND window, double value) { - base::win::ScopedComPtr taskbar; - if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList, - nullptr, - CLSCTX_INPROC_SERVER)) || - FAILED(taskbar->HrInit())) { + if (!InitailizeTaskbar()) return false; - } HRESULT r; if (value > 1.0) - r = taskbar->SetProgressState(window, TBPF_INDETERMINATE); + r = taskbar_->SetProgressState(window, TBPF_INDETERMINATE); else if (value < 0) - r = taskbar->SetProgressState(window, TBPF_NOPROGRESS); + r = taskbar_->SetProgressState(window, TBPF_NOPROGRESS); else - r= taskbar->SetProgressValue(window, static_cast(value * 100), 100); + r= taskbar_->SetProgressValue(window, static_cast(value * 100), 100); return SUCCEEDED(r); } @@ -152,4 +140,15 @@ bool TaskbarHost::HandleThumbarButtonEvent(int button_id) { return false; } +bool TaskbarHost::InitailizeTaskbar() { + if (FAILED(taskbar_.CreateInstance(CLSID_TaskbarList, + nullptr, + CLSCTX_INPROC_SERVER)) || + FAILED(taskbar_->HrInit())) { + return false; + } else { + return true; + } +} + } // namespace atom diff --git a/atom/browser/ui/win/taskbar_host.h b/atom/browser/ui/win/taskbar_host.h index 22ea4cbb31a2..755f867eb132 100644 --- a/atom/browser/ui/win/taskbar_host.h +++ b/atom/browser/ui/win/taskbar_host.h @@ -5,13 +5,14 @@ #ifndef ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_ #define ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_ -#include +#include #include #include #include #include "base/callback.h" +#include "base/win/scoped_comptr.h" #include "ui/gfx/image/image.h" namespace atom { @@ -39,9 +40,15 @@ class TaskbarHost { bool HandleThumbarButtonEvent(int button_id); private: + // Initailize the taskbar object. + bool InitailizeTaskbar(); + using CallbackMap = std::map; CallbackMap callback_map_; + // The COM object of taskbar. + base::win::ScopedComPtr taskbar_; + // Whether we have already added the buttons to thumbar. bool thumbar_buttons_added_;