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 5#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h" 6 7@implementation FlutterCallbackInformation 8@end 9 10@implementation FlutterCallbackCache 11 12+ (FlutterCallbackInformation*)lookupCallbackInformation:(int64_t)handle { 13 auto info = flutter::DartCallbackCache::GetCallbackInformation(handle); 14 if (info == nullptr) { 15 return nil; 16 } 17 FlutterCallbackInformation* new_info = [[FlutterCallbackInformation alloc] init]; 18 new_info.callbackName = [NSString stringWithUTF8String:info->name.c_str()]; 19 new_info.callbackClassName = [NSString stringWithUTF8String:info->class_name.c_str()]; 20 new_info.callbackLibraryPath = [NSString stringWithUTF8String:info->library_path.c_str()]; 21 return new_info; 22} 23 24+ (void)setCachePath:(NSString*)path { 25 assert(path != nil); 26 flutter::DartCallbackCache::SetCachePath([path UTF8String]); 27 NSString* cache_path = 28 [NSString stringWithUTF8String:flutter::DartCallbackCache::GetCachePath().c_str()]; 29 // Set the "Do Not Backup" flag to ensure that the cache isn't moved off disk in 30 // low-memory situations. 31 if (![[NSFileManager defaultManager] fileExistsAtPath:cache_path]) { 32 [[NSFileManager defaultManager] createFileAtPath:cache_path contents:nil attributes:nil]; 33 NSError* error = nil; 34 NSURL* URL = [NSURL fileURLWithPath:cache_path]; 35 BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES] 36 forKey:NSURLIsExcludedFromBackupKey 37 error:&error]; 38 if (!success) { 39 NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); 40 } 41 } 42} 43 44@end 45