| Index: content/browser/memory/memory_monitor_android.cc
|
| diff --git a/content/browser/memory/memory_monitor_android.cc b/content/browser/memory/memory_monitor_android.cc
|
| index bbe3352176616d1c22ee170175a6b4a6484083f4..70c1e6dc4ca377cd3080b8545f38a1427a2b184b 100644
|
| --- a/content/browser/memory/memory_monitor_android.cc
|
| +++ b/content/browser/memory/memory_monitor_android.cc
|
| @@ -15,27 +15,20 @@ namespace {
|
| const size_t kMBShift = 20;
|
| }
|
|
|
| -// static
|
| -std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() {
|
| - return base::WrapUnique(new MemoryMonitorAndroid);
|
| -}
|
| -
|
| -// static
|
| -bool MemoryMonitorAndroid::Register(JNIEnv* env) {
|
| - return RegisterNativesImpl(env);
|
| -}
|
| +// An implementation of MemoryMonitorAndroid::Delegate using the Android APIs.
|
| +class MemoryMonitorAndroidDelegateImpl : public MemoryMonitorAndroid::Delegate {
|
| + public:
|
| + MemoryMonitorAndroidDelegateImpl() {}
|
| + ~MemoryMonitorAndroidDelegateImpl() override {}
|
|
|
| -MemoryMonitorAndroid::MemoryMonitorAndroid() {}
|
| + using MemoryInfo = MemoryMonitorAndroid::MemoryInfo;
|
| + void GetMemoryInfo(MemoryInfo* out) override;
|
|
|
| -MemoryMonitorAndroid::~MemoryMonitorAndroid() {}
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroidDelegateImpl);
|
| +};
|
|
|
| -int MemoryMonitorAndroid::GetFreeMemoryUntilCriticalMB() {
|
| - MemoryInfo info;
|
| - GetMemoryInfo(&info);
|
| - return (info.avail_mem - info.threshold) >> kMBShift;
|
| -}
|
| -
|
| -void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) {
|
| +void MemoryMonitorAndroidDelegateImpl::GetMemoryInfo(MemoryInfo* out) {
|
| DCHECK(out);
|
| JNIEnv* env = base::android::AttachCurrentThread();
|
| Java_MemoryMonitorAndroid_getMemoryInfo(
|
| @@ -61,6 +54,34 @@ static void GetMemoryInfoCallback(
|
| info->total_mem = total_mem;
|
| }
|
|
|
| +// static
|
| +std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() {
|
| + auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl);
|
| + return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate)));
|
| +}
|
| +
|
| +// static
|
| +bool MemoryMonitorAndroid::Register(JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +MemoryMonitorAndroid::MemoryMonitorAndroid(std::unique_ptr<Delegate> delegate)
|
| + : delegate_(std::move(delegate)) {
|
| + DCHECK(delegate_.get());
|
| +}
|
| +
|
| +MemoryMonitorAndroid::~MemoryMonitorAndroid() {}
|
| +
|
| +int MemoryMonitorAndroid::GetFreeMemoryUntilCriticalMB() {
|
| + MemoryInfo info;
|
| + GetMemoryInfo(&info);
|
| + return (info.avail_mem - info.threshold) >> kMBShift;
|
| +}
|
| +
|
| +void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) {
|
| + delegate_->GetMemoryInfo(out);
|
| +}
|
| +
|
| // Implementation of a factory function defined in memory_monitor.h.
|
| std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() {
|
| return MemoryMonitorAndroid::Create();
|
|
|