Flutter Engine
fml Namespace Reference

Namespaces

 benchmarking
 
 icu
 
 internal
 
 jni
 
 paths
 
 state
 
 testing
 
 tracing
 

Classes

class  AsciiTrie
 A trie for looking for ASCII prefixes. More...
 
class  AtomicObject
 
class  AutoResetWaitableEvent
 
class  BasicTaskRunner
 An interface over the ability to schedule tasks on a TaskRunner. More...
 
class  BitConverter
 
class  CFRef
 
class  ChronoTimestampProvider
 
class  CommandLine
 
class  ConcurrentMessageLoop
 
class  ConcurrentTaskRunner
 
class  CountDownLatch
 
class  DartTimestampProvider
 TimestampProvider implementation that is backed by Dart_TimelineGetTicks. More...
 
class  DataMapping
 
struct  DebugTaskRunnerChecker
 
struct  DebugThreadChecker
 
class  DelayedTask
 
class  FileMapping
 
class  LogMessage
 
class  LogMessageVoidify
 
struct  LogSettings
 
class  MallocMapping
 A Mapping like NonOwnedMapping, but uses Free as its release proc. More...
 
class  ManualResetWaitableEvent
 
class  Mapping
 
class  MessageLoop
 
class  MessageLoopAndroid
 
class  MessageLoopDarwin
 
class  MessageLoopFuchsia
 
class  MessageLoopImpl
 
class  MessageLoopLinux
 
class  MessageLoopTaskQueues
 
class  MessageLoopWin
 
class  NativeLibrary
 
class  NonOwnedMapping
 
class  PlatformSemaphore
 
class  RasterThreadMerger
 
class  RefCountedThreadSafe
 
class  RefPtr
 
class  scoped_nsobject
 
class  scoped_nsobject< id >
 
class  scoped_nsobject< NSAutoreleasePool >
 
class  scoped_nsprotocol
 
class  ScopedBlock
 
class  ScopedCleanupClosure
 Wraps a closure that is invoked in the destructor unless released by the caller. More...
 
class  ScopedSetLogSettings
 
class  ScopedTemporaryDirectory
 
class  Semaphore
 
class  SharedLock
 
class  SharedMutex
 
class  SharedMutexPosix
 
class  SharedMutexStd
 
class  SharedThreadMerger
 
class  Status
 
class  SymbolMapping
 
class  SyncSwitch
 
class  TaskQueueEntry
 
class  TaskQueueId
 
class  TaskRunner
 
class  TaskRunnerAffineWeakPtr
 
class  TaskRunnerAffineWeakPtrFactory
 
class  TaskRunnerChecker
 
class  TaskSource
 
class  Thread
 
class  ThreadChecker
 
class  ThreadLocalUniquePtr
 
class  TimeDelta
 
class  TimePoint
 
class  TimestampProvider
 
class  UniqueLock
 
struct  UniqueLooperTraits
 
class  UniqueObject
 
class  Wakeable
 
class  WeakPtr
 
class  WeakPtrFactory
 

Typedefs

typedef AsciiTrie::TrieNode TrieNode
 
typedef AsciiTrie::TrieNodePtr TrieNodePtr
 
using Base32DecodeConverter = BitConverter< 5, 8, 16 >
 
using Base32EncodeConverter = BitConverter< 8, 5, 16 >
 
using closure = std::function< void()>
 
using DelayedTaskQueue = std::priority_queue< DelayedTask, std::deque< DelayedTask >, std::greater< DelayedTask > >
 
using FileVisitor = std::function< bool(const fml::UniqueFD &directory, const std::string &filename)>
 
typedef int LogSeverity
 
using WideStringConvertor = std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t >
 
typedef void * RasterThreadMergerId
 
using Milliseconds = std::chrono::duration< double, std::milli >
 
using UniqueFD = UniqueObject< int, internal::os_unix::UniqueFDTraits >
 
using UniqueDir = UniqueObject< DIR *, internal::os_unix::UniqueDirTraits >
 

Enumerations

enum  FilePermission {
  FilePermission::kRead,
  FilePermission::kWrite,
  FilePermission::kReadWrite
}
 
enum  FlushType {
  FlushType::kSingle,
  FlushType::kAll
}
 
enum  OwnershipPolicy {
  OwnershipPolicy::Assume,
  OwnershipPolicy::Retain
}
 
enum  RasterThreadStatus {
  RasterThreadStatus::kRemainsMerged,
  RasterThreadStatus::kRemainsUnmerged,
  RasterThreadStatus::kUnmergedNow
}
 
enum  StatusCode {
  StatusCode::kOk,
  StatusCode::kCancelled,
  StatusCode::kUnknown,
  StatusCode::kInvalidArgument,
  StatusCode::kDeadlineExceeded,
  StatusCode::kNotFound,
  StatusCode::kAlreadyExists,
  StatusCode::kPermissionDenied,
  StatusCode::kResourceExhausted,
  StatusCode::kFailedPrecondition,
  StatusCode::kAborted,
  StatusCode::kOutOfRange,
  StatusCode::kUnimplemented,
  StatusCode::kInternal,
  StatusCode::kUnavailable,
  StatusCode::kDataLoss,
  StatusCode::kUnauthenticated
}
 
enum  TaskSourceGrade {
  TaskSourceGrade::kUserInteraction,
  TaskSourceGrade::kDartMicroTasks,
  TaskSourceGrade::kUnspecified
}
 

Functions

static std::string DemangleSymbolName (const std::string &mangled)
 
static std::string GetSymbolName (void *symbol)
 
std::string BacktraceHere (size_t offset)
 
static std::string SignalNameToString (int signal)
 
static void ToggleSignalHandlers (bool set)
 
static void SignalHandler (int signal)
 
void InstallCrashHandler ()
 
bool IsCrashHandlingSupported ()
 
std::pair< bool, std::string > Base32Encode (std::string_view input)
 
std::pair< bool, std::string > Base32Decode (const std::string &input)
 
std::vector< std::string > CommandLineToArgv (const CommandLine &command_line)
 
template<typename InputIterator >
CommandLine CommandLineFromIteratorsFindFirstPositionalArg (InputIterator first, InputIterator last, InputIterator *first_positional_arg)
 
template<typename InputIterator >
CommandLine CommandLineFromIterators (InputIterator first, InputIterator last)
 
template<typename InputIterator >
CommandLine CommandLineFromIteratorsWithArgv0 (const std::string &argv0, InputIterator first, InputIterator last)
 
CommandLine CommandLineFromArgcArgv (int argc, const char *const *argv)
 
template<typename StringType >
CommandLine CommandLineFromInitializerList (std::initializer_list< StringType > argv)
 
static fml::UniqueFD CreateDirectory (const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
 
fml::UniqueFD CreateDirectory (const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission)
 
bool VisitFilesRecursively (const fml::UniqueFD &directory, const FileVisitor &visitor)
 
fml::UniqueFD OpenFileReadOnly (const fml::UniqueFD &base_directory, const char *path)
 
fml::UniqueFD OpenDirectoryReadOnly (const fml::UniqueFD &base_directory, const char *path)
 
bool RemoveFilesInDirectory (const fml::UniqueFD &directory)
 
bool RemoveDirectoryRecursively (const fml::UniqueFD &parent, const char *directory_name)
 
std::string CreateTemporaryDirectory ()
 
fml::UniqueFD OpenFile (const char *path, bool create_if_necessary, FilePermission permission)
 This can open a directory on POSIX, but not on Windows. More...
 
fml::UniqueFD OpenFile (const fml::UniqueFD &base_directory, const char *path, bool create_if_necessary, FilePermission permission)
 This can open a directory on POSIX, but not on Windows. More...
 
fml::UniqueFD OpenDirectory (const char *path, bool create_if_necessary, FilePermission permission)
 
fml::UniqueFD OpenDirectory (const fml::UniqueFD &base_directory, const char *path, bool create_if_necessary, FilePermission permission)
 
fml::UniqueFD Duplicate (fml::UniqueFD::element_type descriptor)
 
bool IsDirectory (const fml::UniqueFD &directory)
 
bool IsDirectory (const fml::UniqueFD &base_directory, const char *path)
 
bool IsFile (const std::string &path)
 
bool TruncateFile (const fml::UniqueFD &file, size_t size)
 
bool FileExists (const fml::UniqueFD &base_directory, const char *path)
 
bool UnlinkDirectory (const char *path)
 
bool UnlinkDirectory (const fml::UniqueFD &base_directory, const char *path)
 
bool UnlinkFile (const char *path)
 
bool UnlinkFile (const fml::UniqueFD &base_directory, const char *path)
 
bool WriteAtomically (const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
 
bool VisitFiles (const fml::UniqueFD &directory, const FileVisitor &visitor)
 
template<class Type >
constexpr void HashCombineSeed (std::size_t &seed, Type arg)
 
template<class Type , class... Rest>
constexpr void HashCombineSeed (std::size_t &seed, Type arg, Rest... other_args)
 
constexpr std::size_t HashCombine ()
 
template<class... Type>
constexpr std::size_t HashCombine (Type... args)
 
std::string HexEncode (std::string_view input)
 
void SetLogSettings (const LogSettings &settings)
 
LogSettings GetLogSettings ()
 
int GetMinLogLevel ()
 
int GetVlogVerbosity ()
 
bool ShouldCreateLogMessage (LogSeverity severity)
 
void KillProcess ()
 
template<typename T >
internal::CopyableLambda< T > MakeCopyable (T lambda)
 
 TEST (MallocMapping, EmptyContructor)
 
 TEST (MallocMapping, NotEmptyContructor)
 
 TEST (MallocMapping, MoveConstructor)
 
 TEST (MallocMapping, Copy)
 
 TEST (MallocMapping, Release)
 
template<typename T >
RefPtr< T > AdoptRef (T *ptr)
 
template<typename T >
RefPtr< T > Ref (T *ptr)
 
template<typename T , typename... Args>
RefPtr< T > MakeRefCounted (Args &&... args)
 
static ALooper * AcquireLooperForThread ()
 
bool IsPlatformVersionAtLeast (size_t major, size_t minor=0, size_t patch=0)
 
template<class C >
void swap (scoped_nsprotocol< C > &p1, scoped_nsprotocol< C > &p2)
 
template<class C >
bool operator== (C p1, const scoped_nsprotocol< C > &p2)
 
template<class C >
bool operator!= (C p1, const scoped_nsprotocol< C > &p2)
 
NSRange RangeForCharacterAtIndex (NSString *text, NSUInteger index)
 
NSRange RangeForCharactersInRange (NSString *text, NSRange range)
 
void ExecuteAfterTaskObservers ()
 
void CurrentMessageLoopAddAfterTaskObserver (intptr_t key, fit::closure observer)
 
void CurrentMessageLoopRemoveAfterTaskObserver (intptr_t key)
 
bool TimerRearm (int fd, fml::TimePoint time_point)
 Rearms the timer to expire at the given time point. More...
 
bool TimerDrain (int fd)
 
static int ToPosixAccessFlags (FilePermission permission)
 
static int ToPosixCreateModeFlags (FilePermission permission)
 
static int ToPosixProtectionFlags (std::initializer_list< FileMapping::Protection > protection_flags)
 
static bool IsWritable (std::initializer_list< FileMapping::Protection > protection_flags)
 
char * strdup (const char *str1)
 
std::string GetLastErrorMessage ()
 
static std::string GetFullHandlePath (const fml::UniqueFD &handle)
 
static std::string GetAbsolutePath (const fml::UniqueFD &base_directory, const char *subpath)
 
static std::wstring GetTemporaryDirectoryPath ()
 
static DWORD GetDesiredAccessFlags (FilePermission permission)
 
static DWORD GetShareFlags (FilePermission permission)
 
static DWORD GetFileAttributesForUtf8Path (const char *absolute_path)
 
static DWORD GetFileAttributesForUtf8Path (const fml::UniqueFD &base_directory, const char *path)
 
static bool IsWritable (std::initializer_list< FileMapping::Protection > protection_flags)
 
static bool IsExecutable (std::initializer_list< FileMapping::Protection > protection_flags)
 
std::wstring StringToWideString (const std::string &str)
 
std::string WideStringToString (const std::wstring &wstr)
 
template<typename T , std::size_t N>
constexpr std::size_t size (T(&array)[N])
 
 TEST (CountDownLatchTest, CanWaitOnZero)
 
 TEST (CountDownLatchTest, CanWait)
 
template<typename ConditionFn >
bool WaitWithTimeoutImpl (std::unique_lock< std::mutex > *locker, std::condition_variable *cv, ConditionFn condition, TimeDelta timeout)
 
fml::TimePoint ChronoTicksSinceEpoch ()
 
fml::TimePoint DartTimelineTicksSinceEpoch ()
 
template<typename T >
Milliseconds RefreshRateToFrameBudget (T refresh_rate)
 
template<typename Clock , typename Duration >
static int64_t NanosSinceEpoch (std::chrono::time_point< Clock, Duration > time_point)
 
template<class T , class Traits >
void swap (const UniqueObject< T, Traits > &a, const UniqueObject< T, Traits > &b)
 
template<class T , class Traits >
bool operator== (const T &value, const UniqueObject< T, Traits > &object)
 
template<class T , class Traits >
bool operator!= (const T &value, const UniqueObject< T, Traits > &object)
 

Variables

static std::string kKUnknownFrameName = "Unknown"
 
static size_t kKnownSignalHandlers []
 
static std::string kKUnknownFrameName = "Unknown"
 
static constexpr char kEncoding [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
 
static constexpr signed char kDecodeMap []
 
static constexpr int kDecodeMapSize
 
static constexpr char kEncoding [] = "0123456789abcdef"
 
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
 
const LogSeverity LOG_DFATAL = LOG_FATAL
 
FML_THREAD_LOCAL ThreadLocalUniquePtr< MessageLooptls_message_loop
 
FML_THREAD_LOCAL ThreadLocalUniquePtr< TaskSourceGradeHolder > tls_task_source_grade
 
static const TaskQueueId _kUnmerged = TaskQueueId(TaskQueueId::kUnmerged)
 
static constexpr int kClockType = CLOCK_MONOTONIC
 
static constexpr CFTimeInterval kDistantFuture = 1.0e10
 
thread_local std::map< intptr_t, fit::closure > tTaskObservers
 
static constexpr int kClockType = CLOCK_MONOTONIC
 
constexpr Milliseconds kDefaultFrameBudget = Milliseconds(1s) / 60
 

Typedef Documentation

◆ Base32DecodeConverter

using fml::Base32DecodeConverter = typedef BitConverter<5, 8, 16>

Definition at line 49 of file base32.h.

◆ Base32EncodeConverter

using fml::Base32EncodeConverter = typedef BitConverter<8, 5, 16>

Definition at line 50 of file base32.h.

◆ closure

using fml::closure = typedef std::function<void()>

Definition at line 14 of file closure.h.

◆ DelayedTaskQueue

using fml::DelayedTaskQueue = typedef std::priority_queue<DelayedTask, std::deque<DelayedTask>, std::greater<DelayedTask> >

Definition at line 44 of file delayed_task.h.

◆ FileVisitor

using fml::FileVisitor = typedef std::function<bool(const fml::UniqueFD& directory, const std::string& filename)>

Signature of a callback on a file in directory with filename (relative to directory). The returned bool should be false if and only if further traversal should be stopped. For example, a file-search visitor may return false when the file is found so no more visiting is needed.

Definition at line 98 of file file.h.

◆ LogSeverity

typedef int fml::LogSeverity

Definition at line 10 of file log_level.h.

◆ Milliseconds

using fml::Milliseconds = typedef std::chrono::duration<double, std::milli>

Definition at line 18 of file time_delta.h.

◆ RasterThreadMergerId

Definition at line 17 of file shared_thread_merger.h.

◆ TrieNode

Definition at line 10 of file ascii_trie.cc.

◆ TrieNodePtr

Definition at line 11 of file ascii_trie.cc.

◆ UniqueDir

Definition at line 101 of file unique_fd.h.

◆ UniqueFD

Definition at line 100 of file unique_fd.h.

◆ WideStringConvertor

using fml::WideStringConvertor = typedef std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>

Definition at line 15 of file wstring_conversion.h.

Enumeration Type Documentation

◆ FilePermission

enum fml::FilePermission
strong
Enumerator
kRead 
kWrite 
kReadWrite 

Definition at line 24 of file file.h.

◆ FlushType

enum fml::FlushType
strong
Enumerator
kSingle 
kAll 

Definition at line 54 of file message_loop_task_queues.h.

54  {
55  kSingle,
56  kAll,
57 };

◆ OwnershipPolicy

enum fml::OwnershipPolicy
strong
Enumerator
Assume 
Retain 

Definition at line 17 of file scoped_block.h.

17  {
18  // The scoped object takes ownership of an object by taking over an existing
19  // ownership claim.
20  Assume,
21 
22  // The scoped object will retain the object and any initial ownership is
23  // not changed.
24  Retain,
25 };

◆ RasterThreadStatus

Enumerator
kRemainsMerged 
kRemainsUnmerged 
kUnmergedNow 

Definition at line 20 of file raster_thread_merger.h.

◆ StatusCode

enum fml::StatusCode
strong
Enumerator
kOk 
kCancelled 
kUnknown 
kInvalidArgument 
kDeadlineExceeded 
kNotFound 
kAlreadyExists 
kPermissionDenied 
kResourceExhausted 
kFailedPrecondition 
kAborted 
kOutOfRange 
kUnimplemented 
kInternal 
kUnavailable 
kDataLoss 
kUnauthenticated 

Definition at line 12 of file status.h.

◆ TaskSourceGrade

enum fml::TaskSourceGrade
strong

Categories of work dispatched to MessageLoopTaskQueues dispatcher. By specifying the TaskSourceGrade, you indicate the task's importance to the dispatcher.

Enumerator
kUserInteraction 

This TaskSourceGrade indicates that a task is critical to user interaction.

kDartMicroTasks 

This TaskSourceGrade indicates that a task corresponds to servicing a dart micro task. These aren't critical to user interaction.

kUnspecified 

The absence of a specialized TaskSourceGrade.

Definition at line 15 of file task_source_grade.h.

15  {
16  /// This `TaskSourceGrade` indicates that a task is critical to user
17  /// interaction.
19  /// This `TaskSourceGrade` indicates that a task corresponds to servicing a
20  /// dart micro task. These aren't critical to user interaction.
22  /// The absence of a specialized `TaskSourceGrade`.
24 };
The absence of a specialized TaskSourceGrade.

Function Documentation

◆ AcquireLooperForThread()

static ALooper* fml::AcquireLooperForThread ( )
static

Definition at line 16 of file message_loop_android.cc.

References flutter::data, FML_CHECK, FML_DCHECK, fml::UniqueObject< T, Traits >::get(), result, fml::MessageLoopImpl::RunExpiredTasksNow(), TFD_CLOEXEC, TFD_NONBLOCK, TimerDrain(), timerfd_create(), and TimerRearm().

16  {
17  ALooper* looper = ALooper_forThread();
18 
19  if (looper == nullptr) {
20  // No looper has been configured for the current thread. Create one and
21  // return the same.
22  looper = ALooper_prepare(0);
23  }
24 
25  // The thread already has a looper. Acquire a reference to the same and return
26  // it.
27  ALooper_acquire(looper);
28  return looper;
29 }

◆ AdoptRef()

template<typename T >
RefPtr< T > fml::AdoptRef ( T *  ptr)
inline

Definition at line 218 of file ref_ptr.h.

Referenced by flutter_runner::testing::FakePlatformMessageResponse::Create(), fml::NativeLibrary::Create(), fml::NativeLibrary::CreateForCurrentProcess(), and fml::NativeLibrary::CreateWithHandle().

218  {
219 #ifndef NDEBUG
220  ptr->Adopt();
221 #endif
222  return RefPtr<T>(ptr, RefPtr<T>::ADOPT);
223 }

◆ BacktraceHere()

std::string fml::BacktraceHere ( size_t  offset = 0)

Definition at line 58 of file backtrace.cc.

References GetSymbolName().

Referenced by SignalHandler(), and fml::testing::TEST().

58  {
59  constexpr size_t kMaxFrames = 256;
60  void* symbols[kMaxFrames];
61  const auto available_frames = ::backtrace(symbols, kMaxFrames);
62  if (available_frames <= 0) {
63  return "";
64  }
65 
66  std::stringstream stream;
67  for (int i = 1 + offset; i < available_frames; ++i) {
68  stream << "Frame " << i - 1 - offset << ": " << symbols[i] << " "
69  << GetSymbolName(symbols[i]) << std::endl;
70  }
71  return stream.str();
72 }
static std::string GetSymbolName(void *symbol)
Definition: backtrace.cc:49

◆ Base32Decode()

std::pair< bool, std::string > fml::Base32Decode ( const std::string &  input)

Definition at line 54 of file base32.cc.

References fml::BitConverter< from_length, to_length, buffer_length >::Append(), fml::BitConverter< from_length, to_length, buffer_length >::CanExtract(), fml::BitConverter< from_length, to_length, buffer_length >::Extract(), fml::BitConverter< from_length, to_length, buffer_length >::Peek(), and result.

Referenced by flutter::ParseBase32(), and TEST().

54  {
55  std::string result;
56  Base32DecodeConverter converter;
57  for (char c : input) {
58  int map_index = c - '2';
59  if (map_index < 0 || map_index >= kDecodeMapSize ||
60  kDecodeMap[map_index] == -1) {
61  return {false, result};
62  }
63  converter.Append(kDecodeMap[map_index]);
64  if (converter.CanExtract()) {
65  result.push_back(converter.Extract());
66  }
67  }
68  if (converter.Peek() != 0) {
69  // The padding should always be zero. Return false if not.
70  return {false, result};
71  }
72  return {true, result};
73 }
BitConverter< 5, 8, 16 > Base32DecodeConverter
Definition: base32.h:49
static constexpr int kDecodeMapSize
Definition: base32.cc:51
static constexpr signed char kDecodeMap[]
Definition: base32.cc:45
GAsyncResult * result

◆ Base32Encode()

std::pair< bool, std::string > fml::Base32Encode ( std::string_view  input)

Definition at line 14 of file base32.cc.

References fml::BitConverter< from_length, to_length, buffer_length >::Append(), fml::BitConverter< from_length, to_length, buffer_length >::BitsAvailable(), fml::BitConverter< from_length, to_length, buffer_length >::CanAppend(), fml::BitConverter< from_length, to_length, buffer_length >::CanExtract(), fml::BitConverter< from_length, to_length, buffer_length >::Extract(), and fml::BitConverter< from_length, to_length, buffer_length >::Peek().

Referenced by flutter::Shell::RegisterImageDecoder(), and TEST().

14  {
15  if (input.empty()) {
16  return {true, ""};
17  }
18 
19  if (input.size() > std::numeric_limits<size_t>::max() / 8) {
20  return {false, ""};
21  }
22 
23  std::string output;
24  const size_t encoded_length = (input.size() * 8 + 4) / 5;
25  output.reserve(encoded_length);
26 
27  Base32EncodeConverter converter;
28  converter.Append(static_cast<uint8_t>(input[0]));
29  size_t next_byte_index = 1;
30 
31  while (converter.CanExtract()) {
32  output.push_back(kEncoding[converter.Extract()]);
33  if (converter.CanAppend() && next_byte_index < input.size()) {
34  converter.Append(static_cast<uint8_t>(input[next_byte_index++]));
35  }
36  }
37 
38  if (converter.BitsAvailable() > 0) {
39  output.push_back(kEncoding[converter.Peek()]);
40  }
41 
42  return {true, output};
43 }
BitConverter< 8, 5, 16 > Base32EncodeConverter
Definition: base32.h:50
static constexpr char kEncoding[]
Definition: base32.cc:12

◆ ChronoTicksSinceEpoch()

fml::TimePoint fml::ChronoTicksSinceEpoch ( )

Definition at line 21 of file chrono_timestamp_provider.cc.

References fml::ChronoTimestampProvider::Instance(), and fml::ChronoTimestampProvider::Now().

Referenced by fml::testing::CountRemainingTasks(), fml::ChronoTimestampProvider::Instance(), fml::testing::TEST(), and TEST().

21  {
22  return ChronoTimestampProvider::Instance().Now();
23 }

◆ CommandLineFromArgcArgv()

CommandLine fml::CommandLineFromArgcArgv ( int  argc,
const char *const *  argv 
)
inline

Definition at line 222 of file command_line.h.

References CommandLineFromIterators().

Referenced by FlutterEngineInitialize(), GetTestTimeoutFromArgs(), benchmarking::Main(), and main().

222  {
223  return CommandLineFromIterators(argv, argv + argc);
224 }
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)
Definition: command_line.h:201

◆ CommandLineFromInitializerList()

template<typename StringType >
CommandLine fml::CommandLineFromInitializerList ( std::initializer_list< StringType >  argv)
inline

Definition at line 229 of file command_line.h.

References CommandLineFromIterators(), and CommandLineToArgv().

Referenced by flutter::testing::TEST().

230  {
231  return CommandLineFromIterators(argv.begin(), argv.end());
232 }
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)
Definition: command_line.h:201

◆ CommandLineFromIterators()

template<typename InputIterator >
CommandLine fml::CommandLineFromIterators ( InputIterator  first,
InputIterator  last 
)
inline

Definition at line 201 of file command_line.h.

Referenced by CommandLineFromArgcArgv(), CommandLineFromInitializerList(), flutter::CommandLineFromNSProcessInfo(), and flutter::FlutterMain::GetSettings().

202  {
203  return CommandLineFromIteratorsFindFirstPositionalArg<InputIterator>(
204  first, last, nullptr);
205 }

◆ CommandLineFromIteratorsFindFirstPositionalArg()

template<typename InputIterator >
CommandLine fml::CommandLineFromIteratorsFindFirstPositionalArg ( InputIterator  first,
InputIterator  last,
InputIterator *  first_positional_arg 
)
inline

Definition at line 181 of file command_line.h.

References fml::internal::CommandLineBuilder::Build(), and fml::internal::CommandLineBuilder::ProcessArg().

184  {
185  if (first_positional_arg)
186  *first_positional_arg = last;
187  internal::CommandLineBuilder builder;
188  for (auto it = first; it < last; ++it) {
189  if (builder.ProcessArg(*it)) {
190  if (first_positional_arg)
191  *first_positional_arg = it;
192  }
193  }
194  return builder.Build();
195 }

◆ CommandLineFromIteratorsWithArgv0()

template<typename InputIterator >
CommandLine fml::CommandLineFromIteratorsWithArgv0 ( const std::string &  argv0,
InputIterator  first,
InputIterator  last 
)
inline

Definition at line 211 of file command_line.h.

References fml::internal::CommandLineBuilder::Build(), and fml::internal::CommandLineBuilder::ProcessArg().

213  {
214  internal::CommandLineBuilder builder;
215  builder.ProcessArg(argv0);
216  for (auto it = first; it < last; ++it)
217  builder.ProcessArg(*it);
218  return builder.Build();
219 }

◆ CommandLineToArgv()

std::vector< std::string > fml::CommandLineToArgv ( const CommandLine command_line)

Definition at line 141 of file command_line.cc.

References fml::CommandLine::argv0(), fml::CommandLine::has_argv0(), fml::CommandLine::options(), fml::CommandLine::positional_args(), and size().

Referenced by CommandLineFromInitializerList().

141  {
142  if (!command_line.has_argv0()) {
143  return std::vector<std::string>();
144  }
145 
146  std::vector<std::string> argv;
147  const std::vector<CommandLine::Option>& options = command_line.options();
148  const std::vector<std::string>& positional_args =
149  command_line.positional_args();
150  // Reserve space for argv[0], options, maybe a "--" (if needed), and the
151  // positional arguments.
152  argv.reserve(1u + options.size() + 1u + positional_args.size());
153 
154  argv.push_back(command_line.argv0());
155  for (const auto& option : options) {
156  if (option.value.empty()) {
157  argv.push_back("--" + option.name);
158  } else {
159  argv.push_back("--" + option.name + "=" + option.value);
160  }
161  }
162 
163  if (!positional_args.empty()) {
164  // Insert a "--" if necessary.
165  if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' &&
166  positional_args[0][1] == '-') {
167  argv.push_back("--");
168  }
169 
170  argv.insert(argv.end(), positional_args.begin(), positional_args.end());
171  }
172 
173  return argv;
174 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ CreateDirectory() [1/2]

static fml::UniqueFD fml::CreateDirectory ( const fml::UniqueFD base_directory,
const std::vector< std::string > &  components,
FilePermission  permission,
size_t  index 
)
static

Definition at line 12 of file file.cc.

References FML_DCHECK, and OpenDirectory().

Referenced by CreateDirectory(), GetFileAttributesForUtf8Path(), TEST(), and flutter::testing::TEST_F().

15  {
16  FML_DCHECK(index <= components.size());
17 
18  const char* file_path = components[index].c_str();
19 
20  auto directory = OpenDirectory(base_directory, file_path, true, permission);
21 
22  if (!directory.is_valid()) {
23  return {};
24  }
25 
26  if (index == components.size() - 1) {
27  return directory;
28  }
29 
30  return CreateDirectory(directory, components, permission, index + 1);
31 }
#define FML_DCHECK(condition)
Definition: logging.h:86
#define CreateDirectory
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:96

◆ CreateDirectory() [2/2]

fml::UniqueFD fml::CreateDirectory ( const fml::UniqueFD base_directory,
const std::vector< std::string > &  components,
FilePermission  permission 
)

Definition at line 33 of file file.cc.

References CreateDirectory(), and IsDirectory().

35  {
36  if (!IsDirectory(base_directory)) {
37  return {};
38  }
39 
40  if (components.size() == 0) {
41  return {};
42  }
43 
44  return CreateDirectory(base_directory, components, permission, 0);
45 }
#define CreateDirectory
bool IsDirectory(const fml::UniqueFD &directory)
Definition: file_posix.cc:126

◆ CreateTemporaryDirectory()

std::string fml::CreateTemporaryDirectory ( )

Definition at line 24 of file file_posix.cc.

References result.

Referenced by GetFileAttributesForUtf8Path(), and TEST().

24  {
25  char directory_name[] = "/tmp/flutter_XXXXXXXX";
26  auto* result = ::mkdtemp(directory_name);
27  if (result == nullptr) {
28  return "";
29  }
30  return {result};
31 }
GAsyncResult * result

◆ CurrentMessageLoopAddAfterTaskObserver()

void fml::CurrentMessageLoopAddAfterTaskObserver ( intptr_t  key,
fit::closure  observer 
)

Definition at line 19 of file task_observers.cc.

References key.

Referenced by flutter_runner::ComponentV1::Create(), and flutter_runner::ComponentV2::Create().

20  {
21  if (observer) {
22  tTaskObservers[key] = std::move(observer);
23  }
24 }
thread_local std::map< intptr_t, fit::closure > tTaskObservers

◆ CurrentMessageLoopRemoveAfterTaskObserver()

void fml::CurrentMessageLoopRemoveAfterTaskObserver ( intptr_t  key)

Definition at line 26 of file task_observers.cc.

Referenced by flutter_runner::ComponentV1::Create(), and flutter_runner::ComponentV2::Create().

26  {
27  tTaskObservers.erase(key);
28 }
thread_local std::map< intptr_t, fit::closure > tTaskObservers

◆ DartTimelineTicksSinceEpoch()

fml::TimePoint fml::DartTimelineTicksSinceEpoch ( )

Definition at line 34 of file dart_timestamp_provider.cc.

References fml::DartTimestampProvider::Instance(), and fml::DartTimestampProvider::Now().

Referenced by fml::TimePoint::Now().

34  {
35  return DartTimestampProvider::Instance().Now();
36 }

◆ DemangleSymbolName()

static std::string fml::DemangleSymbolName ( const std::string &  mangled)
static

Definition at line 27 of file backtrace.cc.

References kKUnknownFrameName, and length.

Referenced by GetSymbolName().

27  {
28  if (mangled == kKUnknownFrameName) {
29  return kKUnknownFrameName;
30  }
31 
32  int status = 0;
33  size_t length = 0;
34  char* demangled = __cxxabiv1::__cxa_demangle(
35  mangled.data(), // mangled name
36  nullptr, // output buffer (malloc-ed if nullptr)
37  &length, // demangled length
38  &status);
39 
40  if (demangled == nullptr || status != 0) {
41  return mangled;
42  }
43 
44  auto demangled_string = std::string{demangled, length};
45  free(demangled);
46  return demangled_string;
47 }
static std::string kKUnknownFrameName
Definition: backtrace.cc:25
size_t length

◆ Duplicate()

◆ ExecuteAfterTaskObservers()

void fml::ExecuteAfterTaskObservers ( )

Definition at line 13 of file task_observers.cc.

References callback.

13  {
14  for (const auto& callback : tTaskObservers) {
15  callback.second();
16  }
17 }
FlKeyEvent FlKeyResponderAsyncCallback callback
thread_local std::map< intptr_t, fit::closure > tTaskObservers

◆ FileExists()

bool fml::FileExists ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 182 of file file_posix.cc.

References fml::UniqueObject< T, Traits >::get(), fml::UniqueObject< T, Traits >::is_valid(), and flutter::path.

Referenced by GetFileAttributesForUtf8Path(), OpenDirectory(), OpenFile(), and TEST().

182  {
183  if (!base_directory.is_valid()) {
184  return false;
185  }
186 
187  return ::faccessat(base_directory.get(), path, F_OK, 0) == 0;
188 }
const T & get() const
Definition: unique_object.h:87
bool is_valid() const
Definition: unique_object.h:89
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ GetAbsolutePath()

static std::string fml::GetAbsolutePath ( const fml::UniqueFD base_directory,
const char *  subpath 
)
static

Definition at line 68 of file file_win.cc.

References GetFullHandlePath(), and flutter::path.

Referenced by GetFileAttributesForUtf8Path().

69  {
70  std::stringstream stream;
71  stream << GetFullHandlePath(base_directory) << "\\" << subpath;
72  auto path = stream.str();
73  std::replace(path.begin(), path.end(), '/', '\\');
74  return path;
75 }
static std::string GetFullHandlePath(const fml::UniqueFD &handle)
Definition: file_win.cc:27
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ GetDesiredAccessFlags()

static DWORD fml::GetDesiredAccessFlags ( FilePermission  permission)
static

Definition at line 88 of file file_win.cc.

References kRead, kReadWrite, and kWrite.

Referenced by GetFileAttributesForUtf8Path().

88  {
89  switch (permission) {
90  case FilePermission::kRead:
91  return GENERIC_READ;
92  case FilePermission::kWrite:
93  return GENERIC_WRITE;
94  case FilePermission::kReadWrite:
95  return GENERIC_READ | GENERIC_WRITE;
96  }
97  return GENERIC_READ;
98 }

◆ GetFileAttributesForUtf8Path() [1/2]

static DWORD fml::GetFileAttributesForUtf8Path ( const char *  absolute_path)
static

Definition at line 112 of file file_win.cc.

References GetFileAttributes, and StringToWideString().

Referenced by GetFileAttributesForUtf8Path().

112  {
113  return ::GetFileAttributes(StringToWideString(absolute_path).c_str());
114 }
#define GetFileAttributes
std::wstring StringToWideString(const std::string &str)

◆ GetFileAttributesForUtf8Path() [2/2]

static DWORD fml::GetFileAttributesForUtf8Path ( const fml::UniqueFD base_directory,
const char *  path 
)
static

Definition at line 116 of file file_win.cc.

References CreateDirectory(), CreateFile, CreateTemporaryDirectory(), DeleteFile, Duplicate(), FALSE, FileExists(), FindFirstFile, FindNextFile, flags, FML_DLOG, fml::UniqueObject< T, Traits >::get(), GetAbsolutePath(), GetDesiredAccessFlags(), GetFileAttributesForUtf8Path(), GetFullHandlePath(), GetLastError(), GetLastErrorMessage(), fml::Mapping::GetMapping(), GetShareFlags(), fml::Mapping::GetSize(), GetTemporaryDirectoryPath(), INVALID_HANDLE_VALUE, IsDirectory(), IsFile(), fml::FileMapping::kRead, kReadWrite, fml::FileMapping::kWrite, OpenDirectory(), OpenFile(), flutter::path, RemoveDirectory, result, size(), StringToWideString(), TruncateFile(), UnlinkDirectory(), UnlinkFile(), VisitFiles(), WideStringToString(), and WriteAtomically().

117  {
118  std::string full_path = GetFullHandlePath(base_directory) + "\\" + path;
119  return GetFileAttributesForUtf8Path(full_path.c_str());
120 }
static std::string GetFullHandlePath(const fml::UniqueFD &handle)
Definition: file_win.cc:27
static DWORD GetFileAttributesForUtf8Path(const fml::UniqueFD &base_directory, const char *path)
Definition: file_win.cc:116
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ GetFullHandlePath()

static std::string fml::GetFullHandlePath ( const fml::UniqueFD handle)
static

Definition at line 27 of file file_win.cc.

References buffer, FML_DLOG, fml::UniqueObject< T, Traits >::get(), GetLastErrorMessage(), MAX_PATH, result, and WideStringToString().

Referenced by GetAbsolutePath(), and GetFileAttributesForUtf8Path().

27  {
28  // Although the documentation claims that GetFinalPathNameByHandle is
29  // supported for UWP apps, turns out it returns ACCESS_DENIED in this case
30  // hence the need to workaround it by maintaining a map of file handles to
31  // absolute paths populated by fml::OpenDirectory.
32 #ifdef WINUWP
33  std::optional<fml::internal::os_win::DirCacheEntry> found =
34  fml::internal::os_win::UniqueFDTraits::GetCacheEntry(handle.get());
35 
36  if (found) {
37  FILE_ID_INFO info;
38 
39  BOOL result = GetFileInformationByHandleEx(
40  handle.get(), FILE_INFO_BY_HANDLE_CLASS::FileIdInfo, &info,
41  sizeof(FILE_ID_INFO));
42 
43  // Assuming it was possible to retrieve fileinfo, compare the id field. The
44  // handle hasn't been reused if the file identifier is the same as when it
45  // was cached
46  if (result && memcmp(found.value().id.Identifier, info.FileId.Identifier,
47  sizeof(FILE_ID_INFO))) {
48  return WideStringToString(found.value().filename);
49  } else {
50  fml::internal::os_win::UniqueFDTraits::RemoveCacheEntry(handle.get());
51  }
52  }
53 
54  return std::string();
55 #else
56  wchar_t buffer[MAX_PATH] = {0};
57  const DWORD buffer_size = ::GetFinalPathNameByHandle(
58  handle.get(), buffer, MAX_PATH, FILE_NAME_NORMALIZED);
59  if (buffer_size == 0) {
60  FML_DLOG(ERROR) << "Could not get file handle path. "
62  return {};
63  }
64  return WideStringToString({buffer, buffer_size});
65 #endif
66 }
GAsyncResult * result
const T & get() const
Definition: unique_object.h:87
unsigned long DWORD
Definition: windows_types.h:22
int BOOL
Definition: windows_types.h:37
static const uint8_t buffer[]
#define FML_DLOG(severity)
Definition: logging.h:85
std::string GetLastErrorMessage()
Definition: errors_win.cc:15
#define MAX_PATH
std::string WideStringToString(const std::wstring &wstr)

◆ GetLastErrorMessage()

std::string fml::GetLastErrorMessage ( )

Definition at line 15 of file errors_win.cc.

References buffer, flags, GetLastError(), size(), and WideStringToString().

Referenced by GetFileAttributesForUtf8Path(), GetFullHandlePath(), and GetTemporaryDirectoryPath().

15  {
16  DWORD last_error = ::GetLastError();
17  if (last_error == 0) {
18  return {};
19  }
20 
21  const DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
22  FORMAT_MESSAGE_FROM_SYSTEM |
23  FORMAT_MESSAGE_IGNORE_INSERTS;
24 
25  wchar_t* buffer = nullptr;
26  size_t size = ::FormatMessage(
27  flags, // dwFlags
28  NULL, // lpSource
29  last_error, // dwMessageId
30  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // dwLanguageId
31  (LPWSTR)&buffer, // lpBuffer
32  0, // nSize
33  NULL // Arguments
34  );
35 
36  std::wstring message(buffer, size);
37 
38  ::LocalFree(buffer);
39 
40  std::wstringstream stream;
41  stream << message << " (" << last_error << ").";
42 
43  return WideStringToString(stream.str());
44 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
FlutterSemanticsFlag flags
unsigned long DWORD
Definition: windows_types.h:22
static const uint8_t buffer[]
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)
std::string WideStringToString(const std::wstring &wstr)

◆ GetLogSettings()

LogSettings fml::GetLogSettings ( )

Definition at line 38 of file log_settings.cc.

References fml::state::g_log_settings.

Referenced by fml::ScopedSetLogSettings::ScopedSetLogSettings().

38  {
39  return state::g_log_settings;
40 }
LogSettings g_log_settings

◆ GetMinLogLevel()

int fml::GetMinLogLevel ( )

Definition at line 42 of file log_settings.cc.

References fml::state::g_log_settings, and LOG_FATAL.

Referenced by GetVlogVerbosity(), and ShouldCreateLogMessage().

42  {
43  return std::min(state::g_log_settings.min_log_level, LOG_FATAL);
44 }
LogSettings g_log_settings
constexpr LogSeverity LOG_FATAL
Definition: log_level.h:16

◆ GetShareFlags()

static DWORD fml::GetShareFlags ( FilePermission  permission)
static

Definition at line 100 of file file_win.cc.

References kRead, kReadWrite, and kWrite.

Referenced by GetFileAttributesForUtf8Path().

100  {
101  switch (permission) {
102  case FilePermission::kRead:
103  return FILE_SHARE_READ;
104  case FilePermission::kWrite:
105  return FILE_SHARE_WRITE;
106  case FilePermission::kReadWrite:
107  return FILE_SHARE_READ | FILE_SHARE_WRITE;
108  }
109  return FILE_SHARE_READ;
110 }

◆ GetSymbolName()

static std::string fml::GetSymbolName ( void *  symbol)
static

Definition at line 49 of file backtrace.cc.

References DemangleSymbolName(), kKUnknownFrameName, and flutter::name.

Referenced by BacktraceHere().

49  {
50  char name[1024];
51  if (!absl::Symbolize(symbol, name, sizeof(name))) {
52  return kKUnknownFrameName;
53  }
54 
55  return DemangleSymbolName({name});
56 }
static std::string DemangleSymbolName(const std::string &mangled)
Definition: backtrace.cc:27
static std::string kKUnknownFrameName
Definition: backtrace.cc:25
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ GetTemporaryDirectoryPath()

static std::wstring fml::GetTemporaryDirectoryPath ( )
static

Definition at line 77 of file file_win.cc.

References FML_DLOG, GetLastErrorMessage(), and MAX_PATH.

Referenced by GetFileAttributesForUtf8Path().

77  {
78  wchar_t wchar_path[MAX_PATH];
79  auto result_size = ::GetTempPath(MAX_PATH, wchar_path);
80  if (result_size > 0) {
81  return {wchar_path, result_size};
82  }
83  FML_DLOG(ERROR) << "Could not get temporary directory path. "
85  return {};
86 }
#define FML_DLOG(severity)
Definition: logging.h:85
std::string GetLastErrorMessage()
Definition: errors_win.cc:15
#define MAX_PATH

◆ GetVlogVerbosity()

int fml::GetVlogVerbosity ( )

Definition at line 134 of file logging.cc.

References GetMinLogLevel(), and LOG_INFO.

Referenced by fml::LogMessage::stream().

134  {
135  return std::max(-1, LOG_INFO - GetMinLogLevel());
136 }
int GetMinLogLevel()
Definition: log_settings.cc:42
constexpr LogSeverity LOG_INFO
Definition: log_level.h:13

◆ HashCombine() [1/2]

constexpr std::size_t fml::HashCombine ( )

◆ HashCombine() [2/2]

template<class... Type>
constexpr std::size_t fml::HashCombine ( Type...  args)

Definition at line 30 of file hash_combine.h.

References args, HashCombine(), and HashCombineSeed().

30  {
31  std::size_t seed = HashCombine();
32  HashCombineSeed(seed, args...);
33  return seed;
34 }
constexpr std::size_t HashCombine(Type... args)
Definition: hash_combine.h:30
G_BEGIN_DECLS FlValue * args
constexpr void HashCombineSeed(std::size_t &seed, Type arg, Rest... other_args)
Definition: hash_combine.h:18

◆ HashCombineSeed() [1/2]

template<class Type >
constexpr void fml::HashCombineSeed ( std::size_t &  seed,
Type  arg 
)

Definition at line 13 of file hash_combine.h.

Referenced by HashCombine(), and HashCombineSeed().

13  {
14  seed ^= std::hash<Type>{}(arg) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
15 }

◆ HashCombineSeed() [2/2]

template<class Type , class... Rest>
constexpr void fml::HashCombineSeed ( std::size_t &  seed,
Type  arg,
Rest...  other_args 
)

Definition at line 18 of file hash_combine.h.

References HashCombineSeed().

20  {
21  HashCombineSeed(seed, arg);
22  HashCombineSeed(seed, other_args...);
23 }
constexpr void HashCombineSeed(std::size_t &seed, Type arg, Rest... other_args)
Definition: hash_combine.h:18

◆ HexEncode()

std::string fml::HexEncode ( std::string_view  input)

Definition at line 13 of file hex_codec.cc.

References result.

Referenced by flutter::PersistentCache::SkKeyToFilePath(), and TEST().

13  {
14  std::string result;
15  result.reserve(input.size() * 2);
16  for (char c : input) {
17  uint8_t b = static_cast<uint8_t>(c);
18  result.push_back(kEncoding[b >> 4]);
19  result.push_back(kEncoding[b & 0xF]);
20  }
21  return result;
22 }
GAsyncResult * result
static constexpr char kEncoding[]
Definition: hex_codec.cc:11

◆ InstallCrashHandler()

void fml::InstallCrashHandler ( )

Definition at line 134 of file backtrace.cc.

References fml::paths::GetExecutablePath(), and ToggleSignalHandlers().

Referenced by benchmarking::Main(), and main().

134  {
135 #if OS_WIN
136  if (!IsDebuggerPresent()) {
137  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
138  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
139  }
140 #endif
141  auto exe_path = fml::paths::GetExecutablePath();
142  if (exe_path.first) {
143  absl::InitializeSymbolizer(exe_path.second.c_str());
144  }
145  ToggleSignalHandlers(true);
146 }
static void ToggleSignalHandlers(bool set)
Definition: backtrace.cc:123
std::pair< bool, std::string > GetExecutablePath()

◆ IsCrashHandlingSupported()

bool fml::IsCrashHandlingSupported ( )

Definition at line 148 of file backtrace.cc.

Referenced by fml::testing::TEST().

148  {
149  return true;
150 }

◆ IsDirectory() [1/2]

bool fml::IsDirectory ( const fml::UniqueFD directory)

Definition at line 126 of file file_posix.cc.

References fml::UniqueObject< T, Traits >::get(), and fml::UniqueObject< T, Traits >::is_valid().

Referenced by CreateDirectory(), flutter::DirectoryAssetBundle::DirectoryAssetBundle(), GetFileAttributesForUtf8Path(), IsDirectory(), flutter::PersistentCache::Purge(), RemoveFilesInDirectory(), filesystem::TEST(), and VisitFilesRecursively().

126  {
127  if (!directory.is_valid()) {
128  return false;
129  }
130 
131  struct stat stat_result = {};
132 
133  if (::fstat(directory.get(), &stat_result) != 0) {
134  return false;
135  }
136 
137  return S_ISDIR(stat_result.st_mode);
138 }
const T & get() const
Definition: unique_object.h:87
bool is_valid() const
Definition: unique_object.h:89

◆ IsDirectory() [2/2]

bool fml::IsDirectory ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 140 of file file_posix.cc.

References fml::UniqueObject< T, Traits >::is_valid(), IsDirectory(), and OpenFileReadOnly().

140  {
141  UniqueFD file = OpenFileReadOnly(base_directory, path);
142  return (file.is_valid() && IsDirectory(file));
143 }
UniqueObject< int, internal::os_unix::UniqueFDTraits > UniqueFD
Definition: unique_fd.h:100
bool IsDirectory(const fml::UniqueFD &directory)
Definition: file_posix.cc:126
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
fml::UniqueFD OpenFileReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition: file.cc:92

◆ IsExecutable()

static bool fml::IsExecutable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 33 of file mapping_win.cc.

References fml::FileMapping::FileMapping(), and fml::FileMapping::kExecute.

34  {
35  for (auto protection : protection_flags) {
36  if (protection == FileMapping::Protection::kExecute) {
37  return true;
38  }
39  }
40  return false;
41 }

◆ IsFile()

bool fml::IsFile ( const std::string &  path)

Definition at line 145 of file file_posix.cc.

Referenced by FlutterEngineCreateAOTData(), FlutterEngineInitialize(), GetFileAttributesForUtf8Path(), flutter::FlutterMain::GetSettings(), flutter::testing::LoadELFSplitSymbolFromFixturesIfNeccessary(), flutter::testing::LoadELFSymbolFromFixturesIfNeccessary(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), and TEST().

145  {
146  struct stat buf;
147  if (stat(path.c_str(), &buf) != 0) {
148  return false;
149  }
150 
151  return S_ISREG(buf.st_mode);
152 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ IsPlatformVersionAtLeast()

bool fml::IsPlatformVersionAtLeast ( size_t  major,
size_t  minor = 0,
size_t  patch = 0 
)

Definition at line 11 of file platform_version.mm.

11  {
12  const NSOperatingSystemVersion version = {
13  .majorVersion = static_cast<NSInteger>(major),
14  .minorVersion = static_cast<NSInteger>(minor),
15  .patchVersion = static_cast<NSInteger>(patch),
16  };
17  return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:version];
18 }

◆ IsWritable() [1/2]

static bool fml::IsWritable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 23 of file mapping_win.cc.

References fml::FileMapping::kWrite.

24  {
25  for (auto protection : protection_flags) {
26  if (protection == FileMapping::Protection::kWrite) {
27  return true;
28  }
29  }
30  return false;
31 }

◆ IsWritable() [2/2]

static bool fml::IsWritable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 39 of file mapping_posix.cc.

References fml::FileMapping::kWrite, fml::Mapping::Mapping(), and fml::Mapping::~Mapping().

40  {
41  for (auto protection : protection_flags) {
42  if (protection == FileMapping::Protection::kWrite) {
43  return true;
44  }
45  }
46  return false;
47 }

◆ KillProcess()

void fml::KillProcess ( )

◆ MakeCopyable()

template<typename T >
internal::CopyableLambda<T> fml::MakeCopyable ( lambda)

Definition at line 57 of file make_copyable.h.

Referenced by flutter::PlatformMessageResponseDart::Complete(), flutter::PlatformMessageResponseAndroid::Complete(), flutter::PlatformMessageResponseDarwin::Complete(), flutter::PlatformMessageResponseDart::CompleteEmpty(), flutter::PlatformMessageResponseAndroid::CompleteEmpty(), flutter::PlatformMessageResponseDarwin::CompleteEmpty(), flutter::CopyToBitmap(), flutter::Shell::Create(), flutter::ImageDecoder::Decode(), flutter::Rasterizer::Draw(), flutter::EmbedderPlatformMessageResponse::EmbedderPlatformMessageResponse(), flutter::EncodeImage(), flutter_runner::Engine::Engine(), flutter::Shell::GetDartVM(), flutter::MultiFrameCodec::getNextFrame(), flutter::testing::EmbedderTestContext::GetNextSceneImage(), flutter_runner::PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage(), InferMetalPlatformViewCreationCallback(), InferOpenGLPlatformViewCreationCallback(), InferSoftwarePlatformViewCreationCallback(), flutter_runner::FlatlandPlatformView::OnChildViewStatus(), flutter::PersistentCacheStore(), flutter::PrepareKernelMappings(), flutter::Picture::RasterizeToImage(), flutter::testing::RunDartCodeInIsolate(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), flutter::Shell::RunEngine(), flutter::testing::ShellTest::SendEnginePlatformMessage(), flutter::testing::TEST_F(), flutter_runner::VsyncWaiter::VsyncWaiter(), flutter_runner::Engine::~Engine(), flutter::PlatformMessageResponseDart::~PlatformMessageResponseDart(), flutter_runner::Runner::~Runner(), flutter::Shell::~Shell(), and flutter_runner::VsyncWaiter::~VsyncWaiter().

57  {
58  return internal::CopyableLambda<T>(std::move(lambda));
59 }

◆ MakeRefCounted()

template<typename T , typename... Args>
RefPtr<T> fml::MakeRefCounted ( Args &&...  args)

Definition at line 244 of file ref_ptr.h.

References args, and fml::internal::MakeRefCountedHelper< T >::MakeRefCounted().

244  {
246  std::forward<Args>(args)...);
247 }
G_BEGIN_DECLS FlValue * args
RefPtr< T > MakeRefCounted(Args &&... args)
Definition: ref_ptr.h:244

◆ NanosSinceEpoch()

template<typename Clock , typename Duration >
static int64_t fml::NanosSinceEpoch ( std::chrono::time_point< Clock, Duration >  time_point)
static

Definition at line 33 of file time_point.cc.

Referenced by fml::TimePoint::CurrentWallTime().

34  {
35  const auto elapsed = time_point.time_since_epoch();
36  return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
37 }

◆ OpenDirectory() [1/2]

fml::UniqueFD fml::OpenDirectory ( const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

Definition at line 96 of file file_posix.cc.

References flutter::path.

Referenced by CreateDirectory(), fml::paths::GetCachesDirectory(), GetFileAttributesForUtf8Path(), flutter::RunConfiguration::InferFromSettings(), OpenDirectoryReadOnly(), flutter::testing::OpenFixtureAsSkData(), flutter::testing::OpenFixturesDirectory(), flutter::PersistentCache::Purge(), flutter::Shell::RegisterImageDecoder(), RemoveDirectoryRecursively(), flutter::RunTester(), fml::ScopedTemporaryDirectory::ScopedTemporaryDirectory(), flutter::ServiceProtocolFailureError(), flutter::StartupAndShutdownShell(), TEST(), flutter_runner::testing::TEST_F(), and flutter::testing::TEST_F().

98  {
99  return OpenDirectory(fml::UniqueFD{AT_FDCWD}, path, create_if_necessary,
100  permission);
101 }
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:96
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ OpenDirectory() [2/2]

fml::UniqueFD fml::OpenDirectory ( const fml::UniqueFD base_directory,
const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

Definition at line 103 of file file_posix.cc.

References FileExists(), FML_HANDLE_EINTR, fml::UniqueObject< T, Traits >::get(), flutter::path, and ToPosixCreateModeFlags().

106  {
107  if (path == nullptr) {
108  return {};
109  }
110 
111  if (create_if_necessary && !FileExists(base_directory, path)) {
112  if (::mkdirat(base_directory.get(), path,
113  ToPosixCreateModeFlags(permission) | S_IXUSR) != 0) {
114  return {};
115  }
116  }
117 
119  ::openat(base_directory.get(), path, O_RDONLY | O_DIRECTORY))};
120 }
static int ToPosixCreateModeFlags(FilePermission permission)
Definition: file_posix.cc:49
const T & get() const
Definition: unique_object.h:87
#define FML_HANDLE_EINTR(x)
Definition: eintr_wrapper.h:20
bool FileExists(const fml::UniqueFD &base_directory, const char *path)
Definition: file_posix.cc:182
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ OpenDirectoryReadOnly()

fml::UniqueFD fml::OpenDirectoryReadOnly ( const fml::UniqueFD base_directory,
const char *  path 
)

Helper method that calls OpenDirectory with create_if_necessary = false and permission = kRead.

Definition at line 97 of file file.cc.

References kRead, and OpenDirectory().

Referenced by flutter::PersistentCache::LoadSkSLs(), flutter::PersistentCache::Purge(), RemoveFilesInDirectory(), flutter::testing::TEST_F(), and VisitFilesRecursively().

98  {
99  return OpenDirectory(base_directory, path, false, FilePermission::kRead);
100 }
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:96
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ OpenFile() [1/2]

fml::UniqueFD fml::OpenFile ( const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

This can open a directory on POSIX, but not on Windows.

Definition at line 65 of file file_posix.cc.

References flutter::path.

Referenced by fml::FileMapping::CreateReadExecute(), fml::FileMapping::CreateReadOnly(), flutter::DirectoryAssetBundle::DirectoryAssetBundle(), GetFileAttributesForUtf8Path(), flutter::GetVMServiceAssetsArchiveCallback(), OpenFileReadOnly(), flutter::testing::OpenFixture(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), flutter::RunTester(), flutter::ServiceProtocolFailureError(), fml::icu::ICUContext::SetupMapping(), TEST(), and WriteAtomically().

67  {
68  return OpenFile(fml::UniqueFD{AT_FDCWD}, path, create_if_necessary,
69  permission);
70 }
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition: file_posix.cc:65
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ OpenFile() [2/2]

fml::UniqueFD fml::OpenFile ( const fml::UniqueFD base_directory,
const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

This can open a directory on POSIX, but not on Windows.

Definition at line 72 of file file_posix.cc.

References FileExists(), flags, FML_HANDLE_EINTR, fml::UniqueObject< T, Traits >::get(), flutter::mode, flutter::path, ToPosixAccessFlags(), ToPosixCreateModeFlags(), and TRACE_EVENT0.

75  {
76  TRACE_EVENT0("flutter", "fml::OpenFile");
77  if (path == nullptr) {
78  return {};
79  }
80 
81  int flags = 0;
82  int mode = 0;
83 
84  if (create_if_necessary && !FileExists(base_directory, path)) {
85  flags = ToPosixAccessFlags(permission) | O_CREAT | O_TRUNC;
86  mode = ToPosixCreateModeFlags(permission);
87  } else {
88  flags = ToPosixAccessFlags(permission);
89  mode = 0; // Not creating since it already exists.
90  }
91 
92  return fml::UniqueFD{
93  FML_HANDLE_EINTR(::openat(base_directory.get(), path, flags, mode))};
94 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data observatory The hostname IP address on which the Dart Observatory should be served If not defaults to or::depending on whether ipv6 is specified disable Disable the Dart Observatory The observatory is never available in release mode Bind to the IPv6 localhost address for the Dart Observatory Ignored if observatory host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however skia deterministic Skips the call to thus avoiding swapping out some Skia function pointers based on available CPU features This is used to obtain deterministic behavior in Skia rendering disable service auth Disable the requirement for authentication codes for communicating with the VM service start Start the application paused in the Dart debugger trace Trace Skia calls This is useful when debugging the GPU threed By Skia tracing is not enabled to reduce the number of traced events trace Filters out all trace events except those that are specified in this comma separated list of allowed prefixes cache Only cache the shader in SkSL instead of binary or GLSL This should only be used during development phases The generated SkSLs can later be used in the release build for shader precompilation at launch in order to eliminate the shader compile jank trace Trace to the system use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:186
static int ToPosixCreateModeFlags(FilePermission permission)
Definition: file_posix.cc:49
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
const T & get() const
Definition: unique_object.h:87
FlutterSemanticsFlag flags
#define FML_HANDLE_EINTR(x)
Definition: eintr_wrapper.h:20
bool FileExists(const fml::UniqueFD &base_directory, const char *path)
Definition: file_posix.cc:182
static int ToPosixAccessFlags(FilePermission permission)
Definition: file_posix.cc:33
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ OpenFileReadOnly()

fml::UniqueFD fml::OpenFileReadOnly ( const fml::UniqueFD base_directory,
const char *  path 
)

Helper method that calls OpenFile with create_if_necessary = false and permission = kRead.

This can open a directory on POSIX, but not on Windows.

Definition at line 92 of file file.cc.

References kRead, and OpenFile().

Referenced by flutter::DirectoryAssetBundle::DirectoryAssetBundle(), IsDirectory(), flutter::PersistentCache::LoadSkSLs(), and flutter::testing::TEST_F().

93  {
94  return OpenFile(base_directory, path, false, FilePermission::kRead);
95 }
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition: file_posix.cc:65
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ operator!=() [1/2]

template<class C >
bool fml::operator!= ( p1,
const scoped_nsprotocol< C > &  p2 
)

Definition at line 107 of file scoped_nsobject.h.

References fml::scoped_nsprotocol< NST >::get().

107  {
108  return p1 != p2.get();
109 }

◆ operator!=() [2/2]

template<class T , class Traits >
bool fml::operator!= ( const T &  value,
const UniqueObject< T, Traits > &  object 
)

Definition at line 131 of file unique_object.h.

131  {
132  return !(value == object.get());
133 }
uint8_t value

◆ operator==() [1/2]

template<class C >
bool fml::operator== ( p1,
const scoped_nsprotocol< C > &  p2 
)

Definition at line 102 of file scoped_nsobject.h.

References fml::scoped_nsprotocol< NST >::get().

102  {
103  return p1 == p2.get();
104 }

◆ operator==() [2/2]

template<class T , class Traits >
bool fml::operator== ( const T &  value,
const UniqueObject< T, Traits > &  object 
)

Definition at line 126 of file unique_object.h.

126  {
127  return value == object.get();
128 }
uint8_t value

◆ RangeForCharacterAtIndex()

NSRange fml::RangeForCharacterAtIndex ( NSString *  text,
NSUInteger  index 
)

Definition at line 9 of file string_range_sanitization.mm.

Referenced by TEST().

9  {
10  if (text == nil || index > text.length) {
11  return NSMakeRange(NSNotFound, 0);
12  }
13  if (index < text.length)
14  return [text rangeOfComposedCharacterSequenceAtIndex:index];
15  return NSMakeRange(index, 0);
16 }
std::u16string text

◆ RangeForCharactersInRange()

NSRange fml::RangeForCharactersInRange ( NSString *  text,
NSRange  range 
)

Definition at line 18 of file string_range_sanitization.mm.

Referenced by TEST().

18  {
19  if (text == nil || range.location + range.length > text.length) {
20  return NSMakeRange(NSNotFound, 0);
21  }
22  NSRange sanitizedRange = [text rangeOfComposedCharacterSequencesForRange:range];
23  // We don't want to override the length, we just want to make sure we don't
24  // select into the middle of a multi-byte character. Taking the
25  // `sanitizedRange`'s length will end up altering the actual selection.
26  return NSMakeRange(sanitizedRange.location, range.length);
27 }
std::u16string text

◆ Ref()

template<typename T >
RefPtr<T> fml::Ref ( T *  ptr)
inline

Definition at line 233 of file ref_ptr.h.

Referenced by flutter::SkiaUnrefQueue::Unref().

233  {
234  return RefPtr<T>(ptr);
235 }

◆ RefreshRateToFrameBudget()

template<typename T >
Milliseconds fml::RefreshRateToFrameBudget ( refresh_rate)

Definition at line 24 of file time_delta.h.

Referenced by flutter::Shell::GetDartVM().

24  {
25  return Milliseconds(1s) / refresh_rate;
26 }
std::chrono::duration< double, std::milli > Milliseconds
Definition: time_delta.h:18

◆ RemoveDirectoryRecursively()

bool fml::RemoveDirectoryRecursively ( const fml::UniqueFD parent,
const char *  directory_name 
)

Helper method to recursively remove files and subdirectories inside the directory. The directory itself will also be removed.

Return true if and only if all files have been successfully removed.

Definition at line 120 of file file.cc.

References kReadWrite, OpenDirectory(), RemoveFilesInDirectory(), and UnlinkDirectory().

Referenced by flutter::PersistentCache::Purge().

121  {
122  auto dir = fml::OpenDirectory(parent, directory_name, false,
124  return RemoveFilesInDirectory(dir) && UnlinkDirectory(parent, directory_name);
125 }
bool RemoveFilesInDirectory(const fml::UniqueFD &directory)
Definition: file.cc:102
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:96
bool UnlinkDirectory(const char *path)
Definition: file_posix.cc:162

◆ RemoveFilesInDirectory()

bool fml::RemoveFilesInDirectory ( const fml::UniqueFD directory)

Helper method to recursively remove files and subdirectories inside the directory. The directory itself will not be removed.

Return true if and only if all files have been successfully removed.

Definition at line 102 of file file.cc.

References IsDirectory(), OpenDirectoryReadOnly(), UnlinkDirectory(), UnlinkFile(), and VisitFiles().

Referenced by RemoveDirectoryRecursively(), flutter::testing::TEST_F(), and fml::ScopedTemporaryDirectory::~ScopedTemporaryDirectory().

102  {
103  fml::FileVisitor recursive_cleanup = [&recursive_cleanup](
104  const fml::UniqueFD& directory,
105  const std::string& filename) {
106  bool removed;
107  if (fml::IsDirectory(directory, filename.c_str())) {
108  fml::UniqueFD sub_dir =
109  OpenDirectoryReadOnly(directory, filename.c_str());
110  removed = VisitFiles(sub_dir, recursive_cleanup) &&
111  fml::UnlinkDirectory(directory, filename.c_str());
112  } else {
113  removed = fml::UnlinkFile(directory, filename.c_str());
114  }
115  return removed;
116  };
117  return VisitFiles(directory, recursive_cleanup);
118 }
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
Definition: file.h:98
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
Definition: file_posix.cc:235
bool IsDirectory(const fml::UniqueFD &directory)
Definition: file_posix.cc:126
fml::UniqueFD OpenDirectoryReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition: file.cc:97
bool UnlinkFile(const char *path)
Definition: file_posix.cc:170
bool UnlinkDirectory(const char *path)
Definition: file_posix.cc:162

◆ SetLogSettings()

void fml::SetLogSettings ( const LogSettings settings)

Definition at line 28 of file log_settings.cc.

References fml::state::g_log_settings, LOG_FATAL, and fml::LogSettings::min_log_level.

Referenced by fml::ScopedSetLogSettings::ScopedSetLogSettings(), fml::testing::TEST(), and fml::ScopedSetLogSettings::~ScopedSetLogSettings().

28  {
29  // Validate the new settings as we set them.
31  std::min(LOG_FATAL, settings.min_log_level);
32 #if defined(OS_FUCHSIA)
33  // Syslog should accept all logs, since filtering by severity is done by fml.
34  FX_LOG_SET_SEVERITY(ALL);
35 #endif
36 }
LogSettings g_log_settings
LogSeverity min_log_level
Definition: log_settings.h:25
constexpr LogSeverity LOG_FATAL
Definition: log_level.h:16

◆ ShouldCreateLogMessage()

bool fml::ShouldCreateLogMessage ( LogSeverity  severity)

Definition at line 138 of file logging.cc.

References GetMinLogLevel().

Referenced by fml::LogMessage::stream().

138  {
139  return severity >= GetMinLogLevel();
140 }
int GetMinLogLevel()
Definition: log_settings.cc:42

◆ SignalHandler()

static void fml::SignalHandler ( int  signal)
static

Definition at line 109 of file backtrace.cc.

References BacktraceHere(), FML_LOG, SignalNameToString(), and ToggleSignalHandlers().

Referenced by ToggleSignalHandlers().

109  {
110  // We are a crash signal handler. This can only happen once. Since we don't
111  // want to catch crashes while we are generating the crash reports, disable
112  // all set signal handlers to their default values before reporting the crash
113  // and re-raising the signal.
114  ToggleSignalHandlers(false);
115 
116  FML_LOG(ERROR) << "Caught signal " << SignalNameToString(signal)
117  << " during program execution." << std::endl
118  << BacktraceHere(3);
119 
120  ::raise(signal);
121 }
std::string BacktraceHere(size_t offset)
Definition: backtrace.cc:58
#define FML_LOG(severity)
Definition: logging.h:65
static void ToggleSignalHandlers(bool set)
Definition: backtrace.cc:123
static std::string SignalNameToString(int signal)
Definition: backtrace.cc:85

◆ SignalNameToString()

static std::string fml::SignalNameToString ( int  signal)
static

Definition at line 85 of file backtrace.cc.

References ToggleSignalHandlers().

Referenced by SignalHandler().

85  {
86  switch (signal) {
87  case SIGABRT:
88  return "SIGABRT";
89  case SIGFPE:
90  return "SIGFPE";
91  case SIGBUS:
92  return "SIGBUS";
93  case SIGSEGV:
94  return "SIGSEGV";
95  case SIGSYS:
96  return "SIGSYS";
97  case SIGPIPE:
98  return "SIGPIPE";
99  case SIGALRM:
100  return "SIGALRM";
101  case SIGTERM:
102  return "SIGTERM";
103  };
104  return std::to_string(signal);
105 }

◆ size()

template<typename T , std::size_t N>
constexpr std::size_t fml::size ( T(&)  array[N])

Definition at line 13 of file size.h.

Referenced by flutter::GPUSurfaceSoftware::AcquireFrame(), flutter_runner::VulkanSurfacePool::AcquireSurface(), FlutterView::backingStoreForSize:, FlutterIOSurfaceHolder::bindSurfaceToTexture:fbo:size:, flutter_runner::PlatformView::ClampToViewSpace(), CommandLineToArgv(), GoldenImage::compareGoldenToImage:, flutter::Rasterizer::compositor_context(), flutter::ConvertMappingToNSData(), flutter::CopyV(), flutter::FlutterMetalCompositor::CreateBackingStore(), flutter::FlutterGLCompositor::CreateBackingStore(), flutter_runner::VulkanSurfacePool::CreateSurface(), FlutterMetalRenderer::createTextureForSize:, flutter::MessageCodec< rapidjson::Document >::DecodeMessage(), flutter::MethodCodec< rapidjson::Document >::DecodeMethodCall(), flutter_runner_test::MockSemanticsManager::DeleteSemanticNodes(), flutter::Rasterizer::Draw(), flutter::EmbedderExternalTextureGL::EmbedderExternalTextureGL(), flutter::EmbedderExternalTextureMetal::EmbedderExternalTextureMetal(), flutter::EmbedderSurfaceSoftware::EmbedderSurfaceSoftware(), FLTDefaultSettingsForBundle(), FlutterPlatformMessageCreateResponseHandle(), FlutterSizeMake(), tonic::DartConverter< DartConverterMapping >::FromDart(), flutter::GamepadCursorWinUWP::GamepadCursorWinUWP(), flutter::MergedContainerLayer::GetChildContainer(), flutter::testing::GetDebuggerStatus(), GetFileAttributesForUtf8Path(), ui::AXPlatformNodeWinTest::GetIRawElementProviderSimpleFromChildIndex(), GetLastErrorMessage(), ui::AXNode::GetNextSibling(), fml::TaskSource::GetNumPendingTasks(), ui::AXNode::GetOrderedSet(), flutter::FlutterMain::GetSettings(), vulkan::VulkanSwapchain::GetSize(), vulkan::VulkanDevice::GetSurfaceCapabilities(), flutter::GetSymbolMapping(), flutter::DartVM::GetVMLaunchCount(), FlutterOpenGLRenderer::glPresent, flutter_runner::VulkanSurfaceProducer::gr_context(), flutter::WindowWin32::InitializeChild(), FlutterMetalSurfaceManager::initWithDevice:commandQueue:layer:, flutter::IsAllowedDartVMFlag(), android::JenkinsHashMix(), fml::paths::JoinPaths(), tonic::Log(), main(), flutter::testing::MakeTextBlob(), flutter::testing::CanvasCompareTester::MakeTextBlob(), flutter::testing::NormalizeImage(), flutter::PlatformViewAndroid::NotifyChanged(), flutter::FlutterWindowWin32::OnCursorRectUpdated(), OnGetNextDrawable(), flutter::ParseLanguageName(), PopulateSnapshotMappingCallbacks(), flutter::StandardCodecSerializer::ReadValueOfType(), flutter::SomeDataExtensionSerializer::ReadValueOfType(), FlutterStandardReader::readValueOfType:, FlutterIOSurfaceHolder::recreateIOSurfaceWithSize:, flutter::VsyncWaiterAndroid::Register(), flutter::FlutterMain::Register(), flutter::RegisterApi(), flutter::testing::ResetAssetManager(), flutter::testing::EmbedderTestContextGL::SetGLPresentCallback(), FlutterResizeSynchronizer::shouldEnsureSurfaceForSize:, flutter::testing::ShellTestPlatformViewVulkan::SimulateVSync(), flutter::Size::Size(), zircon::dart::System::SocketRead(), base::StringPrintf(), flutter_runner::FlatlandExternalViewEmbedder::SubmitFrame(), flutter_runner::FlatlandExternalViewEmbedder::SupportsDynamicThreadMerging(), flutter_runner::GfxExternalViewEmbedder::SupportsDynamicThreadMerging(), flutter_runner::Surface::Surface(), filesystem::TEST(), flutter::testing::TEST(), flutter::TEST(), flutter_runner::testing::TEST_F(), flutter::testing::TEST_F(), TimerDrain(), TruncateFile(), flutter_runner_test::MockSemanticsManager::UpdateSemanticNodes(), fml::jni::VectorToBufferArray(), flutter::VectorToSize(), zircon::dart::System::VmoGetSize(), zircon::dart::System::VmoMap(), zircon::dart::System::VmoRead(), zircon::dart::System::VmoSetSize(), flutter::WrapOnscreenSurface(), flutter_runner::Engine::WriteProfileToTrace(), flutter::StandardCodecSerializer::WriteSize(), FlutterStandardWriter::writeSize:, flutter::StandardCodecSerializer::WriteValue(), zircon_dart_byte_array_create(), and minikin::WordBreaker::~WordBreaker().

13  {
14  return N;
15 }

◆ strdup()

char * fml::strdup ( const char *  str1)

Definition at line 11 of file posix_wrappers_posix.cc.

Referenced by dart_runner::CreateServiceIsolate(), flutter::DartIsolate::Shutdown(), and flutter::WriteServerErrorResponse().

11  {
12  return ::strdup(str1);
13 }
char * strdup(const char *str1)

◆ StringToWideString()

std::wstring fml::StringToWideString ( const std::string &  str)
inline

Definition at line 17 of file wstring_conversion.h.

Referenced by GetFileAttributesForUtf8Path().

17  {
18  WideStringConvertor converter;
19  return converter.from_bytes(str);
20 }
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t > WideStringConvertor

◆ swap() [1/2]

◆ swap() [2/2]

template<class T , class Traits >
void fml::swap ( const UniqueObject< T, Traits > &  a,
const UniqueObject< T, Traits > &  b 
)

Definition at line 121 of file unique_object.h.

References fml::UniqueObject< T, Traits >::swap().

Referenced by fml::UniqueObject< fdio_ns_t *, UniqueFDIONSTraits >::swap().

121  {
122  a.swap(b);
123 }

◆ TEST() [1/7]

fml::TEST ( MallocMapping  ,
EmptyContructor   
)

Definition at line 10 of file mapping_unittests.cc.

References fml::MallocMapping::GetMapping(), and fml::MallocMapping::GetSize().

10  {
11  MallocMapping mapping;
12  ASSERT_EQ(nullptr, mapping.GetMapping());
13  ASSERT_EQ(0u, mapping.GetSize());
14 }

◆ TEST() [2/7]

fml::TEST ( MallocMapping  ,
NotEmptyContructor   
)

Definition at line 16 of file mapping_unittests.cc.

References fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), and length.

16  {
17  size_t length = 10;
18  MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
19  ASSERT_NE(nullptr, mapping.GetMapping());
20  ASSERT_EQ(length, mapping.GetSize());
21 }
size_t length

◆ TEST() [3/7]

fml::TEST ( CountDownLatchTest  ,
CanWaitOnZero   
)

Definition at line 16 of file count_down_latch_unittests.cc.

References fml::CountDownLatch::Wait().

16  {
17  CountDownLatch latch(0);
18  latch.Wait();
19 }

◆ TEST() [4/7]

fml::TEST ( MallocMapping  ,
MoveConstructor   
)

Definition at line 23 of file mapping_unittests.cc.

References fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), and length.

23  {
24  size_t length = 10;
25  MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
26  MallocMapping moved = std::move(mapping);
27 
28  ASSERT_EQ(nullptr, mapping.GetMapping());
29  ASSERT_EQ(0u, mapping.GetSize());
30  ASSERT_NE(nullptr, moved.GetMapping());
31  ASSERT_EQ(length, moved.GetSize());
32 }
size_t length

◆ TEST() [5/7]

fml::TEST ( CountDownLatchTest  ,
CanWait   
)

Definition at line 26 of file count_down_latch_unittests.cc.

References fml::CountDownLatch::CountDown(), fml::Thread::GetTaskRunner(), and fml::CountDownLatch::Wait().

26  {
27  fml::Thread thread("test_thread");
28  const size_t count = 100;
29  size_t current_count = 0;
30  CountDownLatch latch(count);
31  auto decrement_latch_on_thread = [runner = thread.GetTaskRunner(), &latch,
32  &current_count]() {
33  runner->PostTask([&latch, &current_count]() {
34  std::this_thread::sleep_for(std::chrono::microseconds(100));
35  current_count++;
36  latch.CountDown();
37  });
38  };
39  for (size_t i = 0; i < count; ++i) {
40  decrement_latch_on_thread();
41  }
42  latch.Wait();
43  ASSERT_EQ(current_count, count);
44 }

◆ TEST() [6/7]

fml::TEST ( MallocMapping  ,
Copy   
)

Definition at line 34 of file mapping_unittests.cc.

References fml::MallocMapping::Copy(), fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), and length.

34  {
35  size_t length = 10;
36  MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
37  memset(const_cast<uint8_t*>(mapping.GetMapping()), 0xac, mapping.GetSize());
38  MallocMapping copied =
39  MallocMapping::Copy(mapping.GetMapping(), mapping.GetSize());
40 
41  ASSERT_NE(mapping.GetMapping(), copied.GetMapping());
42  ASSERT_EQ(mapping.GetSize(), copied.GetSize());
43  ASSERT_EQ(
44  0, memcmp(mapping.GetMapping(), copied.GetMapping(), mapping.GetSize()));
45 }
size_t length

◆ TEST() [7/7]

fml::TEST ( MallocMapping  ,
Release   
)

Definition at line 47 of file mapping_unittests.cc.

References fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), length, and fml::MallocMapping::Release().

47  {
48  size_t length = 10;
49  MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
50  free(const_cast<uint8_t*>(mapping.Release()));
51  ASSERT_EQ(nullptr, mapping.GetMapping());
52  ASSERT_EQ(0u, mapping.GetSize());
53 }
size_t length

◆ TimerDrain()

bool fml::TimerDrain ( int  fd)

Drains the timer FD and returns true if it has expired. This may be false in case the timer read is non-blocking and this routine was called before the timer expiry.

Definition at line 58 of file timerfd.cc.

References FML_HANDLE_EINTR, and size().

Referenced by AcquireLooperForThread().

58  {
59  // 8 bytes must be read from a signaled timer file descriptor when signaled.
60  uint64_t fire_count = 0;
61  ssize_t size = FML_HANDLE_EINTR(::read(fd, &fire_count, sizeof(uint64_t)));
62  if (size != sizeof(uint64_t)) {
63  return false;
64  }
65  return fire_count > 0;
66 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define FML_HANDLE_EINTR(x)
Definition: eintr_wrapper.h:20

◆ TimerRearm()

bool fml::TimerRearm ( int  fd,
fml::TimePoint  time_point 
)

Rearms the timer to expire at the given time point.

Definition at line 37 of file timerfd.cc.

References FML_DLOG, NSEC_PER_SEC, result, TFD_TIMER_ABSTIME, timerfd_settime(), fml::TimePoint::ToEpochDelta(), and fml::TimeDelta::ToNanoseconds().

Referenced by AcquireLooperForThread().

37  {
38  uint64_t nano_secs = time_point.ToEpochDelta().ToNanoseconds();
39 
40  // "0" will disarm the timer, desired behavior is to immediately
41  // trigger the timer.
42  if (nano_secs < 1) {
43  nano_secs = 1;
44  }
45 
46  struct itimerspec spec = {};
47  spec.it_value.tv_sec = (time_t)(nano_secs / NSEC_PER_SEC);
48  spec.it_value.tv_nsec = nano_secs % NSEC_PER_SEC;
49  spec.it_interval = spec.it_value; // single expiry.
50 
51  int result = ::timerfd_settime(fd, TFD_TIMER_ABSTIME, &spec, nullptr);
52  if (result != 0) {
53  FML_DLOG(ERROR) << "timerfd_settime err:" << strerror(errno);
54  }
55  return result == 0;
56 }
int timerfd_settime(int ufc, int flags, const struct itimerspec *utmr, struct itimerspec *otmr)
Definition: timerfd.cc:22
#define NSEC_PER_SEC
Definition: timerfd.cc:34
GAsyncResult * result
TimeDelta ToEpochDelta() const
Definition: time_point.h:47
constexpr int64_t ToNanoseconds() const
Definition: time_delta.h:61
#define FML_DLOG(severity)
Definition: logging.h:85
#define TFD_TIMER_ABSTIME
Definition: timerfd.h:29

◆ ToggleSignalHandlers()

static void fml::ToggleSignalHandlers ( bool  set)
static

Definition at line 123 of file backtrace.cc.

References FML_LOG, kKnownSignalHandlers, and SignalHandler().

Referenced by InstallCrashHandler(), SignalHandler(), and SignalNameToString().

123  {
124  for (size_t i = 0; i < sizeof(kKnownSignalHandlers) / sizeof(size_t); ++i) {
125  auto signal_name = kKnownSignalHandlers[i];
126  auto handler = set ? &SignalHandler : SIG_DFL;
127 
128  if (::signal(signal_name, handler) == SIG_ERR) {
129  FML_LOG(ERROR) << "Could not attach signal handler for " << signal_name;
130  }
131  }
132 }
#define FML_LOG(severity)
Definition: logging.h:65
static void SignalHandler(int signal)
Definition: backtrace.cc:109
static size_t kKnownSignalHandlers[]
Definition: backtrace.cc:74

◆ ToPosixAccessFlags()

static int fml::ToPosixAccessFlags ( FilePermission  permission)
static

Definition at line 33 of file file_posix.cc.

References flags, kRead, kReadWrite, and kWrite.

Referenced by OpenFile().

33  {
34  int flags = 0;
35  switch (permission) {
36  case FilePermission::kRead:
37  flags |= O_RDONLY; // read only
38  break;
39  case FilePermission::kWrite:
40  flags |= O_WRONLY; // write only
41  break;
42  case FilePermission::kReadWrite:
43  flags |= O_RDWR; // read-write
44  break;
45  }
46  return flags;
47 }
FlutterSemanticsFlag flags

◆ ToPosixCreateModeFlags()

static int fml::ToPosixCreateModeFlags ( FilePermission  permission)
static

Definition at line 49 of file file_posix.cc.

References kRead, kReadWrite, kWrite, and flutter::mode.

Referenced by OpenDirectory(), and OpenFile().

49  {
50  int mode = 0;
51  switch (permission) {
52  case FilePermission::kRead:
53  mode |= S_IRUSR;
54  break;
55  case FilePermission::kWrite:
56  mode |= S_IWUSR;
57  break;
58  case FilePermission::kReadWrite:
59  mode |= S_IRUSR | S_IWUSR;
60  break;
61  }
62  return mode;
63 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data observatory The hostname IP address on which the Dart Observatory should be served If not defaults to or::depending on whether ipv6 is specified disable Disable the Dart Observatory The observatory is never available in release mode Bind to the IPv6 localhost address for the Dart Observatory Ignored if observatory host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however skia deterministic Skips the call to thus avoiding swapping out some Skia function pointers based on available CPU features This is used to obtain deterministic behavior in Skia rendering disable service auth Disable the requirement for authentication codes for communicating with the VM service start Start the application paused in the Dart debugger trace Trace Skia calls This is useful when debugging the GPU threed By Skia tracing is not enabled to reduce the number of traced events trace Filters out all trace events except those that are specified in this comma separated list of allowed prefixes cache Only cache the shader in SkSL instead of binary or GLSL This should only be used during development phases The generated SkSLs can later be used in the release build for shader precompilation at launch in order to eliminate the shader compile jank trace Trace to the system use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:186

◆ ToPosixProtectionFlags()

static int fml::ToPosixProtectionFlags ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 20 of file mapping_posix.cc.

References flags, fml::FileMapping::kExecute, fml::FileMapping::kRead, and fml::FileMapping::kWrite.

21  {
22  int flags = 0;
23  for (auto protection : protection_flags) {
24  switch (protection) {
25  case FileMapping::Protection::kRead:
26  flags |= PROT_READ;
27  break;
28  case FileMapping::Protection::kWrite:
29  flags |= PROT_WRITE;
30  break;
31  case FileMapping::Protection::kExecute:
32  flags |= PROT_READ | PROT_EXEC;
33  break;
34  }
35  }
36  return flags;
37 }
FlutterSemanticsFlag flags

◆ TruncateFile()

bool fml::TruncateFile ( const fml::UniqueFD file,
size_t  size 
)

Definition at line 154 of file file_posix.cc.

References fml::UniqueObject< T, Traits >::get(), fml::UniqueObject< T, Traits >::is_valid(), and size().

Referenced by GetFileAttributesForUtf8Path(), TEST(), WriteAtomically(), and WriteStringToFile().

154  {
155  if (!file.is_valid()) {
156  return false;
157  }
158 
159  return ::ftruncate(file.get(), size) == 0;
160 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
const T & get() const
Definition: unique_object.h:87
bool is_valid() const
Definition: unique_object.h:89

◆ UnlinkDirectory() [1/2]

bool fml::UnlinkDirectory ( const char *  path)

Definition at line 162 of file file_posix.cc.

References flutter::path.

Referenced by GetFileAttributesForUtf8Path(), RemoveDirectoryRecursively(), RemoveFilesInDirectory(), TEST(), and fml::ScopedTemporaryDirectory::~ScopedTemporaryDirectory().

162  {
163  return UnlinkDirectory(fml::UniqueFD{AT_FDCWD}, path);
164 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
bool UnlinkDirectory(const char *path)
Definition: file_posix.cc:162

◆ UnlinkDirectory() [2/2]

bool fml::UnlinkDirectory ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 166 of file file_posix.cc.

References fml::UniqueObject< T, Traits >::get(), and flutter::path.

166  {
167  return ::unlinkat(base_directory.get(), path, AT_REMOVEDIR) == 0;
168 }
const T & get() const
Definition: unique_object.h:87
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ UnlinkFile() [1/2]

bool fml::UnlinkFile ( const char *  path)

Definition at line 170 of file file_posix.cc.

References flutter::path.

Referenced by GetFileAttributesForUtf8Path(), flutter::PersistentCache::Purge(), RemoveFilesInDirectory(), TEST(), and flutter::testing::TEST_F().

170  {
171  return UnlinkFile(fml::UniqueFD{AT_FDCWD}, path);
172 }
bool UnlinkFile(const char *path)
Definition: file_posix.cc:170
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ UnlinkFile() [2/2]

bool fml::UnlinkFile ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 174 of file file_posix.cc.

References FML_DLOG, fml::UniqueObject< T, Traits >::get(), and flutter::path.

174  {
175  int code = ::unlinkat(base_directory.get(), path, 0);
176  if (code != 0) {
177  FML_DLOG(ERROR) << strerror(errno);
178  }
179  return code == 0;
180 }
const T & get() const
Definition: unique_object.h:87
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
#define FML_DLOG(severity)
Definition: logging.h:85

◆ VisitFiles()

bool fml::VisitFiles ( const fml::UniqueFD directory,
const FileVisitor visitor 
)

Call visitor on all files inside the directory non-recursively. The trivial file "." and ".." will not be visited.

Return false if and only if the visitor returns false during the traversal.

If recursive visiting is needed, call VisitFiles inside the visitor, or use our helper method VisitFilesRecursively.

See also
VisitFilesRecursively.
Note
Procedure doesn't copy all closures.

Definition at line 235 of file file_posix.cc.

References FML_DLOG, fml::UniqueObject< T, Traits >::get(), fml::UniqueObject< T, Traits >::is_valid(), and fml::UniqueObject< T, Traits >::release().

Referenced by flutter::DirectoryAssetBundle::DirectoryAssetBundle(), GetFileAttributesForUtf8Path(), flutter::PersistentCache::LoadSkSLs(), flutter::PersistentCache::Purge(), RemoveFilesInDirectory(), TEST(), and VisitFilesRecursively().

235  {
236  fml::UniqueFD dup_fd(dup(directory.get()));
237  if (!dup_fd.is_valid()) {
238  FML_DLOG(ERROR) << "Can't dup the directory fd. Error: " << strerror(errno);
239  return true; // continue to visit other files
240  }
241 
242  fml::UniqueDir dir(::fdopendir(dup_fd.get()));
243  if (!dir.is_valid()) {
244  FML_DLOG(ERROR) << "Can't open the directory. Error: " << strerror(errno);
245  return true; // continue to visit other files
246  }
247 
248  // The directory fd will be closed by `closedir`.
249  (void)dup_fd.release();
250 
251  // Without `rewinddir`, `readir` will directly return NULL (end of dir is
252  // reached) after a previuos `VisitFiles` call for the same `const
253  // fml::UniqueFd& directory`.
254  rewinddir(dir.get());
255  while (dirent* ent = readdir(dir.get())) {
256  std::string filename = ent->d_name;
257  if (filename != "." && filename != "..") {
258  if (!visitor(directory, filename)) {
259  return false;
260  }
261  }
262  }
263 
264  return true;
265 }
const T & get() const
Definition: unique_object.h:87
#define FML_DLOG(severity)
Definition: logging.h:85

◆ VisitFilesRecursively()

bool fml::VisitFilesRecursively ( const fml::UniqueFD directory,
const FileVisitor visitor 
)

Recursively call visitor on all files inside the directory. Return false if and only if the visitor returns false during the traversal.

This is a helper method that wraps the general VisitFiles method. The VisitFiles is strictly more powerful as it has the access of the recursion stack to the file. For example, VisitFiles may be able to maintain a vector of directory names that lead to a file. That could be useful to compute the relative path between the root directory and the visited file.

See also
VisitFiles.
Note
Procedure doesn't copy all closures.

Definition at line 71 of file file.cc.

References FML_LOG, fml::UniqueObject< T, Traits >::is_valid(), IsDirectory(), OpenDirectoryReadOnly(), and VisitFiles().

Referenced by flutter::DirectoryAssetBundle::DirectoryAssetBundle(), flutter::PersistentCache::Purge(), TEST(), and flutter::testing::TEST_F().

72  {
73  FileVisitor recursive_visitor = [&recursive_visitor, &visitor](
74  const UniqueFD& directory,
75  const std::string& filename) {
76  if (!visitor(directory, filename)) {
77  return false;
78  }
79  if (IsDirectory(directory, filename.c_str())) {
80  UniqueFD sub_dir = OpenDirectoryReadOnly(directory, filename.c_str());
81  if (!sub_dir.is_valid()) {
82  FML_LOG(ERROR) << "Can't open sub-directory: " << filename;
83  return true;
84  }
85  return VisitFiles(sub_dir, recursive_visitor);
86  }
87  return true;
88  };
89  return VisitFiles(directory, recursive_visitor);
90 }
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
Definition: file.h:98
UniqueObject< int, internal::os_unix::UniqueFDTraits > UniqueFD
Definition: unique_fd.h:100
#define FML_LOG(severity)
Definition: logging.h:65
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
Definition: file_posix.cc:235
bool IsDirectory(const fml::UniqueFD &directory)
Definition: file_posix.cc:126
fml::UniqueFD OpenDirectoryReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition: file.cc:97

◆ WaitWithTimeoutImpl()

template<typename ConditionFn >
bool fml::WaitWithTimeoutImpl ( std::unique_lock< std::mutex > *  locker,
std::condition_variable *  cv,
ConditionFn  condition,
TimeDelta  timeout 
)

Definition at line 20 of file waitable_event.cc.

References FML_DCHECK, fml::TimePoint::Now(), and fml::TimeDelta::ToNanoseconds().

Referenced by fml::ManualResetWaitableEvent::WaitWithTimeout().

23  {
24  FML_DCHECK(locker->owns_lock());
25 
26  if (condition()) {
27  return false;
28  }
29 
30  // We may get spurious wakeups.
31  TimeDelta wait_remaining = timeout;
32  TimePoint start = TimePoint::Now();
33  while (true) {
34  if (std::cv_status::timeout ==
35  cv->wait_for(*locker, std::chrono::nanoseconds(
36  wait_remaining.ToNanoseconds()))) {
37  return true; // Definitely timed out.
38  }
39 
40  // We may have been awoken.
41  if (condition()) {
42  return false;
43  }
44 
45  // Or the wakeup may have been spurious.
46  TimePoint now = TimePoint::Now();
47  FML_DCHECK(now >= start);
48  TimeDelta elapsed = now - start;
49  // It's possible that we may have timed out anyway.
50  if (elapsed >= timeout) {
51  return true;
52  }
53 
54  // Otherwise, recalculate the amount that we have left to wait.
55  wait_remaining = timeout - elapsed;
56  }
57 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ WideStringToString()

std::string fml::WideStringToString ( const std::wstring &  wstr)
inline

Definition at line 22 of file wstring_conversion.h.

Referenced by GetFileAttributesForUtf8Path(), GetFullHandlePath(), and GetLastErrorMessage().

22  {
23  WideStringConvertor converter;
24  return converter.to_bytes(wstr);
25 }
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t > WideStringConvertor

◆ WriteAtomically()

bool fml::WriteAtomically ( const fml::UniqueFD base_directory,
const char *  file_name,
const Mapping mapping 
)

Definition at line 190 of file file_posix.cc.

References FML_HANDLE_EINTR, fml::UniqueObject< T, Traits >::get(), fml::Mapping::GetMapping(), fml::Mapping::GetSize(), kReadWrite, OpenFile(), and TruncateFile().

Referenced by GetFileAttributesForUtf8Path(), flutter::PersistentCacheStore(), TEST(), flutter_runner::testing::TEST_F(), flutter::testing::TEST_F(), and flutter::testing::WriteImageToDisk().

192  {
193  if (file_name == nullptr || data.GetMapping() == nullptr) {
194  return false;
195  }
196 
197  std::stringstream stream;
198  stream << file_name << ".temp";
199  const auto temp_file_name = stream.str();
200 
201  auto temp_file = OpenFile(base_directory, temp_file_name.c_str(), true,
202  FilePermission::kReadWrite);
203  if (!temp_file.is_valid()) {
204  return false;
205  }
206 
207  if (!TruncateFile(temp_file, data.GetSize())) {
208  return false;
209  }
210 
211  ssize_t remaining = data.GetSize();
212  ssize_t written = 0;
213  ssize_t offset = 0;
214 
215  while (remaining > 0) {
216  written = FML_HANDLE_EINTR(
217  ::write(temp_file.get(), data.GetMapping() + offset, remaining));
218 
219  if (written == -1) {
220  return false;
221  }
222 
223  remaining -= written;
224  offset += written;
225  }
226 
227  if (::fsync(temp_file.get()) != 0) {
228  return false;
229  }
230 
231  return ::renameat(base_directory.get(), temp_file_name.c_str(),
232  base_directory.get(), file_name) == 0;
233 }
const T & get() const
Definition: unique_object.h:87
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
#define FML_HANDLE_EINTR(x)
Definition: eintr_wrapper.h:20
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition: file_posix.cc:65
bool TruncateFile(const fml::UniqueFD &file, size_t size)
Definition: file_posix.cc:154

Variable Documentation

◆ _kUnmerged

◆ kClockType [1/2]

constexpr int fml::kClockType = CLOCK_MONOTONIC
static

Definition at line 14 of file message_loop_android.cc.

◆ kClockType [2/2]

constexpr int fml::kClockType = CLOCK_MONOTONIC
static

Definition at line 15 of file message_loop_linux.cc.

◆ kDecodeMap

constexpr signed char fml::kDecodeMap[]
static
Initial value:
= {
26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}

Definition at line 45 of file base32.cc.

◆ kDecodeMapSize

constexpr int fml::kDecodeMapSize
static
Initial value:
=
sizeof(kDecodeMap) / sizeof(kDecodeMap[0])
static constexpr signed char kDecodeMap[]
Definition: base32.cc:45

Definition at line 51 of file base32.cc.

◆ kDefaultFrameBudget

constexpr Milliseconds fml::kDefaultFrameBudget = Milliseconds(1s) / 60

◆ kDistantFuture

constexpr CFTimeInterval fml::kDistantFuture = 1.0e10
static

Definition at line 14 of file message_loop_darwin.mm.

◆ kEncoding [1/2]

constexpr char fml::kEncoding[] = "0123456789abcdef"
static

Definition at line 11 of file hex_codec.cc.

◆ kEncoding [2/2]

constexpr char fml::kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
static

Definition at line 12 of file base32.cc.

◆ kKnownSignalHandlers

size_t fml::kKnownSignalHandlers[]
static
Initial value:
= {
SIGABRT,
SIGFPE,
SIGBUS,
SIGSEGV,
SIGSYS,
SIGPIPE,
SIGALRM,
SIGTERM,
}

Definition at line 74 of file backtrace.cc.

Referenced by ToggleSignalHandlers().

◆ kKUnknownFrameName [1/2]

std::string fml::kKUnknownFrameName = "Unknown"
static

Definition at line 9 of file backtrace_stub.cc.

◆ kKUnknownFrameName [2/2]

std::string fml::kKUnknownFrameName = "Unknown"
static

Definition at line 25 of file backtrace.cc.

Referenced by DemangleSymbolName(), and GetSymbolName().

◆ LOG_DFATAL

const LogSeverity fml::LOG_DFATAL = LOG_FATAL

Definition at line 30 of file log_level.h.

◆ LOG_ERROR

constexpr LogSeverity fml::LOG_ERROR = 2

Definition at line 15 of file log_level.h.

Referenced by fml::LogMessage::~LogMessage().

◆ LOG_FATAL

constexpr LogSeverity fml::LOG_FATAL = 3

Definition at line 16 of file log_level.h.

Referenced by GetMinLogLevel(), SetLogSettings(), and fml::LogMessage::~LogMessage().

◆ LOG_INFO

◆ LOG_NUM_SEVERITIES

constexpr LogSeverity fml::LOG_NUM_SEVERITIES = 4

Definition at line 17 of file log_level.h.

◆ LOG_WARNING

constexpr LogSeverity fml::LOG_WARNING = 1

Definition at line 14 of file log_level.h.

Referenced by flutter::testing::TEST_F(), and fml::LogMessage::~LogMessage().

◆ tls_message_loop

Definition at line 17 of file message_loop.cc.

◆ tls_task_source_grade

◆ tTaskObservers

thread_local std::map<intptr_t, fit::closure> fml::tTaskObservers

Definition at line 11 of file task_observers.cc.