Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
flutter::DartCallbackCache Class Reference

#include <callback_cache.h>

Static Public Member Functions

static void SetCachePath (const std::string &path)
 
static std::string GetCachePath ()
 
static int64_t GetCallbackHandle (const std::string &name, const std::string &class_name, const std::string &library_path)
 
static Dart_Handle GetCallback (int64_t handle)
 
static std::unique_ptr< DartCallbackRepresentationGetCallbackInformation (int64_t handle)
 
static void LoadCacheFromDisk ()
 

Detailed Description

Definition at line 24 of file callback_cache.h.

Member Function Documentation

◆ GetCachePath()

static std::string flutter::DartCallbackCache::GetCachePath ( )
inlinestatic

Definition at line 27 of file callback_cache.h.

27{ return cache_path_; }

◆ GetCallback()

Dart_Handle flutter::DartCallbackCache::GetCallback ( int64_t  handle)
static

Definition at line 39 of file callback_cache.cc.

39 {
40 std::scoped_lock lock(mutex_);
41 auto iterator = cache_.find(handle);
42 if (iterator != cache_.end()) {
43 DartCallbackRepresentation cb = iterator->second;
44 return LookupDartClosure(cb.name, cb.class_name, cb.library_path);
45 }
46 return Dart_Null();
47}
DART_EXPORT Dart_Handle Dart_Null(void)

◆ GetCallbackHandle()

int64_t flutter::DartCallbackCache::GetCallbackHandle ( const std::string &  name,
const std::string &  class_name,
const std::string &  library_path 
)
static

Definition at line 49 of file callback_cache.cc.

51 {
52 std::scoped_lock lock(mutex_);
53 std::hash<std::string> hasher;
54 int64_t hash = hasher(name);
55 hash += hasher(class_name);
56 hash += hasher(library_path);
57
58 if (cache_.find(hash) == cache_.end()) {
59 cache_[hash] = {name, class_name, library_path};
60 SaveCacheToDisk();
61 }
62 return hash;
63}
static uint32_t hash(const SkShaderBase::GradientInfo &v)
const char *const class_name
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ GetCallbackInformation()

std::unique_ptr< DartCallbackRepresentation > flutter::DartCallbackCache::GetCallbackInformation ( int64_t  handle)
static

Definition at line 66 of file callback_cache.cc.

66 {
67 std::scoped_lock lock(mutex_);
68 auto iterator = cache_.find(handle);
69 if (iterator != cache_.end()) {
70 return std::make_unique<DartCallbackRepresentation>(iterator->second);
71 }
72 return nullptr;
73}

◆ LoadCacheFromDisk()

void flutter::DartCallbackCache::LoadCacheFromDisk ( )
static

Definition at line 117 of file callback_cache.cc.

117 {
118 std::scoped_lock lock(mutex_);
119
120 // Don't reload the cache if it's already populated.
121 if (!cache_.empty()) {
122 return;
123 }
124 std::ifstream input(cache_path_);
125 if (!input) {
126 return;
127 }
128 std::string cache_contents{std::istreambuf_iterator<char>(input),
129 std::istreambuf_iterator<char>()};
130 Document d;
131 d.Parse(cache_contents.c_str());
132 if (d.HasParseError() || !d.IsArray()) {
133 // Could not parse callback cache, aborting restore.
134 return;
135 }
136 const auto entries = d.GetArray();
137 for (auto* it = entries.begin(); it != entries.end(); ++it) {
138 const auto root_obj = it->GetObject();
139 const auto representation = root_obj[kRepresentationKey].GetObject();
140
141 const int64_t hash = root_obj[kHandleKey].GetInt64();
142 DartCallbackRepresentation cb;
143 cb.name = representation[kNameKey].GetString();
144 cb.class_name = representation[kClassNameKey].GetString();
145 cb.library_path = representation[kLibraryPathKey].GetString();
146 cache_[hash] = cb;
147 }
148}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
static const char * kHandleKey
static const char * kLibraryPathKey
static const char * kClassNameKey
static const char * kNameKey
static const char * kRepresentationKey

◆ SetCachePath()

void flutter::DartCallbackCache::SetCachePath ( const std::string &  path)
static

Definition at line 35 of file callback_cache.cc.

35 {
36 cache_path_ = fml::paths::JoinPaths({path, kCacheName});
37}
static const char * kCacheName
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
std::string JoinPaths(std::initializer_list< std::string > components)
Definition: paths.cc:14

The documentation for this class was generated from the following files: