Remove CJS_RuntimeFactory
authorTom Sepez <tsepez@chromium.org>
Mon, 21 Sep 2015 23:29:20 +0000 (16:29 -0700)
committerTom Sepez <tsepez@chromium.org>
Mon, 21 Sep 2015 23:29:20 +0000 (16:29 -0700)
The Factory Design Pattern isn't buying us anything here over just new'ing
the object we want.

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1360523004 .

fpdfsdk/include/fsdk_mgr.h
fpdfsdk/include/javascript/IJavaScript.h
fpdfsdk/src/fsdk_mgr.cpp
fpdfsdk/src/javascript/JS_Runtime.cpp

index 6b7e287..270160e 100644 (file)
@@ -22,7 +22,6 @@
 #include "javascript/IJavaScript.h"
 
 class CFFL_IFormFiller;
-class CJS_RuntimeFactory;
 class CPDFSDK_ActionHandler;
 class CPDFSDK_Annot;
 class CPDFSDK_Document;
@@ -207,7 +206,6 @@ class CPDFDoc_Environment final {
   CFX_ByteString GetAppName() const { return ""; }
   IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler; }
   FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
-  CJS_RuntimeFactory* GetRuntimeFactory() const { return m_pJSRuntimeFactory; }
 
   CFFL_IFormFiller* GetIFormFiller();             // Creates if not present.
   CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();  // Creates if not present.
@@ -217,13 +215,12 @@ class CPDFDoc_Environment final {
  private:
   CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
   CPDFSDK_ActionHandler* m_pActionHandler;
-  IFXJS_Runtime* m_pJSRuntime;
+  nonstd::unique_ptr<IFXJS_Runtime> m_pJSRuntime;
   FPDF_FORMFILLINFO* const m_pInfo;
   CPDFSDK_Document* m_pSDKDoc;
   CPDF_Document* const m_pPDFDoc;
   CFFL_IFormFiller* m_pIFormFiller;
   IFX_SystemHandler* m_pSysHandler;
-  CJS_RuntimeFactory* m_pJSRuntimeFactory;
 };
 
 class CPDFSDK_Document {
index 47e4c17..3791b88 100644 (file)
@@ -133,30 +133,13 @@ class IFXJS_Context {
 
 class IFXJS_Runtime {
  public:
+  virtual ~IFXJS_Runtime() {}
+
   virtual IFXJS_Context* NewContext() = 0;
   virtual void ReleaseContext(IFXJS_Context* pContext) = 0;
   virtual IFXJS_Context* GetCurrentContext() = 0;
-
   virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0;
   virtual CPDFSDK_Document* GetReaderDocument() = 0;
-
- protected:
-  virtual ~IFXJS_Runtime() {}
-};
-
-class CJS_RuntimeFactory {
- public:
-  CJS_RuntimeFactory() : m_bInit(false), m_nRef(0) {}
-  ~CJS_RuntimeFactory();
-
-  IFXJS_Runtime* NewJSRuntime(CPDFDoc_Environment* pApp);
-  void DeleteJSRuntime(IFXJS_Runtime* pRuntime);
-  void AddRef();
-  void Release();
-
- private:
-  bool m_bInit;
-  int m_nRef;
 };
 
 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_
index 9cbb9de..5b94aef 100644 (file)
@@ -10,6 +10,7 @@
 #include "../include/fsdk_mgr.h"
 #include "../include/formfiller/FFL_FormFiller.h"
 #include "../include/javascript/IJavaScript.h"
+#include "../include/javascript/JS_Runtime.h"
 
 #if _FX_OS_ == _FX_ANDROID_
 #include "time.h"
@@ -203,31 +204,20 @@ FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() {
   return m_pEnv->FFI_GetLocalTime();
 }
 
-CJS_RuntimeFactory* GetJSRuntimeFactory() {
-  static CJS_RuntimeFactory s_JSRuntimeFactory;
-  return &s_JSRuntimeFactory;
-}
-
 CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document* pDoc,
                                          FPDF_FORMFILLINFO* pFFinfo)
     : m_pAnnotHandlerMgr(NULL),
       m_pActionHandler(NULL),
-      m_pJSRuntime(NULL),
       m_pInfo(pFFinfo),
       m_pSDKDoc(NULL),
       m_pPDFDoc(pDoc),
       m_pIFormFiller(NULL) {
   m_pSysHandler = new CFX_SystemHandler(this);
-  m_pJSRuntimeFactory = GetJSRuntimeFactory();
-  m_pJSRuntimeFactory->AddRef();
 }
 
 CPDFDoc_Environment::~CPDFDoc_Environment() {
   delete m_pIFormFiller;
   m_pIFormFiller = NULL;
-  if (m_pJSRuntime && m_pJSRuntimeFactory)
-    m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime);
-  m_pJSRuntimeFactory->Release();
 
   delete m_pSysHandler;
   m_pSysHandler = NULL;
@@ -384,8 +374,8 @@ IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() {
   if (!IsJSInitiated())
     return NULL;
   if (!m_pJSRuntime)
-    m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);
-  return m_pJSRuntime;
+    m_pJSRuntime.reset(new CJS_Runtime(this));
+  return m_pJSRuntime.get();
 }
 
 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() {
index edc8c25..43a4dcd 100644 (file)
 #include "../../include/javascript/global.h"
 #include "../../include/javascript/console.h"
 
-CJS_RuntimeFactory::~CJS_RuntimeFactory() {}
-
-IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) {
-  m_bInit = true;
-  return new CJS_Runtime(pApp);
-}
-void CJS_RuntimeFactory::AddRef() {
-  m_nRef++;
-}
-void CJS_RuntimeFactory::Release() {
-  if (m_bInit) {
-    if (--m_nRef == 0) {
-      FXJS_Release();
-      m_bInit = FALSE;
-    }
-  }
-}
-
-void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) {
-  delete (CJS_Runtime*)pRuntime;
-}
-
 /* ------------------------------ CJS_Runtime ------------------------------ */
 
 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)