Repository: electron/electron
File: shell/browser/api/electron_api_menu.h (C/C++)

Code before:
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_MENU_H_

#include <memory>
#include <string>

#include "base/memory/raw_ptr.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/browser/ui/electron_menu_model.h"
#include "shell/common/gin_helper/constructible.h"
#include "shell/common/gin_helper/pinnable.h"
#include "ui/base/mojom/menu_source_type.mojom-forward.h"

namespace gin {
class Arguments;
}  // namespace gin

namespace electron::api {

class BaseWindow;
class WebFrameMain;

class Menu : public gin::Wrappable<Menu>,
             public gin_helper::EventEmitterMixin<Menu>,
             public gin_helper::Constructible<Menu>,
             public gin_helper::Pinnable<Menu>,
             public ElectronMenuModel::Delegate,
             private ElectronMenuModel::Observer {
 public:
  static Menu* New(gin::Arguments* args);

  // Make public for cppgc::MakeGarbageCollected.
  explicit Menu(gin::Arguments* args);
  ~Menu() override;

  // disable copy
  Menu(const Menu&) = delete;
  Menu& operator=(const Menu&) = delete;

  // gin::Wrappable
  static const gin::WrapperInfo kWrapperInfo;
  const gin::WrapperInfo* wrapper_info() const override;
  const char* GetHumanReadableName() const override;

  // gin_helper::Constructible
  static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
  static const char* GetClassName() { return "Menu"; }

#if BUILDFLAG(IS_MAC)
  // Set the global menubar.
  static void SetApplicationMenu(Menu* menu);

Review comment (refactor):
`gin_helper::Pinnable<Menu>` should be replaced with `gin_helper::SelfKeepAlive<T>`, you can refer api::session for example.

Code after:
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_MENU_H_

#include <memory>
#include <string>

#include "base/memory/raw_ptr.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/browser/ui/electron_menu_model.h"
#include "shell/common/gin_helper/constructible.h"
#include "shell/common/gin_helper/self_keep_alive.h"
#include "ui/base/mojom/menu_source_type.mojom-forward.h"

namespace gin {
class Arguments;
}  // namespace gin

namespace electron::api {

class BaseWindow;
class WebFrameMain;

class Menu : public gin::Wrappable<Menu>,
             public gin_helper::EventEmitterMixin<Menu>,
             public gin_helper::Constructible<Menu>,
             public ElectronMenuModel::Delegate,
             private ElectronMenuModel::Observer {
 public:
  static Menu* New(gin::Arguments* args);

  // Make public for cppgc::MakeGarbageCollected.
  explicit Menu(gin::Arguments* args);
  ~Menu() override;

  // disable copy
  Menu(const Menu&) = delete;
  Menu& operator=(const Menu&) = delete;

  // gin::Wrappable
  static const gin::WrapperInfo kWrapperInfo;
  const gin::WrapperInfo* wrapper_info() const override;
  const char* GetHumanReadableName() const override;

  // gin_helper::Constructible
  static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
  static const char* GetClassName() { return "Menu"; }

#if BUILDFLAG(IS_MAC)
  // Set the global menubar.
  static void SetApplicationMenu(Menu* menu);