aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAbhishek Pandit-Subedi <abhishekpandit@google.com>2021-01-19 20:03:25 -0800
committerAbhishek Pandit-Subedi <abhishekpandit@google.com>2021-02-01 22:58:05 +0000
commit988e73dd1364fca8d26a9c84666c48efc4d24cd3 (patch)
treee6cc537e5592a9f49cb417f3af7e79dc5671af71 /include
parent7396ad40ec4456cfbd417da54de714f4465e89f8 (diff)
downloadbt-988e73dd1364fca8d26a9c84666c48efc4d24cd3.tar.gz
Make build tweaks to support newer libchrome
Android uses a very old version of libchrome and there are several breaking changes in the latest libchrome. Using BASE_VER defined in the libchrome provided by ChromeOS, we add a few abstractions: * AbstractMessageLoop to replace MessageLoop * AbstractObserverList to replace ObserverList * Work around ExportedObject::ResponseSender changing from base::RepeatingCallback to base::OnceCallback Also add a few more workarounds for libchrome differences (missing includes, unresolved symbols, etc). Bug: 177961465 Tag: #refactor Test: run --host bluetooth_test_gd Test: run --host bluetooth_test_common Change-Id: I94bc3dd4cd86bd357d869f23e95de9e53184696d
Diffstat (limited to 'include')
-rw-r--r--include/abstract_message_loop.h81
-rw-r--r--include/abstract_observer_list.h36
2 files changed, 117 insertions, 0 deletions
diff --git a/include/abstract_message_loop.h b/include/abstract_message_loop.h
new file mode 100644
index 000000000..9816e0df4
--- /dev/null
+++ b/include/abstract_message_loop.h
@@ -0,0 +1,81 @@
+//
+// Copyright 2021 Google, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#if defined(BASE_VER) && BASE_VER > 780000
+/* libchrome version < 780000 still has the old message loop. Android still uses
+ * the old libchrome version so use the basic messageloop where that's required.
+ * Elsewhere, use the SingleThreadTaskExecutor instead.
+ */
+#include <base/message_loop/message_loop_current.h>
+#include <base/message_loop/message_pump.h>
+#include <base/task/single_thread_task_executor.h>
+#include <base/test/task_environment.h>
+#include <base/threading/thread.h>
+#include <base/threading/thread_task_runner_handle.h>
+#else
+#include <base/message_loop/message_loop.h>
+#include <base/threading/thread.h>
+#endif
+
+namespace btbase {
+
+#if defined(BASE_VER) && BASE_VER > 780000
+
+class AbstractMessageLoop : public base::SingleThreadTaskExecutor {
+ public:
+ static scoped_refptr<base::SingleThreadTaskRunner> current_task_runner() {
+ return base::ThreadTaskRunnerHandle::Get();
+ }
+};
+
+class AbstractTestMessageLoop : public base::test::TaskEnvironment {
+ public:
+ static scoped_refptr<base::SingleThreadTaskRunner> current_task_runner() {
+ return base::ThreadTaskRunnerHandle::Get();
+ }
+};
+
+// Initialize the test task environment
+#define DEFINE_TEST_TASK_ENV(var) \
+ base::AbstractTestMessageLoop var { \
+ base::test::TaskEnvironment::ThreadingMode::MAIN_THREAD_ONLY \
+ }
+
+inline void set_message_loop_type_IO(base::Thread::Options& options) {
+ options.message_pump_type = base::MessagePumpType::IO;
+}
+
+#else
+class AbstractMessageLoop : public base::MessageLoop {
+ public:
+ static scoped_refptr<base::SingleThreadTaskRunner> current_task_runner() {
+ return base::MessageLoop::current()->task_runner();
+ }
+};
+
+class AbstractTestMessageLoop : public AbstractMessageLoop {};
+
+#define DEFINE_TEST_TASK_ENV(var) base::AbstractTestMessageLoop* var
+
+inline void set_message_loop_type_IO(base::Thread::Options& options) {
+ options.message_loop_type = base::MessageLoop::TYPE_IO;
+}
+
+#endif
+
+} // namespace btbase
diff --git a/include/abstract_observer_list.h b/include/abstract_observer_list.h
new file mode 100644
index 000000000..0f882599e
--- /dev/null
+++ b/include/abstract_observer_list.h
@@ -0,0 +1,36 @@
+//
+// Copyright 2021 Google, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at:
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#pragma once
+
+#include <base/observer_list.h>
+
+namespace btbase {
+#if defined(BASE_VER) && BASE_VER > 780000
+
+// Checked Observers aren't supported in the older libchrome so use unchecked
+// ones instead to preserve behavior.
+template <class ObserverType>
+class AbstractObserverList
+ : public base::ObserverList<ObserverType>::Unchecked {};
+
+#else
+
+template <class ObserverType>
+class AbstractObserverList : public base::ObserverList<ObserverType> {};
+
+#endif
+} // namespace btbase