Make JSExecutorFactory not derive from fbjni::Countable

Summary:
This adds a CountableJSExecutorFactory that derives from Countable. And uses that. Basically it allows code that doesn't need to know about jni or Countable not depend on it.
public

Reviewed By: astreet

Differential Revision: D2905163

fb-gh-sync-id: f2bfd5589a3185bb175ad51660b17be08ba62424
This commit is contained in:
Chris Hopman 2016-02-05 18:09:22 -08:00 committed by facebook-github-bot-2
parent fc94f1e6d0
commit 2c8802f316
5 changed files with 16 additions and 7 deletions

View File

@ -13,7 +13,7 @@ using fbsystrace::FbSystraceSection;
namespace facebook { namespace facebook {
namespace react { namespace react {
Bridge::Bridge(const RefPtr<JSExecutorFactory>& jsExecutorFactory, Callback callback) : Bridge::Bridge(const RefPtr<CountableJSExecutorFactory>& jsExecutorFactory, Callback callback) :
m_callback(std::move(callback)), m_callback(std::move(callback)),
m_destroyed(std::shared_ptr<bool>(new bool(false))) m_destroyed(std::shared_ptr<bool>(new bool(false)))
{ {

View File

@ -22,11 +22,14 @@ struct dynamic;
namespace facebook { namespace facebook {
namespace react { namespace react {
class CountableJSExecutorFactory : public JSExecutorFactory, public Countable {
};
class Bridge : public Countable { class Bridge : public Countable {
public: public:
typedef std::function<void(std::vector<MethodCall>, bool isEndOfBatch)> Callback; typedef std::function<void(std::vector<MethodCall>, bool isEndOfBatch)> Callback;
Bridge(const RefPtr<JSExecutorFactory>& jsExecutorFactory, Callback callback); Bridge(const RefPtr<CountableJSExecutorFactory>& jsExecutorFactory, Callback callback);
virtual ~Bridge(); virtual ~Bridge();
/** /**

View File

@ -5,7 +5,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <jni/Countable.h>
#include "JSModulesUnbundle.h" #include "JSModulesUnbundle.h"
namespace folly { namespace folly {
@ -21,7 +20,7 @@ class JSExecutor;
typedef std::function<void(std::string, bool)> FlushImmediateCallback; typedef std::function<void(std::string, bool)> FlushImmediateCallback;
class JSExecutorFactory : public Countable { class JSExecutorFactory {
public: public:
virtual std::unique_ptr<JSExecutor> createJSExecutor(FlushImmediateCallback cb) = 0; virtual std::unique_ptr<JSExecutor> createJSExecutor(FlushImmediateCallback cb) = 0;
virtual ~JSExecutorFactory() {}; virtual ~JSExecutorFactory() {};

View File

@ -627,7 +627,7 @@ static void create(JNIEnv* env, jobject obj, jobject executor, jobject callback,
auto bridgeCallback = [weakCallback, weakCallbackQueueThread] (std::vector<MethodCall> calls, bool isEndOfBatch) { auto bridgeCallback = [weakCallback, weakCallbackQueueThread] (std::vector<MethodCall> calls, bool isEndOfBatch) {
dispatchCallbacksToJava(weakCallback, weakCallbackQueueThread, std::move(calls), isEndOfBatch); dispatchCallbacksToJava(weakCallback, weakCallbackQueueThread, std::move(calls), isEndOfBatch);
}; };
auto nativeExecutorFactory = extractRefPtr<JSExecutorFactory>(env, executor); auto nativeExecutorFactory = extractRefPtr<CountableJSExecutorFactory>(env, executor);
auto bridge = createNew<Bridge>(nativeExecutorFactory, bridgeCallback); auto bridge = createNew<Bridge>(nativeExecutorFactory, bridgeCallback);
setCountableForJava(env, obj, std::move(bridge)); setCountableForJava(env, obj, std::move(bridge));
} }
@ -774,8 +774,14 @@ static void handleMemoryPressureCritical(JNIEnv* env, jobject obj) {
namespace executors { namespace executors {
struct CountableJSCExecutorFactory : CountableJSExecutorFactory {
virtual std::unique_ptr<JSExecutor> createJSExecutor(FlushImmediateCallback cb) override {
return JSCExecutorFactory().createJSExecutor(cb);
}
};
static void createJSCExecutor(JNIEnv *env, jobject obj) { static void createJSCExecutor(JNIEnv *env, jobject obj) {
auto executor = createNew<JSCExecutorFactory>(); auto executor = createNew<CountableJSCExecutorFactory>();
setCountableForJava(env, obj, std::move(executor)); setCountableForJava(env, obj, std::move(executor));
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <react/Bridge.h>
#include <react/Executor.h> #include <react/Executor.h>
#include <jni/fbjni.h> #include <jni/fbjni.h>
#include <jni.h> #include <jni.h>
@ -14,7 +15,7 @@ namespace react {
* This executor factory can only create a single executor instance because it moves * This executor factory can only create a single executor instance because it moves
* executorInstance global reference to the executor instance it creates. * executorInstance global reference to the executor instance it creates.
*/ */
class ProxyExecutorOneTimeFactory : public JSExecutorFactory { class ProxyExecutorOneTimeFactory : public CountableJSExecutorFactory {
public: public:
ProxyExecutorOneTimeFactory(jni::global_ref<jobject>&& executorInstance) : ProxyExecutorOneTimeFactory(jni::global_ref<jobject>&& executorInstance) :
m_executor(std::move(executorInstance)) {} m_executor(std::move(executorInstance)) {}