Flutter iOS Embedder
FlutterCallbackCache.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include "flutter/fml/logging.h"
8 #include "flutter/lib/ui/plugins/callback_cache.h"
9 
10 @implementation FlutterCallbackInformation
11 
12 - (void)dealloc {
13  [_callbackName release];
14  [_callbackClassName release];
15  [_callbackLibraryPath release];
16  [super dealloc];
17 }
18 
19 @end
20 
21 @implementation FlutterCallbackCache
22 
23 + (FlutterCallbackInformation*)lookupCallbackInformation:(int64_t)handle {
24  auto info = flutter::DartCallbackCache::GetCallbackInformation(handle);
25  if (info == nullptr) {
26  return nil;
27  }
28  FlutterCallbackInformation* new_info = [[[FlutterCallbackInformation alloc] init] autorelease];
29  new_info.callbackName = [NSString stringWithUTF8String:info->name.c_str()];
30  new_info.callbackClassName = [NSString stringWithUTF8String:info->class_name.c_str()];
31  new_info.callbackLibraryPath = [NSString stringWithUTF8String:info->library_path.c_str()];
32  return new_info;
33 }
34 
35 + (void)setCachePath:(NSString*)path {
36  FML_DCHECK(path != nil);
37  flutter::DartCallbackCache::SetCachePath([path UTF8String]);
38  NSString* cache_path =
39  [NSString stringWithUTF8String:flutter::DartCallbackCache::GetCachePath().c_str()];
40  // Set the "Do Not Backup" flag to ensure that the cache isn't moved off disk in
41  // low-memory situations.
42  if (![[NSFileManager defaultManager] fileExistsAtPath:cache_path]) {
43  [[NSFileManager defaultManager] createFileAtPath:cache_path contents:nil attributes:nil];
44  NSError* error = nil;
45  NSURL* URL = [NSURL fileURLWithPath:cache_path];
46  BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES]
47  forKey:NSURLIsExcludedFromBackupKey
48  error:&error];
49  if (!success) {
50  NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
51  }
52  }
53 }
54 
55 @end
FlutterCallbackInformation::callbackLibraryPath
NSString * callbackLibraryPath
Definition: FlutterCallbackCache.h:29
FlutterCallbackCache
Definition: FlutterCallbackCache.h:37
FlutterCallbackCache_Internal.h
FlutterCallbackInformation::callbackName
NSString * callbackName
Definition: FlutterCallbackCache.h:21
FlutterCallbackInformation::callbackClassName
NSString * callbackClassName
Definition: FlutterCallbackCache.h:25
FlutterCallbackInformation
Definition: FlutterCallbackCache.h:17