diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 5295af35ae27a5a59a182a8ed59dc2ddeef98045..dfbd2e0e83a90bb3a1c788f40a58e44cc9ac1e28 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -7,19 +7,26 @@ source_set("fml") { "build_config.h", "compiler_specific.h", "eintr_wrapper.h", + "export.h", "file.h", "icu_util.cc", "icu_util.h", + "log_level.h", + "log_settings.cc", + "log_settings.h", + "log_settings_state.cc", + "logging.cc", + "logging.h", "mapping.cc", "mapping.h", - "memory/thread_checker.h", - "memory/weak_ptr.h", - "memory/weak_ptr_internal.cc", - "memory/weak_ptr_internal.h", "memory/ref_counted.h", "memory/ref_counted_internal.h", "memory/ref_ptr.h", "memory/ref_ptr_internal.h", + "memory/thread_checker.h", + "memory/weak_ptr.h", + "memory/weak_ptr_internal.cc", + "memory/weak_ptr_internal.h", "message_loop.cc", "message_loop.h", "message_loop_impl.cc", @@ -136,8 +143,8 @@ executable("fml_unittests") { testonly = true sources = [ - "memory/weak_ptr_unittest.cc", "memory/ref_counted_unittest.cc", + "memory/weak_ptr_unittest.cc", "message_loop_unittests.cc", "thread_local_unittests.cc", "thread_unittests.cc", diff --git a/fml/export.h b/fml/export.h new file mode 100644 index 0000000000000000000000000000000000000000..6173bbb71c314ebe0d1f01549530bacd9551bcb2 --- /dev/null +++ b/fml/export.h @@ -0,0 +1,16 @@ +// Copyright 2017 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_FML_EXPORT_H_ +#define FLUTTER_FML_EXPORT_H_ + +#include "flutter/fml/build_config.h" + +#if OS_WIN +#define FML_EXPORT __declspec(dllimport) +#else +#define FML_EXPORT __attribute__((visibility("default"))) +#endif + +#endif // FLUTTER_FML_EXPORT_H_ diff --git a/fml/icu_util.cc b/fml/icu_util.cc index 88ae64034a5c2a7489e6b20c4d1218d7541e8518..98da2880ab07f119590c68c12578fd61c26eb8d9 100644 --- a/fml/icu_util.cc +++ b/fml/icu_util.cc @@ -8,9 +8,9 @@ #include #include "flutter/fml/build_config.h" +#include "flutter/fml/logging.h" #include "flutter/fml/mapping.h" #include "flutter/fml/paths.h" -#include "lib/fxl/logging.h" #include "third_party/icu/source/common/unicode/udata.h" namespace fml { @@ -92,7 +92,7 @@ class ICUContext { void InitializeICUOnce(const std::string& icu_data_path) { static ICUContext* context = new ICUContext(icu_data_path); - FXL_CHECK(context->IsValid()) + FML_CHECK(context->IsValid()) << "Must be able to initialize the ICU context. Tried: " << icu_data_path; } diff --git a/fml/log_level.h b/fml/log_level.h new file mode 100644 index 0000000000000000000000000000000000000000..737e80db2ff68d35f8f89c2f8a4ab4ec5f76d86f --- /dev/null +++ b/fml/log_level.h @@ -0,0 +1,28 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_FML_LOG_LEVEL_H_ +#define FLUTTER_FML_LOG_LEVEL_H_ + +namespace fml { + +typedef int LogSeverity; + +// Default log levels. Negative values can be used for verbose log levels. +constexpr LogSeverity LOG_INFO = 0; +constexpr LogSeverity LOG_WARNING = 1; +constexpr LogSeverity LOG_ERROR = 2; +constexpr LogSeverity LOG_FATAL = 3; +constexpr LogSeverity LOG_NUM_SEVERITIES = 4; + +// LOG_DFATAL is LOG_FATAL in debug mode, ERROR in normal mode +#ifdef NDEBUG +const LogSeverity LOG_DFATAL = LOG_ERROR; +#else +const LogSeverity LOG_DFATAL = LOG_FATAL; +#endif + +} // namespace fml + +#endif // FLUTTER_FML_LOG_LEVEL_H_ diff --git a/fml/log_settings.cc b/fml/log_settings.cc new file mode 100644 index 0000000000000000000000000000000000000000..80d0e22fc99d663661fbfe693feb875b720816ea --- /dev/null +++ b/fml/log_settings.cc @@ -0,0 +1,37 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/fml/log_settings.h" + +#include +#include + +#include +#include + +#include "flutter/fml/logging.h" + +namespace fml { +namespace state { + +// Defined in log_settings_state.cc. +extern LogSettings g_log_settings; + +} // namespace state + +void SetLogSettings(const LogSettings& settings) { + // Validate the new settings as we set them. + state::g_log_settings.min_log_level = + std::min(LOG_FATAL, settings.min_log_level); +} + +LogSettings GetLogSettings() { + return state::g_log_settings; +} + +int GetMinLogLevel() { + return std::min(state::g_log_settings.min_log_level, LOG_FATAL); +} + +} // namespace fml diff --git a/fml/log_settings.h b/fml/log_settings.h new file mode 100644 index 0000000000000000000000000000000000000000..ea3381dfbcabb30ddc2c5a9cc5d604c3f1fd9dc8 --- /dev/null +++ b/fml/log_settings.h @@ -0,0 +1,40 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_FML_LOG_SETTINGS_H_ +#define FLUTTER_FML_LOG_SETTINGS_H_ + +#include "flutter/fml/log_level.h" + +#include + +namespace fml { + +// Settings which control the behavior of FML logging. +struct LogSettings { + // The minimum logging level. + // Anything at or above this level will be logged (if applicable). + // Anything below this level will be silently ignored. + // + // The log level defaults to 0 (LOG_INFO). + // + // Log messages for FML_VLOG(x) (from flutter/fml/logging.h) are logged + // at level -x, so setting the min log level to negative values enables + // verbose logging. + LogSeverity min_log_level = LOG_INFO; +}; + +// Gets the active log settings for the current process. +void SetLogSettings(const LogSettings& settings); + +// Sets the active log settings for the current process. +LogSettings GetLogSettings(); + +// Gets the minimum log level for the current process. Never returs a value +// higher than LOG_FATAL. +int GetMinLogLevel(); + +} // namespace fml + +#endif // FLUTTER_FML_LOG_SETTINGS_H_ diff --git a/fml/log_settings_state.cc b/fml/log_settings_state.cc new file mode 100644 index 0000000000000000000000000000000000000000..148c0a43e877b6c66189324a990377d25d35f031 --- /dev/null +++ b/fml/log_settings_state.cc @@ -0,0 +1,14 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/fml/log_settings.h" + +namespace fml { +namespace state { + +// Declared in log_settings.cc. +LogSettings g_log_settings; + +} // namespace state +} // namespace fml diff --git a/fml/logging.cc b/fml/logging.cc new file mode 100644 index 0000000000000000000000000000000000000000..7503c8e70040946218a433ee067e511268f1bbbd --- /dev/null +++ b/fml/logging.cc @@ -0,0 +1,104 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include +#include + +#include "flutter/fml/build_config.h" +#include "flutter/fml/log_settings.h" +#include "flutter/fml/logging.h" + +#if defined(OS_ANDROID) +#include +#elif defined(OS_IOS) +#include +#endif + +namespace fml { +namespace { + +const char* const kLogSeverityNames[LOG_NUM_SEVERITIES] = {"INFO", "WARNING", + "ERROR", "FATAL"}; + +const char* GetNameForLogSeverity(LogSeverity severity) { + if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES) + return kLogSeverityNames[severity]; + return "UNKNOWN"; +} + +const char* StripDots(const char* path) { + while (strncmp(path, "../", 3) == 0) + path += 3; + return path; +} + +const char* StripPath(const char* path) { + auto p = strrchr(path, '/'); + if (p) + return p + 1; + else + return path; +} + +} // namespace + +LogMessage::LogMessage(LogSeverity severity, + const char* file, + int line, + const char* condition) + : severity_(severity), file_(file), line_(line) { + stream_ << "["; + if (severity >= LOG_INFO) + stream_ << GetNameForLogSeverity(severity); + else + stream_ << "VERBOSE" << -severity; + stream_ << ":" << (severity > LOG_INFO ? StripDots(file_) : StripPath(file_)) + << "(" << line_ << ")] "; + + if (condition) + stream_ << "Check failed: " << condition << ". "; +} + +LogMessage::~LogMessage() { + stream_ << std::endl; + +#if defined(OS_ANDROID) + android_LogPriority priority = + (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN; + switch (severity_) { + case LOG_INFO: + priority = ANDROID_LOG_INFO; + break; + case LOG_WARNING: + priority = ANDROID_LOG_WARN; + break; + case LOG_ERROR: + priority = ANDROID_LOG_ERROR; + break; + case LOG_FATAL: + priority = ANDROID_LOG_FATAL; + break; + } + __android_log_write(priority, "flutter", stream_.str().c_str()); +#elif defined(OS_IOS) + syslog(LOG_ALERT, "%s", stream_.str().c_str()); +#else + std::cerr << stream_.str(); + std::cerr.flush(); +#endif + + if (severity_ >= LOG_FATAL) { + abort(); + } +} + +int GetVlogVerbosity() { + return std::max(-1, LOG_INFO - GetMinLogLevel()); +} + +bool ShouldCreateLogMessage(LogSeverity severity) { + return severity >= GetMinLogLevel(); +} + +} // namespace fml diff --git a/fml/logging.h b/fml/logging.h new file mode 100644 index 0000000000000000000000000000000000000000..178f9b91c0129a5bac230b332592cb5536ab18ed --- /dev/null +++ b/fml/logging.h @@ -0,0 +1,95 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_FML_LOGGING_H_ +#define FLUTTER_FML_LOGGING_H_ + +#include + +#include "flutter/fml/log_level.h" +#include "flutter/fml/macros.h" + +namespace fml { + +class LogMessageVoidify { + public: + void operator&(std::ostream&) {} +}; + +class LogMessage { + public: + LogMessage(LogSeverity severity, + const char* file, + int line, + const char* condition); + ~LogMessage(); + + std::ostream& stream() { return stream_; } + + private: + std::ostringstream stream_; + const LogSeverity severity_; + const char* file_; + const int line_; + + FML_DISALLOW_COPY_AND_ASSIGN(LogMessage); +}; + +// Gets the FML_VLOG default verbosity level. +int GetVlogVerbosity(); + +// Returns true if |severity| is at or above the current minimum log level. +// LOG_FATAL and above is always true. +bool ShouldCreateLogMessage(LogSeverity severity); + +} // namespace fml + +#define FML_LOG_STREAM(severity) \ + ::fml::LogMessage(::fml::LOG_##severity, __FILE__, __LINE__, nullptr).stream() + +#define FML_LAZY_STREAM(stream, condition) \ + !(condition) ? (void)0 : ::fml::LogMessageVoidify() & (stream) + +#define FML_EAT_STREAM_PARAMETERS(ignored) \ + true || (ignored) \ + ? (void)0 \ + : ::fml::LogMessageVoidify() & \ + ::fml::LogMessage(::fml::LOG_FATAL, 0, 0, nullptr).stream() + +#define FML_LOG_IS_ON(severity) \ + (::fml::ShouldCreateLogMessage(::fml::LOG_##severity)) + +#define FML_LOG(severity) \ + FML_LAZY_STREAM(FML_LOG_STREAM(severity), FML_LOG_IS_ON(severity)) + +#define FML_CHECK(condition) \ + FML_LAZY_STREAM( \ + ::fml::LogMessage(::fml::LOG_FATAL, __FILE__, __LINE__, #condition) \ + .stream(), \ + !(condition)) + +#define FML_VLOG_IS_ON(verbose_level) \ + ((verbose_level) <= ::fml::GetVlogVerbosity()) + +// The VLOG macros log with negative verbosities. +#define FML_VLOG_STREAM(verbose_level) \ + ::fml::LogMessage(-verbose_level, __FILE__, __LINE__, nullptr).stream() + +#define FML_VLOG(verbose_level) \ + FML_LAZY_STREAM(FML_VLOG_STREAM(verbose_level), FML_VLOG_IS_ON(verbose_level)) + +#ifndef NDEBUG +#define FML_DLOG(severity) FML_LOG(severity) +#define FML_DCHECK(condition) FML_CHECK(condition) +#else +#define FML_DLOG(severity) FML_EAT_STREAM_PARAMETERS(true) +#define FML_DCHECK(condition) FML_EAT_STREAM_PARAMETERS(condition) +#endif + +#define FML_NOTREACHED() FML_DCHECK(false) + +#define FML_NOTIMPLEMENTED() \ + FML_LOG(ERROR) << "Not implemented in: " << __PRETTY_FUNCTION__ + +#endif // FLUTTER_FML_LOGGING_H_ diff --git a/fml/memory/ref_counted_internal.h b/fml/memory/ref_counted_internal.h index bbe037d47c42737fedbf18d2393774d24fef13b5..2cef256b3442c23651d08c6e22844ee6ce321804 100644 --- a/fml/memory/ref_counted_internal.h +++ b/fml/memory/ref_counted_internal.h @@ -9,8 +9,8 @@ #include +#include "flutter/fml/logging.h" #include "flutter/fml/macros.h" -#include "lib/fxl/logging.h" namespace fml { namespace internal { @@ -20,8 +20,8 @@ class RefCountedThreadSafeBase { public: void AddRef() const { #ifndef NDEBUG - FXL_DCHECK(!adoption_required_); - FXL_DCHECK(!destruction_started_); + FML_DCHECK(!adoption_required_); + FML_DCHECK(!destruction_started_); #endif ref_count_.fetch_add(1u, std::memory_order_relaxed); } @@ -30,7 +30,7 @@ class RefCountedThreadSafeBase { return ref_count_.load(std::memory_order_acquire) == 1u; } - void AssertHasOneRef() const { FXL_DCHECK(HasOneRef()); } + void AssertHasOneRef() const { FML_DCHECK(HasOneRef()); } protected: RefCountedThreadSafeBase(); @@ -39,10 +39,10 @@ class RefCountedThreadSafeBase { // Returns true if the object should self-delete. bool Release() const { #ifndef NDEBUG - FXL_DCHECK(!adoption_required_); - FXL_DCHECK(!destruction_started_); + FML_DCHECK(!adoption_required_); + FML_DCHECK(!destruction_started_); #endif - FXL_DCHECK(ref_count_.load(std::memory_order_acquire) != 0u); + FML_DCHECK(ref_count_.load(std::memory_order_acquire) != 0u); // TODO(vtl): We could add the following: // if (ref_count_.load(std::memory_order_relaxed) == 1u) { // #ifndef NDEBUG @@ -67,7 +67,7 @@ class RefCountedThreadSafeBase { #ifndef NDEBUG void Adopt() { - FXL_DCHECK(adoption_required_); + FML_DCHECK(adoption_required_); adoption_required_ = false; } #endif @@ -95,9 +95,9 @@ inline RefCountedThreadSafeBase::RefCountedThreadSafeBase() inline RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { #ifndef NDEBUG - FXL_DCHECK(!adoption_required_); + FML_DCHECK(!adoption_required_); // Should only be destroyed as a result of |Release()|. - FXL_DCHECK(destruction_started_); + FML_DCHECK(destruction_started_); #endif } diff --git a/fml/memory/ref_ptr.h b/fml/memory/ref_ptr.h index 098ea40920d6826c22b1fa19a2b06a731bd90979..3c92f5042a1b73cba1568f1e00477483d72e229e 100644 --- a/fml/memory/ref_ptr.h +++ b/fml/memory/ref_ptr.h @@ -12,9 +12,9 @@ #include #include +#include "flutter/fml/logging.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/ref_ptr_internal.h" -#include "lib/fxl/logging.h" namespace fml { @@ -107,12 +107,12 @@ class RefPtr final { T* get() const { return ptr_; } T& operator*() const { - FXL_DCHECK(ptr_); + FML_DCHECK(ptr_); return *ptr_; } T* operator->() const { - FXL_DCHECK(ptr_); + FML_DCHECK(ptr_); return ptr_; } @@ -189,7 +189,7 @@ class RefPtr final { friend RefPtr AdoptRef(T*); enum AdoptTag { ADOPT }; - RefPtr(T* ptr, AdoptTag) : ptr_(ptr) { FXL_DCHECK(ptr_); } + RefPtr(T* ptr, AdoptTag) : ptr_(ptr) { FML_DCHECK(ptr_); } T* ptr_; }; diff --git a/fml/memory/thread_checker.h b/fml/memory/thread_checker.h index 23e55f3e4d546aefd5aafe89b5b380977b605aae..2180683309d6c07677864818f908eaa3cb0fd023 100644 --- a/fml/memory/thread_checker.h +++ b/fml/memory/thread_checker.h @@ -16,8 +16,8 @@ #include #endif +#include "flutter/fml/logging.h" #include "flutter/fml/macros.h" -#include "lib/fxl/logging.h" namespace fml { @@ -58,7 +58,7 @@ class ThreadChecker final { #ifndef NDEBUG #define FML_DECLARE_THREAD_CHECKER(c) fml::ThreadChecker c #define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) \ - FXL_DCHECK((c).IsCreationThreadCurrent()) + FML_DCHECK((c).IsCreationThreadCurrent()) #else #define FML_DECLARE_THREAD_CHECKER(c) #define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) ((void)0) diff --git a/fml/memory/weak_ptr.h b/fml/memory/weak_ptr.h index cf9485452e59a67afae90b679ceb9fc90b7d6fdd..e0f5f427b3fd716c6a3b938f80c6c6568f7ceb92 100644 --- a/fml/memory/weak_ptr.h +++ b/fml/memory/weak_ptr.h @@ -10,10 +10,10 @@ #include +#include "flutter/fml/logging.h" #include "flutter/fml/memory/ref_counted.h" #include "flutter/fml/memory/thread_checker.h" #include "flutter/fml/memory/weak_ptr_internal.h" -#include "lib/fxl/logging.h" namespace fml { @@ -86,13 +86,13 @@ class WeakPtr { T& operator*() const { FML_DCHECK_CREATION_THREAD_IS_CURRENT(checker_.checker); - FXL_DCHECK(*this); + FML_DCHECK(*this); return *get(); } T* operator->() const { FML_DCHECK_CREATION_THREAD_IS_CURRENT(checker_.checker); - FXL_DCHECK(*this); + FML_DCHECK(*this); return get(); } @@ -161,7 +161,7 @@ class WeakPtrFactory { public: explicit WeakPtrFactory(T* ptr) : ptr_(ptr), flag_(fml::MakeRefCounted()) { - FXL_DCHECK(ptr_); + FML_DCHECK(ptr_); } ~WeakPtrFactory() { diff --git a/fml/memory/weak_ptr_internal.cc b/fml/memory/weak_ptr_internal.cc index e5379cbd3d0fd631fe2d1f71e0820056b3a510a4..c06db4672b5d62a559adc63ca59bfb27f53f7bf9 100644 --- a/fml/memory/weak_ptr_internal.cc +++ b/fml/memory/weak_ptr_internal.cc @@ -4,7 +4,7 @@ #include "flutter/fml/memory/weak_ptr_internal.h" -#include "lib/fxl/logging.h" +#include "flutter/fml/logging.h" namespace fml { namespace internal { @@ -13,12 +13,12 @@ WeakPtrFlag::WeakPtrFlag() : is_valid_(true) {} WeakPtrFlag::~WeakPtrFlag() { // Should be invalidated before destruction. - FXL_DCHECK(!is_valid_); + FML_DCHECK(!is_valid_); } void WeakPtrFlag::Invalidate() { // Invalidation should happen exactly once. - FXL_DCHECK(is_valid_); + FML_DCHECK(is_valid_); is_valid_ = false; } diff --git a/fml/memory/weak_ptr_internal.h b/fml/memory/weak_ptr_internal.h index dca47f1a61295f87407a708e210e00ba420e1d3b..246a2d851da87df33acd532c2621d12409f45a18 100644 --- a/fml/memory/weak_ptr_internal.h +++ b/fml/memory/weak_ptr_internal.h @@ -19,7 +19,7 @@ namespace internal { // This class in not thread-safe, though references may be released on any // thread (allowing weak pointers to be destroyed/reset/reassigned on any // thread). -class FXL_EXPORT WeakPtrFlag : public fml::RefCountedThreadSafe { +class WeakPtrFlag : public fml::RefCountedThreadSafe { public: WeakPtrFlag(); diff --git a/fml/message_loop.cc b/fml/message_loop.cc index 44a0e307c1dd14461fabe15d1b9ea5477c3f3b80..1b98148e66982b4f663769288fdf8c2057f0cb8d 100644 --- a/fml/message_loop.cc +++ b/fml/message_loop.cc @@ -20,7 +20,7 @@ FML_THREAD_LOCAL ThreadLocal tls_message_loop([](intptr_t value) { MessageLoop& MessageLoop::GetCurrent() { auto loop = reinterpret_cast(tls_message_loop.Get()); - FXL_CHECK(loop != nullptr) + FML_CHECK(loop != nullptr) << "MessageLoop::EnsureInitializedForCurrentThread was not called on " "this thread prior to message loop use."; return *loop; @@ -41,8 +41,8 @@ bool MessageLoop::IsInitializedForCurrentThread() { MessageLoop::MessageLoop() : loop_(MessageLoopImpl::Create()), task_runner_(fxl::MakeRefCounted(loop_)) { - FXL_CHECK(loop_); - FXL_CHECK(task_runner_); + FML_CHECK(loop_); + FML_CHECK(task_runner_); } MessageLoop::~MessageLoop() = default; diff --git a/fml/message_loop_impl.cc b/fml/message_loop_impl.cc index d5f8e4e17c2b70e9a24c0cf8f943da86483cadce..c960b7cdb742fb5a726443d04213872bb5b3470d 100644 --- a/fml/message_loop_impl.cc +++ b/fml/message_loop_impl.cc @@ -10,6 +10,7 @@ #include #include "flutter/fml/build_config.h" +#include "flutter/fml/logging.h" #include "flutter/fml/trace_event.h" #if OS_MACOSX @@ -43,7 +44,7 @@ MessageLoopImpl::MessageLoopImpl() : order_(0), terminated_(false) {} MessageLoopImpl::~MessageLoopImpl() = default; void MessageLoopImpl::PostTask(fxl::Closure task, fxl::TimePoint target_time) { - FXL_DCHECK(task != nullptr); + FML_DCHECK(task != nullptr); RegisterTask(task, target_time); } @@ -52,15 +53,15 @@ void MessageLoopImpl::RunExpiredTasksNow() { } void MessageLoopImpl::AddTaskObserver(intptr_t key, fxl::Closure callback) { - FXL_DCHECK(callback != nullptr); - FXL_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this) + FML_DCHECK(callback != nullptr); + FML_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this) << "Message loop task observer must be added on the same thread as the " "loop."; task_observers_[key] = std::move(callback); } void MessageLoopImpl::RemoveTaskObserver(intptr_t key) { - FXL_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this) + FML_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this) << "Message loop task observer must be removed from the same thread as " "the loop."; task_observers_.erase(key); @@ -100,7 +101,7 @@ void MessageLoopImpl::DoTerminate() { void MessageLoopImpl::RegisterTask(fxl::Closure task, fxl::TimePoint target_time) { - FXL_DCHECK(task != nullptr); + FML_DCHECK(task != nullptr); if (terminated_) { // If the message loop has already been terminated, PostTask should destruct // |task| synchronously within this function. diff --git a/fml/platform/android/jni_util.cc b/fml/platform/android/jni_util.cc index be53c3ce6184ad35639ae4dffe37935496f2fd49..86884327beb251d4a39e98a6eeedadc117260f7c 100644 --- a/fml/platform/android/jni_util.cc +++ b/fml/platform/android/jni_util.cc @@ -7,26 +7,26 @@ #include #include -#include "lib/fxl/logging.h" +#include "flutter/fml/logging.h" namespace fml { namespace jni { static JavaVM* g_jvm = nullptr; -#define ASSERT_NO_EXCEPTION() FXL_CHECK(env->ExceptionCheck() == JNI_FALSE); +#define ASSERT_NO_EXCEPTION() FML_CHECK(env->ExceptionCheck() == JNI_FALSE); void InitJavaVM(JavaVM* vm) { - FXL_DCHECK(g_jvm == nullptr); + FML_DCHECK(g_jvm == nullptr); g_jvm = vm; } JNIEnv* AttachCurrentThread() { - FXL_DCHECK(g_jvm != nullptr) + FML_DCHECK(g_jvm != nullptr) << "Trying to attach to current thread without calling InitJavaVM first."; JNIEnv* env = nullptr; jint ret = g_jvm->AttachCurrentThread(&env, nullptr); - FXL_DCHECK(JNI_OK == ret); + FML_DCHECK(JNI_OK == ret); return env; } @@ -97,10 +97,10 @@ std::vector StringArrayToVector(JNIEnv* env, jobjectArray array) { ScopedJavaLocalRef VectorToStringArray( JNIEnv* env, const std::vector& vector) { - FXL_DCHECK(env); + FML_DCHECK(env); ScopedJavaLocalRef string_clazz(env, env->FindClass("java/lang/String")); - FXL_DCHECK(!string_clazz.is_null()); + FML_DCHECK(!string_clazz.is_null()); jobjectArray joa = env->NewObjectArray(vector.size(), string_clazz.obj(), NULL); ASSERT_NO_EXCEPTION(); diff --git a/fml/platform/android/jni_weak_ref.cc b/fml/platform/android/jni_weak_ref.cc index c28f6660b667e15adedda344e2eada5d95405506..ffd2b3c85573835a86be3285f49a2053aeb0dec0 100644 --- a/fml/platform/android/jni_weak_ref.cc +++ b/fml/platform/android/jni_weak_ref.cc @@ -4,8 +4,8 @@ #include "flutter/fml/platform/android/jni_weak_ref.h" +#include "flutter/fml/logging.h" #include "flutter/fml/platform/android/jni_util.h" -#include "lib/fxl/logging.h" namespace fml { namespace jni { @@ -20,7 +20,7 @@ JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef( JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj) : obj_(env->NewWeakGlobalRef(obj)) { - FXL_DCHECK(obj_); + FML_DCHECK(obj_); } JavaObjectWeakGlobalRef::~JavaObjectWeakGlobalRef() { @@ -46,8 +46,9 @@ ScopedJavaLocalRef GetRealObject(JNIEnv* env, jweak obj) { jobject real = NULL; if (obj) { real = env->NewLocalRef(obj); - if (!real) - FXL_DLOG(ERROR) << "The real object has been deleted!"; + if (!real) { + FML_DLOG(ERROR) << "The real object has been deleted!"; + } } return ScopedJavaLocalRef(env, real); } diff --git a/fml/platform/android/message_loop_android.cc b/fml/platform/android/message_loop_android.cc index 0720c5ef8a28bd1ecb66a4e9d535e4d211e25c83..b2298cb799131562aeed914087056fe29ce32398 100644 --- a/fml/platform/android/message_loop_android.cc +++ b/fml/platform/android/message_loop_android.cc @@ -32,8 +32,8 @@ MessageLoopAndroid::MessageLoopAndroid() : looper_(AcquireLooperForThread()), timer_fd_(::timerfd_create(kClockType, TFD_NONBLOCK | TFD_CLOEXEC)), running_(false) { - FXL_CHECK(looper_.is_valid()); - FXL_CHECK(timer_fd_.is_valid()); + FML_CHECK(looper_.is_valid()); + FML_CHECK(timer_fd_.is_valid()); static const int kWakeEvents = ALOOPER_EVENT_INPUT; @@ -51,16 +51,16 @@ MessageLoopAndroid::MessageLoopAndroid() read_event_fd, // callback this // baton ); - FXL_CHECK(add_result == 1); + FML_CHECK(add_result == 1); } MessageLoopAndroid::~MessageLoopAndroid() { int remove_result = ::ALooper_removeFd(looper_.get(), timer_fd_.get()); - FXL_CHECK(remove_result == 1); + FML_CHECK(remove_result == 1); } void MessageLoopAndroid::Run() { - FXL_DCHECK(looper_.get() == ALooper_forThread()); + FML_DCHECK(looper_.get() == ALooper_forThread()); running_ = true; @@ -84,7 +84,7 @@ void MessageLoopAndroid::Terminate() { void MessageLoopAndroid::WakeUp(fxl::TimePoint time_point) { bool result = TimerRearm(timer_fd_.get(), time_point); - FXL_DCHECK(result); + FML_DCHECK(result); } void MessageLoopAndroid::OnEventFired() { diff --git a/fml/platform/android/scoped_java_ref.cc b/fml/platform/android/scoped_java_ref.cc index d682f60a4fd0569a9748143ce708a98d1e6f0e7c..f8d68c0f0df79ca819d5ef8672e5f2c5452cee1f 100644 --- a/fml/platform/android/scoped_java_ref.cc +++ b/fml/platform/android/scoped_java_ref.cc @@ -4,8 +4,8 @@ #include "flutter/fml/platform/android/scoped_java_ref.h" +#include "flutter/fml/logging.h" #include "flutter/fml/platform/android/jni_util.h" -#include "lib/fxl/logging.h" namespace fml { namespace jni { @@ -14,13 +14,13 @@ static const int kDefaultLocalFrameCapacity = 16; ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env) : env_(env) { int failed = env_->PushLocalFrame(kDefaultLocalFrameCapacity); - FXL_DCHECK(!failed); + FML_DCHECK(!failed); } ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env, int capacity) : env_(env) { int failed = env_->PushLocalFrame(capacity); - FXL_DCHECK(!failed); + FML_DCHECK(!failed); } ScopedJavaLocalFrame::~ScopedJavaLocalFrame() { @@ -31,7 +31,7 @@ JavaRef::JavaRef() : obj_(NULL) {} JavaRef::JavaRef(JNIEnv* env, jobject obj) : obj_(obj) { if (obj) { - FXL_DCHECK(env && env->GetObjectRefType(obj) == JNILocalRefType); + FML_DCHECK(env && env->GetObjectRefType(obj) == JNILocalRefType); } } @@ -41,7 +41,7 @@ JNIEnv* JavaRef::SetNewLocalRef(JNIEnv* env, jobject obj) { if (!env) { env = AttachCurrentThread(); } else { - FXL_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread. + FML_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread. } if (obj) obj = env->NewLocalRef(obj); @@ -55,7 +55,7 @@ void JavaRef::SetNewGlobalRef(JNIEnv* env, jobject obj) { if (!env) { env = AttachCurrentThread(); } else { - FXL_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread. + FML_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread. } if (obj) obj = env->NewGlobalRef(obj); @@ -66,7 +66,7 @@ void JavaRef::SetNewGlobalRef(JNIEnv* env, jobject obj) { void JavaRef::ResetLocalRef(JNIEnv* env) { if (obj_) { - FXL_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread. + FML_DCHECK(env == AttachCurrentThread()); // Is |env| on correct thread. env->DeleteLocalRef(obj_); obj_ = NULL; } diff --git a/fml/platform/darwin/message_loop_darwin.mm b/fml/platform/darwin/message_loop_darwin.mm index 6693ab23bac636335bb6ffffa406816cc58fe0bc..1ba0bb2d239ca03f9fc7bd64103fb2e3e31847ec 100644 --- a/fml/platform/darwin/message_loop_darwin.mm +++ b/fml/platform/darwin/message_loop_darwin.mm @@ -7,13 +7,15 @@ #include #include +#include "flutter/fml/logging.h" + namespace fml { static constexpr CFTimeInterval kDistantFuture = 1.0e10; MessageLoopDarwin::MessageLoopDarwin() : running_(false), loop_((CFRunLoopRef)CFRetain(CFRunLoopGetCurrent())) { - FXL_DCHECK(loop_ != nullptr); + FML_DCHECK(loop_ != nullptr); // Setup the delayed wake source. CFRunLoopTimerContext timer_context = { @@ -25,7 +27,7 @@ MessageLoopDarwin::MessageLoopDarwin() reinterpret_cast(&MessageLoopDarwin::OnTimerFire) /* callout */, &timer_context /* context */)); - FXL_DCHECK(delayed_wake_timer_ != nullptr); + FML_DCHECK(delayed_wake_timer_ != nullptr); CFRunLoopAddTimer(loop_, delayed_wake_timer_, kCFRunLoopCommonModes); } @@ -35,7 +37,7 @@ MessageLoopDarwin::~MessageLoopDarwin() { } void MessageLoopDarwin::Run() { - FXL_DCHECK(loop_ == CFRunLoopGetCurrent()); + FML_DCHECK(loop_ == CFRunLoopGetCurrent()); running_ = true; diff --git a/fml/platform/linux/message_loop_linux.cc b/fml/platform/linux/message_loop_linux.cc index 2868f137e5d71b3dd3cd3eb46712e8dbb51bf38d..8effa4d188f75e8f3bf8164df0a360b4f782f704 100644 --- a/fml/platform/linux/message_loop_linux.cc +++ b/fml/platform/linux/message_loop_linux.cc @@ -18,15 +18,15 @@ MessageLoopLinux::MessageLoopLinux() : epoll_fd_(FML_HANDLE_EINTR(::epoll_create(1 /* unused */))), timer_fd_(::timerfd_create(kClockType, TFD_NONBLOCK | TFD_CLOEXEC)), running_(false) { - FXL_CHECK(epoll_fd_.is_valid()); - FXL_CHECK(timer_fd_.is_valid()); + FML_CHECK(epoll_fd_.is_valid()); + FML_CHECK(timer_fd_.is_valid()); bool added_source = AddOrRemoveTimerSource(true); - FXL_CHECK(added_source); + FML_CHECK(added_source); } MessageLoopLinux::~MessageLoopLinux() { bool removed_source = AddOrRemoveTimerSource(false); - FXL_CHECK(removed_source); + FML_CHECK(removed_source); } bool MessageLoopLinux::AddOrRemoveTimerSource(bool add) { @@ -78,7 +78,7 @@ void MessageLoopLinux::Terminate() { void MessageLoopLinux::WakeUp(fxl::TimePoint time_point) { bool result = TimerRearm(timer_fd_.get(), time_point); - FXL_DCHECK(result); + FML_DCHECK(result); } void MessageLoopLinux::OnEventFired() { diff --git a/fml/platform/win/message_loop_win.cc b/fml/platform/win/message_loop_win.cc index 67c592b3ea3ea7c3fae413a3a952169364848217..51bfec9f280ca0987eda0ce1d832cab4dd4b8ec9 100644 --- a/fml/platform/win/message_loop_win.cc +++ b/fml/platform/win/message_loop_win.cc @@ -8,7 +8,7 @@ namespace fml { MessageLoopWin::MessageLoopWin() : timer_(CreateWaitableTimer(NULL, FALSE, NULL)) { - FXL_CHECK(timer_.is_valid()); + FML_CHECK(timer_.is_valid()); } MessageLoopWin::~MessageLoopWin() = default; @@ -17,7 +17,7 @@ void MessageLoopWin::Run() { running_ = true; while (running_) { - FXL_CHECK(WaitForSingleObject(timer_.get(), INFINITE) == 0); + FML_CHECK(WaitForSingleObject(timer_.get(), INFINITE) == 0); RunExpiredTasksNow(); } } @@ -33,7 +33,7 @@ void MessageLoopWin::WakeUp(fxl::TimePoint time_point) { if (time_point > now) { due_time.QuadPart = (time_point - now).ToNanoseconds() / -100; } - FXL_CHECK(SetWaitableTimer(timer_.get(), &due_time, 0, NULL, NULL, FALSE)); + FML_CHECK(SetWaitableTimer(timer_.get(), &due_time, 0, NULL, NULL, FALSE)); } } // namespace fml diff --git a/fml/task_runner.cc b/fml/task_runner.cc index 95f91de8e9124668542322b7e0a56e70c05b70d2..cb505d4f38c42178f7c6916959cd998c0e2c3699 100644 --- a/fml/task_runner.cc +++ b/fml/task_runner.cc @@ -8,6 +8,7 @@ #include +#include "flutter/fml/logging.h" #include "flutter/fml/message_loop.h" #include "flutter/fml/message_loop_impl.h" @@ -15,7 +16,7 @@ namespace fml { TaskRunner::TaskRunner(fxl::RefPtr loop) : loop_(std::move(loop)) { - FXL_CHECK(loop_); + FML_CHECK(loop_); } TaskRunner::~TaskRunner() = default; @@ -42,7 +43,7 @@ bool TaskRunner::RunsTasksOnCurrentThread() { void TaskRunner::RunNowOrPostTask(fxl::RefPtr runner, fxl::Closure task) { - FXL_DCHECK(runner); + FML_DCHECK(runner); if (runner->RunsTasksOnCurrentThread()) { task(); } else { diff --git a/fml/thread_local.h b/fml/thread_local.h index e450097abd6bb7771c616e12196d59b7158d508f..a36d80601f6e6669e3661b2924300597dc848307 100644 --- a/fml/thread_local.h +++ b/fml/thread_local.h @@ -8,8 +8,8 @@ #include #include "flutter/fml/build_config.h" +#include "flutter/fml/logging.h" #include "flutter/fml/macros.h" -#include "lib/fxl/logging.h" #define FML_THREAD_LOCAL_PTHREADS OS_MACOSX || OS_LINUX || OS_ANDROID @@ -59,7 +59,7 @@ class ThreadLocal { }; static inline void ThreadLocalDestroy(void* value) { - FXL_CHECK(value != nullptr); + FML_CHECK(value != nullptr); auto box = reinterpret_cast(value); box->DestroyValue(); delete box; @@ -71,14 +71,14 @@ class ThreadLocal { ThreadLocal(ThreadLocalDestroyCallback destroy) : destroy_(destroy) { auto callback = reinterpret_cast(&ThreadLocal::ThreadLocalDestroy); - FXL_CHECK(pthread_key_create(&_key, callback) == 0); + FML_CHECK(pthread_key_create(&_key, callback) == 0); } void Set(intptr_t value) { auto box = reinterpret_cast(pthread_getspecific(_key)); if (box == nullptr) { box = new Box(destroy_, value); - FXL_CHECK(pthread_setspecific(_key, box) == 0); + FML_CHECK(pthread_setspecific(_key, box) == 0); } else { box->SetValue(value); } @@ -99,7 +99,7 @@ class ThreadLocal { delete reinterpret_cast(pthread_getspecific(_key)); // Finally, collect the key - FXL_CHECK(pthread_key_delete(_key) == 0); + FML_CHECK(pthread_key_delete(_key) == 0); } private: diff --git a/fml/thread_local_unittests.cc b/fml/thread_local_unittests.cc index 70d84300f69ae6450290583b604a5202096ae2c2..9ae5f82d35e160ff1032f5b8221b4204ff5d4ec6 100644 --- a/fml/thread_local_unittests.cc +++ b/fml/thread_local_unittests.cc @@ -4,6 +4,7 @@ #include +#include "flutter/fml/logging.h" #include "flutter/fml/thread_local.h" #include "gtest/gtest.h" diff --git a/fml/unique_object.h b/fml/unique_object.h index 4feabe57d6e5afbce6227a8abf7e15b51b5fdcc7..e5f2f8690a644cb1ed41c4142cde532947a4a625 100644 --- a/fml/unique_object.h +++ b/fml/unique_object.h @@ -8,8 +8,8 @@ #include #include "flutter/fml/compiler_specific.h" +#include "flutter/fml/logging.h" #include "flutter/fml/macros.h" -#include "lib/fxl/logging.h" namespace fml { @@ -60,7 +60,7 @@ class UniqueObject { } void reset(const T& value = Traits::InvalidValue()) { - FXL_CHECK(data_.generic == Traits::InvalidValue() || + FML_CHECK(data_.generic == Traits::InvalidValue() || data_.generic != value); FreeIfNecessary(); data_.generic = value; diff --git a/travis/licenses_golden/licenses_flutter b/travis/licenses_golden/licenses_flutter index f44f0cf2094198b897f3203cfcf6bfce2d3e2634..2f1a14a2903930ced993cad3d158ba723650d109 100644 --- a/travis/licenses_golden/licenses_flutter +++ b/travis/licenses_golden/licenses_flutter @@ -655,6 +655,41 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==================================================================================================== +==================================================================================================== +LIBRARY: engine +ORIGIN: ../../../garnet/LICENSE +TYPE: LicenseType.bsd +FILE: ../../../flutter/fml/export.h +---------------------------------------------------------------------------------------------------- +Copyright 2017 The Fuchsia Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==================================================================================================== + ==================================================================================================== LIBRARY: engine ORIGIN: ../../../third_party/icu/scripts/LICENSE @@ -817,6 +852,12 @@ TYPE: LicenseType.bsd FILE: ../../../flutter/fml/build_config.h FILE: ../../../flutter/fml/compiler_specific.h FILE: ../../../flutter/fml/eintr_wrapper.h +FILE: ../../../flutter/fml/log_level.h +FILE: ../../../flutter/fml/log_settings.cc +FILE: ../../../flutter/fml/log_settings.h +FILE: ../../../flutter/fml/log_settings_state.cc +FILE: ../../../flutter/fml/logging.cc +FILE: ../../../flutter/fml/logging.h FILE: ../../../flutter/fml/memory/ref_counted.h FILE: ../../../flutter/fml/memory/ref_counted_internal.h FILE: ../../../flutter/fml/memory/ref_counted_unittest.cc @@ -1141,4 +1182,4 @@ 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. ==================================================================================================== -Total license count: 11 +Total license count: 12