Replace usage of base::Callback with std::function
base::Callback comes from libchrome which is undermaintained. Since
C++11 there's standard library support for function objects. Migrate to
a more well knowned solution for function objects.
Test: th
Change-Id: Id19bcd7e92691f57d97520f8f1f4909ca9c25b33
diff --git a/libbinderwrapper/Android.bp b/libbinderwrapper/Android.bp
index 75f43ee..87c55fa 100644
--- a/libbinderwrapper/Android.bp
+++ b/libbinderwrapper/Android.bp
@@ -26,13 +26,10 @@
"-Werror",
"-Wno-unused-parameter",
- // for libchrome
- "-Wno-sign-promo",
],
export_include_dirs: ["include"],
shared_libs: [
"libbinder",
- "libchrome",
"libutils",
],
}
diff --git a/libbinderwrapper/binder_wrapper.cc b/libbinderwrapper/binder_wrapper.cc
index ca9c1df..f5e7476 100644
--- a/libbinderwrapper/binder_wrapper.cc
+++ b/libbinderwrapper/binder_wrapper.cc
@@ -16,7 +16,7 @@
#include <binderwrapper/binder_wrapper.h>
-#include <base/logging.h>
+#include <android-base/logging.h>
#include "real_binder_wrapper.h"
diff --git a/libbinderwrapper/include/binderwrapper/binder_test_base.h b/libbinderwrapper/include/binderwrapper/binder_test_base.h
index 06543de..46eca3f 100644
--- a/libbinderwrapper/include/binderwrapper/binder_test_base.h
+++ b/libbinderwrapper/include/binderwrapper/binder_test_base.h
@@ -17,7 +17,6 @@
#ifndef SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_TEST_BASE_H_
#define SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_TEST_BASE_H_
-#include <base/macros.h>
#include <gtest/gtest.h>
namespace android {
@@ -37,7 +36,7 @@
StubBinderWrapper* binder_wrapper_; // Not owned.
private:
- DISALLOW_COPY_AND_ASSIGN(BinderTestBase);
+ BinderTestBase(const BinderTestBase&) = delete;
};
} // namespace android
diff --git a/libbinderwrapper/include/binderwrapper/binder_wrapper.h b/libbinderwrapper/include/binderwrapper/binder_wrapper.h
index a104bff..fc5708b 100644
--- a/libbinderwrapper/include/binderwrapper/binder_wrapper.h
+++ b/libbinderwrapper/include/binderwrapper/binder_wrapper.h
@@ -19,9 +19,9 @@
#include <sys/types.h>
+#include <functional>
#include <string>
-#include <base/callback.h>
#include <utils/StrongPointer.h>
namespace android {
@@ -68,9 +68,8 @@
// Registers |callback| to be invoked when |binder| dies. If another callback
// is currently registered for |binder|, it will be replaced.
- virtual bool RegisterForDeathNotifications(
- const sp<IBinder>& binder,
- const ::base::Closure& callback) = 0;
+ virtual bool RegisterForDeathNotifications(const sp<IBinder>& binder,
+ const std::function<void()>&) = 0;
// Unregisters the callback, if any, for |binder|.
virtual bool UnregisterForDeathNotifications(const sp<IBinder>& binder) = 0;
diff --git a/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h b/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h
index 9d4578e..2a7f77e 100644
--- a/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h
+++ b/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h
@@ -21,7 +21,6 @@
#include <string>
#include <vector>
-#include <base/macros.h>
#include <binder/Binder.h>
#include <binder/IBinder.h>
#include <binderwrapper/binder_wrapper.h>
@@ -98,7 +97,7 @@
const sp<IBinder>& binder) override;
sp<BBinder> CreateLocalBinder() override;
bool RegisterForDeathNotifications(const sp<IBinder>& binder,
- const ::base::Closure& callback) override;
+ const std::function<void()>& callback) override;
bool UnregisterForDeathNotifications(const sp<IBinder>& binder) override;
uid_t GetCallingUid() override;
pid_t GetCallingPid() override;
@@ -119,13 +118,13 @@
// Map from binder handle to the callback that should be invoked on binder
// death.
- std::map<sp<IBinder>, ::base::Closure> death_callbacks_;
+ std::map<sp<IBinder>, std::function<void()>> death_callbacks_;
// Values to return from GetCallingUid() and GetCallingPid();
uid_t calling_uid_;
pid_t calling_pid_;
- DISALLOW_COPY_AND_ASSIGN(StubBinderWrapper);
+ StubBinderWrapper(const StubBinderWrapper&) = delete;
};
} // namespace android
diff --git a/libbinderwrapper/real_binder_wrapper.cc b/libbinderwrapper/real_binder_wrapper.cc
index f93f183..d214ce3 100644
--- a/libbinderwrapper/real_binder_wrapper.cc
+++ b/libbinderwrapper/real_binder_wrapper.cc
@@ -16,7 +16,8 @@
#include "real_binder_wrapper.h"
-#include <base/logging.h>
+#include <android-base/logging.h>
+
#include <binder/Binder.h>
#include <binder/IBinder.h>
#include <binder/IPCThreadState.h>
@@ -29,20 +30,18 @@
// be awkward.
class RealBinderWrapper::DeathRecipient : public IBinder::DeathRecipient {
public:
- explicit DeathRecipient(const ::base::Closure& callback)
- : callback_(callback) {}
- ~DeathRecipient() = default;
+ explicit DeathRecipient(const std::function<void()>& callback)
+ : callback_(std::move(callback)) {}
+ ~DeathRecipient() = default;
- // IBinder::DeathRecipient:
- void binderDied(const wp<IBinder>& who) override {
- callback_.Run();
- }
+ // IBinder::DeathRecipient:
+ void binderDied(const wp<IBinder>& who) override { callback_(); }
private:
// Callback to run in response to binder death.
- ::base::Closure callback_;
+ std::function<void()> callback_;
- DISALLOW_COPY_AND_ASSIGN(DeathRecipient);
+ DISALLOW_COPY_AND_ASSIGN(DeathRecipient);
};
RealBinderWrapper::RealBinderWrapper() = default;
@@ -83,9 +82,8 @@
return sp<BBinder>(new BBinder());
}
-bool RealBinderWrapper::RegisterForDeathNotifications(
- const sp<IBinder>& binder,
- const ::base::Closure& callback) {
+bool RealBinderWrapper::RegisterForDeathNotifications(const sp<IBinder>& binder,
+ const std::function<void()>& callback) {
sp<DeathRecipient> recipient(new DeathRecipient(callback));
if (binder->linkToDeath(recipient) != OK) {
LOG(ERROR) << "Failed to register for death notifications on "
diff --git a/libbinderwrapper/real_binder_wrapper.h b/libbinderwrapper/real_binder_wrapper.h
index fa05383..d0468f0 100644
--- a/libbinderwrapper/real_binder_wrapper.h
+++ b/libbinderwrapper/real_binder_wrapper.h
@@ -19,7 +19,6 @@
#include <map>
-#include <base/macros.h>
#include <binderwrapper/binder_wrapper.h>
namespace android {
@@ -38,7 +37,7 @@
const sp<IBinder>& binder) override;
sp<BBinder> CreateLocalBinder() override;
bool RegisterForDeathNotifications(const sp<IBinder>& binder,
- const ::base::Closure& callback) override;
+ const std::function<void()>& callback) override;
bool UnregisterForDeathNotifications(const sp<IBinder>& binder) override;
uid_t GetCallingUid() override;
pid_t GetCallingPid() override;
@@ -50,7 +49,7 @@
// death.
std::map<sp<IBinder>, sp<DeathRecipient>> death_recipients_;
- DISALLOW_COPY_AND_ASSIGN(RealBinderWrapper);
+ RealBinderWrapper(const RealBinderWrapper&) = delete;
};
} // namespace android
diff --git a/libbinderwrapper/stub_binder_wrapper.cc b/libbinderwrapper/stub_binder_wrapper.cc
index 8e75f62..fabf122 100644
--- a/libbinderwrapper/stub_binder_wrapper.cc
+++ b/libbinderwrapper/stub_binder_wrapper.cc
@@ -16,7 +16,8 @@
#include <binderwrapper/stub_binder_wrapper.h>
-#include <base/logging.h>
+#include <android-base/logging.h>
+
#include <binder/Binder.h>
#include <binder/IBinder.h>
@@ -41,8 +42,7 @@
void StubBinderWrapper::NotifyAboutBinderDeath(const sp<IBinder>& binder) {
const auto it = death_callbacks_.find(binder);
- if (it != death_callbacks_.end())
- it->second.Run();
+ if (it != death_callbacks_.end()) it->second();
}
sp<IBinder> StubBinderWrapper::GetService(const std::string& service_name) {
@@ -62,9 +62,8 @@
return binder;
}
-bool StubBinderWrapper::RegisterForDeathNotifications(
- const sp<IBinder>& binder,
- const ::base::Closure& callback) {
+bool StubBinderWrapper::RegisterForDeathNotifications(const sp<IBinder>& binder,
+ const std::function<void()>& callback) {
death_callbacks_[binder] = callback;
return true;
}